use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method visit.
@Override
public void visit(BLangAction actionNode) {
BSymbol actionSymbol = actionNode.symbol;
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, symbolEnv);
actionNode.workers.forEach(w -> this.acceptNode(w, actionEnv));
this.blockOwnerStack.push(actionNode);
acceptNode(actionNode.body, actionEnv);
this.blockOwnerStack.pop();
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangTransformer transformerNode) {
validateTransformerMappingTypes(transformerNode);
boolean safeConversion = transformerNode.retParams.size() == 1;
Name name = getTransformerSymbolName(transformerNode);
BTransformerSymbol transformerSymbol = Symbols.createTransformerSymbol(Flags.asMask(transformerNode.flagSet), name, env.enclPkg.symbol.pkgID, null, safeConversion, env.scope.owner);
transformerNode.symbol = transformerSymbol;
// If this is a default transformer, check whether this transformer conflicts with a built-in conversion
if (transformerNode.name.value.isEmpty()) {
BType targetType = transformerNode.retParams.get(0).type;
BSymbol symbol = symResolver.resolveConversionOperator(transformerNode.source.type, targetType);
if (symbol != symTable.notFoundSymbol) {
dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_CONFLICTS_WITH_CONVERSION, transformerNode.source.type, targetType);
return;
}
}
// Define the transformer
SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerSymbol.scope, env);
transformerNode.symbol = transformerSymbol;
defineSymbol(transformerNode.pos, transformerSymbol);
transformerEnv.scope = transformerSymbol.scope;
// Define transformer source.
defineNode(transformerNode.source, transformerEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method validateFunctionsAttachedToStructs.
private void validateFunctionsAttachedToStructs(BLangFunction funcNode, BInvokableSymbol funcSymbol, SymbolEnv invokableEnv) {
BInvokableType funcType = (BInvokableType) funcSymbol.type;
BStructSymbol structSymbol = (BStructSymbol) funcNode.receiver.type.tsymbol;
BSymbol symbol = symResolver.lookupMemberSymbol(funcNode.receiver.pos, structSymbol.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;
}
BStructType structType = (BStructType) funcNode.receiver.type;
BAttachedFunction attachedFunc = new BAttachedFunction(names.fromIdNode(funcNode.name), funcSymbol, funcType);
structSymbol.attachedFuncs.add(attachedFunc);
if (funcNode.name.value.equals(structType.tsymbol.name.value + Names.INIT_FUNCTION_SUFFIX.value)) {
structSymbol.defaultsValuesInitFunc = attachedFunc;
return;
}
// Check whether this attached function is a struct initializer.
if (!structType.tsymbol.name.value.equals(funcNode.name.value)) {
// Not a struct initializer.
return;
}
if (!funcNode.requiredParams.isEmpty() || !funcNode.retParams.isEmpty()) {
dlog.error(funcNode.pos, DiagnosticCode.INVALID_STRUCT_INITIALIZER_FUNCTION, funcNode.name.value, funcNode.receiver.type.toString());
}
structSymbol.initializerFunc = attachedFunc;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangXMLNS xmlnsNode) {
String nsURI = (String) ((BLangLiteral) xmlnsNode.namespaceURI).value;
if (xmlnsNode.prefix.value != null && nsURI.isEmpty()) {
dlog.error(xmlnsNode.pos, DiagnosticCode.INVALID_NAMESPACE_DECLARATION, xmlnsNode.prefix);
}
// set the prefix of the default namespace
if (xmlnsNode.prefix.value == null) {
xmlnsNode.prefix.value = XMLConstants.DEFAULT_NS_PREFIX;
}
BXMLNSSymbol xmlnsSymbol = Symbols.createXMLNSSymbol(names.fromIdNode(xmlnsNode.prefix), nsURI, env.enclPkg.symbol.pkgID, env.scope.owner);
xmlnsNode.symbol = xmlnsSymbol;
// First check for package-imports with the same alias.
// Here we do not check for owner equality, since package import is always at the package
// level, but the namespace declaration can be at any level.
BSymbol foundSym = symResolver.lookupSymbol(env, xmlnsSymbol.name, SymTag.PACKAGE);
if (foundSym != symTable.notFoundSymbol) {
dlog.error(xmlnsNode.pos, DiagnosticCode.REDECLARED_SYMBOL, xmlnsSymbol.name);
return;
}
// Define it in the enclosing scope. Here we check for the owner equality,
// to support overriding of namespace declarations defined at package level.
defineSymbol(xmlnsNode.pos, xmlnsSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol 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;
}
Aggregations