use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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.types.BType 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);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangIndexBasedAccess indexBasedAccessExpr) {
BType actualType = symTable.errType;
// First analyze the variable reference expression.
checkExpr(indexBasedAccessExpr.expr, this.env, Lists.of(symTable.noType));
BType indexExprType;
BType varRefType = indexBasedAccessExpr.expr.type;
BLangExpression indexExpr = indexBasedAccessExpr.indexExpr;
switch(varRefType.tag) {
case TypeTags.STRUCT:
indexExprType = checkIndexExprForStructFieldAccess(indexExpr);
if (indexExprType.tag == TypeTags.STRING) {
String fieldName = (String) ((BLangLiteral) indexExpr).value;
actualType = checkStructFieldAccess(indexBasedAccessExpr, names.fromString(fieldName), varRefType);
}
break;
case TypeTags.MAP:
indexExprType = checkExpr(indexExpr, this.env, Lists.of(symTable.stringType)).get(0);
if (indexExprType.tag == TypeTags.STRING) {
actualType = ((BMapType) varRefType).getConstraint();
}
break;
case TypeTags.JSON:
BType constraintType = ((BJSONType) varRefType).constraint;
if (constraintType.tag == TypeTags.STRUCT) {
indexExprType = checkIndexExprForStructFieldAccess(indexExpr);
if (indexExprType.tag != TypeTags.STRING) {
break;
}
String fieldName = (String) ((BLangLiteral) indexExpr).value;
BType fieldType = checkStructFieldAccess(indexBasedAccessExpr, names.fromString(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;
}
} else {
indexExprType = checkExpr(indexExpr, this.env, Lists.of(symTable.noType)).get(0);
if (indexExprType.tag != TypeTags.STRING && indexExprType.tag != TypeTags.INT) {
dlog.error(indexExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.stringType, indexExprType);
break;
}
}
actualType = symTable.jsonType;
break;
case TypeTags.ARRAY:
indexExprType = checkExpr(indexExpr, this.env, Lists.of(symTable.intType)).get(0);
if (indexExprType.tag == TypeTags.INT) {
actualType = ((BArrayType) varRefType).getElementType();
}
break;
case TypeTags.XML:
if (indexBasedAccessExpr.lhsVar) {
dlog.error(indexBasedAccessExpr.pos, DiagnosticCode.CANNOT_UPDATE_XML_SEQUENCE);
break;
}
checkExpr(indexExpr, this.env).get(0);
actualType = symTable.xmlType;
break;
case TypeTags.ERROR:
// Do nothing
break;
default:
dlog.error(indexBasedAccessExpr.pos, DiagnosticCode.OPERATION_DOES_NOT_SUPPORT_INDEXING, indexBasedAccessExpr.expr.type);
}
resultTypes = types.checkTypes(indexBasedAccessExpr, Lists.of(actualType), this.expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType 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;
}
Aggregations