use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangCompoundAssignment compoundAssignment) {
List<BType> expTypes = new ArrayList<>();
BLangExpression varRef = compoundAssignment.varRef;
if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF && varRef.getKind() != NodeKind.INDEX_BASED_ACCESS_EXPR && varRef.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR && varRef.getKind() != NodeKind.XML_ATTRIBUTE_ACCESS_EXPR) {
dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
expTypes.add(symTable.errType);
} else {
this.typeChecker.checkExpr(varRef, env).get(0);
expTypes.add(varRef.type);
}
this.typeChecker.checkExpr(compoundAssignment.expr, env).get(0);
if (expTypes.get(0) != symTable.errType && compoundAssignment.expr.type != symTable.errType) {
BSymbol opSymbol = this.symResolver.resolveBinaryOperator(compoundAssignment.opKind, expTypes.get(0), compoundAssignment.expr.type);
if (opSymbol == symTable.notFoundSymbol) {
dlog.error(compoundAssignment.pos, DiagnosticCode.BINARY_OP_INCOMPATIBLE_TYPES, compoundAssignment.opKind, expTypes.get(0), compoundAssignment.expr.type);
} else {
compoundAssignment.modifiedExpr = getBinaryExpr(varRef, compoundAssignment.expr, compoundAssignment.opKind, opSymbol);
this.types.checkTypes(compoundAssignment.modifiedExpr, Lists.of(compoundAssignment.modifiedExpr.type), expTypes);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangMatch matchNode) {
List<BType> exprTypes = typeChecker.checkExpr(matchNode.expr, env, Lists.of(symTable.noType));
if (exprTypes.size() > 1) {
dlog.error(matchNode.expr.pos, DiagnosticCode.MULTI_VAL_EXPR_IN_SINGLE_VAL_CONTEXT);
return;
} else if (exprTypes.size() == 0) {
dlog.error(matchNode.expr.pos, DiagnosticCode.INVALID_EXPR_IN_MATCH_STMT);
return;
} else if (exprTypes.get(0).tag == TypeTags.UNION) {
BUnionType unionType = (BUnionType) exprTypes.get(0);
exprTypes = new ArrayList<>(unionType.memberTypes);
}
// visit patterns
matchNode.patternClauses.forEach(patternClause -> patternClause.accept(this));
matchNode.exprTypes = exprTypes;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method validateTransformerMappingType.
private void validateTransformerMappingType(BLangVariable param) {
BType type = param.type;
if (types.isValueType(type) || (type instanceof BBuiltInRefType) || type.tag == TypeTags.STRUCT) {
return;
}
dlog.error(param.pos, DiagnosticCode.TRANSFORMER_UNSUPPORTED_TYPES, type);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangBind bindNode) {
List<BType> expTypes = new ArrayList<>();
// Check each LHS expression.
BLangExpression varRef = bindNode.varRef;
((BLangVariableReference) varRef).lhsVar = true;
expTypes.add(typeChecker.checkExpr(varRef, env).get(0));
checkConstantAssignment(varRef);
typeChecker.checkExpr(bindNode.expr, this.env, expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangExpressionStmt exprStmtNode) {
// Creates a new environment here.
SymbolEnv stmtEnv = new SymbolEnv(exprStmtNode, this.env.scope);
this.env.copyTo(stmtEnv);
List<BType> bTypes = typeChecker.checkExpr(exprStmtNode.expr, stmtEnv, new ArrayList<>());
if (bTypes.size() > 0 && !(bTypes.size() == 1 && bTypes.get(0) == symTable.errType)) {
dlog.error(exprStmtNode.pos, DiagnosticCode.ASSIGNMENT_REQUIRED);
}
}
Aggregations