use of org.wso2.carbon.apimgt.core.models.Function 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);
}
use of org.wso2.carbon.apimgt.core.models.Function 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.carbon.apimgt.core.models.Function 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.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class SymbolEnter method createInitFunction.
private BLangFunction createInitFunction(DiagnosticPos pos, String name, Name sufix) {
BLangFunction initFunction = (BLangFunction) TreeBuilder.createFunctionNode();
initFunction.setName(createIdentifier(name + sufix.getValue()));
initFunction.flagSet = EnumSet.of(Flag.PUBLIC);
initFunction.pos = pos;
// Create body of the init function
BLangBlockStmt body = (BLangBlockStmt) TreeBuilder.createBlockNode();
body.pos = pos;
initFunction.setBody(body);
return initFunction;
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class SymbolEnter method defineAttachedFunctions.
private void defineAttachedFunctions(BLangFunction funcNode, BInvokableSymbol funcSymbol, SymbolEnv invokableEnv, boolean isValidAttachedFunc) {
BInvokableType funcType = (BInvokableType) funcSymbol.type;
BTypeSymbol typeSymbol = funcNode.receiver.type.tsymbol;
// Check whether there exists a struct field with the same name as the function name.
if (isValidAttachedFunc) {
if (typeSymbol.tag == SymTag.STRUCT) {
validateFunctionsAttachedToStructs(funcNode, funcSymbol, invokableEnv);
} else if (typeSymbol.tag == SymTag.OBJECT) {
validateFunctionsAttachedToObject(funcNode, funcSymbol, invokableEnv);
}
}
defineNode(funcNode.receiver, invokableEnv);
funcSymbol.receiverSymbol = funcNode.receiver.symbol;
funcType.setReceiverType(funcNode.receiver.symbol.type);
}
Aggregations