public Declarator make(Symbol sym, int dim, ASTree init) { Declarator d = new Declarator(this.varType, this.arrayDim + dim); d.qualifiedClass = this.qualifiedClass; d.setLeft(sym); append(d, init); return d; }
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; }
public Declarator(ASTList className, int dim) { super(null); varType = CLASS; arrayDim = dim; localVar = -1; qualifiedClass = astToClassName(className, '/'); }
public void atVariable(Variable v) throws CompileError { Declarator d = v.getDeclarator(); exprType = d.getType(); arrayDim = d.getArrayDim(); className = d.getClassName(); }
public void atDeclarator(Declarator d) throws CompileError { d.setLocalVar(getMaxLocals()); d.setClassName(resolveClassName(d.getClassName())); int size; if (is2word(d.getType(), d.getArrayDim())) size = 2; else size = 1; incMaxLocals(size); /* NOTE: Array initializers has not been supported. */ ASTree init = d.getInitializer(); if (init != null) { doTypeCheck(init); atVariableAssign(null, '=', null, d, init, false); } }
protected int getLocalVar(Declarator d) { int v = d.getLocalVar(); if (v < 0) { v = getMaxLocals(); // delayed variable allocation. d.setLocalVar(v); incMaxLocals(1); } return v; }
d.addArrayDim(parseArrayDimension()); if (isConstructor && d.getArrayDim() > 0) throw new SyntaxError(lex);
Stmnt block = (Stmnt)p.getRight(); decl.setLocalVar(var); CtClass type = resolver.lookupClassByJvmName(decl.getClassName()); decl.setClassName(MemberResolver.javaToJvmName(type.getName())); bc.addExceptionHandler(start, end, bc.currentPc(), type); bc.growStack(1);
private void atPlusPlus(int token, ASTree oprand, Expr expr) throws CompileError { boolean isPost = oprand == null; // ++i or i++? if (isPost) oprand = expr.oprand2(); if (oprand instanceof Variable) { Declarator d = ((Variable)oprand).getDeclarator(); exprType = d.getType(); arrayDim = d.getArrayDim(); } else { if (oprand instanceof Expr) { Expr e = (Expr)oprand; if (e.getOperator() == ARRAY) { atArrayRead(e.oprand1(), e.oprand2()); // arrayDim should be 0. int t = exprType; if (t == INT || t == BYTE || t == CHAR || t == SHORT) exprType = INT; return; } } atFieldPlusPlus(oprand); } }
/** * Makes the given variable name available. * * @param typeDesc the type descriptor of the variable * @param varName variable name * @param varNo an index into the local variable array */ public void recordVariable(String typeDesc, String varName, int varNo, SymbolTable tbl) throws CompileError { char c; int dim = 0; while ((c = typeDesc.charAt(dim)) == '[') ++dim; int type = MemberResolver.descToType(c); String cname = null; if (type == CLASS) { if (dim == 0) cname = typeDesc.substring(1, typeDesc.length() - 1); else cname = typeDesc.substring(dim + 1, typeDesc.length() - 1); } Declarator decl = new Declarator(type, cname, dim, varNo, new Symbol(varName)); tbl.append(varName, decl); }
public ASTList parseMember1(SymbolTable tbl) throws CompileError { ASTList mods = parseMemberMods(); Declarator d; boolean isConstructor = false; if (lex.lookAhead() == Identifier && lex.lookAhead(1) == '(') { d = new Declarator(VOID, 0); isConstructor = true; } else d = parseFormalType(tbl); if (lex.get() != Identifier) throw new SyntaxError(lex); String name; if (isConstructor) name = MethodDecl.initName; else name = lex.getString(); d.setVariable(new Symbol(name)); if (isConstructor || lex.lookAhead() == '(') return parseMethod1(tbl, isConstructor, mods, d); else return parseField(tbl, mods, d); }
private Declarator parseDeclarator(SymbolTable tbl, Declarator d) throws CompileError { if (lex.get() != Identifier || d.getType() == VOID) throw new SyntaxError(lex); String name = lex.getString(); Symbol symbol = new Symbol(name); int dim = parseArrayDimension(); ASTree init = null; if (lex.lookAhead() == '=') { lex.get(); init = parseInitializer(tbl); } Declarator decl = d.make(symbol, dim, init); tbl.append(name, decl); return decl; }
public Symbol getVariable() { return (Symbol)getLeft(); }
public String toString() { return identifier + ":" + declarator.getType(); }
@Override public void atDeclarator(Declarator d) throws CompileError { d.setLocalVar(getMaxLocals()); d.setClassName(resolveClassName(d.getClassName())); int size; if (is2word(d.getType(), d.getArrayDim())) size = 2; else size = 1; incMaxLocals(size); /* NOTE: Array initializers has not been supported. */ ASTree init = d.getInitializer(); if (init != null) { doTypeCheck(init); atVariableAssign(null, '=', null, d, init, false); } }
public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); }
protected int getLocalVar(Declarator d) { int v = d.getLocalVar(); if (v < 0) { v = getMaxLocals(); // delayed variable allocation. d.setLocalVar(v); incMaxLocals(1); } return v; }
d.addArrayDim(parseArrayDimension()); if (isConstructor && d.getArrayDim() > 0) throw new SyntaxError(lex);