use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangXMLNS xmlnsNode) {
BLangXMLNS generatedXMLNSNode;
xmlnsNode.namespaceURI = rewriteExpr(xmlnsNode.namespaceURI);
BSymbol ownerSymbol = xmlnsNode.symbol.owner;
// Local namespace declaration in a function/resource/action/worker
if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
generatedXMLNSNode = new BLangLocalXMLNS();
} else {
generatedXMLNSNode = new BLangPackageXMLNS();
}
generatedXMLNSNode.namespaceURI = xmlnsNode.namespaceURI;
generatedXMLNSNode.prefix = xmlnsNode.prefix;
generatedXMLNSNode.symbol = xmlnsNode.symbol;
result = generatedXMLNSNode;
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangSimpleVarRef varRefExpr) {
BLangSimpleVarRef genVarRefExpr = varRefExpr;
// XML qualified name reference. e.g: ns0:foo
if (varRefExpr.pkgSymbol != null && varRefExpr.pkgSymbol.tag == SymTag.XMLNS) {
BLangXMLQName qnameExpr = new BLangXMLQName(varRefExpr.variableName);
qnameExpr.nsSymbol = (BXMLNSSymbol) varRefExpr.pkgSymbol;
qnameExpr.localname = varRefExpr.variableName;
qnameExpr.prefix = varRefExpr.pkgAlias;
qnameExpr.namespaceURI = qnameExpr.nsSymbol.namespaceURI;
qnameExpr.isUsedInXML = false;
qnameExpr.pos = varRefExpr.pos;
qnameExpr.type = symTable.stringType;
result = qnameExpr;
return;
}
BSymbol ownerSymbol = varRefExpr.symbol.owner;
if ((varRefExpr.symbol.tag & SymTag.FUNCTION) == SymTag.FUNCTION && varRefExpr.symbol.type.tag == TypeTags.INVOKABLE) {
genVarRefExpr = new BLangFunctionVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
// Local variable in a function/resource/action/worker
genVarRefExpr = new BLangLocalVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
// Field variable in a receiver
genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.STRUCT) == SymTag.STRUCT) {
genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymbol.tag & SymTag.SERVICE) == SymTag.SERVICE) {
// Package variable | service variable
// We consider both of them as package level variables
genVarRefExpr = new BLangPackageVarRef(varRefExpr.symbol);
// Only locking service level and package level variables
if (!enclLocks.isEmpty()) {
enclLocks.peek().addLockVariable(varRefExpr.symbol);
}
}
genVarRefExpr.type = varRefExpr.type;
result = genVarRefExpr;
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointInit.
private BLangBlockStmt generateEndpointInit(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol) {
final String epName = endpoint.name.value;
final DiagnosticPos pos = endpoint.pos;
BLangBlockStmt temp = new BLangBlockStmt();
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
final BLangExpression newExpr;
if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
// Handle Endpoint Assignment.
newExpr = endpoint.configurationExpr;
} else if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
// Handle Endpoint initialization.
newExpr = ASTBuilderUtil.createEmptyRecordLiteral(pos, endpoint.symbol.type);
} else {
newExpr = null;
}
// EPType ep_name = {};
if (env.enclInvokable != null) {
// In callable unit, endpoint is same scope variable.
final BLangVariableDef epNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
epNewStmt.var = epVariable;
epNewStmt.var.expr = newExpr;
} else {
// This is an init function. ep variable is defined in outside.
if (env.enclService != null) {
// Add to endpoint variable to relevant location
final BLangVariableDef epVarDef = ASTBuilderUtil.createVariableDef(pos);
epVarDef.var = epVariable;
env.enclService.vars.add(epVarDef);
}
final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(pos, temp);
assignmentStmt.varRefs.add(ASTBuilderUtil.createVariableRef(pos, epVariable.symbol));
assignmentStmt.expr = newExpr;
}
return temp;
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endTypeDefinition.
public void endTypeDefinition(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicStruct) {
// TODO only adding object type for now
if (!this.objectStack.isEmpty()) {
BLangObject objectNode = (BLangObject) this.objectStack.pop();
objectNode.pos = pos;
objectNode.setName(this.createIdentifier(identifier));
if (publicStruct) {
objectNode.flagSet.add(Flag.PUBLIC);
}
objectNode.isAnonymous = false;
// Create an user defined type with object type
TypeNode objectType = createUserDefinedType(pos, ws, (BLangIdentifier) TreeBuilder.createIdentifierNode(), objectNode.name);
// Create and add receiver to attached functions
BLangVariable receiver = (BLangVariable) TreeBuilder.createVariableNode();
receiver.pos = pos;
IdentifierNode name = createIdentifier(Names.SELF.getValue());
receiver.setName(name);
receiver.addWS(ws);
receiver.docTag = DocTag.RECEIVER;
receiver.setTypeNode(objectType);
// Cache receiver to add to init function in symbolEnter
objectNode.receiver = receiver;
objectNode.functions.forEach(f -> f.setReceiver(receiver));
this.compUnit.addTopLevelNode(objectNode);
}
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addFunctionType.
public void addFunctionType(DiagnosticPos pos, Set<Whitespace> ws, boolean paramsAvail, boolean paramsTypeOnly, boolean retParamsAvail) {
// TODO : Fix function main ()(boolean , function(string x)(float, int)){} issue
BLangFunctionTypeNode functionTypeNode = (BLangFunctionTypeNode) TreeBuilder.createFunctionTypeNode();
functionTypeNode.pos = pos;
functionTypeNode.returnsKeywordExists = true;
if (retParamsAvail) {
// functionTypeNode.addWS(commaWsStack.pop());
functionTypeNode.returnParamTypeNodes.add(this.varStack.pop().getTypeNode());
}
if (paramsAvail) {
functionTypeNode.addWS(commaWsStack.pop());
this.varListStack.pop().forEach(v -> functionTypeNode.paramTypeNodes.add(v.getTypeNode()));
}
functionTypeNode.addWS(ws);
addType(functionTypeNode);
}
Aggregations