Search in sources :

Example 46 with ExprNode

use of kalang.ast.ExprNode in project kalang by kasonyang.

the class AstBuilder method visitExprStat.

@Override
public AstNode visitExprStat(ExprStatContext ctx) {
    ExprNode expr = visitExpression(ctx.expression());
    ExprStmt es = new ExprStmt(expr);
    mapAst(es, ctx);
    return es;
}
Also used : ExprNode(kalang.ast.ExprNode) ExprStmt(kalang.ast.ExprStmt)

Example 47 with ExprNode

use of kalang.ast.ExprNode in project kalang by kasonyang.

the class AstUtil method matchTypes.

/**
 * @param args
 * @param from
 * @param target
 * @return array when matched,null when not
 */
@Nullable
public static ExprNode[] matchTypes(ExprNode[] args, Type[] from, Type[] target) {
    if (args == null)
        return null;
    if (from == null || from.length == 0) {
        if (target == null || target.length == 0) {
            return args;
        } else {
            return null;
        }
    }
    if (from.length != target.length || from.length != args.length) {
        return null;
    }
    if (from.length == 0)
        return new ExprNode[0];
    ExprNode[] newParams = new ExprNode[from.length];
    for (int i = 0; i < from.length; i++) {
        Type f = from[i];
        Type t = target[i];
        newParams[i] = matchType(f, t, args[i]);
        if (newParams[i] == null)
            return null;
    }
    return newParams;
}
Also used : ExprNode(kalang.ast.ExprNode) ArrayType(kalang.core.ArrayType) Type(kalang.core.Type) ObjectType(kalang.core.ObjectType) GenericType(kalang.core.GenericType) ClassType(kalang.core.ClassType) Nullable(javax.annotation.Nullable)

Aggregations

ExprNode (kalang.ast.ExprNode)47 ObjectType (kalang.core.ObjectType)23 ArrayType (kalang.core.ArrayType)17 GenericType (kalang.core.GenericType)17 Type (kalang.core.Type)17 ClassType (kalang.core.ClassType)16 PrimitiveType (kalang.core.PrimitiveType)15 WildcardType (kalang.core.WildcardType)14 ExprStmt (kalang.ast.ExprStmt)13 AssignExpr (kalang.ast.AssignExpr)12 BlockStmt (kalang.ast.BlockStmt)10 AmbiguousMethodException (kalang.AmbiguousMethodException)9 MethodNotFoundException (kalang.MethodNotFoundException)9 ClassReference (kalang.ast.ClassReference)9 ThisExpr (kalang.ast.ThisExpr)8 ExpressionContext (kalang.antlr.KalangParser.ExpressionContext)7 Statement (kalang.ast.Statement)7 LocalVarNode (kalang.ast.LocalVarNode)6 ObjectInvokeExpr (kalang.ast.ObjectInvokeExpr)6 VarExpr (kalang.ast.VarExpr)6