use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method handleForeachVariables.
// Private methods
private void handleForeachVariables(BLangForeach foreachStmt, List<BType> varTypes, SymbolEnv env) {
for (int i = 0; i < foreachStmt.varRefs.size(); i++) {
BLangExpression varRef = foreachStmt.varRefs.get(i);
// foreach variables supports only simpleVarRef expressions only.
if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
continue;
}
BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
simpleVarRef.lhsVar = true;
Name varName = names.fromIdNode(simpleVarRef.variableName);
if (varName == Names.IGNORE) {
simpleVarRef.type = this.symTable.noType;
typeChecker.checkExpr(simpleVarRef, env);
continue;
}
// Check variable symbol for existence.
BSymbol symbol = symResolver.lookupSymbol(env, varName, SymTag.VARIABLE);
if (symbol == symTable.notFoundSymbol) {
symbolEnter.defineVarSymbol(simpleVarRef.pos, Collections.emptySet(), varTypes.get(i), varName, env);
typeChecker.checkExpr(simpleVarRef, env);
} else {
dlog.error(simpleVarRef.pos, DiagnosticCode.REDECLARED_SYMBOL, varName);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method getTypeOfExprInFieldAccess.
private BType getTypeOfExprInFieldAccess(BLangExpression expr) {
// First check whether variable expression is of type enum.
if (expr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) expr;
BSymbol symbol = symResolver.lookupSymbolInPackage(varRef.pos, env, names.fromIdNode(varRef.pkgAlias), names.fromIdNode(varRef.variableName), SymTag.ENUM);
if (symbol != symTable.notFoundSymbol) {
expr.type = symbol.type;
return symbol.type;
}
}
checkExpr(expr, this.env, Lists.of(symTable.noType));
return expr.type;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkStructLiteralKeyExpr.
private BType checkStructLiteralKeyExpr(BLangRecordKey key, BType recordType, RecordKind recKind) {
Name fieldName;
BLangExpression keyExpr = key.expr;
if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) keyExpr;
fieldName = names.fromIdNode(varRef.variableName);
} else {
// keys of the struct literal can only be a varRef (identifier)
dlog.error(keyExpr.pos, DiagnosticCode.INVALID_STRUCT_LITERAL_KEY);
return symTable.errType;
}
// Check weather the struct field exists
BSymbol fieldSymbol = symResolver.resolveStructField(keyExpr.pos, this.env, fieldName, recordType.tsymbol);
if (fieldSymbol == symTable.notFoundSymbol) {
dlog.error(keyExpr.pos, DiagnosticCode.UNDEFINED_STRUCT_FIELD, fieldName, recordType.tsymbol);
return symTable.errType;
}
// Setting the struct field symbol for future use in Desugar and code generator.
key.fieldSymbol = (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 checkUnNamedTransformerInvocation.
private List<BType> checkUnNamedTransformerInvocation(BLangTypeConversionExpr conversionExpr, BType sourceType, BType targetType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
// Check whether a transformer is available for the two types
BSymbol symbol = symResolver.resolveTransformer(env, sourceType, targetType);
if (symbol == symTable.notFoundSymbol) {
// check whether a casting is possible, to provide user a hint.
BSymbol castSymbol = symResolver.resolveConversionOperator(sourceType, targetType);
if (castSymbol == symTable.notFoundSymbol) {
dlog.error(conversionExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES_CONVERSION, sourceType, targetType);
} else {
dlog.error(conversionExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES_CONVERSION_WITH_SUGGESTION, sourceType, targetType);
}
} else {
BTransformerSymbol transformerSymbol = (BTransformerSymbol) symbol;
conversionExpr.conversionSymbol = transformerSymbol;
if (conversionExpr.conversionSymbol.safe) {
((BInvokableType) transformerSymbol.type).retTypes.add(symTable.errStructType);
}
actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, transformerSymbol);
}
return actualTypes;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangXMLQName bLangXMLQName) {
String prefix = bLangXMLQName.prefix.value;
resultTypes = Lists.of(types.checkType(bLangXMLQName, symTable.stringType, expTypes.get(0)));
if (env.node.getKind() == NodeKind.XML_ATTRIBUTE && prefix.isEmpty() && bLangXMLQName.localname.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
((BLangXMLAttribute) env.node).isNamespaceDeclr = true;
return;
}
if (env.node.getKind() == NodeKind.XML_ATTRIBUTE && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
((BLangXMLAttribute) env.node).isNamespaceDeclr = true;
return;
}
if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
dlog.error(bLangXMLQName.pos, DiagnosticCode.INVALID_NAMESPACE_PREFIX, prefix);
bLangXMLQName.type = symTable.errType;
return;
}
BSymbol xmlnsSymbol = symResolver.lookupSymbol(env, names.fromIdNode(bLangXMLQName.prefix), SymTag.XMLNS);
if (prefix.isEmpty() && xmlnsSymbol == symTable.notFoundSymbol) {
return;
}
if (!prefix.isEmpty() && xmlnsSymbol == symTable.notFoundSymbol) {
dlog.error(bLangXMLQName.pos, DiagnosticCode.UNDEFINED_SYMBOL, prefix);
bLangXMLQName.type = symTable.errType;
return;
}
bLangXMLQName.namespaceURI = ((BXMLNSSymbol) xmlnsSymbol).namespaceURI;
bLangXMLQName.nsSymbol = (BXMLNSSymbol) xmlnsSymbol;
}
Aggregations