use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method analyzeNode.
BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
SymbolEnv prevEnv = this.env;
BType preExpType = this.expType;
DiagnosticCode preDiagCode = this.diagCode;
// TODO Check the possibility of using a try/finally here
this.env = env;
this.expType = expType;
this.diagCode = diagCode;
node.accept(this);
this.env = prevEnv;
this.expType = preExpType;
this.diagCode = preDiagCode;
return resType;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangEndpoint endpointNode) {
endpointNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENDPOINT);
this.analyzeDef(annotationAttachment, env);
});
if (endpointNode.configurationExpr == null) {
return;
}
BType configType = symTable.errType;
if (endpointNode.symbol != null && endpointNode.symbol.type.tag == TypeTags.STRUCT) {
if (endpointNode.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
// Init expression.
configType = endpointSPIAnalyzer.getEndpointConfigType((BStructSymbol) endpointNode.symbol.type.tsymbol);
} else {
// assign Expression.
configType = endpointNode.symbol.type;
}
}
this.typeChecker.checkExpr(endpointNode.configurationExpr, env, Lists.of(configType));
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method handleServiceTypeStruct.
private void handleServiceTypeStruct(BLangService serviceNode) {
if (serviceNode.serviceTypeStruct != null) {
final BType serviceStructType = symResolver.resolveTypeNode(serviceNode.serviceTypeStruct, env);
serviceNode.endpointType = endpointSPIAnalyzer.getEndpointTypeFromServiceType(serviceNode.serviceTypeStruct.pos, serviceStructType);
if (serviceNode.endpointType != null) {
serviceNode.endpointClientType = endpointSPIAnalyzer.getClientType((BStructSymbol) serviceNode.endpointType.tsymbol);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangAssignment assignNode) {
if (assignNode.isDeclaredWithVar()) {
handleAssignNodeWithVar(assignNode);
return;
}
// Check each LHS expression.
List<BType> expTypes = new ArrayList<>();
for (BLangExpression expr : assignNode.varRefs) {
// In assignment, lhs supports only simpleVarRef, indexBasedAccess, filedBasedAccess expressions.
if (expr.getKind() != NodeKind.SIMPLE_VARIABLE_REF && expr.getKind() != NodeKind.INDEX_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.XML_ATTRIBUTE_ACCESS_EXPR) {
dlog.error(expr.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, expr);
expTypes.add(symTable.errType);
continue;
}
// Evaluate the variable reference expression.
BLangVariableReference varRef = (BLangVariableReference) expr;
varRef.lhsVar = true;
typeChecker.checkExpr(varRef, env);
// Check whether we've got an enumerator access expression here.
if (varRef.getKind() == NodeKind.FIELD_BASED_ACCESS_EXPR && ((BLangFieldBasedAccess) varRef).expr.type.tag == TypeTags.ENUM) {
dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
expTypes.add(symTable.errType);
continue;
}
expTypes.add(varRef.type);
checkConstantAssignment(varRef);
}
if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
BTupleType tupleType = new BTupleType(expTypes);
expTypes = Lists.of(tupleType);
}
if (!assignNode.safeAssignment) {
typeChecker.checkExpr(assignNode.expr, this.env, expTypes);
return;
}
// Assume that there is only one variable reference in LHS
// Continue the validate if this is a safe assignment operator
handleSafeAssignment(assignNode.pos, assignNode.varRefs.get(0).type, assignNode.expr, this.env);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangTypeConversionExpr conversionExpr) {
// Set error type as the actual type.
// List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
List<BType> actualTypes;
BType targetType = symResolver.resolveTypeNode(conversionExpr.typeNode, env);
conversionExpr.targetType = targetType;
BType sourceType = checkExpr(conversionExpr.expr, env, Lists.of(symTable.noType)).get(0);
if (conversionExpr.transformerInvocation == null) {
// Lookup for built-in type conversion operator symbol
BSymbol symbol = symResolver.resolveConversionOperator(sourceType, targetType);
if (symbol == symTable.notFoundSymbol) {
// If not found, look for unnamed transformers for the given types
actualTypes = checkUnNamedTransformerInvocation(conversionExpr, sourceType, targetType);
} else {
BConversionOperatorSymbol conversionSym = (BConversionOperatorSymbol) symbol;
conversionExpr.conversionSymbol = conversionSym;
actualTypes = getActualTypesOfConversionExpr(conversionExpr, targetType, sourceType, conversionSym);
}
} else {
actualTypes = checkNamedTransformerInvocation(conversionExpr, sourceType, targetType);
}
resultTypes = types.checkTypes(conversionExpr, actualTypes, expTypes);
}
Aggregations