use of org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangUnaryExpr unaryExpr) {
BType exprType = null;
BType actualType = symTable.errType;
if (OperatorKind.TYPEOF.equals(unaryExpr.operator)) {
// Handle typeof operator separately
if (unaryExpr.expr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) unaryExpr.expr;
Name varRefName = names.fromIdNode((varRef).variableName);
Name pkgAlias = names.fromIdNode((varRef).pkgAlias);
// Resolve symbol for BLangSimpleVarRef
BSymbol varRefSybmol = symResolver.lookupSymbolInPackage(unaryExpr.pos, env, pkgAlias, varRefName, SymTag.VARIABLE);
if (varRefSybmol == symTable.notFoundSymbol) {
// Resolve symbol for User Defined Type ( converted from BLangSimpleVarRef )
BLangTypeofExpr typeAccessExpr = getTypeAccessExpression(varRef);
unaryExpr.expr = typeAccessExpr;
actualType = typeAccessExpr.type;
resultTypes = types.checkTypes(unaryExpr, Lists.of(actualType), expTypes);
return;
} else {
// Check type if resolved as BLangSimpleVarRef
exprType = checkExpr(unaryExpr.expr, env).get(0);
}
} else {
// Check type if resolved as non BLangSimpleVarRef Expression
exprType = checkExpr(unaryExpr.expr, env).get(0);
}
if (exprType != symTable.errType) {
unaryExpr.opSymbol = Symbols.createTypeofOperatorSymbol(exprType, types, symTable, names);
actualType = unaryExpr.opSymbol.type.getReturnTypes().get(0);
}
} else {
exprType = checkExpr(unaryExpr.expr, env).get(0);
if (exprType != symTable.errType) {
BSymbol symbol = symResolver.resolveUnaryOperator(unaryExpr.pos, unaryExpr.operator, exprType);
if (symbol == symTable.notFoundSymbol) {
dlog.error(unaryExpr.pos, DiagnosticCode.UNARY_OP_INCOMPATIBLE_TYPES, unaryExpr.operator, exprType);
} else {
unaryExpr.opSymbol = (BOperatorSymbol) symbol;
actualType = symbol.type.getReturnTypes().get(0);
}
}
}
resultTypes = types.checkTypes(unaryExpr, Lists.of(actualType), expTypes);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr in project ballerina by ballerina-lang.
the class TypeChecker method getTypeAccessExpression.
private BLangTypeofExpr getTypeAccessExpression(BLangSimpleVarRef varRef) {
BLangUserDefinedType userDefinedType = new BLangUserDefinedType();
userDefinedType.pkgAlias = varRef.pkgAlias;
userDefinedType.typeName = varRef.variableName;
userDefinedType.pos = varRef.pos;
BLangTypeofExpr typeAccessExpr = (BLangTypeofExpr) TreeBuilder.createTypeAccessNode();
typeAccessExpr.typeNode = userDefinedType;
typeAccessExpr.resolvedType = symResolver.resolveTypeNode(userDefinedType, env);
typeAccessExpr.pos = varRef.pos;
typeAccessExpr.type = symTable.typeDesc;
return typeAccessExpr;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr in project ballerina by ballerina-lang.
the class Desugar method createInvocationFromTableExpr.
private BLangInvocation createInvocationFromTableExpr(BLangTableQueryExpression tableQueryExpression) {
List<BLangExpression> args = new ArrayList<>();
List<BType> retTypes = new ArrayList<>();
String functionName = QUERY_TABLE_WITHOUT_JOIN_CLAUSE;
// Order matters, because these are the args for a function invocation.
args.add(getSQLPreparedStatement(tableQueryExpression));
args.add(getFromTableVarRef(tableQueryExpression));
// BLangTypeofExpr
retTypes.add(tableQueryExpression.type);
BLangSimpleVarRef joinTable = getJoinTableVarRef(tableQueryExpression);
if (joinTable != null) {
args.add(joinTable);
functionName = QUERY_TABLE_WITH_JOIN_CLAUSE;
}
args.add(getSQLStatementParameters(tableQueryExpression));
args.add(getReturnType(tableQueryExpression));
return createInvocationNode(functionName, args, retTypes);
}
Aggregations