use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SymbolResolver method getBinaryOpForNullChecks.
private BSymbol getBinaryOpForNullChecks(OperatorKind opKind, BType lhsType, BType rhsType) {
if (opKind != OperatorKind.EQUAL && opKind != OperatorKind.NOT_EQUAL) {
return symTable.notFoundSymbol;
}
int opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ_NULL : InstructionCodes.RNE_NULL;
if (lhsType.tag == TypeTags.NULL && (rhsType.tag == TypeTags.STRUCT || rhsType.tag == TypeTags.CONNECTOR || rhsType.tag == TypeTags.ENUM || rhsType.tag == TypeTags.INVOKABLE)) {
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
if ((lhsType.tag == TypeTags.STRUCT || lhsType.tag == TypeTags.CONNECTOR || lhsType.tag == TypeTags.ENUM || lhsType.tag == TypeTags.INVOKABLE) && rhsType.tag == TypeTags.NULL) {
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
if (lhsType.tag == TypeTags.ENUM && rhsType.tag == TypeTags.ENUM && lhsType == rhsType) {
opcode = (opKind == OperatorKind.EQUAL) ? InstructionCodes.REQ : InstructionCodes.RNE;
List<BType> paramTypes = Lists.of(lhsType, rhsType);
List<BType> retTypes = Lists.of(symTable.booleanType);
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
return new BOperatorSymbol(names.fromString(opKind.value()), null, opType, null, opcode);
}
return symTable.notFoundSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SymbolResolver method visit.
public void visit(BLangUserDefinedType userDefinedTypeNode) {
// 1) Resolve the package scope using the package alias.
// If the package alias is not empty or null, then find the package scope,
// if not use the current package scope.
// 2) lookup the typename in the package scope returned from step 1.
// 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error'
BSymbol pkgSymbol = resolvePkgSymbol(userDefinedTypeNode.pos, this.env, names.fromIdNode(userDefinedTypeNode.pkgAlias));
if (pkgSymbol == symTable.notFoundSymbol) {
resultType = symTable.errType;
return;
}
Name typeName = names.fromIdNode(userDefinedTypeNode.typeName);
BSymbol symbol = symTable.notFoundSymbol;
// Only valued types and ANNOTATION type allowed.
if (env.scope.owner.tag == SymTag.ANNOTATION) {
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.ANNOTATION);
}
// 3) Lookup the current package scope.
if (symbol == symTable.notFoundSymbol) {
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.VARIABLE_NAME);
}
if (symbol == symTable.notFoundSymbol) {
// 4) Lookup the root scope for types such as 'error'
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, symTable.rootScope, this.env, typeName, SymTag.VARIABLE_NAME);
}
if (symbol == symTable.notFoundSymbol) {
dlog.error(userDefinedTypeNode.pos, diagCode, typeName);
resultType = symTable.errType;
return;
}
if (symbol.kind == SymbolKind.CONNECTOR) {
userDefinedTypeNode.flagSet = EnumSet.of(Flag.CONNECTOR);
}
resultType = symbol.type;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SymbolResolver method resolveOperator.
private BSymbol resolveOperator(ScopeEntry entry, List<BType> types) {
BSymbol foundSymbol = symTable.notFoundSymbol;
while (entry != NOT_FOUND_ENTRY) {
BInvokableType opType = (BInvokableType) entry.symbol.type;
if (types.size() == opType.paramTypes.size()) {
boolean match = true;
for (int i = 0; i < types.size(); i++) {
if (types.get(i).tag != opType.paramTypes.get(i).tag) {
match = false;
}
}
if (match) {
foundSymbol = entry.symbol;
break;
}
}
entry = entry.next;
}
return foundSymbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangConnector connectorNode) {
BSymbol connectorSymbol = connectorNode.symbol;
SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, env);
attachTaintTableBasedOnAnnotations(connectorNode);
connectorNode.varDefs.forEach(var -> var.accept(this));
analyzeNode(connectorNode.initFunction, connectorEnv);
analyzeNode(connectorNode.initAction, connectorEnv);
connectorNode.actions.forEach(action -> analyzeNode(action, connectorEnv));
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class CodeAnalyzer method visit.
public void visit(BLangInvocation invocationExpr) {
analyzeExpr(invocationExpr.expr);
analyzeExprs(invocationExpr.requiredArgs);
analyzeExprs(invocationExpr.namedArgs);
analyzeExprs(invocationExpr.restArgs);
checkDuplicateNamedArgs(invocationExpr.namedArgs);
// Null check is to ignore Negative path where symbol does not get resolved at TypeChecker.
if ((invocationExpr.symbol != null) && invocationExpr.symbol.kind == SymbolKind.FUNCTION) {
BSymbol funcSymbol = invocationExpr.symbol;
if (Symbols.isFlagOn(funcSymbol.flags, Flags.DEPRECATED)) {
dlog.warning(invocationExpr.pos, DiagnosticCode.USAGE_OF_DEPRECATED_FUNCTION, names.fromIdNode(invocationExpr.name));
}
}
}
Aggregations