private ASTree parseParExpression(SymbolTable tbl) throws CompileError { if (lex.get() != '(') throw new SyntaxError(lex); ASTree expr = parseExpression(tbl); if (lex.get() != ')') throw new SyntaxError(lex); return expr; }
private ASTree parseBinaryExpr(SymbolTable tbl) throws CompileError { ASTree expr = parseUnaryExpr(tbl); for (;;) { int t = lex.lookAhead(); int p = getOpPrecedence(t); if (p == 0) return expr; else expr = binaryExpr2(tbl, expr, p); } }
private ASTree parseInitializer(SymbolTable tbl) throws CompileError { if (lex.lookAhead() == '{') return parseArrayInitializer(tbl); else return parseExpression(tbl); }
private Declarator parseFormalParam(SymbolTable tbl) throws CompileError { Declarator d = parseFormalType(tbl); if (lex.get() != Identifier) throw new SyntaxError(lex); String name = lex.getString(); d.setVariable(new Symbol(name)); d.addArrayDim(parseArrayDimension()); tbl.append(name, d); return d; }
private Stmnt parseReturn(SymbolTable tbl) throws CompileError { int t = lex.get(); // RETURN Stmnt s = new Stmnt(t); if (lex.lookAhead() != ';') s.setLeft(parseExpression(tbl)); if (lex.get() != ';') throw new CompileError("; is missing", lex); return s; }
private ASTree parseConditionalExpr(SymbolTable tbl) throws CompileError { ASTree cond = parseBinaryExpr(tbl); if (lex.lookAhead() == '?') { lex.get(); ASTree thenExpr = parseExpression(tbl); if (lex.get() != ':') throw new CompileError(": is missing", lex); ASTree elseExpr = parseExpression(tbl); return new CondExpr(cond, thenExpr, elseExpr); } else return cond; }
private Stmnt parseDo(SymbolTable tbl) throws CompileError { int t = lex.get(); // DO Stmnt body = parseStatement(tbl); if (lex.get() != WHILE || lex.get() != '(') throw new SyntaxError(lex); ASTree expr = parseExpression(tbl); if (lex.get() != ')' || lex.get() != ';') throw new SyntaxError(lex); return new Stmnt(t, expr, body); }
private Stmnt parseSynchronized(SymbolTable tbl) throws CompileError { int t = lex.get(); // SYNCHRONIZED if (lex.get() != '(') throw new SyntaxError(lex); ASTree expr = parseExpression(tbl); if (lex.get() != ')') throw new SyntaxError(lex); Stmnt body = parseBlock(tbl); return new Stmnt(t, expr, body); }
private ASTree parseArrayIndex(SymbolTable tbl) throws CompileError { lex.get(); // '[' if (lex.lookAhead() == ']') { lex.get(); return null; } else { ASTree index = parseExpression(tbl); if (lex.get() != ']') throw new CompileError("] is missing", lex); return index; } }
private Stmnt parseThrow(SymbolTable tbl) throws CompileError { int t = lex.get(); // THROW ASTree expr = parseExpression(tbl); if (lex.get() != ';') throw new CompileError("; is missing", lex); return new Stmnt(t, expr); }
private int computeLabel(ASTree expr) throws CompileError { doTypeCheck(expr); expr = TypeChecker.stripPlusExpr(expr); if (expr instanceof IntConst) return (int)((IntConst)expr).get(); else throw new CompileError("bad case label"); }
public void doNumCast(CtClass type) throws CompileError { if (arrayDim == 0 && !isRefType(exprType)) if (type instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)type; atNumCastExpr(exprType, MemberResolver.descToType(pt.getDescriptor())); } else throw new CompileError("type mismatch"); } }
/** * Parsers an expression. */ public static ASTree parseExpr(String src, SymbolTable st) throws CompileError { Parser p = new Parser(new Lex(src)); return p.parseExpression(st); }
private int parseArrayDimension() throws CompileError { int arrayDim = 0; while (lex.lookAhead() == '[') { ++arrayDim; lex.get(); if (lex.get() != ']') throw new CompileError("] is missing", lex); } return arrayDim; }
protected String getAccessibleConstructor(String desc, CtClass declClass, MethodInfo minfo) throws CompileError { if (isEnclosing(declClass, thisClass)) { AccessorMaker maker = declClass.getAccessorMaker(); if (maker != null) return maker.getConstructor(declClass, desc, minfo); } throw new CompileError("the called constructor is private in " + declClass.getName()); }
private void computeBinExprType(BinExpr expr, int token, int type1) throws CompileError { // arrayDim should be 0. int type2 = exprType; if (token == LSHIFT || token == RSHIFT || token == ARSHIFT) exprType = type1; else insertCast(expr, type1, type2); if (CodeGen.isP_INT(exprType) && exprType != BOOLEAN) exprType = INT; // type1 may be BYTE, ... }
public JvstCodeGen(Bytecode b, CtClass cc, ClassPool cp) { super(b, cc, cp); setTypeChecker(new JvstTypeChecker(cc, cp, this)); }
private boolean nextIsClassCast() { int i = nextIsClassType(1); if (i < 0) return false; int t = lex.lookAhead(i); if (t != ')') return false; t = lex.lookAhead(i + 1); return t == '(' || t == NULL || t == StringL || t == Identifier || t == THIS || t == SUPER || t == NEW || t == TRUE || t == FALSE || t == LongConstant || t == IntConstant || t == CharConstant || t == DoubleConstant || t == FloatConstant; }
public boolean compileBooleanExpr(boolean branchIf, ASTree expr) throws CompileError { doTypeCheck(expr); return booleanExpr(branchIf, expr); }
/** * Prepares to use $proceed(). */ public void recordProceed(ProceedHandler h) { gen.setProceedHandler(h, proceedName); }