use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangAction actionNode) {
BInvokableSymbol actionSymbol = Symbols.createActionSymbol(Flags.asMask(actionNode.flagSet), names.fromIdNode(actionNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
SymbolEnv invokableEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, env);
defineInvokableSymbol(actionNode, actionSymbol, invokableEnv);
actionNode.endpoints.forEach(ep -> defineNode(ep, invokableEnv));
// TODO check below as it create a new symbol for the connector
BVarSymbol varSymbol = new BVarSymbol(Flags.asMask(EnumSet.noneOf(Flag.class)), names.fromIdNode((BLangIdentifier) createIdentifier(Names.CONNECTOR.getValue())), env.enclPkg.symbol.pkgID, actionSymbol.owner.type, invokableEnv.scope.owner);
actionSymbol.receiverSymbol = varSymbol;
((BInvokableType) actionSymbol.type).setReceiverType(varSymbol.type);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv 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);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolEnter method validateFunctionsAttachedToObject.
private void validateFunctionsAttachedToObject(BLangFunction funcNode, BInvokableSymbol funcSymbol, SymbolEnv invokableEnv) {
BInvokableType funcType = (BInvokableType) funcSymbol.type;
BStructSymbol objectSymbol = (BStructSymbol) funcNode.receiver.type.tsymbol;
BSymbol symbol = symResolver.lookupMemberSymbol(funcNode.receiver.pos, objectSymbol.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;
}
BAttachedFunction attachedFunc = new BAttachedFunction(names.fromIdNode(funcNode.name), funcSymbol, funcType);
objectSymbol.attachedFuncs.add(attachedFunc);
// Check whether this attached function is a object initializer.
if (!Names.OBJECT_INIT_SUFFIX.value.equals(funcNode.name.value)) {
// Not a object initializer.
return;
}
if (!funcNode.retParams.isEmpty()) {
// TODO change message
dlog.error(funcNode.pos, DiagnosticCode.INVALID_STRUCT_INITIALIZER_FUNCTION, funcNode.name.value, funcNode.receiver.type.toString());
}
objectSymbol.initializerFunc = attachedFunc;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SymbolResolver method addNamespacesInScope.
private void addNamespacesInScope(Map<Name, BXMLNSSymbol> namespaces, SymbolEnv env) {
if (env == null) {
return;
}
env.scope.entries.forEach((name, scopeEntry) -> {
if (scopeEntry.symbol.kind == SymbolKind.XMLNS) {
BXMLNSSymbol nsSymbol = (BXMLNSSymbol) scopeEntry.symbol;
// Skip if the namespace is already added, by a child scope. That means it has been overridden.
if (!namespaces.containsKey(name)) {
namespaces.put(name, nsSymbol);
}
}
});
addNamespacesInScope(namespaces, env.enclEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class TaintAnalyzer method analyzeNode.
// Private
private <T extends BLangNode, U extends SymbolEnv> void analyzeNode(T t, U u) {
SymbolEnv prevEnv = this.env;
this.env = u;
t.accept(this);
this.env = prevEnv;
}
Aggregations