use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method defineConnectorInitFunction.
private void defineConnectorInitFunction(BLangConnector connector, SymbolEnv conEnv) {
BLangFunction initFunction = createInitFunction(connector.pos, connector.getName().getValue(), Names.INIT_FUNCTION_SUFFIX);
// Add connector as a parameter to the init function
BLangVariable param = (BLangVariable) TreeBuilder.createVariableNode();
param.pos = connector.pos;
param.setName(this.createIdentifier(Names.CONNECTOR.getValue()));
BLangUserDefinedType connectorType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
connectorType.pos = connector.pos;
connectorType.typeName = connector.name;
connectorType.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
param.setTypeNode(connectorType);
initFunction.addParameter(param);
// Add connector level variables to the init function
connector.varDefs.stream().filter(f -> f.var.expr != null).forEachOrdered(v -> initFunction.body.addStatement(createAssignmentStmt(v.var)));
addInitReturnStatement(initFunction.body);
connector.initFunction = initFunction;
BLangAction initAction = createNativeInitAction(connector.pos);
connector.initAction = initAction;
defineNode(connector.initFunction, conEnv);
defineNode(connector.initAction, conEnv);
connector.symbol.initFunctionSymbol = connector.initFunction.symbol;
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangVariable varNode) {
// this is a field variable defined for object init function
if (varNode.isField) {
Name varName = names.fromIdNode(varNode.name);
BVarSymbol fieldVar = (BVarSymbol) symResolver.resolveObjectField(varNode.pos, env, varName, env.enclObject.symbol.type.tsymbol);
varNode.type = fieldVar.type;
varName = getFieldSymbolName(((BLangFunction) env.enclInvokable).receiver, varNode);
BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
env.enclObject.initFunction.initFunctionStmts.put(fieldVar, (BLangStatement) createAssignmentStmt(varNode, varSymbol, fieldVar));
varSymbol.docTag = varNode.docTag;
varNode.symbol = varSymbol;
return;
}
// assign the type to var type node
if (varNode.type == null) {
varNode.type = symResolver.resolveTypeNode(varNode.typeNode, env);
}
Name varName = names.fromIdNode(varNode.name);
if (varName == Names.EMPTY || varName == Names.IGNORE) {
// e.g. function foo() (int);
return;
}
BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
varSymbol.docTag = varNode.docTag;
varNode.symbol = varSymbol;
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method definePackageInitFunctions.
private void definePackageInitFunctions(BLangPackage pkgNode, SymbolEnv env) {
BLangFunction initFunction = pkgNode.initFunction;
// Add package level namespace declarations to the init function
pkgNode.xmlnsList.forEach(xmlns -> {
initFunction.body.addStatement(createNamespaceDeclrStatement(xmlns));
});
// Add global variables to the init function
pkgNode.globalVars.stream().filter(f -> f.expr != null).forEachOrdered(v -> initFunction.body.addStatement(createAssignmentStmt(v)));
addInitReturnStatement(initFunction.body);
defineNode(pkgNode.initFunction, env);
pkgNode.symbol.initFunctionSymbol = pkgNode.initFunction.symbol;
addInitReturnStatement(pkgNode.startFunction.body);
defineNode(pkgNode.startFunction, env);
pkgNode.symbol.startFunctionSymbol = pkgNode.startFunction.symbol;
addInitReturnStatement(pkgNode.stopFunction.body);
defineNode(pkgNode.stopFunction, env);
pkgNode.symbol.stopFunctionSymbol = pkgNode.stopFunction.symbol;
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangFunction funcNode) {
boolean validAttachedFunc = validateFuncReceiver(funcNode);
BInvokableSymbol funcSymbol = Symbols.createFunctionSymbol(Flags.asMask(funcNode.flagSet), getFuncSymbolName(funcNode), env.enclPkg.symbol.pkgID, null, env.scope.owner);
SymbolEnv invokableEnv = SymbolEnv.createFunctionEnv(funcNode, funcSymbol.scope, env);
defineInvokableSymbol(funcNode, funcSymbol, invokableEnv);
// Define function receiver if any.
if (funcNode.receiver != null) {
defineAttachedFunctions(funcNode, funcSymbol, invokableEnv, validAttachedFunc);
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method defineServiceInitFunction.
private void defineServiceInitFunction(BLangService service, SymbolEnv conEnv) {
BLangFunction initFunction = createInitFunction(service.pos, service.getName().getValue(), Names.INIT_FUNCTION_SUFFIX);
// Add service level variables to the init function
service.vars.stream().filter(f -> f.var.expr != null).forEachOrdered(v -> initFunction.body.addStatement(createAssignmentStmt(v.var)));
addInitReturnStatement(initFunction.body);
service.initFunction = initFunction;
defineNode(service.initFunction, conEnv);
// service.symbol.initFunctionSymbol = service.initFunction.symbol;
}
Aggregations