use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangSimpleVarRef varRefExpr) {
// Set error type as the actual type.
BType actualType = symTable.errType;
Name varName = names.fromIdNode(varRefExpr.variableName);
if (varName == Names.IGNORE) {
if (varRefExpr.lhsVar) {
varRefExpr.type = this.symTable.noType;
} else {
varRefExpr.type = this.symTable.errType;
dlog.error(varRefExpr.pos, DiagnosticCode.UNDERSCORE_NOT_ALLOWED);
}
varRefExpr.symbol = new BVarSymbol(0, varName, env.enclPkg.symbol.pkgID, actualType, env.scope.owner);
resultTypes = Lists.of(varRefExpr.type);
return;
}
varRefExpr.pkgSymbol = symResolver.resolveImportSymbol(varRefExpr.pos, env, names.fromIdNode(varRefExpr.pkgAlias));
if (varRefExpr.pkgSymbol.tag == SymTag.XMLNS) {
actualType = symTable.stringType;
} else if (varRefExpr.pkgSymbol != symTable.notFoundSymbol) {
BSymbol symbol = symResolver.lookupSymbolInPackage(varRefExpr.pos, env, names.fromIdNode(varRefExpr.pkgAlias), varName, SymTag.VARIABLE_NAME);
if ((symbol.tag & SymTag.VARIABLE) == SymTag.VARIABLE) {
BVarSymbol varSym = (BVarSymbol) symbol;
checkSefReferences(varRefExpr.pos, env, varSym);
varRefExpr.symbol = varSym;
actualType = varSym.type;
} else {
dlog.error(varRefExpr.pos, DiagnosticCode.UNDEFINED_SYMBOL, varName.toString());
}
}
// Check type compatibility
resultTypes = types.checkTypes(varRefExpr, Lists.of(actualType), expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkStructFieldAccess.
private BType checkStructFieldAccess(BLangVariableReference varReferExpr, Name fieldName, BType structType) {
BSymbol fieldSymbol = symResolver.resolveStructField(varReferExpr.pos, this.env, fieldName, structType.tsymbol);
if (fieldSymbol == symTable.notFoundSymbol) {
dlog.error(varReferExpr.pos, DiagnosticCode.UNDEFINED_STRUCT_FIELD, fieldName, structType.tsymbol);
return symTable.errType;
}
// Setting the field symbol. This is used during the code generation phase
varReferExpr.symbol = (BVarSymbol) fieldSymbol;
return fieldSymbol.type;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method concatSimilarKindXMLNodes.
/**
* Concatenate the consecutive text type nodes, and get the reduced set of children.
*
* @param exprs Child nodes
* @param xmlElementEnv
* @return Reduced set of children
*/
private List<BLangExpression> concatSimilarKindXMLNodes(List<BLangExpression> exprs, SymbolEnv xmlElementEnv) {
List<BLangExpression> newChildren = new ArrayList<BLangExpression>();
BLangExpression strConcatExpr = null;
for (BLangExpression expr : exprs) {
BType exprType = checkExpr((BLangExpression) expr, xmlElementEnv).get(0);
if (exprType == symTable.xmlType) {
if (strConcatExpr != null) {
newChildren.add(getXMLTextLiteral(strConcatExpr));
strConcatExpr = null;
}
newChildren.add(expr);
continue;
}
BSymbol opSymbol = symResolver.resolveBinaryOperator(OperatorKind.ADD, symTable.stringType, exprType);
if (opSymbol == symTable.notFoundSymbol && exprType != symTable.errType) {
dlog.error(expr.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.xmlType, exprType);
}
if (strConcatExpr == null) {
strConcatExpr = expr;
continue;
}
strConcatExpr = getBinaryAddExpr(strConcatExpr, expr, opSymbol);
}
// Add remaining concatenated text nodes as children
if (strConcatExpr != null) {
newChildren.add(getXMLTextLiteral(strConcatExpr));
}
return newChildren;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class Symbols method createConversionOperatorSymbol.
public static BConversionOperatorSymbol createConversionOperatorSymbol(final BType sourceType, final BType targetType, final BType errorType, boolean implicit, boolean safe, int opcode, PackageID pkgID, BSymbol owner) {
List<BType> paramTypes = Lists.of(sourceType, targetType);
List<BType> retTypes = new ArrayList<>(1);
if (safe) {
retTypes.add(targetType);
} else if (targetType.tag == TypeTags.UNION && targetType instanceof BUnionType) {
BUnionType unionType = (BUnionType) targetType;
unionType.memberTypes.add(errorType);
retTypes.add(unionType);
} else {
Set<BType> memberTypes = new HashSet<>(2);
memberTypes.add(targetType);
memberTypes.add(errorType);
BUnionType unionType = new BUnionType(null, memberTypes, false);
retTypes.add(unionType);
}
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(pkgID, opType, owner, implicit, safe, opcode);
symbol.kind = SymbolKind.CONVERSION_OPERATOR;
return symbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol 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;
}
Aggregations