use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineObjectMembers.
private void defineObjectMembers(List<? extends BLangObject> objects, SymbolEnv pkgEnv) {
objects.forEach(obj -> {
SymbolEnv objEnv = SymbolEnv.createObjectEnv(obj, obj.symbol.scope, pkgEnv);
defineObjectInitFunction(obj, objEnv);
obj.functions.forEach(f -> defineNode(f, objEnv));
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineObjectFields.
private void defineObjectFields(List<? extends BLangObject> objectNodes, SymbolEnv pkgEnv) {
objectNodes.forEach(object -> {
// Create object type
SymbolEnv objectEnv = SymbolEnv.createObjectEnv(object, object.symbol.scope, pkgEnv);
BStructType objectType = (BStructType) object.symbol.type;
objectType.fields = object.fields.stream().peek(field -> defineNode(field, objectEnv)).map(field -> new BStructField(names.fromIdNode(field.name), field.symbol)).collect(Collectors.toList());
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method validateFunctionsAttachedToStructs.
private void validateFunctionsAttachedToStructs(BLangFunction funcNode, BInvokableSymbol funcSymbol, SymbolEnv invokableEnv) {
BInvokableType funcType = (BInvokableType) funcSymbol.type;
BStructSymbol structSymbol = (BStructSymbol) funcNode.receiver.type.tsymbol;
BSymbol symbol = symResolver.lookupMemberSymbol(funcNode.receiver.pos, structSymbol.scope, invokableEnv, names.fromIdNode(funcNode.name), SymTag.VARIABLE);
if (symbol != symTable.notFoundSymbol) {
dlog.error(funcNode.pos, DiagnosticCode.STRUCT_FIELD_AND_FUNC_WITH_SAME_NAME, funcNode.name.value, funcNode.receiver.type.toString());
return;
}
BStructType structType = (BStructType) funcNode.receiver.type;
BAttachedFunction attachedFunc = new BAttachedFunction(names.fromIdNode(funcNode.name), funcSymbol, funcType);
structSymbol.attachedFuncs.add(attachedFunc);
if (funcNode.name.value.equals(structType.tsymbol.name.value + Names.INIT_FUNCTION_SUFFIX.value)) {
structSymbol.defaultsValuesInitFunc = attachedFunc;
return;
}
// Check whether this attached function is a struct initializer.
if (!structType.tsymbol.name.value.equals(funcNode.name.value)) {
// Not a struct initializer.
return;
}
if (!funcNode.requiredParams.isEmpty() || !funcNode.retParams.isEmpty()) {
dlog.error(funcNode.pos, DiagnosticCode.INVALID_STRUCT_INITIALIZER_FUNCTION, funcNode.name.value, funcNode.receiver.type.toString());
}
structSymbol.initializerFunc = attachedFunc;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineConnectorParams.
private void defineConnectorParams(List<BLangConnector> connectors, SymbolEnv pkgEnv) {
connectors.forEach(connector -> {
SymbolEnv conEnv = SymbolEnv.createConnectorEnv(connector, connector.symbol.scope, pkgEnv);
defineConnectorSymbolParams(connector, connector.symbol, conEnv);
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
// Visitor methods
@Override
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.DEFINE)) {
return;
}
// Create PackageSymbol.
BPackageSymbol pSymbol = createPackageSymbol(pkgNode);
SymbolEnv builtinEnv = this.symTable.pkgEnvMap.get(symTable.builtInPackageSymbol);
SymbolEnv pkgEnv = SymbolEnv.createPkgEnv(pkgNode, pSymbol.scope, builtinEnv);
this.symTable.pkgEnvMap.put(pSymbol, pkgEnv);
createPackageInitFunctions(pkgNode);
// visit the package node recursively and define all package level symbols.
// And maintain a list of created package symbols.
pkgNode.imports.forEach(importNode -> defineNode(importNode, pkgEnv));
// Define struct nodes.
pkgNode.enums.forEach(enumNode -> defineNode(enumNode, pkgEnv));
// Define struct nodes.
pkgNode.structs.forEach(struct -> defineNode(struct, pkgEnv));
// Define object nodes
pkgNode.objects.forEach(object -> defineNode(object, pkgEnv));
// Define connector nodes.
pkgNode.connectors.forEach(con -> defineNode(con, pkgEnv));
// Define connector params and type.
defineConnectorParams(pkgNode.connectors, pkgEnv);
// Define transformer nodes.
pkgNode.transformers.forEach(tansformer -> defineNode(tansformer, pkgEnv));
// Define service and resource nodes.
pkgNode.services.forEach(service -> defineNode(service, pkgEnv));
// Define struct field nodes.
defineStructFields(pkgNode.structs, pkgEnv);
// Define object field nodes.
defineObjectFields(pkgNode.objects, pkgEnv);
// Define connector action nodes.
defineConnectorMembers(pkgNode.connectors, pkgEnv);
// Define object functions
defineObjectMembers(pkgNode.objects, pkgEnv);
// Define function nodes.
pkgNode.functions.forEach(func -> defineNode(func, pkgEnv));
// Define transformer params
defineTransformerMembers(pkgNode.transformers, pkgEnv);
// Define service resource nodes.
defineServiceMembers(pkgNode.services, pkgEnv);
// Define annotation nodes.
pkgNode.annotations.forEach(annot -> defineNode(annot, pkgEnv));
resolveAnnotationAttributeTypes(pkgNode.annotations, pkgEnv);
pkgNode.globalVars.forEach(var -> defineNode(var, pkgEnv));
pkgNode.globalEndpoints.forEach(ep -> defineNode(ep, pkgEnv));
definePackageInitFunctions(pkgNode, pkgEnv);
pkgNode.completedPhases.add(CompilerPhase.DEFINE);
}
Aggregations