use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangBinaryExpr binaryExpr) {
BType lhsType = checkExpr(binaryExpr.lhsExpr, env).get(0);
BType rhsType = checkExpr(binaryExpr.rhsExpr, env).get(0);
// Set error type as the actual type.
BType actualType = symTable.errType;
// Look up operator symbol if both rhs and lhs types are error types
if (lhsType != symTable.errType && rhsType != symTable.errType) {
BSymbol opSymbol = symResolver.resolveBinaryOperator(binaryExpr.opKind, lhsType, rhsType);
if (opSymbol == symTable.notFoundSymbol) {
dlog.error(binaryExpr.pos, DiagnosticCode.BINARY_OP_INCOMPATIBLE_TYPES, binaryExpr.opKind, lhsType, rhsType);
} else {
binaryExpr.opSymbol = (BOperatorSymbol) opSymbol;
actualType = opSymbol.type.getReturnTypes().get(0);
}
}
resultTypes = types.checkTypes(binaryExpr, Lists.of(actualType), expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangFieldBasedAccess fieldAccessExpr) {
// First analyze the variable reference expression.
BType actualType = symTable.errType;
BType varRefType = getTypeOfExprInFieldAccess(fieldAccessExpr.expr);
if (fieldAccessExpr.fieldType == FieldType.ALL && varRefType.tag != TypeTags.XML) {
dlog.error(fieldAccessExpr.pos, DiagnosticCode.CANNOT_GET_ALL_FIELDS, varRefType);
}
Name fieldName = names.fromIdNode(fieldAccessExpr.field);
switch(varRefType.tag) {
case TypeTags.STRUCT:
actualType = checkStructFieldAccess(fieldAccessExpr, fieldName, varRefType);
break;
case TypeTags.MAP:
actualType = ((BMapType) varRefType).getConstraint();
break;
case TypeTags.JSON:
BType constraintType = ((BJSONType) varRefType).constraint;
if (constraintType.tag == TypeTags.STRUCT) {
BType fieldType = checkStructFieldAccess(fieldAccessExpr, fieldName, constraintType);
// If the type of the field is struct, treat it as constraint JSON type.
if (fieldType.tag == TypeTags.STRUCT) {
actualType = new BJSONType(TypeTags.JSON, fieldType, symTable.jsonType.tsymbol);
break;
}
}
actualType = symTable.jsonType;
break;
case TypeTags.ENUM:
// Enumerator access expressions only allow enum type name as the first part e.g state.INSTALLED,
BEnumType enumType = (BEnumType) varRefType;
if (fieldAccessExpr.expr.getKind() != NodeKind.SIMPLE_VARIABLE_REF || !((BLangSimpleVarRef) fieldAccessExpr.expr).variableName.value.equals(enumType.tsymbol.name.value)) {
dlog.error(fieldAccessExpr.pos, DiagnosticCode.INVALID_ENUM_EXPR, enumType.tsymbol.name.value);
break;
}
BSymbol symbol = symResolver.lookupMemberSymbol(fieldAccessExpr.pos, enumType.tsymbol.scope, this.env, fieldName, SymTag.VARIABLE);
if (symbol == symTable.notFoundSymbol) {
dlog.error(fieldAccessExpr.pos, DiagnosticCode.UNDEFINED_SYMBOL, fieldName.value);
break;
}
fieldAccessExpr.symbol = (BVarSymbol) symbol;
actualType = fieldAccessExpr.expr.type;
break;
case TypeTags.XML:
if (fieldAccessExpr.lhsVar) {
dlog.error(fieldAccessExpr.pos, DiagnosticCode.CANNOT_UPDATE_XML_SEQUENCE);
break;
}
actualType = symTable.xmlType;
break;
case TypeTags.ERROR:
// Do nothing
break;
default:
dlog.error(fieldAccessExpr.pos, DiagnosticCode.OPERATION_DOES_NOT_SUPPORT_FIELD_ACCESS, varRefType);
}
resultTypes = types.checkTypes(fieldAccessExpr, Lists.of(actualType), this.expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkFunctionInvocationExpr.
private void checkFunctionInvocationExpr(BLangInvocation iExpr, BStructType structType) {
String funcName = iExpr.name.value;
Name uniqueFuncName = names.fromString(Symbols.getAttachedFuncSymbolName(structType.tsymbol.name.value, funcName));
BPackageSymbol packageSymbol = (BPackageSymbol) structType.tsymbol.owner;
BSymbol funcSymbol = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, uniqueFuncName, SymTag.FUNCTION);
if (funcSymbol == symTable.notFoundSymbol) {
// Check functions defined within the struct.
Name functionName = names.fromString(Symbols.getAttachedFuncSymbolName(iExpr.expr.symbol.type.tsymbol.name.value, iExpr.name.value));
funcSymbol = symResolver.resolveStructField(iExpr.pos, env, functionName, iExpr.expr.symbol.type.tsymbol);
if (funcSymbol == symTable.notFoundSymbol) {
// Check, any function pointer in struct field with given name.
funcSymbol = symResolver.resolveStructField(iExpr.pos, env, names.fromIdNode(iExpr.name), iExpr.expr.symbol.type.tsymbol);
if (funcSymbol == symTable.notFoundSymbol || funcSymbol.type.tag != TypeTags.INVOKABLE) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION_IN_STRUCT, funcName, structType);
resultTypes = getListWithErrorTypes(expTypes.size());
return;
}
if ((funcSymbol.flags & Flags.ATTACHED) != Flags.ATTACHED) {
iExpr.functionPointerInvocation = true;
}
}
} else {
// Attached function found
// Check for the explicit initializer function invocation
BStructSymbol.BAttachedFunction initializerFunc = ((BStructSymbol) structType.tsymbol).initializerFunc;
if (initializerFunc != null && initializerFunc.funcName.value.equals(funcName)) {
dlog.error(iExpr.pos, DiagnosticCode.STRUCT_INITIALIZER_INVOKED, structType.tsymbol.toString());
}
}
iExpr.symbol = funcSymbol;
checkInvocationParamAndReturnType(iExpr);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkActionInvocationExpr.
private void checkActionInvocationExpr(BLangInvocation iExpr, BType conType) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
if (conType == symTable.errType || conType.tag != TypeTags.STRUCT || iExpr.expr.symbol.tag != SymTag.ENDPOINT) {
dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION);
resultTypes = actualTypes;
return;
}
final BEndpointVarSymbol epSymbol = (BEndpointVarSymbol) iExpr.expr.symbol;
if (!epSymbol.interactable) {
dlog.error(iExpr.pos, DiagnosticCode.ENDPOINT_NOT_SUPPORT_INTERACTIONS, epSymbol.name);
resultTypes = actualTypes;
return;
}
BSymbol conSymbol = epSymbol.clientSymbol;
if (conSymbol == null || conSymbol == symTable.notFoundSymbol || conSymbol == symTable.errSymbol || conSymbol.tag != SymTag.STRUCT) {
dlog.error(iExpr.pos, DiagnosticCode.INVALID_ACTION_INVOCATION);
resultTypes = actualTypes;
return;
}
Name actionName = names.fromIdNode(iExpr.name);
Name uniqueFuncName = names.fromString(Symbols.getAttachedFuncSymbolName(conSymbol.name.value, actionName.value));
BPackageSymbol packageSymbol = (BPackageSymbol) conSymbol.owner;
BSymbol actionSym = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, uniqueFuncName, SymTag.FUNCTION);
if (actionSym == symTable.errSymbol || actionSym == symTable.notFoundSymbol) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_ACTION, actionName, epSymbol.name, conSymbol.type);
resultTypes = actualTypes;
return;
}
iExpr.symbol = actionSym;
checkInvocationParamAndReturnType(iExpr);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkFunctionInvocationExpr.
private void checkFunctionInvocationExpr(BLangInvocation iExpr, BType bType) {
Name funcName = names.fromString(Symbols.getAttachedFuncSymbolName(bType.toString(), iExpr.name.value));
BPackageSymbol packageSymbol = (BPackageSymbol) bType.tsymbol.owner;
BSymbol funcSymbol = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, funcName, SymTag.FUNCTION);
if (funcSymbol == symTable.notFoundSymbol) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION, funcName);
resultTypes = getListWithErrorTypes(expTypes.size());
return;
}
iExpr.symbol = funcSymbol;
checkInvocationParamAndReturnType(iExpr);
}
Aggregations