use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangResource resourceNode) {
BInvokableSymbol resourceSymbol = Symbols.createResourceSymbol(Flags.asMask(resourceNode.flagSet), names.fromIdNode(resourceNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
SymbolEnv invokableEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, env);
if (!resourceNode.getParameters().isEmpty() && resourceNode.getParameters().get(0) != null && resourceNode.getParameters().get(0).typeNode == null) {
// This is endpoint variable. Setting temporary type for now till we find actual type at semantic phase.
resourceNode.getParameters().get(0).type = symTable.endpointType;
}
defineInvokableSymbol(resourceNode, resourceSymbol, invokableEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineInvokableSymbolParams.
private void defineInvokableSymbolParams(BLangInvokableNode invokableNode, BInvokableSymbol symbol, SymbolEnv invokableEnv) {
List<BVarSymbol> paramSymbols = invokableNode.requiredParams.stream().peek(varNode -> defineNode(varNode, invokableEnv)).map(varNode -> varNode.symbol).collect(Collectors.toList());
List<BVarSymbol> namedParamSymbols = invokableNode.defaultableParams.stream().peek(varDefNode -> defineNode(varDefNode.var, invokableEnv)).map(varDefNode -> varDefNode.var.symbol).collect(Collectors.toList());
List<BVarSymbol> retParamSymbols = invokableNode.retParams.stream().peek(varNode -> defineNode(varNode, invokableEnv)).filter(varNode -> varNode.symbol != null).map(varNode -> varNode.symbol).collect(Collectors.toList());
symbol.params = paramSymbols;
symbol.retParams = retParamSymbols;
symbol.defaultableParams = namedParamSymbols;
// Create function type
List<BType> paramTypes = paramSymbols.stream().map(paramSym -> paramSym.type).collect(Collectors.toList());
namedParamSymbols.forEach(paramSymbol -> paramTypes.add(paramSymbol.type));
if (invokableNode.restParam != null) {
defineNode(invokableNode.restParam, invokableEnv);
symbol.restParam = invokableNode.restParam.symbol;
paramTypes.add(symbol.restParam.type);
}
List<BType> retTypes = invokableNode.retParams.stream().map(varNode -> varNode.type != null ? varNode.type : varNode.typeNode.type).collect(Collectors.toList());
symbol.type = new BInvokableType(paramTypes, retTypes, null);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineObjectInitFunction.
private void defineObjectInitFunction(BLangObject object, SymbolEnv conEnv) {
BLangFunction initFunction = object.initFunction;
if (initFunction == null) {
initFunction = createInitFunction(object.pos, "", Names.OBJECT_INIT_SUFFIX);
}
initFunction.attachedFunction = true;
// Set cached receiver to the init function
initFunction.receiver = object.receiver;
initFunction.flagSet.add(Flag.ATTACHED);
// Add object level variables to the init function
BLangFunction finalInitFunction = initFunction;
object.fields.stream().filter(f -> f.expr != null).forEachOrdered(v -> finalInitFunction.initFunctionStmts.put(v.symbol, (BLangStatement) createAssignmentStmt(v)));
object.initFunction = initFunction;
defineNode(object.initFunction, conEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineEndpointVarSymbol.
public BEndpointVarSymbol defineEndpointVarSymbol(DiagnosticPos pos, Set<Flag> flagSet, BType varType, Name varName, SymbolEnv env) {
// Create variable symbol
Scope enclScope = env.scope;
BEndpointVarSymbol varSymbol = new BEndpointVarSymbol(Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
// Find duplicates
if (!symResolver.checkForUniqueSymbol(pos, env, varSymbol, SymTag.VARIABLE_NAME)) {
varSymbol.type = symTable.errType;
}
enclScope.define(varSymbol.name, varSymbol);
return varSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method defineConnectorSymbolParams.
private void defineConnectorSymbolParams(BLangConnector connectorNode, BConnectorSymbol symbol, SymbolEnv connectorEnv) {
List<BVarSymbol> paramSymbols = connectorNode.params.stream().peek(varNode -> defineNode(varNode, connectorEnv)).map(varNode -> varNode.symbol).collect(Collectors.toList());
symbol.params = paramSymbols;
// Create connector type
List<BType> paramTypes = paramSymbols.stream().map(paramSym -> paramSym.type).collect(Collectors.toList());
symbol.type = new BConnectorType(paramTypes, symbol);
}
Aggregations