aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/compiler
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-23 17:08:37 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-04-23 17:08:37 +0000
commitcdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6 (patch)
tree0471a4d9b985b11969ecd6f521f660e3d468f1d1 /src/main/javassist/compiler
parentfb431982111b03608b888953f7ed8ba7e98f421c (diff)
downloadjavassist-cdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6.tar.gz
javassist-cdeddfd6fc34a06734f9fa525cf5c7437a6c8fb6.zip
Changed the copyright notices and removed tab characters.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@9 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler')
-rw-r--r--src/main/javassist/compiler/CodeGen.java2315
-rw-r--r--src/main/javassist/compiler/CompileError.java43
-rw-r--r--src/main/javassist/compiler/Javac.java359
-rw-r--r--src/main/javassist/compiler/JvstCodeGen.java851
-rw-r--r--src/main/javassist/compiler/KeywordTable.java43
-rw-r--r--src/main/javassist/compiler/Lex.java881
-rw-r--r--src/main/javassist/compiler/MemberCodeGen.java1677
-rw-r--r--src/main/javassist/compiler/NoFieldException.java37
-rw-r--r--src/main/javassist/compiler/Parser.java1559
-rw-r--r--src/main/javassist/compiler/ProceedHandler.java33
-rw-r--r--src/main/javassist/compiler/SymbolTable.java47
-rw-r--r--src/main/javassist/compiler/SyntaxError.java33
-rw-r--r--src/main/javassist/compiler/TokenId.java103
-rw-r--r--src/main/javassist/compiler/ast/ASTList.java137
-rw-r--r--src/main/javassist/compiler/ast/ASTree.java45
-rw-r--r--src/main/javassist/compiler/ast/AssignExpr.java39
-rw-r--r--src/main/javassist/compiler/ast/BinExpr.java35
-rw-r--r--src/main/javassist/compiler/ast/CastExpr.java43
-rw-r--r--src/main/javassist/compiler/ast/CondExpr.java33
-rw-r--r--src/main/javassist/compiler/ast/Declarator.java113
-rw-r--r--src/main/javassist/compiler/ast/DoubleConst.java33
-rw-r--r--src/main/javassist/compiler/ast/Expr.java61
-rw-r--r--src/main/javassist/compiler/ast/FieldDecl.java35
-rw-r--r--src/main/javassist/compiler/ast/InstanceOfExpr.java39
-rw-r--r--src/main/javassist/compiler/ast/IntConst.java33
-rw-r--r--src/main/javassist/compiler/ast/Keyword.java33
-rw-r--r--src/main/javassist/compiler/ast/Member.java33
-rw-r--r--src/main/javassist/compiler/ast/MethodDecl.java39
-rw-r--r--src/main/javassist/compiler/ast/NewExpr.java71
-rw-r--r--src/main/javassist/compiler/ast/Pair.java49
-rw-r--r--src/main/javassist/compiler/ast/Stmnt.java53
-rw-r--r--src/main/javassist/compiler/ast/StringL.java33
-rw-r--r--src/main/javassist/compiler/ast/Symbol.java33
-rw-r--r--src/main/javassist/compiler/ast/Variable.java37
-rw-r--r--src/main/javassist/compiler/ast/Visitor.java31
35 files changed, 4327 insertions, 4712 deletions
diff --git a/src/main/javassist/compiler/CodeGen.java b/src/main/javassist/compiler/CodeGen.java
index 9a5f6771..d061e320 100644
--- a/src/main/javassist/compiler/CodeGen.java
+++ b/src/main/javassist/compiler/CodeGen.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import java.util.ArrayList;
@@ -54,34 +43,34 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
/* The following fields are used by atXXX() methods
* for returning the type of the compiled expression.
*/
- protected int exprType; // VOID, NULL, CLASS, BOOLEAN, INT, ...
+ protected int exprType; // VOID, NULL, CLASS, BOOLEAN, INT, ...
protected int arrayDim;
- protected String className; // JVM-internal representation
+ protected String className; // JVM-internal representation
public CodeGen(Bytecode b) {
- bytecode = b;
- tempVar = -1;
- inStaticMethod = false;
- breakList = null;
- continueList = null;
+ bytecode = b;
+ tempVar = -1;
+ inStaticMethod = false;
+ breakList = null;
+ continueList = null;
}
protected static void fatal() throws CompileError {
- throw new CompileError("fatal");
+ throw new CompileError("fatal");
}
public static boolean is2word(int type, int dim) {
- return dim == 0 && (type == DOUBLE || type == LONG);
+ return dim == 0 && (type == DOUBLE || type == LONG);
}
public int getMaxLocals() { return bytecode.getMaxLocals(); }
public void setMaxLocals(int n) {
- bytecode.setMaxLocals(n);
+ bytecode.setMaxLocals(n);
}
protected void incMaxLocals(int size) {
- bytecode.incMaxLocals(size);
+ bytecode.incMaxLocals(size);
}
/**
@@ -89,23 +78,23 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
* stored in.
*/
protected int getTempVar() {
- if (tempVar < 0) {
- tempVar = getMaxLocals();
- incMaxLocals(2);
- }
+ if (tempVar < 0) {
+ tempVar = getMaxLocals();
+ incMaxLocals(2);
+ }
- return tempVar;
+ return tempVar;
}
protected int getLocalVar(Declarator d) {
- int v = d.getLocalVar();
- if (v < 0) {
- v = getMaxLocals(); // delayed variable allocation.
- d.setLocalVar(v);
- incMaxLocals(1);
- }
+ int v = d.getLocalVar();
+ if (v < 0) {
+ v = getMaxLocals(); // delayed variable allocation.
+ d.setLocalVar(v);
+ incMaxLocals(1);
+ }
- return v;
+ return v;
}
/**
@@ -124,76 +113,76 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
* For example, this converts Object into java/lang/Object.
*/
protected abstract String resolveClassName(ASTList name)
- throws CompileError;
+ throws CompileError;
/* Expands a simple class name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
protected abstract String resolveClassName(String jvmClassName)
- throws CompileError;
+ throws CompileError;
/**
- * @param name the JVM-internal representation.
- * name is not exapnded to java.lang.*.
+ * @param name the JVM-internal representation.
+ * name is not exapnded to java.lang.*.
*/
protected static String toJvmArrayName(String name, int dim) {
- if (name == null)
- return null;
+ if (name == null)
+ return null;
- if (dim == 0)
- return name;
- else {
- StringBuffer sbuf = new StringBuffer();
- int d = dim;
- while (d-- > 0)
- sbuf.append('[');
+ if (dim == 0)
+ return name;
+ else {
+ StringBuffer sbuf = new StringBuffer();
+ int d = dim;
+ while (d-- > 0)
+ sbuf.append('[');
- sbuf.append('L');
- sbuf.append(name);
- sbuf.append(';');
+ sbuf.append('L');
+ sbuf.append(name);
+ sbuf.append(';');
- return sbuf.toString();
- }
+ return sbuf.toString();
+ }
}
protected static String toJvmTypeName(int type, int dim) {
- char c = 'I';
- switch(type) {
- case BOOLEAN :
- c = 'Z';
- break;
- case BYTE :
- c = 'B';
- break;
- case CHAR :
- c = 'C';
- break;
- case SHORT :
- c = 'S';
- break;
- case INT :
- c = 'I';
- break;
- case LONG :
- c = 'J';
- break;
- case FLOAT :
- c = 'F';
- break;
- case DOUBLE :
- c = 'D';
- break;
- case VOID :
- c = 'V';
- break;
- }
-
- StringBuffer sbuf = new StringBuffer();
- while (dim-- > 0)
- sbuf.append('[');
-
- sbuf.append(c);
- return sbuf.toString();
+ char c = 'I';
+ switch(type) {
+ case BOOLEAN :
+ c = 'Z';
+ break;
+ case BYTE :
+ c = 'B';
+ break;
+ case CHAR :
+ c = 'C';
+ break;
+ case SHORT :
+ c = 'S';
+ break;
+ case INT :
+ c = 'I';
+ break;
+ case LONG :
+ c = 'J';
+ break;
+ case FLOAT :
+ c = 'F';
+ break;
+ case DOUBLE :
+ c = 'D';
+ break;
+ case VOID :
+ c = 'V';
+ break;
+ }
+
+ StringBuffer sbuf = new StringBuffer();
+ while (dim-- > 0)
+ sbuf.append('[');
+
+ sbuf.append(c);
+ return sbuf.toString();
}
@@ -204,353 +193,353 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
public void atSymbol(Symbol n) throws CompileError { fatal(); }
public void atFieldDecl(FieldDecl field) throws CompileError {
- field.getInit().accept(this);
+ field.getInit().accept(this);
}
public void atMethodDecl(MethodDecl method) throws CompileError {
- ASTList mods = method.getModifiers();
- setMaxLocals(1);
- while (mods != null) {
- Keyword k = (Keyword)mods.head();
- mods = mods.tail();
- if (k.get() == STATIC) {
- setMaxLocals(0);
- inStaticMethod = true;
- }
- }
-
- ASTList params = method.getParams();
- while (params != null) {
- atDeclarator((Declarator)params.head());
- params = params.tail();
- }
-
- Stmnt s = method.getBody();
- atMethodBody(s, method.isConstructor(),
- method.getReturn().getType() == VOID);
+ ASTList mods = method.getModifiers();
+ setMaxLocals(1);
+ while (mods != null) {
+ Keyword k = (Keyword)mods.head();
+ mods = mods.tail();
+ if (k.get() == STATIC) {
+ setMaxLocals(0);
+ inStaticMethod = true;
+ }
+ }
+
+ ASTList params = method.getParams();
+ while (params != null) {
+ atDeclarator((Declarator)params.head());
+ params = params.tail();
+ }
+
+ Stmnt s = method.getBody();
+ atMethodBody(s, method.isConstructor(),
+ method.getReturn().getType() == VOID);
}
public void atMethodBody(Stmnt s, boolean isCons, boolean isVoid)
- throws CompileError
+ throws CompileError
{
- if (s == null)
- return;
+ if (s == null)
+ return;
- if (isCons && needsSuperCall(s))
- insertDefaultSuperCall();
+ if (isCons && needsSuperCall(s))
+ insertDefaultSuperCall();
- s.accept(this);
- if (isVoid
- && (bytecode.read(bytecode.currentPc() - 1) & 0xff)
- != Opcode.RETURN) {
- bytecode.addOpcode(Opcode.RETURN);
- }
+ s.accept(this);
+ if (isVoid
+ && (bytecode.read(bytecode.currentPc() - 1) & 0xff)
+ != Opcode.RETURN) {
+ bytecode.addOpcode(Opcode.RETURN);
+ }
}
private boolean needsSuperCall(Stmnt body) {
- if (body.getOperator() == BLOCK) {
- Stmnt first = (Stmnt)body.head();
- if (first != null && first.getOperator() == EXPR) {
- ASTree expr = first.head();
- if (expr != null && expr instanceof Expr
- && ((Expr)expr).getOperator() == CALL) {
- ASTree target = ((Expr)expr).head();
- if (target instanceof Keyword) {
- int token = ((Keyword)target).get();
- return token != THIS && token != SUPER;
- }
- }
- }
- }
-
- return true;
+ if (body.getOperator() == BLOCK) {
+ Stmnt first = (Stmnt)body.head();
+ if (first != null && first.getOperator() == EXPR) {
+ ASTree expr = first.head();
+ if (expr != null && expr instanceof Expr
+ && ((Expr)expr).getOperator() == CALL) {
+ ASTree target = ((Expr)expr).head();
+ if (target instanceof Keyword) {
+ int token = ((Keyword)target).get();
+ return token != THIS && token != SUPER;
+ }
+ }
+ }
+ }
+
+ return true;
}
protected abstract void insertDefaultSuperCall() throws CompileError;
public void atStmnt(Stmnt st) throws CompileError {
- if (st == null)
- return; // empty
-
- int op = st.getOperator();
- if (op == EXPR) {
- ASTree expr = st.getLeft();
- if (expr instanceof AssignExpr)
- atAssignExpr((AssignExpr)expr, false);
- else if (isPlusPlusExpr(expr)) {
- Expr e = (Expr)expr;
- atPlusPlus(e.getOperator(), e.oprand1(), e, false);
- }
- else {
- expr.accept(this);
- if (is2word(exprType, arrayDim))
- bytecode.addOpcode(POP2);
- else if (exprType != VOID)
- bytecode.addOpcode(POP);
- }
- }
- else if (op == DECL || op == BLOCK) {
- ASTList list = st;
- while (list != null) {
- ASTree h = list.head();
- list = list.tail();
- if (h != null)
- h.accept(this);
- }
- }
- else if (op == IF)
- atIfStmnt(st);
- else if (op == WHILE || op == DO)
- atWhileStmnt(st, op == WHILE);
- else if (op == FOR)
- atForStmnt(st);
- else if (op == BREAK || op == CONTINUE)
- atBreakStmnt(st, op == BREAK);
- else if (op == TokenId.RETURN)
- atReturnStmnt(st);
- else if (op == THROW)
- atThrowStmnt(st);
- else if (op == TRY)
- atTryStmnt(st);
- else // LABEL, SWITCH label stament might be null?.
- throw new CompileError(
- "sorry, not supported statement: TokenId " + op);
+ if (st == null)
+ return; // empty
+
+ int op = st.getOperator();
+ if (op == EXPR) {
+ ASTree expr = st.getLeft();
+ if (expr instanceof AssignExpr)
+ atAssignExpr((AssignExpr)expr, false);
+ else if (isPlusPlusExpr(expr)) {
+ Expr e = (Expr)expr;
+ atPlusPlus(e.getOperator(), e.oprand1(), e, false);
+ }
+ else {
+ expr.accept(this);
+ if (is2word(exprType, arrayDim))
+ bytecode.addOpcode(POP2);
+ else if (exprType != VOID)
+ bytecode.addOpcode(POP);
+ }
+ }
+ else if (op == DECL || op == BLOCK) {
+ ASTList list = st;
+ while (list != null) {
+ ASTree h = list.head();
+ list = list.tail();
+ if (h != null)
+ h.accept(this);
+ }
+ }
+ else if (op == IF)
+ atIfStmnt(st);
+ else if (op == WHILE || op == DO)
+ atWhileStmnt(st, op == WHILE);
+ else if (op == FOR)
+ atForStmnt(st);
+ else if (op == BREAK || op == CONTINUE)
+ atBreakStmnt(st, op == BREAK);
+ else if (op == TokenId.RETURN)
+ atReturnStmnt(st);
+ else if (op == THROW)
+ atThrowStmnt(st);
+ else if (op == TRY)
+ atTryStmnt(st);
+ else // LABEL, SWITCH label stament might be null?.
+ throw new CompileError(
+ "sorry, not supported statement: TokenId " + op);
}
private void atIfStmnt(Stmnt st) throws CompileError {
- ASTree expr = st.head();
- Stmnt thenp = (Stmnt)st.tail().head();
- Stmnt elsep = (Stmnt)st.tail().tail().head();
- booleanExpr(false, expr);
- int pc = bytecode.currentPc();
- int pc2 = 0;
- bytecode.addIndex(0); // correct later
+ ASTree expr = st.head();
+ Stmnt thenp = (Stmnt)st.tail().head();
+ Stmnt elsep = (Stmnt)st.tail().tail().head();
+ booleanExpr(false, expr);
+ int pc = bytecode.currentPc();
+ int pc2 = 0;
+ bytecode.addIndex(0); // correct later
- if (thenp != null)
- thenp.accept(this);
+ if (thenp != null)
+ thenp.accept(this);
- if (elsep != null) {
- bytecode.addOpcode(Opcode.GOTO);
- pc2 = bytecode.currentPc();
- bytecode.addIndex(0);
- }
+ if (elsep != null) {
+ bytecode.addOpcode(Opcode.GOTO);
+ pc2 = bytecode.currentPc();
+ bytecode.addIndex(0);
+ }
- bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
+ bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
- if (elsep != null) {
- elsep.accept(this);
- bytecode.write16bit(pc2, bytecode.currentPc() - pc2 + 1);
- }
+ if (elsep != null) {
+ elsep.accept(this);
+ bytecode.write16bit(pc2, bytecode.currentPc() - pc2 + 1);
+ }
}
private void atWhileStmnt(Stmnt st, boolean notDo) throws CompileError {
- ArrayList prevBreakList = breakList;
- ArrayList prevContList = continueList;
- breakList = new ArrayList();
- continueList = new ArrayList();
+ ArrayList prevBreakList = breakList;
+ ArrayList prevContList = continueList;
+ breakList = new ArrayList();
+ continueList = new ArrayList();
- ASTree expr = st.head();
- Stmnt body = (Stmnt)st.tail();
+ ASTree expr = st.head();
+ Stmnt body = (Stmnt)st.tail();
- int pc = 0;
- if (notDo) {
- bytecode.addOpcode(Opcode.GOTO);
- pc = bytecode.currentPc();
- bytecode.addIndex(0);
- }
+ int pc = 0;
+ if (notDo) {
+ bytecode.addOpcode(Opcode.GOTO);
+ pc = bytecode.currentPc();
+ bytecode.addIndex(0);
+ }
- int pc2 = bytecode.currentPc();
- if (body != null)
- body.accept(this);
+ int pc2 = bytecode.currentPc();
+ if (body != null)
+ body.accept(this);
- int pc3 = bytecode.currentPc();
- if (notDo)
- bytecode.write16bit(pc, pc3 - pc + 1);
+ int pc3 = bytecode.currentPc();
+ if (notDo)
+ bytecode.write16bit(pc, pc3 - pc + 1);
- booleanExpr(true, expr);
- bytecode.addIndex(pc2 - bytecode.currentPc() + 1);
+ booleanExpr(true, expr);
+ bytecode.addIndex(pc2 - bytecode.currentPc() + 1);
- patchGoto(breakList, bytecode.currentPc());
- patchGoto(continueList, pc3);
- continueList = prevContList;
- breakList = prevBreakList;
+ patchGoto(breakList, bytecode.currentPc());
+ patchGoto(continueList, pc3);
+ continueList = prevContList;
+ breakList = prevBreakList;
}
private void patchGoto(ArrayList list, int targetPc) {
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- int pc = ((Integer)list.get(i)).intValue();
- bytecode.write16bit(pc, targetPc - pc + 1);
- }
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ int pc = ((Integer)list.get(i)).intValue();
+ bytecode.write16bit(pc, targetPc - pc + 1);
+ }
}
private void atForStmnt(Stmnt st) throws CompileError {
- ArrayList prevBreakList = breakList;
- ArrayList prevContList = continueList;
- breakList = new ArrayList();
- continueList = new ArrayList();
+ ArrayList prevBreakList = breakList;
+ ArrayList prevContList = continueList;
+ breakList = new ArrayList();
+ continueList = new ArrayList();
- Stmnt init = (Stmnt)st.head();
- ASTList p = st.tail();
- ASTree expr = p.head();
- p = p.tail();
- Stmnt update = (Stmnt)p.head();
- Stmnt body = (Stmnt)p.tail();
+ Stmnt init = (Stmnt)st.head();
+ ASTList p = st.tail();
+ ASTree expr = p.head();
+ p = p.tail();
+ Stmnt update = (Stmnt)p.head();
+ Stmnt body = (Stmnt)p.tail();
- if (init != null)
- init.accept(this);
+ if (init != null)
+ init.accept(this);
- int pc = bytecode.currentPc();
- int pc2 = 0;
- if (expr != null) {
- booleanExpr(false, expr);
- pc2 = bytecode.currentPc();
- bytecode.addIndex(0);
- }
+ int pc = bytecode.currentPc();
+ int pc2 = 0;
+ if (expr != null) {
+ booleanExpr(false, expr);
+ pc2 = bytecode.currentPc();
+ bytecode.addIndex(0);
+ }
- if (body != null)
- body.accept(this);
+ if (body != null)
+ body.accept(this);
- int pc3 = bytecode.currentPc();
- if (update != null)
- update.accept(this);
+ int pc3 = bytecode.currentPc();
+ if (update != null)
+ update.accept(this);
- bytecode.addOpcode(Opcode.GOTO);
- bytecode.addIndex(pc - bytecode.currentPc() + 1);
+ bytecode.addOpcode(Opcode.GOTO);
+ bytecode.addIndex(pc - bytecode.currentPc() + 1);
- int pc4 = bytecode.currentPc();
- if (expr != null)
- bytecode.write16bit(pc2, pc4 - pc2 + 1);
+ int pc4 = bytecode.currentPc();
+ if (expr != null)
+ bytecode.write16bit(pc2, pc4 - pc2 + 1);
- patchGoto(breakList, pc4);
- patchGoto(continueList, pc3);
- continueList = prevContList;
- breakList = prevBreakList;
+ patchGoto(breakList, pc4);
+ patchGoto(continueList, pc3);
+ continueList = prevContList;
+ breakList = prevBreakList;
}
private void atBreakStmnt(Stmnt st, boolean notCont)
- throws CompileError
+ throws CompileError
{
- if (st.head() != null)
- throw new CompileError(
- "sorry, not support labeled break or continue");
+ if (st.head() != null)
+ throw new CompileError(
+ "sorry, not support labeled break or continue");
- bytecode.addOpcode(Opcode.GOTO);
- Integer pc = new Integer(bytecode.currentPc());
- bytecode.addIndex(0);
- if (notCont)
- breakList.add(pc);
- else
- continueList.add(pc);
+ bytecode.addOpcode(Opcode.GOTO);
+ Integer pc = new Integer(bytecode.currentPc());
+ bytecode.addIndex(0);
+ if (notCont)
+ breakList.add(pc);
+ else
+ continueList.add(pc);
}
protected void atReturnStmnt(Stmnt st) throws CompileError {
- atReturnStmnt2(st.getLeft());
+ atReturnStmnt2(st.getLeft());
}
protected final void atReturnStmnt2(ASTree result) throws CompileError {
- int op;
- if (result == null)
- op = Opcode.RETURN;
- else {
- result.accept(this);
- if (arrayDim > 0)
- op = ARETURN;
- else {
- int type = exprType;
- if (type == DOUBLE)
- op = DRETURN;
- else if (type == FLOAT)
- op = FRETURN;
- else if (type == LONG)
- op = LRETURN;
- else if (isRefType(type))
- op = ARETURN;
- else
- op = IRETURN;
- }
- }
-
- bytecode.addOpcode(op);
+ int op;
+ if (result == null)
+ op = Opcode.RETURN;
+ else {
+ result.accept(this);
+ if (arrayDim > 0)
+ op = ARETURN;
+ else {
+ int type = exprType;
+ if (type == DOUBLE)
+ op = DRETURN;
+ else if (type == FLOAT)
+ op = FRETURN;
+ else if (type == LONG)
+ op = LRETURN;
+ else if (isRefType(type))
+ op = ARETURN;
+ else
+ op = IRETURN;
+ }
+ }
+
+ bytecode.addOpcode(op);
}
private void atThrowStmnt(Stmnt st) throws CompileError {
- ASTree e = st.getLeft();
- e.accept(this);
- if (exprType != CLASS || arrayDim > 0)
- throw new CompileError("bad throw statement");
+ ASTree e = st.getLeft();
+ e.accept(this);
+ if (exprType != CLASS || arrayDim > 0)
+ throw new CompileError("bad throw statement");
- bytecode.addOpcode(ATHROW);
+ bytecode.addOpcode(ATHROW);
}
protected abstract void atTryStmnt(Stmnt st) throws CompileError;
private static boolean isPlusPlusExpr(ASTree expr) {
- if (expr instanceof Expr) {
- int op = ((Expr)expr).getOperator();
- return op == PLUSPLUS || op == MINUSMINUS;
- }
+ if (expr instanceof Expr) {
+ int op = ((Expr)expr).getOperator();
+ return op == PLUSPLUS || op == MINUSMINUS;
+ }
- return false;
+ return false;
}
public void atDeclarator(Declarator d) throws CompileError {
- d.setLocalVar(getMaxLocals());
- d.setClassName(resolveClassName(d.getClassName()));
+ d.setLocalVar(getMaxLocals());
+ d.setClassName(resolveClassName(d.getClassName()));
- int size;
- if (is2word(d.getType(), d.getArrayDim()))
- size = 2;
- else
- size = 1;
+ int size;
+ if (is2word(d.getType(), d.getArrayDim()))
+ size = 2;
+ else
+ size = 1;
- incMaxLocals(size);
+ incMaxLocals(size);
- /* NOTE: Array initializers has not been supported.
- */
- ASTree init = d.getInitializer();
- if (init != null)
- atVariableAssign(null, '=', null, d, init, false);
+ /* NOTE: Array initializers has not been supported.
+ */
+ ASTree init = d.getInitializer();
+ if (init != null)
+ atVariableAssign(null, '=', null, d, init, false);
}
public abstract void atNewExpr(NewExpr n) throws CompileError;
public void atAssignExpr(AssignExpr expr) throws CompileError {
- atAssignExpr(expr, true);
+ atAssignExpr(expr, true);
}
protected void atAssignExpr(AssignExpr expr, boolean doDup)
- throws CompileError
+ throws CompileError
{
- // =, %=, &=, *=, /=, +=, -=, ^=, |=, <<=, >>=, >>>=
- int op = expr.getOperator();
- ASTree left = expr.oprand1();
- ASTree right = expr.oprand2();
- if (left instanceof Variable)
- atVariableAssign(expr, op, (Variable)left,
- ((Variable)left).getDeclarator(),
- right, doDup);
- else {
- if (left instanceof Expr) {
- Expr e = (Expr)left;
- if (e.getOperator() == ARRAY) {
- atArrayAssign(expr, op, (Expr)left, right, doDup);
- return;
- }
- }
-
- atFieldAssign(expr, op, left, right, doDup);
- }
+ // =, %=, &=, *=, /=, +=, -=, ^=, |=, <<=, >>=, >>>=
+ int op = expr.getOperator();
+ ASTree left = expr.oprand1();
+ ASTree right = expr.oprand2();
+ if (left instanceof Variable)
+ atVariableAssign(expr, op, (Variable)left,
+ ((Variable)left).getDeclarator(),
+ right, doDup);
+ else {
+ if (left instanceof Expr) {
+ Expr e = (Expr)left;
+ if (e.getOperator() == ARRAY) {
+ atArrayAssign(expr, op, (Expr)left, right, doDup);
+ return;
+ }
+ }
+
+ atFieldAssign(expr, op, left, right, doDup);
+ }
}
protected static void badAssign(Expr expr) throws CompileError {
- String msg;
- if (expr == null)
- msg = "incompatible type for assignment";
- else
- msg = "incompatible type for " + expr.getName();
+ String msg;
+ if (expr == null)
+ msg = "incompatible type for assignment";
+ else
+ msg = "incompatible type for " + expr.getName();
- throw new CompileError(msg);
+ throw new CompileError(msg);
}
/* op is either =, %=, &=, *=, /=, +=, -=, ^=, |=, <<=, >>=, or >>>=.
@@ -558,187 +547,187 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
* expr and var can be null.
*/
private void atVariableAssign(Expr expr, int op, Variable var,
- Declarator d, ASTree right,
- boolean doDup) throws CompileError
+ Declarator d, ASTree right,
+ boolean doDup) throws CompileError
{
- int varType = d.getType();
- int varArray = d.getArrayDim();
- String varClass = d.getClassName();
- int varNo = getLocalVar(d);
-
- if (op != '=')
- atVariable(var);
-
- atAssignCore(expr, op, right, varType, varArray, varClass);
-
- if (doDup)
- if (is2word(varType, varArray))
- bytecode.addOpcode(DUP2);
- else
- bytecode.addOpcode(DUP);
-
- if (varArray > 0)
- bytecode.addAstore(varNo);
- else if (varType == DOUBLE)
- bytecode.addDstore(varNo);
- else if (varType == FLOAT)
- bytecode.addFstore(varNo);
- else if (varType == LONG)
- bytecode.addLstore(varNo);
- else if (isRefType(varType))
- bytecode.addAstore(varNo);
- else
- bytecode.addIstore(varNo);
-
- exprType = varType;
- arrayDim = varArray;
- className = varClass;
+ int varType = d.getType();
+ int varArray = d.getArrayDim();
+ String varClass = d.getClassName();
+ int varNo = getLocalVar(d);
+
+ if (op != '=')
+ atVariable(var);
+
+ atAssignCore(expr, op, right, varType, varArray, varClass);
+
+ if (doDup)
+ if (is2word(varType, varArray))
+ bytecode.addOpcode(DUP2);
+ else
+ bytecode.addOpcode(DUP);
+
+ if (varArray > 0)
+ bytecode.addAstore(varNo);
+ else if (varType == DOUBLE)
+ bytecode.addDstore(varNo);
+ else if (varType == FLOAT)
+ bytecode.addFstore(varNo);
+ else if (varType == LONG)
+ bytecode.addLstore(varNo);
+ else if (isRefType(varType))
+ bytecode.addAstore(varNo);
+ else
+ bytecode.addIstore(varNo);
+
+ exprType = varType;
+ arrayDim = varArray;
+ className = varClass;
}
private void atArrayAssign(Expr expr, int op, Expr array,
- ASTree right, boolean doDup) throws CompileError
+ ASTree right, boolean doDup) throws CompileError
{
- arrayAccess(array.oprand1(), array.oprand2());
+ arrayAccess(array.oprand1(), array.oprand2());
- if (op != '=') {
- bytecode.addOpcode(DUP2);
- bytecode.addOpcode(getArrayReadOp(exprType, arrayDim));
- }
+ if (op != '=') {
+ bytecode.addOpcode(DUP2);
+ bytecode.addOpcode(getArrayReadOp(exprType, arrayDim));
+ }
- int aType = exprType;
- int aDim = arrayDim;
- String cname = className;
+ int aType = exprType;
+ int aDim = arrayDim;
+ String cname = className;
- atAssignCore(expr, op, right, aType, aDim, cname);
+ atAssignCore(expr, op, right, aType, aDim, cname);
- if (doDup)
- if (is2word(aType, aDim))
- bytecode.addOpcode(DUP2_X2);
- else
- bytecode.addOpcode(DUP_X2);
+ if (doDup)
+ if (is2word(aType, aDim))
+ bytecode.addOpcode(DUP2_X2);
+ else
+ bytecode.addOpcode(DUP_X2);
- bytecode.addOpcode(getArrayWriteOp(aType, aDim));
- exprType = aType;
- arrayDim = aDim;
- className = cname;
+ bytecode.addOpcode(getArrayWriteOp(aType, aDim));
+ exprType = aType;
+ arrayDim = aDim;
+ className = cname;
}
protected abstract void atFieldAssign(Expr expr, int op, ASTree left,
- ASTree right, boolean doDup) throws CompileError;
+ ASTree right, boolean doDup) throws CompileError;
protected void atAssignCore(Expr expr, int op, ASTree right,
- int type, int dim, String cname)
- throws CompileError
+ int type, int dim, String cname)
+ throws CompileError
{
- right.accept(this);
- if (invalidDim(exprType, arrayDim, className, type, dim, cname, false)
- || (op != '=' && dim > 0))
- badAssign(expr);
+ right.accept(this);
+ if (invalidDim(exprType, arrayDim, className, type, dim, cname, false)
+ || (op != '=' && dim > 0))
+ badAssign(expr);
- if (op == PLUS_E && dim == 0 && type == CLASS)
- atStringConcatExpr(expr, type, dim, cname);
- else if (op != '=') {
- int token = assignOps[op - MOD_E];
- int k = lookupBinOp(token);
- if (k < 0)
- fatal();
+ if (op == PLUS_E && dim == 0 && type == CLASS)
+ atStringConcatExpr(expr, type, dim, cname);
+ else if (op != '=') {
+ int token = assignOps[op - MOD_E];
+ int k = lookupBinOp(token);
+ if (k < 0)
+ fatal();
- atArithBinExpr(expr, token, k, type);
- }
+ atArithBinExpr(expr, token, k, type);
+ }
- if (op != '=' || (dim == 0 && !isRefType(type)))
- atNumCastExpr(exprType, type);
+ if (op != '=' || (dim == 0 && !isRefType(type)))
+ atNumCastExpr(exprType, type);
- // type check should be done here.
+ // type check should be done here.
}
private boolean invalidDim(int srcType, int srcDim, String srcClass,
- int destType, int destDim, String destClass,
- boolean isCast)
+ int destType, int destDim, String destClass,
+ boolean isCast)
{
- if (srcDim != destDim)
- if (srcType == NULL)
- return false;
- else if (destDim == 0 && destType == CLASS
- && jvmJavaLangObject.equals(destClass))
- return false;
- else if (isCast && srcDim == 0 && srcType == CLASS
- && jvmJavaLangObject.equals(srcClass))
- return false;
- else
- return true;
+ if (srcDim != destDim)
+ if (srcType == NULL)
+ return false;
+ else if (destDim == 0 && destType == CLASS
+ && jvmJavaLangObject.equals(destClass))
+ return false;
+ else if (isCast && srcDim == 0 && srcType == CLASS
+ && jvmJavaLangObject.equals(srcClass))
+ return false;
+ else
+ return true;
- return false;
+ return false;
}
public void atCondExpr(CondExpr expr) throws CompileError {
- booleanExpr(false, expr.condExpr());
- int pc = bytecode.currentPc();
- bytecode.addIndex(0); // correct later
- expr.thenExpr().accept(this);
- bytecode.addOpcode(Opcode.GOTO);
- int pc2 = bytecode.currentPc();
- bytecode.addIndex(0);
- bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
- expr.elseExpr().accept(this);
- bytecode.write16bit(pc2, bytecode.currentPc() - pc2 + 1);
+ booleanExpr(false, expr.condExpr());
+ int pc = bytecode.currentPc();
+ bytecode.addIndex(0); // correct later
+ expr.thenExpr().accept(this);
+ bytecode.addOpcode(Opcode.GOTO);
+ int pc2 = bytecode.currentPc();
+ bytecode.addIndex(0);
+ bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
+ expr.elseExpr().accept(this);
+ bytecode.write16bit(pc2, bytecode.currentPc() - pc2 + 1);
}
private final int[] binOp = {
- '+', DADD, FADD, LADD, IADD,
- '-', DSUB, FSUB, LSUB, ISUB,
- '*', DMUL, FMUL, LMUL, IMUL,
- '/', DDIV, FDIV, LDIV, IDIV,
- '%', DREM, FREM, LREM, IREM,
- '|', NOP, NOP, LOR, IOR,
- '^', NOP, NOP, LXOR, IXOR,
- '&', NOP, NOP, LAND, IAND,
- LSHIFT, NOP, NOP, LSHL, ISHL,
- RSHIFT, NOP, NOP, LSHR, ISHR,
- ARSHIFT, NOP, NOP, LUSHR, IUSHR };
+ '+', DADD, FADD, LADD, IADD,
+ '-', DSUB, FSUB, LSUB, ISUB,
+ '*', DMUL, FMUL, LMUL, IMUL,
+ '/', DDIV, FDIV, LDIV, IDIV,
+ '%', DREM, FREM, LREM, IREM,
+ '|', NOP, NOP, LOR, IOR,
+ '^', NOP, NOP, LXOR, IXOR,
+ '&', NOP, NOP, LAND, IAND,
+ LSHIFT, NOP, NOP, LSHL, ISHL,
+ RSHIFT, NOP, NOP, LSHR, ISHR,
+ ARSHIFT, NOP, NOP, LUSHR, IUSHR };
private int lookupBinOp(int token) {
- int[] code = binOp;
- int s = code.length;
- for (int k = 0; k < s; k = k + 5)
- if (code[k] == token)
- return k;
+ int[] code = binOp;
+ int s = code.length;
+ for (int k = 0; k < s; k = k + 5)
+ if (code[k] == token)
+ return k;
- return -1;
+ return -1;
}
public void atBinExpr(BinExpr expr) throws CompileError {
- int token = expr.getOperator();
-
- /* arithmetic operators: +, -, *, /, %, |, ^, &, <<, >>, >>>
- */
- int k = lookupBinOp(token);
- if (k >= 0) {
- expr.oprand1().accept(this);
- int type1 = exprType;
- int dim1 = arrayDim;
- String cname1 = className;
- expr.oprand2().accept(this);
- if (dim1 != arrayDim)
- throw new CompileError("incompatible array types");
-
- if (token == '+' && dim1 == 0
- && (type1 == CLASS || exprType == CLASS))
- atStringConcatExpr(expr, type1, dim1, cname1);
- else
- atArithBinExpr(expr, token, k, type1);
-
- return;
- }
-
- /* equation: &&, ||, ==, !=, <=, >=, <, >
- */
- booleanExpr(true, expr);
- bytecode.addIndex(7);
- bytecode.addIconst(0); // false
- bytecode.addOpcode(Opcode.GOTO);
- bytecode.addIndex(4);
- bytecode.addIconst(1); // true
+ int token = expr.getOperator();
+
+ /* arithmetic operators: +, -, *, /, %, |, ^, &, <<, >>, >>>
+ */
+ int k = lookupBinOp(token);
+ if (k >= 0) {
+ expr.oprand1().accept(this);
+ int type1 = exprType;
+ int dim1 = arrayDim;
+ String cname1 = className;
+ expr.oprand2().accept(this);
+ if (dim1 != arrayDim)
+ throw new CompileError("incompatible array types");
+
+ if (token == '+' && dim1 == 0
+ && (type1 == CLASS || exprType == CLASS))
+ atStringConcatExpr(expr, type1, dim1, cname1);
+ else
+ atArithBinExpr(expr, token, k, type1);
+
+ return;
+ }
+
+ /* equation: &&, ||, ==, !=, <=, >=, <, >
+ */
+ booleanExpr(true, expr);
+ bytecode.addIndex(7);
+ bytecode.addIconst(0); // false
+ bytecode.addOpcode(Opcode.GOTO);
+ bytecode.addIndex(4);
+ bytecode.addIconst(1); // true
}
/* arrayDim values of the two oprands must be equal.
@@ -746,94 +735,94 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
* throws an exception.
*/
private void atArithBinExpr(Expr expr, int token,
- int index, int type1) throws CompileError
+ int index, int type1) throws CompileError
{
- if (arrayDim != 0)
- badTypes(expr);
-
- int type2 = exprType;
- if (token == LSHIFT || token == RSHIFT || token == ARSHIFT)
- if (type2 == INT || type2 == SHORT
- || type2 == CHAR || type2 == BYTE)
- exprType = type1;
- else
- badTypes(expr);
- else
- convertOprandTypes(type1, type2, expr);
-
- int p = typePrecedence(exprType);
- if (p >= 0) {
- int op = binOp[index + p + 1];
- if (op != NOP) {
- if (p == P_INT)
- exprType = INT; // type1 may be BYTE, ...
-
- bytecode.addOpcode(op);
- return;
- }
- }
-
- badTypes(expr);
+ if (arrayDim != 0)
+ badTypes(expr);
+
+ int type2 = exprType;
+ if (token == LSHIFT || token == RSHIFT || token == ARSHIFT)
+ if (type2 == INT || type2 == SHORT
+ || type2 == CHAR || type2 == BYTE)
+ exprType = type1;
+ else
+ badTypes(expr);
+ else
+ convertOprandTypes(type1, type2, expr);
+
+ int p = typePrecedence(exprType);
+ if (p >= 0) {
+ int op = binOp[index + p + 1];
+ if (op != NOP) {
+ if (p == P_INT)
+ exprType = INT; // type1 may be BYTE, ...
+
+ bytecode.addOpcode(op);
+ return;
+ }
+ }
+
+ badTypes(expr);
}
private void atStringConcatExpr(Expr expr, int type1, int dim1,
- String cname1) throws CompileError
+ String cname1) throws CompileError
{
- int type2 = exprType;
- int dim2 = arrayDim;
- boolean type2Is2 = is2word(type2, dim2);
- boolean type2IsString
- = (type2 == CLASS && jvmJavaLangString.equals(className));
+ int type2 = exprType;
+ int dim2 = arrayDim;
+ boolean type2Is2 = is2word(type2, dim2);
+ boolean type2IsString
+ = (type2 == CLASS && jvmJavaLangString.equals(className));
- if (type2Is2)
- convToString(type2, dim2);
+ if (type2Is2)
+ convToString(type2, dim2);
- if (is2word(type1, dim1)) {
- bytecode.addOpcode(DUP_X2);
- bytecode.addOpcode(POP);
- }
- else
- bytecode.addOpcode(SWAP);
+ if (is2word(type1, dim1)) {
+ bytecode.addOpcode(DUP_X2);
+ bytecode.addOpcode(POP);
+ }
+ else
+ bytecode.addOpcode(SWAP);
- convToString(type1, dim1);
- bytecode.addOpcode(SWAP);
+ convToString(type1, dim1);
+ bytecode.addOpcode(SWAP);
- if (!type2Is2 && !type2IsString)
- convToString(type2, dim2);
+ if (!type2Is2 && !type2IsString)
+ convToString(type2, dim2);
- bytecode.addInvokevirtual(javaLangString, "concat",
- "(Ljava/lang/String;)Ljava/lang/String;");
- exprType = CLASS;
- arrayDim = 0;
- className = jvmJavaLangString;
+ bytecode.addInvokevirtual(javaLangString, "concat",
+ "(Ljava/lang/String;)Ljava/lang/String;");
+ exprType = CLASS;
+ arrayDim = 0;
+ className = jvmJavaLangString;
}
private void convToString(int type, int dim) throws CompileError {
- final String method = "valueOf";
-
- if (isRefType(type) || dim > 0)
- bytecode.addInvokestatic(javaLangString, method,
- "(Ljava/lang/Object;)Ljava/lang/String;");
- else if (type == DOUBLE)
- bytecode.addInvokestatic(javaLangString, method,
- "(D)Ljava/lang/String;");
- else if (type == FLOAT)
- bytecode.addInvokestatic(javaLangString, method,
- "(F)Ljava/lang/String;");
- else if (type == LONG)
- bytecode.addInvokestatic(javaLangString, method,
- "(J)Ljava/lang/String;");
- else if (type == BOOLEAN)
- bytecode.addInvokestatic(javaLangString, method,
- "(Z)Ljava/lang/String;");
- else if (type == CHAR)
- bytecode.addInvokestatic(javaLangString, method,
- "(C)Ljava/lang/String;");
- else if (type == VOID)
- throw new CompileError("void type expression");
- else /* INT, BYTE, SHORT */
- bytecode.addInvokestatic(javaLangString, method,
- "(I)Ljava/lang/String;");
+ final String method = "valueOf";
+
+ if (isRefType(type) || dim > 0)
+ bytecode.addInvokestatic(javaLangString, method,
+ "(Ljava/lang/Object;)Ljava/lang/String;");
+ else if (type == DOUBLE)
+ bytecode.addInvokestatic(javaLangString, method,
+ "(D)Ljava/lang/String;");
+ else if (type == FLOAT)
+ bytecode.addInvokestatic(javaLangString, method,
+ "(F)Ljava/lang/String;");
+ else if (type == LONG)
+ bytecode.addInvokestatic(javaLangString, method,
+ "(J)Ljava/lang/String;");
+ else if (type == BOOLEAN)
+ bytecode.addInvokestatic(javaLangString, method,
+ "(Z)Ljava/lang/String;");
+ else if (type == CHAR)
+ bytecode.addInvokestatic(javaLangString, method,
+ "(C)Ljava/lang/String;");
+ else if (type == VOID)
+ throw new CompileError("void type expression");
+ else /* INT, BYTE, SHORT */
+ bytecode.addInvokestatic(javaLangString, method,
+ "(I)Ljava/lang/String;");
}
/* Produces the opcode to branch if the condition is true.
@@ -843,80 +832,80 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
* false.
*/
private void booleanExpr(boolean branchIf, ASTree expr)
- throws CompileError
+ throws CompileError
{
- boolean isAndAnd;
- int op = getCompOperator(expr);
- if (op == EQ) { // ==, !=, ...
- BinExpr bexpr = (BinExpr)expr;
- int type1 = compileOprands(bexpr);
- compareExpr(branchIf, bexpr.getOperator(), type1, bexpr);
- }
- else if (op == '!')
- booleanExpr(!branchIf, ((Expr)expr).oprand1());
- else if ((isAndAnd = (op == ANDAND)) || op == OROR) {
- BinExpr bexpr = (BinExpr)expr;
- booleanExpr(!isAndAnd, bexpr.oprand1());
- int pc = bytecode.currentPc();
- bytecode.addIndex(0); // correct later
-
- booleanExpr(isAndAnd, bexpr.oprand2());
- bytecode.write16bit(pc, bytecode.currentPc() - pc + 3);
- if (branchIf != isAndAnd) {
- bytecode.addIndex(6); // skip GOTO instruction
- bytecode.addOpcode(Opcode.GOTO);
- }
- }
- else { // others
- expr.accept(this);
- bytecode.addOpcode(branchIf ? IFNE : IFEQ);
- }
-
- exprType = BOOLEAN;
- arrayDim = 0;
+ boolean isAndAnd;
+ int op = getCompOperator(expr);
+ if (op == EQ) { // ==, !=, ...
+ BinExpr bexpr = (BinExpr)expr;
+ int type1 = compileOprands(bexpr);
+ compareExpr(branchIf, bexpr.getOperator(), type1, bexpr);
+ }
+ else if (op == '!')
+ booleanExpr(!branchIf, ((Expr)expr).oprand1());
+ else if ((isAndAnd = (op == ANDAND)) || op == OROR) {
+ BinExpr bexpr = (BinExpr)expr;
+ booleanExpr(!isAndAnd, bexpr.oprand1());
+ int pc = bytecode.currentPc();
+ bytecode.addIndex(0); // correct later
+
+ booleanExpr(isAndAnd, bexpr.oprand2());
+ bytecode.write16bit(pc, bytecode.currentPc() - pc + 3);
+ if (branchIf != isAndAnd) {
+ bytecode.addIndex(6); // skip GOTO instruction
+ bytecode.addOpcode(Opcode.GOTO);
+ }
+ }
+ else { // others
+ expr.accept(this);
+ bytecode.addOpcode(branchIf ? IFNE : IFEQ);
+ }
+
+ exprType = BOOLEAN;
+ arrayDim = 0;
}
private static int getCompOperator(ASTree expr) throws CompileError {
- if (expr instanceof Expr) {
- Expr bexpr = (Expr)expr;
- int token = bexpr.getOperator();
- if (token == '!')
- return '!';
- else if ((bexpr instanceof BinExpr)
- && token != OROR && token != ANDAND
- && token != '&' && token != '|')
- return EQ; // ==, !=, ...
- else
- return token;
- }
-
- return ' '; // others
+ if (expr instanceof Expr) {
+ Expr bexpr = (Expr)expr;
+ int token = bexpr.getOperator();
+ if (token == '!')
+ return '!';
+ else if ((bexpr instanceof BinExpr)
+ && token != OROR && token != ANDAND
+ && token != '&' && token != '|')
+ return EQ; // ==, !=, ...
+ else
+ return token;
+ }
+
+ return ' '; // others
}
private int compileOprands(BinExpr expr) throws CompileError {
- expr.oprand1().accept(this);
- int type1 = exprType;
- int dim1 = arrayDim;
- expr.oprand2().accept(this);
- if (dim1 != arrayDim)
- throw new CompileError("incompatible array types");
+ expr.oprand1().accept(this);
+ int type1 = exprType;
+ int dim1 = arrayDim;
+ expr.oprand2().accept(this);
+ if (dim1 != arrayDim)
+ throw new CompileError("incompatible array types");
- return type1;
+ return type1;
}
private final int ifOp[] = { EQ, IF_ICMPEQ, IF_ICMPNE,
- NEQ, IF_ICMPNE, IF_ICMPEQ,
- LE, IF_ICMPLE, IF_ICMPGT,
- GE, IF_ICMPGE, IF_ICMPLT,
- '<', IF_ICMPLT, IF_ICMPGE,
- '>', IF_ICMPGT, IF_ICMPLE };
+ NEQ, IF_ICMPNE, IF_ICMPEQ,
+ LE, IF_ICMPLE, IF_ICMPGT,
+ GE, IF_ICMPGE, IF_ICMPLT,
+ '<', IF_ICMPLT, IF_ICMPGE,
+ '>', IF_ICMPGT, IF_ICMPLE };
private final int ifOp2[] = { EQ, IFEQ, IFNE,
- NEQ, IFNE, IFEQ,
- LE, IFLE, IFGT,
- GE, IFGE, IFLT,
- '<', IFLT, IFGE,
- '>', IFGT, IFLE };
+ NEQ, IFNE, IFEQ,
+ LE, IFLE, IFGT,
+ GE, IFGE, IFLT,
+ '<', IFLT, IFGE,
+ '>', IFGT, IFLE };
/* Produces the opcode to branch if the condition is true.
* The oprands are not produced.
@@ -924,60 +913,60 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
* Parameter expr - compare expression ==, !=, <=, >=, <, >
*/
private void compareExpr(boolean branchIf,
- int token, int type1, BinExpr expr)
- throws CompileError
+ int token, int type1, BinExpr expr)
+ throws CompileError
{
- if (arrayDim == 0)
- convertOprandTypes(type1, exprType, expr);
-
- int p = typePrecedence(exprType);
- if (p == P_OTHER || arrayDim > 0)
- if (token == EQ)
- bytecode.addOpcode(branchIf ? IF_ACMPEQ : IF_ACMPNE);
- else if (token == NEQ)
- bytecode.addOpcode(branchIf ? IF_ACMPNE : IF_ACMPEQ);
- else
- badTypes(expr);
- else
- if (p == P_INT) {
- int op[] = ifOp;
- for (int i = 0; i < op.length; i += 3)
- if (op[i] == token) {
- bytecode.addOpcode(op[i + (branchIf ? 1 : 2)]);
- return;
- }
-
- badTypes(expr);
- }
- else {
- if (p == P_DOUBLE)
- if (token == '<' || token == LE)
- bytecode.addOpcode(DCMPG);
- else
- bytecode.addOpcode(DCMPL);
- else if (p == P_FLOAT)
- if (token == '<' || token == LE)
- bytecode.addOpcode(FCMPG);
- else
- bytecode.addOpcode(FCMPL);
- else if (p == P_LONG)
- bytecode.addOpcode(LCMP); // 1: >, 0: =, -1: <
- else
- fatal();
-
- int[] op = ifOp2;
- for (int i = 0; i < op.length; i += 3)
- if (op[i] == token) {
- bytecode.addOpcode(op[i + (branchIf ? 1 : 2)]);
- return;
- }
-
- badTypes(expr);
- }
+ if (arrayDim == 0)
+ convertOprandTypes(type1, exprType, expr);
+
+ int p = typePrecedence(exprType);
+ if (p == P_OTHER || arrayDim > 0)
+ if (token == EQ)
+ bytecode.addOpcode(branchIf ? IF_ACMPEQ : IF_ACMPNE);
+ else if (token == NEQ)
+ bytecode.addOpcode(branchIf ? IF_ACMPNE : IF_ACMPEQ);
+ else
+ badTypes(expr);
+ else
+ if (p == P_INT) {
+ int op[] = ifOp;
+ for (int i = 0; i < op.length; i += 3)
+ if (op[i] == token) {
+ bytecode.addOpcode(op[i + (branchIf ? 1 : 2)]);
+ return;
+ }
+
+ badTypes(expr);
+ }
+ else {
+ if (p == P_DOUBLE)
+ if (token == '<' || token == LE)
+ bytecode.addOpcode(DCMPG);
+ else
+ bytecode.addOpcode(DCMPL);
+ else if (p == P_FLOAT)
+ if (token == '<' || token == LE)
+ bytecode.addOpcode(FCMPG);
+ else
+ bytecode.addOpcode(FCMPL);
+ else if (p == P_LONG)
+ bytecode.addOpcode(LCMP); // 1: >, 0: =, -1: <
+ else
+ fatal();
+
+ int[] op = ifOp2;
+ for (int i = 0; i < op.length; i += 3)
+ if (op[i] == token) {
+ bytecode.addOpcode(op[i + (branchIf ? 1 : 2)]);
+ return;
+ }
+
+ badTypes(expr);
+ }
}
protected static void badTypes(Expr expr) throws CompileError {
- throw new CompileError("invalid types for " + expr.getName());
+ throw new CompileError("invalid types for " + expr.getName());
}
private static final int P_DOUBLE = 0;
@@ -987,244 +976,244 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
private static final int P_OTHER = -1;
protected static boolean isRefType(int type) {
- return type == CLASS || type == NULL;
+ return type == CLASS || type == NULL;
}
private static int typePrecedence(int type) {
- if (type == DOUBLE)
- return P_DOUBLE;
- else if (type == FLOAT)
- return P_FLOAT;
- else if (type == LONG)
- return P_LONG;
- else if (isRefType(type))
- return P_OTHER;
- else if (type == VOID)
- return P_OTHER; // this is wrong, but ...
- else
- return P_INT; // BOOLEAN, BYTE, CHAR, SHORT, INT
+ if (type == DOUBLE)
+ return P_DOUBLE;
+ else if (type == FLOAT)
+ return P_FLOAT;
+ else if (type == LONG)
+ return P_LONG;
+ else if (isRefType(type))
+ return P_OTHER;
+ else if (type == VOID)
+ return P_OTHER; // this is wrong, but ...
+ else
+ return P_INT; // BOOLEAN, BYTE, CHAR, SHORT, INT
}
private static final int[] castOp = {
- /* D F L I */
- /* double */ NOP, D2F, D2L, D2I,
- /* float */ F2D, NOP, F2L, F2I,
- /* long */ L2D, L2F, NOP, L2I,
- /* other */ I2D, I2F, I2L, NOP };
+ /* D F L I */
+ /* double */ NOP, D2F, D2L, D2I,
+ /* float */ F2D, NOP, F2L, F2I,
+ /* long */ L2D, L2F, NOP, L2I,
+ /* other */ I2D, I2F, I2L, NOP };
/* do implicit type conversion.
* arrayDim values of the two oprands must be zero.
*/
private void convertOprandTypes(int type1, int type2, Expr expr)
- throws CompileError
+ throws CompileError
{
- boolean rightStrong;
- int type1_p = typePrecedence(type1);
- int type2_p = typePrecedence(type2);
-
- if (type2_p < 0 && type1_p < 0) // not primitive types
- return;
-
- if (type2_p < 0 || type1_p < 0) // either is not a primitive type
- badTypes(expr);
-
- int op, result_type;
- if (type1_p <= type2_p) {
- rightStrong = false;
- exprType = type1;
- op = castOp[type2_p * 4 + type1_p];
- result_type = type1_p;
- }
- else {
- rightStrong = true;
- op = castOp[type1_p * 4 + type2_p];
- result_type = type2_p;
- }
-
- if (rightStrong) {
- if (result_type == P_DOUBLE || result_type == P_LONG) {
- if (type1_p == P_DOUBLE || type1_p == P_LONG)
- bytecode.addOpcode(DUP2_X2);
- else
- bytecode.addOpcode(DUP2_X1);
-
- bytecode.addOpcode(POP2);
- bytecode.addOpcode(op);
- bytecode.addOpcode(DUP2_X2);
- bytecode.addOpcode(POP2);
- }
- else if (result_type == P_FLOAT) {
- bytecode.addOpcode(SWAP);
- bytecode.addOpcode(op);
- bytecode.addOpcode(SWAP);
- }
- else
- fatal();
- }
- else if (op != NOP)
- bytecode.addOpcode(op);
+ boolean rightStrong;
+ int type1_p = typePrecedence(type1);
+ int type2_p = typePrecedence(type2);
+
+ if (type2_p < 0 && type1_p < 0) // not primitive types
+ return;
+
+ if (type2_p < 0 || type1_p < 0) // either is not a primitive type
+ badTypes(expr);
+
+ int op, result_type;
+ if (type1_p <= type2_p) {
+ rightStrong = false;
+ exprType = type1;
+ op = castOp[type2_p * 4 + type1_p];
+ result_type = type1_p;
+ }
+ else {
+ rightStrong = true;
+ op = castOp[type1_p * 4 + type2_p];
+ result_type = type2_p;
+ }
+
+ if (rightStrong) {
+ if (result_type == P_DOUBLE || result_type == P_LONG) {
+ if (type1_p == P_DOUBLE || type1_p == P_LONG)
+ bytecode.addOpcode(DUP2_X2);
+ else
+ bytecode.addOpcode(DUP2_X1);
+
+ bytecode.addOpcode(POP2);
+ bytecode.addOpcode(op);
+ bytecode.addOpcode(DUP2_X2);
+ bytecode.addOpcode(POP2);
+ }
+ else if (result_type == P_FLOAT) {
+ bytecode.addOpcode(SWAP);
+ bytecode.addOpcode(op);
+ bytecode.addOpcode(SWAP);
+ }
+ else
+ fatal();
+ }
+ else if (op != NOP)
+ bytecode.addOpcode(op);
}
public void atCastExpr(CastExpr expr) throws CompileError {
- String cname = resolveClassName(expr.getClassName());
- String toClass = checkCastExpr(expr, cname);
- int srcType = exprType;
- exprType = expr.getType();
- arrayDim = expr.getArrayDim();
- className = cname;
- if (toClass == null)
- atNumCastExpr(srcType, exprType); // built-in type
- else
- bytecode.addCheckcast(toClass);
+ String cname = resolveClassName(expr.getClassName());
+ String toClass = checkCastExpr(expr, cname);
+ int srcType = exprType;
+ exprType = expr.getType();
+ arrayDim = expr.getArrayDim();
+ className = cname;
+ if (toClass == null)
+ atNumCastExpr(srcType, exprType); // built-in type
+ else
+ bytecode.addCheckcast(toClass);
}
public void atInstanceOfExpr(InstanceOfExpr expr) throws CompileError {
- String cname = resolveClassName(expr.getClassName());
- String toClass = checkCastExpr(expr, cname);
- bytecode.addInstanceof(toClass);
- exprType = BOOLEAN;
- arrayDim = 0;
+ String cname = resolveClassName(expr.getClassName());
+ String toClass = checkCastExpr(expr, cname);
+ bytecode.addInstanceof(toClass);
+ exprType = BOOLEAN;
+ arrayDim = 0;
}
private String checkCastExpr(CastExpr expr, String name)
- throws CompileError
+ throws CompileError
{
- final String msg = "invalid cast";
- ASTree oprand = expr.getOprand();
- int dim = expr.getArrayDim();
- int type = expr.getType();
- oprand.accept(this);
- int srcType = exprType;
- if (invalidDim(srcType, arrayDim, className, type, dim, name, true)
- || srcType == VOID || type == VOID)
- throw new CompileError(msg);
-
- if (type == CLASS) {
- if (!isRefType(srcType))
- throw new CompileError(msg);
-
- return toJvmArrayName(name, dim);
- }
- else
- if (dim > 0)
- return toJvmTypeName(type, dim);
- else
- return null; // built-in type
+ final String msg = "invalid cast";
+ ASTree oprand = expr.getOprand();
+ int dim = expr.getArrayDim();
+ int type = expr.getType();
+ oprand.accept(this);
+ int srcType = exprType;
+ if (invalidDim(srcType, arrayDim, className, type, dim, name, true)
+ || srcType == VOID || type == VOID)
+ throw new CompileError(msg);
+
+ if (type == CLASS) {
+ if (!isRefType(srcType))
+ throw new CompileError(msg);
+
+ return toJvmArrayName(name, dim);
+ }
+ else
+ if (dim > 0)
+ return toJvmTypeName(type, dim);
+ else
+ return null; // built-in type
}
void atNumCastExpr(int srcType, int destType)
- throws CompileError
+ throws CompileError
{
- if (srcType == destType)
- return;
-
- int op, op2;
- int stype = typePrecedence(srcType);
- int dtype = typePrecedence(destType);
- if (0 <= stype && stype < 3)
- op = castOp[stype * 4 + dtype];
- else
- op = NOP;
-
- if (destType == DOUBLE)
- op2 = I2D;
- else if (destType == FLOAT)
- op2 = I2F;
- else if (destType == LONG)
- op2 = I2L;
- else if (destType == SHORT)
- op2 = I2S;
- else if (destType == CHAR)
- op2 = I2C;
- else if (destType == BYTE)
- op2 = I2B;
- else
- op2 = NOP;
-
- if (op != NOP)
- bytecode.addOpcode(op);
-
- if (op == NOP || op == L2I || op == F2I || op == D2I)
- if (op2 != NOP)
- bytecode.addOpcode(op2);
+ if (srcType == destType)
+ return;
+
+ int op, op2;
+ int stype = typePrecedence(srcType);
+ int dtype = typePrecedence(destType);
+ if (0 <= stype && stype < 3)
+ op = castOp[stype * 4 + dtype];
+ else
+ op = NOP;
+
+ if (destType == DOUBLE)
+ op2 = I2D;
+ else if (destType == FLOAT)
+ op2 = I2F;
+ else if (destType == LONG)
+ op2 = I2L;
+ else if (destType == SHORT)
+ op2 = I2S;
+ else if (destType == CHAR)
+ op2 = I2C;
+ else if (destType == BYTE)
+ op2 = I2B;
+ else
+ op2 = NOP;
+
+ if (op != NOP)
+ bytecode.addOpcode(op);
+
+ if (op == NOP || op == L2I || op == F2I || op == D2I)
+ if (op2 != NOP)
+ bytecode.addOpcode(op2);
}
public void atExpr(Expr expr) throws CompileError {
- // method call, array access, member access,
- // (unary) +, (unary) -, ++, --, !, ~
-
- int token = expr.getOperator();
- ASTree oprand = expr.oprand1();
- if (token == CALL) // method call
- atMethodCall(expr);
- else if (token == '.')
- if (((Symbol)expr.oprand2()).get().equals("length"))
- atArrayLength(expr);
- else
- atFieldRead(expr);
- else if (token == MEMBER) { // field read
- if (!atClassObject(expr)) // .class
- atFieldRead(expr);
- }
- else if (token == ARRAY)
- atArrayRead(oprand, expr.oprand2());
- else if (token == PLUSPLUS || token == MINUSMINUS)
- atPlusPlus(token, oprand, expr, true);
- else if (token == '!') {
- booleanExpr(false, expr);
- bytecode.addIndex(7);
- bytecode.addIconst(1);
- bytecode.addOpcode(Opcode.GOTO);
- bytecode.addIndex(4);
- bytecode.addIconst(0);
- }
- else {
- expr.oprand1().accept(this);
- int type = typePrecedence(exprType);
- if (arrayDim > 0)
- badType(expr);
-
- if (token == '-') {
- if (type == P_DOUBLE)
- bytecode.addOpcode(DNEG);
- else if (type == P_FLOAT)
- bytecode.addOpcode(FNEG);
- else if (type == P_LONG)
- bytecode.addOpcode(LNEG);
- else if (type == P_INT) {
- bytecode.addOpcode(INEG);
- exprType = INT; // type may be BYTE, ...
- }
- else
- badType(expr);
- }
- else if (token == '~') {
- if (type == P_INT) {
- bytecode.addIconst(-1);
- bytecode.addOpcode(IXOR);
- exprType = INT; // type may be BYTE. ...
- }
- else if (type == P_LONG) {
- bytecode.addLconst(-1);
- bytecode.addOpcode(LXOR);
- }
- else
- badType(expr);
-
- }
- else if (token == '+') {
- if (type == P_OTHER)
- badType(expr);
-
- // do nothing. ignore.
- }
- else
- fatal();
- }
+ // method call, array access, member access,
+ // (unary) +, (unary) -, ++, --, !, ~
+
+ int token = expr.getOperator();
+ ASTree oprand = expr.oprand1();
+ if (token == CALL) // method call
+ atMethodCall(expr);
+ else if (token == '.')
+ if (((Symbol)expr.oprand2()).get().equals("length"))
+ atArrayLength(expr);
+ else
+ atFieldRead(expr);
+ else if (token == MEMBER) { // field read
+ if (!atClassObject(expr)) // .class
+ atFieldRead(expr);
+ }
+ else if (token == ARRAY)
+ atArrayRead(oprand, expr.oprand2());
+ else if (token == PLUSPLUS || token == MINUSMINUS)
+ atPlusPlus(token, oprand, expr, true);
+ else if (token == '!') {
+ booleanExpr(false, expr);
+ bytecode.addIndex(7);
+ bytecode.addIconst(1);
+ bytecode.addOpcode(Opcode.GOTO);
+ bytecode.addIndex(4);
+ bytecode.addIconst(0);
+ }
+ else {
+ expr.oprand1().accept(this);
+ int type = typePrecedence(exprType);
+ if (arrayDim > 0)
+ badType(expr);
+
+ if (token == '-') {
+ if (type == P_DOUBLE)
+ bytecode.addOpcode(DNEG);
+ else if (type == P_FLOAT)
+ bytecode.addOpcode(FNEG);
+ else if (type == P_LONG)
+ bytecode.addOpcode(LNEG);
+ else if (type == P_INT) {
+ bytecode.addOpcode(INEG);
+ exprType = INT; // type may be BYTE, ...
+ }
+ else
+ badType(expr);
+ }
+ else if (token == '~') {
+ if (type == P_INT) {
+ bytecode.addIconst(-1);
+ bytecode.addOpcode(IXOR);
+ exprType = INT; // type may be BYTE. ...
+ }
+ else if (type == P_LONG) {
+ bytecode.addLconst(-1);
+ bytecode.addOpcode(LXOR);
+ }
+ else
+ badType(expr);
+
+ }
+ else if (token == '+') {
+ if (type == P_OTHER)
+ badType(expr);
+
+ // do nothing. ignore.
+ }
+ else
+ fatal();
+ }
}
protected static void badType(Expr expr) throws CompileError {
- throw new CompileError("invalid type for " + expr.getName());
+ throw new CompileError("invalid type for " + expr.getName());
}
protected abstract void atMethodCall(Expr expr) throws CompileError;
@@ -1232,328 +1221,328 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
protected abstract void atFieldRead(ASTree expr) throws CompileError;
public boolean atClassObject(Expr expr) throws CompileError {
- if (!((Symbol)expr.oprand2()).get().equals("class"))
- return false;
+ if (!((Symbol)expr.oprand2()).get().equals("class"))
+ return false;
- if (resolveClassName((ASTList)expr.oprand1()) == null)
- return false;
+ if (resolveClassName((ASTList)expr.oprand1()) == null)
+ return false;
- throw new CompileError(".class is not supported");
+ throw new CompileError(".class is not supported");
}
public void atArrayLength(Expr expr) throws CompileError {
- expr.oprand1().accept(this);
- if (arrayDim == 0)
- throw new CompileError(".length applied to a non array");
+ expr.oprand1().accept(this);
+ if (arrayDim == 0)
+ throw new CompileError(".length applied to a non array");
- bytecode.addOpcode(ARRAYLENGTH);
- exprType = INT;
- arrayDim = 0;
+ bytecode.addOpcode(ARRAYLENGTH);
+ exprType = INT;
+ arrayDim = 0;
}
public void atArrayRead(ASTree array, ASTree index)
- throws CompileError
+ throws CompileError
{
- int op;
- arrayAccess(array, index);
- bytecode.addOpcode(getArrayReadOp(exprType, arrayDim));
+ int op;
+ arrayAccess(array, index);
+ bytecode.addOpcode(getArrayReadOp(exprType, arrayDim));
}
protected void arrayAccess(ASTree array, ASTree index)
- throws CompileError
+ throws CompileError
{
- array.accept(this);
- int type = exprType;
- int dim = arrayDim;
- if (dim == 0)
- throw new CompileError("bad array access");
+ array.accept(this);
+ int type = exprType;
+ int dim = arrayDim;
+ if (dim == 0)
+ throw new CompileError("bad array access");
- String cname = className;
+ String cname = className;
- index.accept(this);
- if (typePrecedence(exprType) != P_INT || arrayDim > 0)
- throw new CompileError("bad array index");
+ index.accept(this);
+ if (typePrecedence(exprType) != P_INT || arrayDim > 0)
+ throw new CompileError("bad array index");
- exprType = type;
- arrayDim = dim - 1;
- className = cname;
+ exprType = type;
+ arrayDim = dim - 1;
+ className = cname;
}
protected static int getArrayReadOp(int type, int dim) {
- int op;
- if (dim > 0)
- return AALOAD;
-
- switch (type) {
- case DOUBLE :
- return DALOAD;
- case FLOAT :
- return FALOAD;
- case LONG :
- return LALOAD;
- case INT :
- return IALOAD;
- case SHORT :
- return SALOAD;
- case CHAR :
- return CALOAD;
- case BYTE :
- case BOOLEAN :
- return BALOAD;
- default :
- return AALOAD;
- }
+ int op;
+ if (dim > 0)
+ return AALOAD;
+
+ switch (type) {
+ case DOUBLE :
+ return DALOAD;
+ case FLOAT :
+ return FALOAD;
+ case LONG :
+ return LALOAD;
+ case INT :
+ return IALOAD;
+ case SHORT :
+ return SALOAD;
+ case CHAR :
+ return CALOAD;
+ case BYTE :
+ case BOOLEAN :
+ return BALOAD;
+ default :
+ return AALOAD;
+ }
}
protected static int getArrayWriteOp(int type, int dim) {
- int op;
- if (dim > 0)
- return AASTORE;
-
- switch (type) {
- case DOUBLE :
- return DASTORE;
- case FLOAT :
- return FASTORE;
- case LONG :
- return LASTORE;
- case INT :
- return IASTORE;
- case CHAR :
- return CASTORE;
- case BYTE :
- case BOOLEAN :
- return BASTORE;
- default :
- return AASTORE;
- }
+ int op;
+ if (dim > 0)
+ return AASTORE;
+
+ switch (type) {
+ case DOUBLE :
+ return DASTORE;
+ case FLOAT :
+ return FASTORE;
+ case LONG :
+ return LASTORE;
+ case INT :
+ return IASTORE;
+ case CHAR :
+ return CASTORE;
+ case BYTE :
+ case BOOLEAN :
+ return BASTORE;
+ default :
+ return AASTORE;
+ }
}
private void atPlusPlus(int token, ASTree oprand, Expr expr,
- boolean doDup) throws CompileError
+ boolean doDup) throws CompileError
{
- boolean isPost = oprand == null; // ++i or i++?
- if (isPost)
- oprand = expr.oprand2();
-
- if (oprand instanceof Variable) {
- Declarator d = ((Variable)oprand).getDeclarator();
- int t = exprType = d.getType();
- arrayDim = d.getArrayDim();
- int var = getLocalVar(d);
- if (arrayDim > 0)
- badType(expr);
-
- if (t == DOUBLE) {
- bytecode.addDload(var);
- if (doDup && isPost)
- bytecode.addOpcode(DUP2);
-
- bytecode.addDconst(1.0);
- bytecode.addOpcode(token == PLUSPLUS ? DADD : DSUB);
- if (doDup && !isPost)
- bytecode.addOpcode(DUP2);
-
- bytecode.addDstore(var);
- }
- else if (t == LONG) {
- bytecode.addLload(var);
- if (doDup && isPost)
- bytecode.addOpcode(DUP2);
-
- bytecode.addLconst((long)1);
- bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB);
- if (doDup && !isPost)
- bytecode.addOpcode(DUP2);
-
- bytecode.addLstore(var);
- }
- else if (t == FLOAT) {
- bytecode.addFload(var);
- if (doDup && isPost)
- bytecode.addOpcode(DUP);
-
- bytecode.addFconst(1.0f);
- bytecode.addOpcode(token == PLUSPLUS ? FADD : FSUB);
- if (doDup && !isPost)
- bytecode.addOpcode(DUP);
-
- bytecode.addFstore(var);
- }
- else if (t == BYTE || t == CHAR || t == SHORT || t == INT) {
- if (doDup && isPost)
- bytecode.addIload(var);
-
- bytecode.addOpcode(IINC);
- bytecode.add(var);
- bytecode.add(token == PLUSPLUS ? 1 : -1);
-
- if (doDup && !isPost)
- bytecode.addIload(var);
- }
- else
- badType(expr);
- }
- else {
- if (oprand instanceof Expr) {
- Expr e = (Expr)oprand;
- if (e.getOperator() == ARRAY) {
- atArrayPlusPlus(token, isPost, e, doDup);
- return;
- }
- }
-
- atFieldPlusPlus(token, isPost, oprand, expr, doDup);
- }
+ boolean isPost = oprand == null; // ++i or i++?
+ if (isPost)
+ oprand = expr.oprand2();
+
+ if (oprand instanceof Variable) {
+ Declarator d = ((Variable)oprand).getDeclarator();
+ int t = exprType = d.getType();
+ arrayDim = d.getArrayDim();
+ int var = getLocalVar(d);
+ if (arrayDim > 0)
+ badType(expr);
+
+ if (t == DOUBLE) {
+ bytecode.addDload(var);
+ if (doDup && isPost)
+ bytecode.addOpcode(DUP2);
+
+ bytecode.addDconst(1.0);
+ bytecode.addOpcode(token == PLUSPLUS ? DADD : DSUB);
+ if (doDup && !isPost)
+ bytecode.addOpcode(DUP2);
+
+ bytecode.addDstore(var);
+ }
+ else if (t == LONG) {
+ bytecode.addLload(var);
+ if (doDup && isPost)
+ bytecode.addOpcode(DUP2);
+
+ bytecode.addLconst((long)1);
+ bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB);
+ if (doDup && !isPost)
+ bytecode.addOpcode(DUP2);
+
+ bytecode.addLstore(var);
+ }
+ else if (t == FLOAT) {
+ bytecode.addFload(var);
+ if (doDup && isPost)
+ bytecode.addOpcode(DUP);
+
+ bytecode.addFconst(1.0f);
+ bytecode.addOpcode(token == PLUSPLUS ? FADD : FSUB);
+ if (doDup && !isPost)
+ bytecode.addOpcode(DUP);
+
+ bytecode.addFstore(var);
+ }
+ else if (t == BYTE || t == CHAR || t == SHORT || t == INT) {
+ if (doDup && isPost)
+ bytecode.addIload(var);
+
+ bytecode.addOpcode(IINC);
+ bytecode.add(var);
+ bytecode.add(token == PLUSPLUS ? 1 : -1);
+
+ if (doDup && !isPost)
+ bytecode.addIload(var);
+ }
+ else
+ badType(expr);
+ }
+ else {
+ if (oprand instanceof Expr) {
+ Expr e = (Expr)oprand;
+ if (e.getOperator() == ARRAY) {
+ atArrayPlusPlus(token, isPost, e, doDup);
+ return;
+ }
+ }
+
+ atFieldPlusPlus(token, isPost, oprand, expr, doDup);
+ }
}
public void atArrayPlusPlus(int token, boolean isPost,
- Expr expr, boolean doDup) throws CompileError
+ Expr expr, boolean doDup) throws CompileError
{
- arrayAccess(expr.oprand1(), expr.oprand2());
- int t = exprType;
- int dim = arrayDim;
- if (dim > 0)
- badType(expr);
+ arrayAccess(expr.oprand1(), expr.oprand2());
+ int t = exprType;
+ int dim = arrayDim;
+ if (dim > 0)
+ badType(expr);
- bytecode.addOpcode(DUP2);
- bytecode.addOpcode(getArrayReadOp(t, arrayDim));
- int dup_code = is2word(t, dim) ? DUP2_X2 : DUP_X2;
- atPlusPlusCore(dup_code, doDup, token, isPost, expr);
- bytecode.addOpcode(getArrayWriteOp(t, dim));
+ bytecode.addOpcode(DUP2);
+ bytecode.addOpcode(getArrayReadOp(t, arrayDim));
+ int dup_code = is2word(t, dim) ? DUP2_X2 : DUP_X2;
+ atPlusPlusCore(dup_code, doDup, token, isPost, expr);
+ bytecode.addOpcode(getArrayWriteOp(t, dim));
}
protected void atPlusPlusCore(int dup_code, boolean doDup,
- int token, boolean isPost,
- Expr expr) throws CompileError
+ int token, boolean isPost,
+ Expr expr) throws CompileError
{
- int t = exprType;
-
- if (doDup && isPost)
- bytecode.addOpcode(dup_code);
-
- if (t == INT || t == BYTE || t == CHAR || t == SHORT) {
- bytecode.addIconst(1);
- bytecode.addOpcode(token == PLUSPLUS ? IADD : ISUB);
- exprType = INT;
- }
- else if (t == LONG) {
- bytecode.addLconst((long)1);
- bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB);
- }
- else if (t == FLOAT) {
- bytecode.addFconst(1.0f);
- bytecode.addOpcode(token == PLUSPLUS ? FADD : FSUB);
- }
- else if (t == DOUBLE) {
- bytecode.addDconst(1.0);
- bytecode.addOpcode(token == PLUSPLUS ? DADD : DSUB);
- }
- else
- badType(expr);
-
- if (doDup && !isPost)
- bytecode.addOpcode(dup_code);
+ int t = exprType;
+
+ if (doDup && isPost)
+ bytecode.addOpcode(dup_code);
+
+ if (t == INT || t == BYTE || t == CHAR || t == SHORT) {
+ bytecode.addIconst(1);
+ bytecode.addOpcode(token == PLUSPLUS ? IADD : ISUB);
+ exprType = INT;
+ }
+ else if (t == LONG) {
+ bytecode.addLconst((long)1);
+ bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB);
+ }
+ else if (t == FLOAT) {
+ bytecode.addFconst(1.0f);
+ bytecode.addOpcode(token == PLUSPLUS ? FADD : FSUB);
+ }
+ else if (t == DOUBLE) {
+ bytecode.addDconst(1.0);
+ bytecode.addOpcode(token == PLUSPLUS ? DADD : DSUB);
+ }
+ else
+ badType(expr);
+
+ if (doDup && !isPost)
+ bytecode.addOpcode(dup_code);
}
protected abstract void atFieldPlusPlus(int token, boolean isPost,
- ASTree oprand, Expr expr, boolean doDup) throws CompileError;
+ ASTree oprand, Expr expr, boolean doDup) throws CompileError;
public abstract void atMember(Member n) throws CompileError;
public void atVariable(Variable v) throws CompileError {
- Declarator d = v.getDeclarator();
- exprType = d.getType();
- arrayDim = d.getArrayDim();
- className = d.getClassName();
- int var = getLocalVar(d);
-
- if (arrayDim > 0)
- bytecode.addAload(var);
- else
- switch (exprType) {
- case CLASS :
- bytecode.addAload(var);
- break;
- case LONG :
- bytecode.addLload(var);
- break;
- case FLOAT :
- bytecode.addFload(var);
- break;
- case DOUBLE :
- bytecode.addDload(var);
- break;
- default : // BOOLEAN, BYTE, CHAR, SHORT, INT
- bytecode.addIload(var);
- break;
- }
+ Declarator d = v.getDeclarator();
+ exprType = d.getType();
+ arrayDim = d.getArrayDim();
+ className = d.getClassName();
+ int var = getLocalVar(d);
+
+ if (arrayDim > 0)
+ bytecode.addAload(var);
+ else
+ switch (exprType) {
+ case CLASS :
+ bytecode.addAload(var);
+ break;
+ case LONG :
+ bytecode.addLload(var);
+ break;
+ case FLOAT :
+ bytecode.addFload(var);
+ break;
+ case DOUBLE :
+ bytecode.addDload(var);
+ break;
+ default : // BOOLEAN, BYTE, CHAR, SHORT, INT
+ bytecode.addIload(var);
+ break;
+ }
}
public void atKeyword(Keyword k) throws CompileError {
- arrayDim = 0;
- int token = k.get();
- switch (token) {
- case TRUE :
- bytecode.addIconst(1);
- exprType = BOOLEAN;
- break;
- case FALSE :
- bytecode.addIconst(0);
- exprType = BOOLEAN;
- break;
- case NULL :
- bytecode.addOpcode(ACONST_NULL);
- exprType = NULL;
- break;
- case THIS :
- case SUPER :
- if (inStaticMethod)
- throw new CompileError("not-available: "
- + (token == THIS ? "this" : "super"));
-
- bytecode.addAload(0);
- exprType = CLASS;
- if (token == THIS)
- className = getThisName();
- else
- className = getSuperName();
- break;
- default :
- fatal();
- }
+ arrayDim = 0;
+ int token = k.get();
+ switch (token) {
+ case TRUE :
+ bytecode.addIconst(1);
+ exprType = BOOLEAN;
+ break;
+ case FALSE :
+ bytecode.addIconst(0);
+ exprType = BOOLEAN;
+ break;
+ case NULL :
+ bytecode.addOpcode(ACONST_NULL);
+ exprType = NULL;
+ break;
+ case THIS :
+ case SUPER :
+ if (inStaticMethod)
+ throw new CompileError("not-available: "
+ + (token == THIS ? "this" : "super"));
+
+ bytecode.addAload(0);
+ exprType = CLASS;
+ if (token == THIS)
+ className = getThisName();
+ else
+ className = getSuperName();
+ break;
+ default :
+ fatal();
+ }
}
public void atStringL(StringL s) throws CompileError {
- exprType = CLASS;
- arrayDim = 0;
- className = "java/lang/String";
- bytecode.addLdc(s.get());
+ exprType = CLASS;
+ arrayDim = 0;
+ className = "java/lang/String";
+ bytecode.addLdc(s.get());
}
public void atIntConst(IntConst i) throws CompileError {
- arrayDim = 0;
- long value = i.get();
- int type = i.getType();
- if (type == IntConstant || type == CharConstant) {
- exprType = (type == IntConstant ? INT : CHAR);
- bytecode.addIconst((int)value);
- }
- else {
- exprType = LONG;
- bytecode.addLconst(value);
- }
+ arrayDim = 0;
+ long value = i.get();
+ int type = i.getType();
+ if (type == IntConstant || type == CharConstant) {
+ exprType = (type == IntConstant ? INT : CHAR);
+ bytecode.addIconst((int)value);
+ }
+ else {
+ exprType = LONG;
+ bytecode.addLconst(value);
+ }
}
public void atDoubleConst(DoubleConst d) throws CompileError {
- arrayDim = 0;
- if (d.getType() == DoubleConstant) {
- exprType = DOUBLE;
- bytecode.addDconst(d.get());
- }
- else {
- exprType = FLOAT;
- bytecode.addFconst((float)d.get());
- }
+ arrayDim = 0;
+ if (d.getType() == DoubleConstant) {
+ exprType = DOUBLE;
+ bytecode.addDconst(d.get());
+ }
+ else {
+ exprType = FLOAT;
+ bytecode.addFconst((float)d.get());
+ }
}
}
diff --git a/src/main/javassist/compiler/CompileError.java b/src/main/javassist/compiler/CompileError.java
index 98b97ef5..43b3c4e6 100644
--- a/src/main/javassist/compiler/CompileError.java
+++ b/src/main/javassist/compiler/CompileError.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
public class CompileError extends Exception {
@@ -30,20 +19,20 @@ public class CompileError extends Exception {
private String reason;
public CompileError(String s, Lex l) {
- reason = s;
- lex = l;
+ reason = s;
+ lex = l;
}
public CompileError(String s) {
- reason = s;
- lex = null;
+ reason = s;
+ lex = null;
}
public String getMessage() {
- return reason;
+ return reason;
}
public String toString() {
- return "compile error: " + reason;
+ return "compile error: " + reason;
}
}
diff --git a/src/main/javassist/compiler/Javac.java b/src/main/javassist/compiler/Javac.java
index 8f15ca81..5546e176 100644
--- a/src/main/javassist/compiler/Javac.java
+++ b/src/main/javassist/compiler/Javac.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import javassist.CtClass;
@@ -51,12 +40,12 @@ public class Javac {
/**
* Constructs a compiler.
*
- * @param thisClass the class that a compiled method/field
- * belongs to.
+ * @param thisClass the class that a compiled method/field
+ * belongs to.
*/
public Javac(CtClass thisClass) {
- this(new Bytecode(thisClass.getClassFile2().getConstPool(), 0, 0),
- thisClass);
+ this(new Bytecode(thisClass.getClassFile2().getConstPool(), 0, 0),
+ thisClass);
}
/**
@@ -64,13 +53,13 @@ public class Javac {
* The produced bytecode is stored in the <code>Bytecode</code> object
* specified by <code>b</code>.
*
- * @param thisClass the class that a compiled method/field
- * belongs to.
+ * @param thisClass the class that a compiled method/field
+ * belongs to.
*/
public Javac(Bytecode b, CtClass thisClass) {
- gen = new JvstCodeGen(b, thisClass, thisClass.getClassPool());
- stable = new SymbolTable();
- bytecode = b;
+ gen = new JvstCodeGen(b, thisClass, thisClass.getClassPool());
+ stable = new SymbolTable();
+ bytecode = b;
}
/**
@@ -86,128 +75,128 @@ public class Javac {
* <p>In a method or constructor body, $0, $1, ... and $_
* are not available.
*
- * @return a <code>CtMethod</code>, <code>CtConstructor</code>,
- * or <code>CtField</code> object.
+ * @return a <code>CtMethod</code>, <code>CtConstructor</code>,
+ * or <code>CtField</code> object.
* @see #recordProceed(String,String)
*/
public CtMember compile(String src) throws CompileError {
- Parser p = new Parser(new Lex(src));
- ASTList mem = p.parseMember1(stable);
- try {
- if (mem instanceof FieldDecl)
- return compileField((FieldDecl)mem);
- else
- return compileMethod(p, (MethodDecl)mem);
- }
- catch (CannotCompileException e) {
- throw new CompileError(e.getMessage());
- }
+ Parser p = new Parser(new Lex(src));
+ ASTList mem = p.parseMember1(stable);
+ try {
+ if (mem instanceof FieldDecl)
+ return compileField((FieldDecl)mem);
+ else
+ return compileMethod(p, (MethodDecl)mem);
+ }
+ catch (CannotCompileException e) {
+ throw new CompileError(e.getMessage());
+ }
}
public static class CtFieldWithInit extends CtField {
- private ASTree init;
+ private ASTree init;
- CtFieldWithInit(CtClass type, String name, CtClass declaring)
- throws CannotCompileException
- {
- super(type, name, declaring);
- init = null;
- }
+ CtFieldWithInit(CtClass type, String name, CtClass declaring)
+ throws CannotCompileException
+ {
+ super(type, name, declaring);
+ init = null;
+ }
- protected void setInit(ASTree i) { init = i; }
+ protected void setInit(ASTree i) { init = i; }
- protected ASTree getInitAST() {
- return init;
- }
+ protected ASTree getInitAST() {
+ return init;
+ }
}
private CtField compileField(FieldDecl fd)
- throws CompileError, CannotCompileException
+ throws CompileError, CannotCompileException
{
- CtFieldWithInit f;
- Declarator d = fd.getDeclarator();
- f = new CtFieldWithInit(gen.lookupClass(d), d.getVariable().get(),
- gen.getThisClass());
- f.setModifiers(gen.getModifiers(fd.getModifiers()));
- if (fd.getInit() != null)
- f.setInit(fd.getInit());
-
- return f;
+ CtFieldWithInit f;
+ Declarator d = fd.getDeclarator();
+ f = new CtFieldWithInit(gen.lookupClass(d), d.getVariable().get(),
+ gen.getThisClass());
+ f.setModifiers(gen.getModifiers(fd.getModifiers()));
+ if (fd.getInit() != null)
+ f.setInit(fd.getInit());
+
+ return f;
}
private CtMember compileMethod(Parser p, MethodDecl md)
- throws CompileError
+ throws CompileError
{
- int mod = gen.getModifiers(md.getModifiers());
- CtClass[] plist = gen.makeParamList(md);
- CtClass[] tlist = gen.makeThrowsList(md);
- recordParams(plist, Modifier.isStatic(mod));
- md = p.parseMethod2(stable, md);
- try {
- if (md.isConstructor()) {
- CtConstructor cons = new CtConstructor(plist,
- gen.getThisClass());
- cons.setModifiers(mod);
- md.accept(gen);
- cons.getMethodInfo().setCodeAttribute(
- bytecode.toCodeAttribute());
- cons.setExceptionTypes(tlist);
- return cons;
- }
- else {
- Declarator r = md.getReturn();
- CtClass rtype = gen.lookupClass(r);
- recordReturnType(rtype, false);
- CtMethod method = new CtMethod(rtype, r.getVariable().get(),
- plist, gen.getThisClass());
- method.setModifiers(mod);
- gen.setThisMethod(method);
- md.accept(gen);
- if (md.getBody() != null)
- method.getMethodInfo().setCodeAttribute(
- bytecode.toCodeAttribute());
- else
- method.setModifiers(mod | Modifier.ABSTRACT);
-
- method.setExceptionTypes(tlist);
- return method;
- }
- }
- catch (NotFoundException e) {
- throw new CompileError(e.toString());
- }
+ int mod = gen.getModifiers(md.getModifiers());
+ CtClass[] plist = gen.makeParamList(md);
+ CtClass[] tlist = gen.makeThrowsList(md);
+ recordParams(plist, Modifier.isStatic(mod));
+ md = p.parseMethod2(stable, md);
+ try {
+ if (md.isConstructor()) {
+ CtConstructor cons = new CtConstructor(plist,
+ gen.getThisClass());
+ cons.setModifiers(mod);
+ md.accept(gen);
+ cons.getMethodInfo().setCodeAttribute(
+ bytecode.toCodeAttribute());
+ cons.setExceptionTypes(tlist);
+ return cons;
+ }
+ else {
+ Declarator r = md.getReturn();
+ CtClass rtype = gen.lookupClass(r);
+ recordReturnType(rtype, false);
+ CtMethod method = new CtMethod(rtype, r.getVariable().get(),
+ plist, gen.getThisClass());
+ method.setModifiers(mod);
+ gen.setThisMethod(method);
+ md.accept(gen);
+ if (md.getBody() != null)
+ method.getMethodInfo().setCodeAttribute(
+ bytecode.toCodeAttribute());
+ else
+ method.setModifiers(mod | Modifier.ABSTRACT);
+
+ method.setExceptionTypes(tlist);
+ return method;
+ }
+ }
+ catch (NotFoundException e) {
+ throw new CompileError(e.toString());
+ }
}
/**
* Compiles a method (or constructor) body.
*/
public Bytecode compileBody(CtBehavior method, String src)
- throws CompileError
+ throws CompileError
{
- try {
- int mod = method.getModifiers();
- recordParams(method.getParameterTypes(), Modifier.isStatic(mod));
-
- CtClass rtype;
- if (method instanceof CtMethod) {
- gen.setThisMethod((CtMethod)method);
- rtype = ((CtMethod)method).getReturnType();
- }
- else
- rtype = CtClass.voidType;
-
- recordReturnType(rtype, false);
- boolean isVoid = rtype == CtClass.voidType;
-
- Parser p = new Parser(new Lex(src));
- SymbolTable stb = new SymbolTable(stable);
- Stmnt s = p.parseStatement(stb);
- gen.atMethodBody(s, method instanceof CtConstructor, isVoid);
- return bytecode;
- }
- catch (NotFoundException e) {
- throw new CompileError(e.toString());
- }
+ try {
+ int mod = method.getModifiers();
+ recordParams(method.getParameterTypes(), Modifier.isStatic(mod));
+
+ CtClass rtype;
+ if (method instanceof CtMethod) {
+ gen.setThisMethod((CtMethod)method);
+ rtype = ((CtMethod)method).getReturnType();
+ }
+ else
+ rtype = CtClass.voidType;
+
+ recordReturnType(rtype, false);
+ boolean isVoid = rtype == CtClass.voidType;
+
+ Parser p = new Parser(new Lex(src));
+ SymbolTable stb = new SymbolTable(stable);
+ Stmnt s = p.parseStatement(stb);
+ gen.atMethodBody(s, method instanceof CtConstructor, isVoid);
+ return bytecode;
+ }
+ catch (NotFoundException e) {
+ throw new CompileError(e.toString());
+ }
}
/**
@@ -220,9 +209,9 @@ public class Javac {
* <code>isStatic</code> must be recorded before compilation.
*/
public void recordParams(CtClass[] params, boolean isStatic)
- throws CompileError
+ throws CompileError
{
- gen.recordParams(params, isStatic, "$", "$args", "$$", stable);
+ gen.recordParams(params, isStatic, "$", "$args", "$$", stable);
}
/**
@@ -235,19 +224,19 @@ public class Javac {
* <code>compileExpr()</code>. The correct value of
* <code>isStatic</code> must be recorded before compilation.
*
- * @paaram use0 true if $0 is used.
- * @param varNo the register number of $0 (use0 is true)
- * or $1 (otherwise).
- * @param target the type of $0 (it can be null if use0 is false).
- * @param isStatic true if the method in which the compiled bytecode
- * is embedded is static.
+ * @paaram use0 true if $0 is used.
+ * @param varNo the register number of $0 (use0 is true)
+ * or $1 (otherwise).
+ * @param target the type of $0 (it can be null if use0 is false).
+ * @param isStatic true if the method in which the compiled bytecode
+ * is embedded is static.
*/
public void recordParams(String target, CtClass[] params,
- boolean use0, int varNo, boolean isStatic)
- throws CompileError
+ boolean use0, int varNo, boolean isStatic)
+ throws CompileError
{
- gen.recordParams(params, isStatic, "$", "$args", "$$",
- use0, varNo, target, stable);
+ gen.recordParams(params, isStatic, "$", "$args", "$$",
+ use0, varNo, target, stable);
}
/**
@@ -258,15 +247,15 @@ public class Javac {
* <p>If the return type is void, ($r) does nothing.
* The type of $_ is java.lang.Object.
*
- * @param useResultVar true if $_ is used.
- * @return -1 or the variable index assigned to $_.
+ * @param useResultVar true if $_ is used.
+ * @return -1 or the variable index assigned to $_.
*/
public int recordReturnType(CtClass type, boolean useResultVar)
- throws CompileError
+ throws CompileError
{
- gen.recordType(type);
- return gen.recordReturnType(type, "$r",
- (useResultVar ? resultVarName : null), stable);
+ gen.recordType(type);
+ return gen.recordReturnType(type, "$r",
+ (useResultVar ? resultVarName : null), stable);
}
/**
@@ -274,19 +263,19 @@ public class Javac {
* the value of $type.
*/
public void recordType(CtClass t) {
- gen.recordType(t);
+ gen.recordType(t);
}
/**
* Makes the given variable available.
*
- * @param type variable type
- * @param name variable name
+ * @param type variable type
+ * @param name variable name
*/
public int recordVariable(CtClass type, String name)
- throws CompileError
+ throws CompileError
{
- return gen.recordVariable(type, name, stable);
+ return gen.recordVariable(type, name, stable);
}
/**
@@ -294,39 +283,39 @@ public class Javac {
* If the return type of $proceed() is void, null is pushed on the
* stack.
*
- * @param target an expression specifying the target object.
- * if null, "this" is the target.
- * @param method the method name.
+ * @param target an expression specifying the target object.
+ * if null, "this" is the target.
+ * @param method the method name.
*/
public void recordProceed(String target, String method)
- throws CompileError
+ throws CompileError
{
- Parser p = new Parser(new Lex(target));
- final ASTree texpr = p.parseExpression(stable);
- final String m = method;
-
- ProceedHandler h = new ProceedHandler() {
- public void doit(JvstCodeGen gen, Bytecode b, ASTList args)
- throws CompileError
- {
- ASTree expr = new Member(m);
- if (texpr != null)
- expr = Expr.make('.', texpr, expr);
-
- expr = Expr.make(TokenId.CALL, expr, args);
- expr.accept(gen);
- gen.addNullIfVoid();
- }
- };
-
- gen.setProceedHandler(h, proceedName);
+ Parser p = new Parser(new Lex(target));
+ final ASTree texpr = p.parseExpression(stable);
+ final String m = method;
+
+ ProceedHandler h = new ProceedHandler() {
+ public void doit(JvstCodeGen gen, Bytecode b, ASTList args)
+ throws CompileError
+ {
+ ASTree expr = new Member(m);
+ if (texpr != null)
+ expr = Expr.make('.', texpr, expr);
+
+ expr = Expr.make(TokenId.CALL, expr, args);
+ expr.accept(gen);
+ gen.addNullIfVoid();
+ }
+ };
+
+ gen.setProceedHandler(h, proceedName);
}
/**
* Prepares to use $proceed().
*/
public void recordProceed(ProceedHandler h) {
- gen.setProceedHandler(h, proceedName);
+ gen.setProceedHandler(h, proceedName);
}
/**
@@ -340,12 +329,12 @@ public class Javac {
* ($0, $1, ..) are available.
*/
public void compileStmnt(String src) throws CompileError {
- Parser p = new Parser(new Lex(src));
- SymbolTable stb = new SymbolTable(stable);
+ Parser p = new Parser(new Lex(src));
+ SymbolTable stb = new SymbolTable(stable);
// while (p.hasMore()) {
- Stmnt s = p.parseStatement(stb);
- if (s != null)
- s.accept(gen);
+ Stmnt s = p.parseStatement(stb);
+ if (s != null)
+ s.accept(gen);
// }
}
@@ -359,9 +348,9 @@ public class Javac {
* have been invoked.
*/
public void compileExpr(String src) throws CompileError {
- Parser p = new Parser(new Lex(src));
- ASTree e = p.parseExpression(stable);
- compileExpr(e);
+ Parser p = new Parser(new Lex(src));
+ ASTree e = p.parseExpression(stable);
+ compileExpr(e);
}
/**
@@ -374,7 +363,7 @@ public class Javac {
* have been invoked.
*/
public void compileExpr(ASTree e) throws CompileError {
- if (e != null)
- e.accept(gen);
+ if (e != null)
+ e.accept(gen);
}
}
diff --git a/src/main/javassist/compiler/JvstCodeGen.java b/src/main/javassist/compiler/JvstCodeGen.java
index 6a365e16..e895bdce 100644
--- a/src/main/javassist/compiler/JvstCodeGen.java
+++ b/src/main/javassist/compiler/JvstCodeGen.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import javassist.*;
@@ -35,157 +24,157 @@ public class JvstCodeGen extends MemberCodeGen {
private String paramArrayName = null;
private String paramListName = null;
private CtClass[] paramTypeList = null;
- private int paramVarBase = 0; // variable index for $0 or $1.
- private boolean useParam0 = false; // true if $0 is used.
- private String param0Type = null; // JVM name
+ private int paramVarBase = 0; // variable index for $0 or $1.
+ private boolean useParam0 = false; // true if $0 is used.
+ private String param0Type = null; // JVM name
private static final String sigName = "$sig";
private static final String dollarTypeName = "$type";
private static final String clazzName = "$class";
private CtClass dollarType = null;
private CtClass returnType = null;
private String returnCastName = null;
- private String returnVarName = null; // null if $_ is not used.
+ private String returnVarName = null; // null if $_ is not used.
private static final String wrapperCastName = "$w";
private String proceedName = null;
private static final String cflowName = "$cflow";
- private ProceedHandler procHandler = null; // null if not used.
+ private ProceedHandler procHandler = null; // null if not used.
public JvstCodeGen(Bytecode b, CtClass cc, ClassPool cp) {
- super(b, cc, cp);
+ super(b, cc, cp);
}
/* Index of $1.
*/
private int indexOfParam1() {
- return paramVarBase + (useParam0 ? 1 : 0);
+ return paramVarBase + (useParam0 ? 1 : 0);
}
/* Records a ProceedHandler obejct.
*
- * @param name the name of the special method call.
- * it is usually $proceed.
+ * @param name the name of the special method call.
+ * it is usually $proceed.
*/
public void setProceedHandler(ProceedHandler h, String name) {
- proceedName = name;
- procHandler = h;
+ proceedName = name;
+ procHandler = h;
}
/* If the type of the expression compiled last is void,
* add ACONST_NULL and change exprType, arrayDim, className.
*/
public void addNullIfVoid() {
- if (exprType == VOID) {
- bytecode.addOpcode(ACONST_NULL);
- exprType = CLASS;
- arrayDim = 0;
- className = jvmJavaLangObject;
- }
+ if (exprType == VOID) {
+ bytecode.addOpcode(ACONST_NULL);
+ exprType = CLASS;
+ arrayDim = 0;
+ className = jvmJavaLangObject;
+ }
}
/* To support $args, $sig, and $type.
* $args is an array of parameter list.
*/
public void atMember(Member mem) throws CompileError {
- String name = mem.get();
- if (name.equals(paramArrayName)) {
- compileParameterList(bytecode, paramTypeList, indexOfParam1());
- exprType = CLASS;
- arrayDim = 1;
- className = jvmJavaLangObject;
- }
- else if (name.equals(sigName)) {
- bytecode.addLdc(Descriptor.ofMethod(returnType, paramTypeList));
- bytecode.addInvokestatic("javassist/runtime/Desc", "getParams",
- "(Ljava/lang/String;)[Ljava/lang/Class;");
- exprType = CLASS;
- arrayDim = 1;
- className = "java/lang/Class";
- }
- else if (name.equals(dollarTypeName)) {
- if (dollarType == null)
- throw new CompileError(dollarType + " is not available");
-
- bytecode.addLdc(Descriptor.of(dollarType));
- callGetType("getType");
- }
- else if (name.equals(clazzName)) {
- if (param0Type == null)
- throw new CompileError(clazzName + " is not available");
-
- bytecode.addLdc(param0Type);
- callGetType("getClazz");
- }
- else
- super.atMember(mem);
+ String name = mem.get();
+ if (name.equals(paramArrayName)) {
+ compileParameterList(bytecode, paramTypeList, indexOfParam1());
+ exprType = CLASS;
+ arrayDim = 1;
+ className = jvmJavaLangObject;
+ }
+ else if (name.equals(sigName)) {
+ bytecode.addLdc(Descriptor.ofMethod(returnType, paramTypeList));
+ bytecode.addInvokestatic("javassist/runtime/Desc", "getParams",
+ "(Ljava/lang/String;)[Ljava/lang/Class;");
+ exprType = CLASS;
+ arrayDim = 1;
+ className = "java/lang/Class";
+ }
+ else if (name.equals(dollarTypeName)) {
+ if (dollarType == null)
+ throw new CompileError(dollarType + " is not available");
+
+ bytecode.addLdc(Descriptor.of(dollarType));
+ callGetType("getType");
+ }
+ else if (name.equals(clazzName)) {
+ if (param0Type == null)
+ throw new CompileError(clazzName + " is not available");
+
+ bytecode.addLdc(param0Type);
+ callGetType("getClazz");
+ }
+ else
+ super.atMember(mem);
}
private void callGetType(String method) {
- bytecode.addInvokestatic("javassist/runtime/Desc", method,
- "(Ljava/lang/String;)Ljava/lang/Class;");
- exprType = CLASS;
- arrayDim = 0;
- className = "java/lang/Class";
+ bytecode.addInvokestatic("javassist/runtime/Desc", method,
+ "(Ljava/lang/String;)Ljava/lang/Class;");
+ exprType = CLASS;
+ arrayDim = 0;
+ className = "java/lang/Class";
}
private void atSigOrType(String sig) throws CompileError {
}
protected void atFieldAssign(Expr expr, int op, ASTree left,
- ASTree right, boolean doDup) throws CompileError
+ ASTree right, boolean doDup) throws CompileError
{
- if (left instanceof Member
- && ((Member)left).get().equals(paramArrayName)) {
- if (op != '=')
- throw new CompileError("bad operator for " + paramArrayName);
+ if (left instanceof Member
+ && ((Member)left).get().equals(paramArrayName)) {
+ if (op != '=')
+ throw new CompileError("bad operator for " + paramArrayName);
- right.accept(this);
- if (arrayDim != 1 || exprType != CLASS)
- throw new CompileError("invalid type for " + paramArrayName);
+ right.accept(this);
+ if (arrayDim != 1 || exprType != CLASS)
+ throw new CompileError("invalid type for " + paramArrayName);
- atAssignParamList(paramTypeList, bytecode);
- if (!doDup)
- bytecode.addOpcode(POP);
- }
- else
- super.atFieldAssign(expr, op, left, right, doDup);
+ atAssignParamList(paramTypeList, bytecode);
+ if (!doDup)
+ bytecode.addOpcode(POP);
+ }
+ else
+ super.atFieldAssign(expr, op, left, right, doDup);
}
protected void atAssignParamList(CtClass[] params, Bytecode code)
- throws CompileError
+ throws CompileError
{
- if (params == null)
- return;
+ if (params == null)
+ return;
- int varNo = indexOfParam1();
- int n = params.length;
- for (int i = 0; i < n; ++i) {
- code.addOpcode(DUP);
- code.addIconst(i);
- code.addOpcode(AALOAD);
- compileUnwrapValue(params[i], code);
- code.addStore(varNo, params[i]);
- varNo += is2word(exprType, arrayDim) ? 2 : 1;
- }
+ int varNo = indexOfParam1();
+ int n = params.length;
+ for (int i = 0; i < n; ++i) {
+ code.addOpcode(DUP);
+ code.addIconst(i);
+ code.addOpcode(AALOAD);
+ compileUnwrapValue(params[i], code);
+ code.addStore(varNo, params[i]);
+ varNo += is2word(exprType, arrayDim) ? 2 : 1;
+ }
}
public void atCastExpr(CastExpr expr) throws CompileError {
- ASTList classname = expr.getClassName();
- if (classname != null && expr.getArrayDim() == 0) {
- ASTree p = classname.head();
- if (p instanceof Symbol && classname.tail() == null) {
- String typename = ((Symbol)p).get();
- if (typename.equals(returnCastName)) {
- atCastToRtype(expr);
- return;
- }
- else if (typename.equals(wrapperCastName)) {
- atCastToWrapper(expr);
- return;
- }
- }
- }
-
- super.atCastExpr(expr);
+ ASTList classname = expr.getClassName();
+ if (classname != null && expr.getArrayDim() == 0) {
+ ASTree p = classname.head();
+ if (p instanceof Symbol && classname.tail() == null) {
+ String typename = ((Symbol)p).get();
+ if (typename.equals(returnCastName)) {
+ atCastToRtype(expr);
+ return;
+ }
+ else if (typename.equals(wrapperCastName)) {
+ atCastToWrapper(expr);
+ return;
+ }
+ }
+ }
+
+ super.atCastExpr(expr);
}
/**
@@ -193,79 +182,79 @@ public class JvstCodeGen extends MemberCodeGen {
* If the return type is void, this does nothing.
*/
protected void atCastToRtype(CastExpr expr) throws CompileError {
- expr.getOprand().accept(this);
- if (!isRefType(exprType) || arrayDim > 0)
- throw new CompileError("invalid type for " + returnCastName);
+ expr.getOprand().accept(this);
+ if (!isRefType(exprType) || arrayDim > 0)
+ throw new CompileError("invalid type for " + returnCastName);
- compileUnwrapValue(returnType, bytecode);
+ compileUnwrapValue(returnType, bytecode);
}
protected void atCastToWrapper(CastExpr expr) throws CompileError {
- expr.getOprand().accept(this);
- if (isRefType(exprType) || arrayDim > 0)
- return; // Object type. do nothing.
-
- CtClass clazz = lookupClass(exprType, arrayDim, className);
- if (clazz instanceof CtPrimitiveType) {
- CtPrimitiveType pt = (CtPrimitiveType)clazz;
- String wrapper = pt.getWrapperName();
- bytecode.addNew(wrapper); // new <wrapper>
- bytecode.addOpcode(DUP); // dup
- if (pt.getDataSize() > 1)
- bytecode.addOpcode(DUP2_X2); // dup2_x2
- else
- bytecode.addOpcode(DUP2_X1); // dup2_x1
-
- bytecode.addOpcode(POP2); // pop2
- bytecode.addInvokespecial(wrapper, "<init>",
- "(" + pt.getDescriptor() + ")V");
- // invokespecial
- exprType = CLASS;
- arrayDim = 0;
- className = jvmJavaLangObject;
- }
+ expr.getOprand().accept(this);
+ if (isRefType(exprType) || arrayDim > 0)
+ return; // Object type. do nothing.
+
+ CtClass clazz = lookupClass(exprType, arrayDim, className);
+ if (clazz instanceof CtPrimitiveType) {
+ CtPrimitiveType pt = (CtPrimitiveType)clazz;
+ String wrapper = pt.getWrapperName();
+ bytecode.addNew(wrapper); // new <wrapper>
+ bytecode.addOpcode(DUP); // dup
+ if (pt.getDataSize() > 1)
+ bytecode.addOpcode(DUP2_X2); // dup2_x2
+ else
+ bytecode.addOpcode(DUP2_X1); // dup2_x1
+
+ bytecode.addOpcode(POP2); // pop2
+ bytecode.addInvokespecial(wrapper, "<init>",
+ "(" + pt.getDescriptor() + ")V");
+ // invokespecial
+ exprType = CLASS;
+ arrayDim = 0;
+ className = jvmJavaLangObject;
+ }
}
/* Delegates to a ProcHandler object if the method call is
* $proceed(). It may process $cflow().
*/
protected void atMethodCall(Expr expr) throws CompileError {
- ASTree method = expr.oprand1();
- if (method instanceof Member) {
- String name = ((Member)method).get();
- if (procHandler != null && name.equals(proceedName)) {
- procHandler.doit(this, bytecode, (ASTList)expr.oprand2());
- return;
- }
- else if (name.equals(cflowName)) {
- atCflow((ASTList)expr.oprand2());
- return;
- }
- }
-
- super.atMethodCall(expr);
+ ASTree method = expr.oprand1();
+ if (method instanceof Member) {
+ String name = ((Member)method).get();
+ if (procHandler != null && name.equals(proceedName)) {
+ procHandler.doit(this, bytecode, (ASTList)expr.oprand2());
+ return;
+ }
+ else if (name.equals(cflowName)) {
+ atCflow((ASTList)expr.oprand2());
+ return;
+ }
+ }
+
+ super.atMethodCall(expr);
}
/* To support $cflow().
*/
protected void atCflow(ASTList cname) throws CompileError {
- StringBuffer sbuf = new StringBuffer();
- if (cname == null || cname.tail() != null)
- throw new CompileError("bad " + cflowName);
+ StringBuffer sbuf = new StringBuffer();
+ if (cname == null || cname.tail() != null)
+ throw new CompileError("bad " + cflowName);
- makeCflowName(sbuf, cname.head());
- String name = sbuf.toString();
- Object[] names = classPool.lookupCflow(name);
- if (names == null)
- throw new CompileError("no such a " + cflowName + ": " + name);
+ makeCflowName(sbuf, cname.head());
+ String name = sbuf.toString();
+ Object[] names = classPool.lookupCflow(name);
+ if (names == null)
+ throw new CompileError("no such a " + cflowName + ": " + name);
- bytecode.addGetstatic((String)names[0], (String)names[1],
- "Ljavassist/runtime/Cflow;");
- bytecode.addInvokevirtual("javassist.runtime.Cflow",
- "value", "()I");
- exprType = INT;
- arrayDim = 0;
- className = null;
+ bytecode.addGetstatic((String)names[0], (String)names[1],
+ "Ljavassist/runtime/Cflow;");
+ bytecode.addInvokevirtual("javassist.runtime.Cflow",
+ "value", "()I");
+ exprType = INT;
+ arrayDim = 0;
+ className = null;
}
/* Syntax:
@@ -274,122 +263,122 @@ public class JvstCodeGen extends MemberCodeGen {
* <cflow name> : <identifier> ('.' <identifier>)*
*/
private static void makeCflowName(StringBuffer sbuf, ASTree name)
- throws CompileError
+ throws CompileError
{
- if (name instanceof Symbol) {
- sbuf.append(((Symbol)name).get());
- return;
- }
- else if (name instanceof Expr) {
- Expr expr = (Expr)name;
- if (expr.getOperator() == '.') {
- makeCflowName(sbuf, expr.oprand1());
- sbuf.append('.');
- makeCflowName(sbuf, expr.oprand2());
- return;
- }
- }
-
- throw new CompileError("bad " + cflowName);
+ if (name instanceof Symbol) {
+ sbuf.append(((Symbol)name).get());
+ return;
+ }
+ else if (name instanceof Expr) {
+ Expr expr = (Expr)name;
+ if (expr.getOperator() == '.') {
+ makeCflowName(sbuf, expr.oprand1());
+ sbuf.append('.');
+ makeCflowName(sbuf, expr.oprand2());
+ return;
+ }
+ }
+
+ throw new CompileError("bad " + cflowName);
}
/* To support $$. ($$) is equivalent to ($1, ..., $n).
* It can be used only as a parameter list of method call.
*/
public boolean isParamListName(ASTList args) {
- if (paramTypeList != null
- && args != null && args.tail() == null) {
- ASTree left = args.head();
- return (left instanceof Member
- && ((Member)left).get().equals(paramListName));
- }
- else
- return false;
+ if (paramTypeList != null
+ && args != null && args.tail() == null) {
+ ASTree left = args.head();
+ return (left instanceof Member
+ && ((Member)left).get().equals(paramListName));
+ }
+ else
+ return false;
}
/*
public int atMethodArgsLength(ASTList args) {
- if (!isParamListName(args))
- return super.atMethodArgsLength(args);
+ if (!isParamListName(args))
+ return super.atMethodArgsLength(args);
- return paramTypeList.length;
+ return paramTypeList.length;
}
*/
public int atMethodArgsLength(ASTList args) {
- String pname = paramListName;
- int n = 0;
- while (args != null) {
- ASTree a = args.head();
- if (a instanceof Member && ((Member)a).get().equals(pname)) {
- if (paramTypeList != null)
- n += paramTypeList.length;
- }
- else
- ++n;
+ String pname = paramListName;
+ int n = 0;
+ while (args != null) {
+ ASTree a = args.head();
+ if (a instanceof Member && ((Member)a).get().equals(pname)) {
+ if (paramTypeList != null)
+ n += paramTypeList.length;
+ }
+ else
+ ++n;
- args = args.tail();
- }
+ args = args.tail();
+ }
- return n;
+ return n;
}
public void atMethodArgs(ASTList args, int[] types, int[] dims,
- String[] cnames) throws CompileError {
- CtClass[] params = paramTypeList;
- String pname = paramListName;
- int i = 0;
- while (args != null) {
- ASTree a = args.head();
- if (a instanceof Member && ((Member)a).get().equals(pname)) {
- if (params != null) {
- int n = params.length;
- int regno = indexOfParam1();
- for (int k = 0; k < n; ++k) {
- CtClass p = params[k];
- regno += bytecode.addLoad(regno, p);
- setType(p);
- types[i] = exprType;
- dims[i] = arrayDim;
- cnames[i] = className;
- ++i;
- }
- }
- }
- else {
- a.accept(this);
- types[i] = exprType;
- dims[i] = arrayDim;
- cnames[i] = className;
- ++i;
- }
-
- args = args.tail();
- }
+ String[] cnames) throws CompileError {
+ CtClass[] params = paramTypeList;
+ String pname = paramListName;
+ int i = 0;
+ while (args != null) {
+ ASTree a = args.head();
+ if (a instanceof Member && ((Member)a).get().equals(pname)) {
+ if (params != null) {
+ int n = params.length;
+ int regno = indexOfParam1();
+ for (int k = 0; k < n; ++k) {
+ CtClass p = params[k];
+ regno += bytecode.addLoad(regno, p);
+ setType(p);
+ types[i] = exprType;
+ dims[i] = arrayDim;
+ cnames[i] = className;
+ ++i;
+ }
+ }
+ }
+ else {
+ a.accept(this);
+ types[i] = exprType;
+ dims[i] = arrayDim;
+ cnames[i] = className;
+ ++i;
+ }
+
+ args = args.tail();
+ }
}
/*
public void atMethodArgs(ASTList args, int[] types, int[] dims,
- String[] cnames) throws CompileError {
- if (!isParamListName(args)) {
- super.atMethodArgs(args, types, dims, cnames);
- return;
- }
-
- CtClass[] params = paramTypeList;
- if (params == null)
- return;
-
- int n = params.length;
- int regno = indexOfParam1();
- for (int i = 0; i < n; ++i) {
- CtClass p = params[i];
- regno += bytecode.addLoad(regno, p);
- setType(p);
- types[i] = exprType;
- dims[i] = arrayDim;
- cnames[i] = className;
- }
+ String[] cnames) throws CompileError {
+ if (!isParamListName(args)) {
+ super.atMethodArgs(args, types, dims, cnames);
+ return;
+ }
+
+ CtClass[] params = paramTypeList;
+ if (params == null)
+ return;
+
+ int n = params.length;
+ int regno = indexOfParam1();
+ for (int i = 0; i < n; ++i) {
+ CtClass p = params[i];
+ regno += bytecode.addLoad(regno, p);
+ setType(p);
+ types[i] = exprType;
+ dims[i] = arrayDim;
+ cnames[i] = className;
+ }
}
*/
@@ -397,18 +386,18 @@ public class JvstCodeGen extends MemberCodeGen {
* Makes it valid to write "return <expr>;" for a void method.
*/
protected void atReturnStmnt(Stmnt st) throws CompileError {
- ASTree result = st.getLeft();
- if (result != null && returnType == CtClass.voidType) {
- result.accept(this);
- if (is2word(exprType, arrayDim))
- bytecode.addOpcode(POP2);
- else if (exprType != VOID)
- bytecode.addOpcode(POP);
+ ASTree result = st.getLeft();
+ if (result != null && returnType == CtClass.voidType) {
+ result.accept(this);
+ if (is2word(exprType, arrayDim))
+ bytecode.addOpcode(POP2);
+ else if (exprType != VOID)
+ bytecode.addOpcode(POP);
- result = null;
- }
+ result = null;
+ }
- atReturnStmnt2(result);
+ atReturnStmnt2(result);
}
/**
@@ -418,30 +407,30 @@ public class JvstCodeGen extends MemberCodeGen {
* <p>If the return type is void, ($r) does nothing.
* The type of $_ is java.lang.Object.
*
- * @param resultName null if $_ is not used.
- * @return -1 or the variable index assigned to $_.
+ * @param resultName null if $_ is not used.
+ * @return -1 or the variable index assigned to $_.
*/
public int recordReturnType(CtClass type, String castName,
- String resultName, SymbolTable tbl) throws CompileError
+ String resultName, SymbolTable tbl) throws CompileError
{
- returnType = type;
- returnCastName = castName;
- returnVarName = resultName;
- if (resultName == null)
- return -1;
- else {
- int varNo = getMaxLocals();
- int locals = varNo + recordVar(type, resultName, varNo, tbl);
- setMaxLocals(locals);
- return varNo;
- }
+ returnType = type;
+ returnCastName = castName;
+ returnVarName = resultName;
+ if (resultName == null)
+ return -1;
+ else {
+ int varNo = getMaxLocals();
+ int locals = varNo + recordVar(type, resultName, varNo, tbl);
+ setMaxLocals(locals);
+ return varNo;
+ }
}
/**
* Makes $type available.
*/
public void recordType(CtClass t) {
- dollarType = t;
+ dollarType = t;
}
/**
@@ -450,12 +439,12 @@ public class JvstCodeGen extends MemberCodeGen {
* if the method is static, then $0 is not available.
*/
public void recordParams(CtClass[] params, boolean isStatic,
- String prefix, String paramVarName,
- String paramsName, SymbolTable tbl)
- throws CompileError
+ String prefix, String paramVarName,
+ String paramsName, SymbolTable tbl)
+ throws CompileError
{
- recordParams(params, isStatic, prefix, paramVarName,
- paramsName, !isStatic, 0, getThisName(), tbl);
+ recordParams(params, isStatic, prefix, paramVarName,
+ paramsName, !isStatic, 0, getThisName(), tbl);
}
/**
@@ -463,83 +452,83 @@ public class JvstCodeGen extends MemberCodeGen {
* $0 is available only if use0 is true. It might not be equivalent
* to THIS.
*
- * @paaram use0 true if $0 is used.
- * @param paramBase the register number of $0 (use0 is true)
- * or $1 (otherwise).
- * @param target the class of $0. If use0 is false, target
- * can be null.
- * @param isStatic true if the method in which the compiled bytecode
- * is embedded is static.
+ * @paaram use0 true if $0 is used.
+ * @param paramBase the register number of $0 (use0 is true)
+ * or $1 (otherwise).
+ * @param target the class of $0. If use0 is false, target
+ * can be null.
+ * @param isStatic true if the method in which the compiled bytecode
+ * is embedded is static.
*/
public void recordParams(CtClass[] params, boolean isStatic,
- String prefix, String paramVarName,
- String paramsName, boolean use0,
- int paramBase, String target,
- SymbolTable tbl)
- throws CompileError
+ String prefix, String paramVarName,
+ String paramsName, boolean use0,
+ int paramBase, String target,
+ SymbolTable tbl)
+ throws CompileError
{
- int varNo;
+ int varNo;
- paramTypeList = params;
- paramArrayName = paramVarName;
- paramListName = paramsName;
- paramVarBase = paramBase;
- useParam0 = use0;
+ paramTypeList = params;
+ paramArrayName = paramVarName;
+ paramListName = paramsName;
+ paramVarBase = paramBase;
+ useParam0 = use0;
- param0Type = jvmToJavaName(target);
+ param0Type = jvmToJavaName(target);
- inStaticMethod = isStatic;
- varNo = paramBase;
- if (use0) {
- String varName = prefix + "0";
- Declarator decl
- = new Declarator(CLASS, javaToJvmName(target), 0, varNo++,
- new Symbol(varName));
- tbl.append(varName, decl);
- }
+ inStaticMethod = isStatic;
+ varNo = paramBase;
+ if (use0) {
+ String varName = prefix + "0";
+ Declarator decl
+ = new Declarator(CLASS, javaToJvmName(target), 0, varNo++,
+ new Symbol(varName));
+ tbl.append(varName, decl);
+ }
- for (int i = 0; i < params.length; ++i)
- varNo += recordVar(params[i], prefix + (i + 1), varNo, tbl);
+ for (int i = 0; i < params.length; ++i)
+ varNo += recordVar(params[i], prefix + (i + 1), varNo, tbl);
- if (getMaxLocals() < varNo)
- setMaxLocals(varNo);
+ if (getMaxLocals() < varNo)
+ setMaxLocals(varNo);
}
/**
* Makes the given variable name available.
*
- * @param type variable type
- * @param varName variable name
+ * @param type variable type
+ * @param varName variable name
*/
public int recordVariable(CtClass type, String varName, SymbolTable tbl)
- throws CompileError
+ throws CompileError
{
- if (varName == null)
- return -1;
- else {
- int varNo = getMaxLocals();
- int locals = varNo + recordVar(type, varName, varNo, tbl);
- setMaxLocals(locals);
- return varNo;
- }
+ if (varName == null)
+ return -1;
+ else {
+ int varNo = getMaxLocals();
+ int locals = varNo + recordVar(type, varName, varNo, tbl);
+ setMaxLocals(locals);
+ return varNo;
+ }
}
private int recordVar(CtClass cc, String varName, int varNo,
- SymbolTable tbl) throws CompileError
+ SymbolTable tbl) throws CompileError
{
- if (cc == CtClass.voidType) {
- exprType = CLASS;
- arrayDim = 0;
- className = jvmJavaLangObject;
- }
- else
- setType(cc);
+ if (cc == CtClass.voidType) {
+ exprType = CLASS;
+ arrayDim = 0;
+ className = jvmJavaLangObject;
+ }
+ else
+ setType(cc);
- Declarator decl
- = new Declarator(exprType, className, arrayDim,
- varNo, new Symbol(varName));
- tbl.append(varName, decl);
- return is2word(exprType, arrayDim) ? 2 : 1;
+ Declarator decl
+ = new Declarator(exprType, className, arrayDim,
+ varNo, new Symbol(varName));
+ tbl.append(varName, decl);
+ return is2word(exprType, arrayDim) ? 2 : 1;
}
/* compileParameterList() returns the stack size used
@@ -547,105 +536,105 @@ public class JvstCodeGen extends MemberCodeGen {
*
* This method correctly computes the max_stack value.
*
- * @param regno the index of the local variable in which
- * the first argument is received.
- * (0: static method, 1: regular method.)
+ * @param regno the index of the local variable in which
+ * the first argument is received.
+ * (0: static method, 1: regular method.)
*/
public static int compileParameterList(Bytecode code,
- CtClass[] params, int regno) {
- if (params == null) {
- code.addIconst(0); // iconst_0
- code.addAnewarray(javaLangObject); // anewarray Object
- return 1;
- }
- else {
- CtClass[] args = new CtClass[1];
- int n = params.length;
- code.addIconst(n); // iconst_<n>
- code.addAnewarray(javaLangObject); // anewarray Object
- for (int i = 0; i < n; ++i) {
- code.addOpcode(Bytecode.DUP); // dup
- code.addIconst(i); // iconst_<i>
- if (params[i].isPrimitive()) {
- CtPrimitiveType pt = (CtPrimitiveType)params[i];
- String wrapper = pt.getWrapperName();
- code.addNew(wrapper); // new <wrapper>
- code.addOpcode(Bytecode.DUP); // dup
- int s = code.addLoad(regno, pt); // ?load <regno>
- regno += s;
- args[0] = pt;
- code.addInvokespecial(wrapper, "<init>",
- Descriptor.ofMethod(CtClass.voidType, args));
- // invokespecial
- }
- else {
- code.addAload(regno); // aload <regno>
- ++regno;
- }
-
- code.addOpcode(Bytecode.AASTORE); // aastore
- }
-
- return 8;
- }
+ CtClass[] params, int regno) {
+ if (params == null) {
+ code.addIconst(0); // iconst_0
+ code.addAnewarray(javaLangObject); // anewarray Object
+ return 1;
+ }
+ else {
+ CtClass[] args = new CtClass[1];
+ int n = params.length;
+ code.addIconst(n); // iconst_<n>
+ code.addAnewarray(javaLangObject); // anewarray Object
+ for (int i = 0; i < n; ++i) {
+ code.addOpcode(Bytecode.DUP); // dup
+ code.addIconst(i); // iconst_<i>
+ if (params[i].isPrimitive()) {
+ CtPrimitiveType pt = (CtPrimitiveType)params[i];
+ String wrapper = pt.getWrapperName();
+ code.addNew(wrapper); // new <wrapper>
+ code.addOpcode(Bytecode.DUP); // dup
+ int s = code.addLoad(regno, pt); // ?load <regno>
+ regno += s;
+ args[0] = pt;
+ code.addInvokespecial(wrapper, "<init>",
+ Descriptor.ofMethod(CtClass.voidType, args));
+ // invokespecial
+ }
+ else {
+ code.addAload(regno); // aload <regno>
+ ++regno;
+ }
+
+ code.addOpcode(Bytecode.AASTORE); // aastore
+ }
+
+ return 8;
+ }
}
protected void compileUnwrapValue(CtClass type, Bytecode code)
- throws CompileError
+ throws CompileError
{
- if (type instanceof CtPrimitiveType) {
- CtPrimitiveType pt = (CtPrimitiveType)type;
- if (pt != CtClass.voidType) {
- String wrapper = pt.getWrapperName();
- code.addCheckcast(wrapper);
- code.addInvokevirtual(wrapper, pt.getGetMethodName(),
- pt.getGetMethodDescriptor());
- setType(type);
- }
- }
- else {
- code.addCheckcast(type);
- setType(type);
- }
+ if (type instanceof CtPrimitiveType) {
+ CtPrimitiveType pt = (CtPrimitiveType)type;
+ if (pt != CtClass.voidType) {
+ String wrapper = pt.getWrapperName();
+ code.addCheckcast(wrapper);
+ code.addInvokevirtual(wrapper, pt.getGetMethodName(),
+ pt.getGetMethodDescriptor());
+ setType(type);
+ }
+ }
+ else {
+ code.addCheckcast(type);
+ setType(type);
+ }
}
/* Sets exprType, arrayDim, and className;
* If type is void, then this method does nothing.
*/
public void setType(CtClass type) throws CompileError {
- setType(type, 0);
+ setType(type, 0);
}
private void setType(CtClass type, int dim) throws CompileError {
- if (type.isPrimitive()) {
- CtPrimitiveType pt = (CtPrimitiveType)type;
- exprType = descToType(pt.getDescriptor());
- arrayDim = dim;
- className = null;
- }
- else if (type.isArray())
- try {
- setType(type.getComponentType(), dim + 1);
- }
- catch (NotFoundException e) {
- throw new CompileError("undefined type: " + type.getName());
- }
- else {
- exprType = CLASS;
- arrayDim = dim;
- className = javaToJvmName(type.getName());
- }
+ if (type.isPrimitive()) {
+ CtPrimitiveType pt = (CtPrimitiveType)type;
+ exprType = descToType(pt.getDescriptor());
+ arrayDim = dim;
+ className = null;
+ }
+ else if (type.isArray())
+ try {
+ setType(type.getComponentType(), dim + 1);
+ }
+ catch (NotFoundException e) {
+ throw new CompileError("undefined type: " + type.getName());
+ }
+ else {
+ exprType = CLASS;
+ arrayDim = dim;
+ className = javaToJvmName(type.getName());
+ }
}
/* Performs implicit coercion from exprType to type.
*/
public void doNumCast(CtClass type) throws CompileError {
- if (arrayDim == 0 && !isRefType(exprType))
- if (type instanceof CtPrimitiveType) {
- CtPrimitiveType pt = (CtPrimitiveType)type;
- atNumCastExpr(exprType, descToType(pt.getDescriptor()));
- }
- else
- throw new CompileError("type mismatch");
+ if (arrayDim == 0 && !isRefType(exprType))
+ if (type instanceof CtPrimitiveType) {
+ CtPrimitiveType pt = (CtPrimitiveType)type;
+ atNumCastExpr(exprType, descToType(pt.getDescriptor()));
+ }
+ else
+ throw new CompileError("type mismatch");
}
}
diff --git a/src/main/javassist/compiler/KeywordTable.java b/src/main/javassist/compiler/KeywordTable.java
index 57145bf8..833c9447 100644
--- a/src/main/javassist/compiler/KeywordTable.java
+++ b/src/main/javassist/compiler/KeywordTable.java
@@ -1,42 +1,31 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
final class KeywordTable extends java.util.HashMap {
public KeywordTable() { super(); }
public int lookup(String name) {
- Object found = get(name);
- if (found == null)
- return -1;
- else
- return ((Integer)found).intValue();
+ Object found = get(name);
+ if (found == null)
+ return -1;
+ else
+ return ((Integer)found).intValue();
}
public void append(String name, int t) {
- put(name, new Integer(t));
+ put(name, new Integer(t));
}
}
diff --git a/src/main/javassist/compiler/Lex.java b/src/main/javassist/compiler/Lex.java
index fb188de5..69175dee 100644
--- a/src/main/javassist/compiler/Lex.java
+++ b/src/main/javassist/compiler/Lex.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
class Token {
@@ -47,501 +36,501 @@ public class Lex implements TokenId {
* Constructs a lexical analyzer.
*/
public Lex(String s) {
- lastChar = -1;
- textBuffer = new StringBuffer();
- currentToken = new Token();
- lookAheadTokens = null;
-
- input = s;
- position = 0;
- maxlen = s.length();
- lineNumber = 0;
+ lastChar = -1;
+ textBuffer = new StringBuffer();
+ currentToken = new Token();
+ lookAheadTokens = null;
+
+ input = s;
+ position = 0;
+ maxlen = s.length();
+ lineNumber = 0;
}
public int get() {
- if (lookAheadTokens == null)
- return get(currentToken);
- else {
- Token t;
- currentToken = t = lookAheadTokens;
- lookAheadTokens = lookAheadTokens.next;
- return t.tokenId;
- }
+ if (lookAheadTokens == null)
+ return get(currentToken);
+ else {
+ Token t;
+ currentToken = t = lookAheadTokens;
+ lookAheadTokens = lookAheadTokens.next;
+ return t.tokenId;
+ }
}
/**
* Looks at the next token.
*/
public int lookAhead() {
- return lookAhead(0);
+ return lookAhead(0);
}
public int lookAhead(int i) {
- Token tk = lookAheadTokens;
- if (tk == null) {
- lookAheadTokens = tk = currentToken; // reuse an object!
- tk.next = null;
- get(tk);
- }
-
- for (; i-- > 0; tk = tk.next)
- if (tk.next == null) {
- Token tk2;
- tk.next = tk2 = new Token();
- get(tk2);
- }
-
- currentToken = tk;
- return tk.tokenId;
+ Token tk = lookAheadTokens;
+ if (tk == null) {
+ lookAheadTokens = tk = currentToken; // reuse an object!
+ tk.next = null;
+ get(tk);
+ }
+
+ for (; i-- > 0; tk = tk.next)
+ if (tk.next == null) {
+ Token tk2;
+ tk.next = tk2 = new Token();
+ get(tk2);
+ }
+
+ currentToken = tk;
+ return tk.tokenId;
}
public String getString() {
- return currentToken.textValue;
+ return currentToken.textValue;
}
public long getLong() {
- return currentToken.longValue;
+ return currentToken.longValue;
}
public double getDouble() {
- return currentToken.doubleValue;
+ return currentToken.doubleValue;
}
private int get(Token token) {
- int t;
- do {
- t = readLine(token);
- } while (t == '\n');
- token.tokenId = t;
- return t;
+ int t;
+ do {
+ t = readLine(token);
+ } while (t == '\n');
+ token.tokenId = t;
+ return t;
}
private int readLine(Token token) {
- int c = getNextNonWhiteChar();
- if(c < 0)
- return c;
- else if(c == '\n') {
- ++lineNumber;
- return '\n';
- }
- else if (c == '\'')
- return readCharConst(token);
- else if (c == '"')
- return readStringL(token);
- else if ('0' <= c && c <= '9')
- return readNumber(c, token);
- else if(c == '.'){
- c = getc();
- if ('0' <= c && c <= '9') {
- StringBuffer tbuf = textBuffer;
- tbuf.setLength(0);
- tbuf.append('.');
- return readDouble(tbuf, c, token);
- }
- else{
- ungetc(c);
- return readSeparator('.');
- }
- }
- else if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_'
- || c == '$')
- return readIdentifier(c, token);
- else
- return readSeparator(c);
+ int c = getNextNonWhiteChar();
+ if(c < 0)
+ return c;
+ else if(c == '\n') {
+ ++lineNumber;
+ return '\n';
+ }
+ else if (c == '\'')
+ return readCharConst(token);
+ else if (c == '"')
+ return readStringL(token);
+ else if ('0' <= c && c <= '9')
+ return readNumber(c, token);
+ else if(c == '.'){
+ c = getc();
+ if ('0' <= c && c <= '9') {
+ StringBuffer tbuf = textBuffer;
+ tbuf.setLength(0);
+ tbuf.append('.');
+ return readDouble(tbuf, c, token);
+ }
+ else{
+ ungetc(c);
+ return readSeparator('.');
+ }
+ }
+ else if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_'
+ || c == '$')
+ return readIdentifier(c, token);
+ else
+ return readSeparator(c);
}
private int getNextNonWhiteChar() {
- int c;
- do {
- c = getc();
- if (c == '/') {
- c = getc();
- if (c == '/')
- do {
- c = getc();
- } while (c != '\n' && c != '\r' && c != -1);
- else if (c == '*')
- while (true) {
- c = getc();
- if (c == -1)
- break;
- else if (c == '*')
- if ((c = getc()) == '/') {
- c = ' ';
- break;
- }
- else
- ungetc(c);
- }
- else {
- ungetc(c);
- c = '/';
- }
- }
- } while(isBlank(c));
- return c;
+ int c;
+ do {
+ c = getc();
+ if (c == '/') {
+ c = getc();
+ if (c == '/')
+ do {
+ c = getc();
+ } while (c != '\n' && c != '\r' && c != -1);
+ else if (c == '*')
+ while (true) {
+ c = getc();
+ if (c == -1)
+ break;
+ else if (c == '*')
+ if ((c = getc()) == '/') {
+ c = ' ';
+ break;
+ }
+ else
+ ungetc(c);
+ }
+ else {
+ ungetc(c);
+ c = '/';
+ }
+ }
+ } while(isBlank(c));
+ return c;
}
private int readCharConst(Token token) {
- int c;
- int value = 0;
- while ((c = getc()) != '\'')
- if (c == '\\')
- value = readEscapeChar();
- else if (c < 0x20) {
- if (c == '\n')
- ++lineNumber;
-
- return BadToken;
- }
- else
- value = c;
-
- token.longValue = value;
- return CharConstant;
+ int c;
+ int value = 0;
+ while ((c = getc()) != '\'')
+ if (c == '\\')
+ value = readEscapeChar();
+ else if (c < 0x20) {
+ if (c == '\n')
+ ++lineNumber;
+
+ return BadToken;
+ }
+ else
+ value = c;
+
+ token.longValue = value;
+ return CharConstant;
}
private int readEscapeChar() {
- int c = getc();
- if (c == 'n')
- c = '\n';
- else if (c == 't')
- c = '\t';
- else if (c == 'r')
- c = '\r';
- else if (c == 'f')
- c = '\f';
- else if (c == '\n')
- ++lineNumber;
-
- return c;
+ int c = getc();
+ if (c == 'n')
+ c = '\n';
+ else if (c == 't')
+ c = '\t';
+ else if (c == 'r')
+ c = '\r';
+ else if (c == 'f')
+ c = '\f';
+ else if (c == '\n')
+ ++lineNumber;
+
+ return c;
}
private int readStringL(Token token) {
- int c;
- StringBuffer tbuf = textBuffer;
- tbuf.setLength(0);
- for (;;) {
- while ((c = getc()) != '"') {
- if (c == '\\')
- c = readEscapeChar();
- else if (c == '\n' || c < 0) {
- ++lineNumber;
- return BadToken;
- }
-
- tbuf.append((char)c);
- }
-
- for (;;) {
- c = getc();
- if (c == '\n')
- ++lineNumber;
- else if (!isBlank(c))
- break;
- }
-
- if (c != '"') {
- ungetc(c);
- break;
- }
- }
-
- token.textValue = tbuf.toString();
- return StringL;
+ int c;
+ StringBuffer tbuf = textBuffer;
+ tbuf.setLength(0);
+ for (;;) {
+ while ((c = getc()) != '"') {
+ if (c == '\\')
+ c = readEscapeChar();
+ else if (c == '\n' || c < 0) {
+ ++lineNumber;
+ return BadToken;
+ }
+
+ tbuf.append((char)c);
+ }
+
+ for (;;) {
+ c = getc();
+ if (c == '\n')
+ ++lineNumber;
+ else if (!isBlank(c))
+ break;
+ }
+
+ if (c != '"') {
+ ungetc(c);
+ break;
+ }
+ }
+
+ token.textValue = tbuf.toString();
+ return StringL;
}
private int readNumber(int c, Token token) {
- long value = 0;
- int c2 = getc();
- if (c == '0')
- if (c2 == 'X' || c2 == 'x')
- for (;;) {
- c = getc();
- if ('0' <= c && c <= '9')
- value = value * 16 + (long)(c - '0');
- else if ('A' <= c && c <= 'F')
- value = value * 16 + (long)(c - 'A' + 10);
- else if ('a' <= c && c <= 'f')
- value = value * 16 + (long)(c - 'a' + 10);
- else {
- token.longValue = value;
- if (c == 'L' || c == 'l')
- return LongConstant;
- else {
- ungetc(c);
- return IntConstant;
- }
- }
- }
- else if ('0' <= c2 && c2 <= '7') {
- value = c2 - '0';
- for (;;) {
- c = getc();
- if ('0' <= c && c <= '7')
- value = value * 8 + (long)(c - '0');
- else {
- token.longValue = value;
- if (c == 'L' || c == 'l')
- return LongConstant;
- else {
- ungetc(c);
- return IntConstant;
- }
- }
- }
- }
-
- value = c - '0';
- while ('0' <= c2 && c2 <= '9') {
- value = value * 10 + c2 - '0';
- c2 = getc();
- }
-
- token.longValue = value;
- if (c2 == 'F' || c2 == 'f') {
- token.doubleValue = (double)value;
- return FloatConstant;
- }
- else if (c2 == 'E' || c2 == 'e' || c2 == '.') {
- StringBuffer tbuf = textBuffer;
- tbuf.setLength(0);
- tbuf.append(value);
- return readDouble(tbuf, c2, token);
- }
- else if (c2 == 'L' || c2 == 'l')
- return LongConstant;
- else {
- ungetc(c2);
- return IntConstant;
- }
+ long value = 0;
+ int c2 = getc();
+ if (c == '0')
+ if (c2 == 'X' || c2 == 'x')
+ for (;;) {
+ c = getc();
+ if ('0' <= c && c <= '9')
+ value = value * 16 + (long)(c - '0');
+ else if ('A' <= c && c <= 'F')
+ value = value * 16 + (long)(c - 'A' + 10);
+ else if ('a' <= c && c <= 'f')
+ value = value * 16 + (long)(c - 'a' + 10);
+ else {
+ token.longValue = value;
+ if (c == 'L' || c == 'l')
+ return LongConstant;
+ else {
+ ungetc(c);
+ return IntConstant;
+ }
+ }
+ }
+ else if ('0' <= c2 && c2 <= '7') {
+ value = c2 - '0';
+ for (;;) {
+ c = getc();
+ if ('0' <= c && c <= '7')
+ value = value * 8 + (long)(c - '0');
+ else {
+ token.longValue = value;
+ if (c == 'L' || c == 'l')
+ return LongConstant;
+ else {
+ ungetc(c);
+ return IntConstant;
+ }
+ }
+ }
+ }
+
+ value = c - '0';
+ while ('0' <= c2 && c2 <= '9') {
+ value = value * 10 + c2 - '0';
+ c2 = getc();
+ }
+
+ token.longValue = value;
+ if (c2 == 'F' || c2 == 'f') {
+ token.doubleValue = (double)value;
+ return FloatConstant;
+ }
+ else if (c2 == 'E' || c2 == 'e' || c2 == '.') {
+ StringBuffer tbuf = textBuffer;
+ tbuf.setLength(0);
+ tbuf.append(value);
+ return readDouble(tbuf, c2, token);
+ }
+ else if (c2 == 'L' || c2 == 'l')
+ return LongConstant;
+ else {
+ ungetc(c2);
+ return IntConstant;
+ }
}
private int readDouble(StringBuffer sbuf, int c, Token token) {
- if (c != 'E' && c != 'e') {
- sbuf.append((char)c);
- for (;;) {
- c = getc();
- if ('0' <= c && c <= '9')
- sbuf.append((char)c);
- else
- break;
- }
- }
-
- if (c == 'E' || c == 'e') {
- sbuf.append((char)c);
- c = getc();
- if (c == '+' || c == '-') {
- sbuf.append((char)c);
- c = getc();
- }
-
- while ('0' <= c && c <= '9') {
- sbuf.append((char)c);
- c = getc();
- }
- }
-
- try {
- token.doubleValue = Double.parseDouble(sbuf.toString());
- }
- catch (NumberFormatException e) {
- return BadToken;
- }
-
- if (c == 'F' || c == 'f')
- return FloatConstant;
- else {
- ungetc(c);
- return DoubleConstant;
- }
+ if (c != 'E' && c != 'e') {
+ sbuf.append((char)c);
+ for (;;) {
+ c = getc();
+ if ('0' <= c && c <= '9')
+ sbuf.append((char)c);
+ else
+ break;
+ }
+ }
+
+ if (c == 'E' || c == 'e') {
+ sbuf.append((char)c);
+ c = getc();
+ if (c == '+' || c == '-') {
+ sbuf.append((char)c);
+ c = getc();
+ }
+
+ while ('0' <= c && c <= '9') {
+ sbuf.append((char)c);
+ c = getc();
+ }
+ }
+
+ try {
+ token.doubleValue = Double.parseDouble(sbuf.toString());
+ }
+ catch (NumberFormatException e) {
+ return BadToken;
+ }
+
+ if (c == 'F' || c == 'f')
+ return FloatConstant;
+ else {
+ ungetc(c);
+ return DoubleConstant;
+ }
}
// !"#$%&'( )*+,-./0 12345678 9:;<=>?
private static final int[] equalOps
- = { NEQ, 0, 0, 0, MOD_E, AND_E, 0, 0,
- 0, MUL_E, PLUS_E, 0, MINUS_E, 0, DIV_E, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, LE, EQ, GE, 0 };
+ = { NEQ, 0, 0, 0, MOD_E, AND_E, 0, 0,
+ 0, MUL_E, PLUS_E, 0, MINUS_E, 0, DIV_E, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, LE, EQ, GE, 0 };
private int readSeparator(int c) {
- int c2, c3;
- if ('!' <= c && c <= '?') {
- int t = equalOps[c - '!'];
- if (t == 0)
- return c;
- else {
- c2 = getc();
- if (c == c2)
- switch (c) {
- case '=' :
- return EQ;
- case '+' :
- return PLUSPLUS;
- case '-' :
- return MINUSMINUS;
- case '&' :
- return ANDAND;
- case '<' :
- c3 = getc();
- if (c3 == '=')
- return LSHIFT_E;
- else {
- ungetc(c3);
- return LSHIFT;
- }
- case '>' :
- c3 = getc();
- if (c3 == '=')
- return RSHIFT_E;
- else if (c3 == '>') {
- c3 = getc();
- if (c3 == '=')
- return ARSHIFT_E;
- else {
- ungetc(c3);
- return ARSHIFT;
- }
- }
- else {
- ungetc(c3);
- return RSHIFT;
- }
- default :
- break;
- }
- else if (c2 == '=')
- return t;
- }
- }
- else if (c == '^') {
- c2 = getc();
- if (c2 == '=')
- return EXOR_E;
- }
- else if (c == '|') {
- c2 = getc();
- if (c2 == '=')
- return OR_E;
- else if (c2 == '|')
- return OROR;
- }
- else
- return c;
-
- ungetc(c2);
- return c;
+ int c2, c3;
+ if ('!' <= c && c <= '?') {
+ int t = equalOps[c - '!'];
+ if (t == 0)
+ return c;
+ else {
+ c2 = getc();
+ if (c == c2)
+ switch (c) {
+ case '=' :
+ return EQ;
+ case '+' :
+ return PLUSPLUS;
+ case '-' :
+ return MINUSMINUS;
+ case '&' :
+ return ANDAND;
+ case '<' :
+ c3 = getc();
+ if (c3 == '=')
+ return LSHIFT_E;
+ else {
+ ungetc(c3);
+ return LSHIFT;
+ }
+ case '>' :
+ c3 = getc();
+ if (c3 == '=')
+ return RSHIFT_E;
+ else if (c3 == '>') {
+ c3 = getc();
+ if (c3 == '=')
+ return ARSHIFT_E;
+ else {
+ ungetc(c3);
+ return ARSHIFT;
+ }
+ }
+ else {
+ ungetc(c3);
+ return RSHIFT;
+ }
+ default :
+ break;
+ }
+ else if (c2 == '=')
+ return t;
+ }
+ }
+ else if (c == '^') {
+ c2 = getc();
+ if (c2 == '=')
+ return EXOR_E;
+ }
+ else if (c == '|') {
+ c2 = getc();
+ if (c2 == '=')
+ return OR_E;
+ else if (c2 == '|')
+ return OROR;
+ }
+ else
+ return c;
+
+ ungetc(c2);
+ return c;
}
private int readIdentifier(int c, Token token) {
- StringBuffer tbuf = textBuffer;
- tbuf.setLength(0);
-
- do {
- tbuf.append((char)c);
- c = getc();
- } while ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_'
- || c == '$' || '0' <= c && c <= '9');
-
- ungetc(c);
-
- String name = tbuf.toString();
- int t = ktable.lookup(name);
- if (t >= 0)
- return t;
- else {
- /* tbuf.toString() is executed quickly since it does not
- * need memory copy. Using a hand-written extensible
- * byte-array class instead of StringBuffer is not a good idea
- * for execution speed. Converting a byte array to a String
- * object is very slow. Using an extensible char array
- * might be OK.
- */
- token.textValue = name;
- return Identifier;
- }
+ StringBuffer tbuf = textBuffer;
+ tbuf.setLength(0);
+
+ do {
+ tbuf.append((char)c);
+ c = getc();
+ } while ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_'
+ || c == '$' || '0' <= c && c <= '9');
+
+ ungetc(c);
+
+ String name = tbuf.toString();
+ int t = ktable.lookup(name);
+ if (t >= 0)
+ return t;
+ else {
+ /* tbuf.toString() is executed quickly since it does not
+ * need memory copy. Using a hand-written extensible
+ * byte-array class instead of StringBuffer is not a good idea
+ * for execution speed. Converting a byte array to a String
+ * object is very slow. Using an extensible char array
+ * might be OK.
+ */
+ token.textValue = name;
+ return Identifier;
+ }
}
private static final KeywordTable ktable = new KeywordTable();
static {
- ktable.append("abstract", ABSTRACT);
- ktable.append("boolean", BOOLEAN);
- ktable.append("break", BREAK);
- ktable.append("byte", BYTE);
- ktable.append("case", CASE);
- ktable.append("catch", CATCH);
- ktable.append("char", CHAR);
- ktable.append("class", CLASS);
- ktable.append("const", CONST);
- ktable.append("continue", CONTINUE);
- ktable.append("default", DEFAULT);
- ktable.append("do", DO);
- ktable.append("double", DOUBLE);
- ktable.append("else", ELSE);
- ktable.append("extends", EXTENDS);
- ktable.append("false", FALSE);
- ktable.append("final", FINAL);
- ktable.append("finally", FINALLY);
- ktable.append("float", FLOAT);
- ktable.append("for", FOR);
- ktable.append("goto", GOTO);
- ktable.append("if", IF);
- ktable.append("implements", IMPLEMENTS);
- ktable.append("import", IMPORT);
- ktable.append("instanceof", INSTANCEOF);
- ktable.append("int", INT);
- ktable.append("interface", INTERFACE);
- ktable.append("long", LONG);
- ktable.append("native", NATIVE);
- ktable.append("new", NEW);
- ktable.append("null", NULL);
- ktable.append("package", PACKAGE);
- ktable.append("private", PRIVATE);
- ktable.append("protected", PROTECTED);
- ktable.append("public", PUBLIC);
- ktable.append("return", RETURN);
- ktable.append("short", SHORT);
- ktable.append("static", STATIC);
- ktable.append("strict", STRICT);
- ktable.append("super", SUPER);
- ktable.append("switch", SWITCH);
- ktable.append("synchronized", SYNCHRONIZED);
- ktable.append("this", THIS);
- ktable.append("throw", THROW);
- ktable.append("throws", THROWS);
- ktable.append("transient", TRANSIENT);
- ktable.append("true", TRUE);
- ktable.append("try", TRY);
- ktable.append("void", VOID);
- ktable.append("volatile", VOLATILE);
- ktable.append("while", WHILE);
+ ktable.append("abstract", ABSTRACT);
+ ktable.append("boolean", BOOLEAN);
+ ktable.append("break", BREAK);
+ ktable.append("byte", BYTE);
+ ktable.append("case", CASE);
+ ktable.append("catch", CATCH);
+ ktable.append("char", CHAR);
+ ktable.append("class", CLASS);
+ ktable.append("const", CONST);
+ ktable.append("continue", CONTINUE);
+ ktable.append("default", DEFAULT);
+ ktable.append("do", DO);
+ ktable.append("double", DOUBLE);
+ ktable.append("else", ELSE);
+ ktable.append("extends", EXTENDS);
+ ktable.append("false", FALSE);
+ ktable.append("final", FINAL);
+ ktable.append("finally", FINALLY);
+ ktable.append("float", FLOAT);
+ ktable.append("for", FOR);
+ ktable.append("goto", GOTO);
+ ktable.append("if", IF);
+ ktable.append("implements", IMPLEMENTS);
+ ktable.append("import", IMPORT);
+ ktable.append("instanceof", INSTANCEOF);
+ ktable.append("int", INT);
+ ktable.append("interface", INTERFACE);
+ ktable.append("long", LONG);
+ ktable.append("native", NATIVE);
+ ktable.append("new", NEW);
+ ktable.append("null", NULL);
+ ktable.append("package", PACKAGE);
+ ktable.append("private", PRIVATE);
+ ktable.append("protected", PROTECTED);
+ ktable.append("public", PUBLIC);
+ ktable.append("return", RETURN);
+ ktable.append("short", SHORT);
+ ktable.append("static", STATIC);
+ ktable.append("strict", STRICT);
+ ktable.append("super", SUPER);
+ ktable.append("switch", SWITCH);
+ ktable.append("synchronized", SYNCHRONIZED);
+ ktable.append("this", THIS);
+ ktable.append("throw", THROW);
+ ktable.append("throws", THROWS);
+ ktable.append("transient", TRANSIENT);
+ ktable.append("true", TRUE);
+ ktable.append("try", TRY);
+ ktable.append("void", VOID);
+ ktable.append("volatile", VOLATILE);
+ ktable.append("while", WHILE);
}
private static boolean isBlank(int c) {
- return c == ' ' || c == '\t' || c == '\f' || c == '\r'
- || c == '\n';
+ return c == ' ' || c == '\t' || c == '\f' || c == '\r'
+ || c == '\n';
}
private static boolean isDigit(int c) {
- return '0' <= c && c <= '9';
+ return '0' <= c && c <= '9';
}
private void ungetc(int c) {
- lastChar = c;
+ lastChar = c;
}
private int getc() {
- if (lastChar < 0)
- if (position < maxlen)
- return input.charAt(position++);
- else
- return -1;
- else {
- int c = lastChar;
- lastChar = -1;
- return c;
- }
+ if (lastChar < 0)
+ if (position < maxlen)
+ return input.charAt(position++);
+ else
+ return -1;
+ else {
+ int c = lastChar;
+ lastChar = -1;
+ return c;
+ }
}
}
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java
index d457a836..c9f18b61 100644
--- a/src/main/javassist/compiler/MemberCodeGen.java
+++ b/src/main/javassist/compiler/MemberCodeGen.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import java.util.List;
@@ -40,17 +29,17 @@ public class MemberCodeGen extends CodeGen {
protected boolean resultStatic;
public MemberCodeGen(Bytecode b, CtClass cc, ClassPool cp) {
- super(b);
- classPool = cp;
- thisClass = cc;
- thisMethod = null;
+ super(b);
+ classPool = cp;
+ thisClass = cc;
+ thisMethod = null;
}
/**
* Records the currently compiled method.
*/
public void setThisMethod(CtMethod m) {
- thisMethod = m.getMethodInfo2();
+ thisMethod = m.getMethodInfo2();
}
public CtClass getThisClass() { return thisClass; }
@@ -59,449 +48,449 @@ public class MemberCodeGen extends CodeGen {
* Returns the JVM-internal representation of this class name.
*/
protected String getThisName() {
- return javaToJvmName(thisClass.getName());
+ return javaToJvmName(thisClass.getName());
}
/**
* Returns the JVM-internal representation of this super class name.
*/
protected String getSuperName() throws CompileError {
- return javaToJvmName(getSuperclass(thisClass).getName());
+ return javaToJvmName(getSuperclass(thisClass).getName());
}
protected void insertDefaultSuperCall() throws CompileError {
- bytecode.addAload(0);
- bytecode.addInvokespecial(getSuperclass(thisClass), "<init>", "()V");
+ bytecode.addAload(0);
+ bytecode.addInvokespecial(getSuperclass(thisClass), "<init>", "()V");
}
protected void atTryStmnt(Stmnt st) throws CompileError {
- Stmnt body = (Stmnt)st.getLeft();
- if (body == null)
- return;
-
- int start = bytecode.currentPc();
- body.accept(this);
- int end = bytecode.currentPc();
-
- bytecode.addOpcode(Opcode.GOTO);
- int pc = bytecode.currentPc();
- bytecode.addIndex(0); // correct later
-
- int var = getMaxLocals();
- incMaxLocals(1);
- ASTList catchList = (ASTList)st.getRight().getLeft();
- while (catchList != null) {
- Pair p = (Pair)catchList.head();
- catchList = catchList.tail();
- Declarator decl = (Declarator)p.getLeft();
- Stmnt block = (Stmnt)p.getRight();
-
- decl.setLocalVar(var);
-
- CtClass type = lookupClass(decl.getClassName());
- decl.setClassName(javaToJvmName(type.getName()));
- bytecode.addExceptionHandler(start, end, bytecode.currentPc(),
- type);
- if (block != null) {
- bytecode.addAstore(var);
- block.accept(this);
- }
-
- bytecode.addOpcode(Opcode.GOTO);
- bytecode.addIndex(pc - bytecode.currentPc());
- }
-
- Stmnt finallyBlock = (Stmnt)st.getRight().getRight().getLeft();
- if (finallyBlock != null)
- throw new CompileError(
- "sorry, finally has not been supported yet");
-
- bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
+ Stmnt body = (Stmnt)st.getLeft();
+ if (body == null)
+ return;
+
+ int start = bytecode.currentPc();
+ body.accept(this);
+ int end = bytecode.currentPc();
+
+ bytecode.addOpcode(Opcode.GOTO);
+ int pc = bytecode.currentPc();
+ bytecode.addIndex(0); // correct later
+
+ int var = getMaxLocals();
+ incMaxLocals(1);
+ ASTList catchList = (ASTList)st.getRight().getLeft();
+ while (catchList != null) {
+ Pair p = (Pair)catchList.head();
+ catchList = catchList.tail();
+ Declarator decl = (Declarator)p.getLeft();
+ Stmnt block = (Stmnt)p.getRight();
+
+ decl.setLocalVar(var);
+
+ CtClass type = lookupClass(decl.getClassName());
+ decl.setClassName(javaToJvmName(type.getName()));
+ bytecode.addExceptionHandler(start, end, bytecode.currentPc(),
+ type);
+ if (block != null) {
+ bytecode.addAstore(var);
+ block.accept(this);
+ }
+
+ bytecode.addOpcode(Opcode.GOTO);
+ bytecode.addIndex(pc - bytecode.currentPc());
+ }
+
+ Stmnt finallyBlock = (Stmnt)st.getRight().getRight().getLeft();
+ if (finallyBlock != null)
+ throw new CompileError(
+ "sorry, finally has not been supported yet");
+
+ bytecode.write16bit(pc, bytecode.currentPc() - pc + 1);
}
public void atNewExpr(NewExpr expr) throws CompileError {
- if (expr.isArray())
- atNewArrayExpr(expr);
- else {
- CtClass clazz = lookupClass(expr.getClassName());
- String cname = clazz.getName();
- ASTList args = expr.getArguments();
- bytecode.addNew(cname);
- bytecode.addOpcode(DUP);
-
- atMethodCall2(clazz, MethodInfo.nameInit, args, false, true);
-
- exprType = CLASS;
- arrayDim = 0;
- className = javaToJvmName(cname);
- }
+ if (expr.isArray())
+ atNewArrayExpr(expr);
+ else {
+ CtClass clazz = lookupClass(expr.getClassName());
+ String cname = clazz.getName();
+ ASTList args = expr.getArguments();
+ bytecode.addNew(cname);
+ bytecode.addOpcode(DUP);
+
+ atMethodCall2(clazz, MethodInfo.nameInit, args, false, true);
+
+ exprType = CLASS;
+ arrayDim = 0;
+ className = javaToJvmName(cname);
+ }
}
public void atNewArrayExpr(NewExpr expr) throws CompileError {
- if (expr.getInitializer() != null)
- throw new CompileError("array initializer is not supported");
-
- int type = expr.getArrayType();
- ASTList size = expr.getArraySize();
- ASTList classname = expr.getClassName();
- if (size.length() > 1) {
- atMultiNewArray(type, classname, size);
- return;
- }
-
- size.head().accept(this);
- exprType = type;
- arrayDim = 1;
- if (type == CLASS) {
- className = resolveClassName(classname);
- bytecode.addAnewarray(jvmToJavaName(className));
- }
- else {
- className = null;
- int atype = 0;
- switch (type) {
- case BOOLEAN :
- atype = T_BOOLEAN;
- break;
- case CHAR :
- atype = T_CHAR;
- break;
- case FLOAT :
- atype = T_FLOAT;
- break;
- case DOUBLE :
- atype = T_DOUBLE;
- break;
- case BYTE :
- atype = T_BYTE;
- break;
- case SHORT :
- atype = T_SHORT;
- break;
- case INT :
- atype = T_INT;
- break;
- case LONG :
- atype = T_LONG;
- break;
- default :
- badNewExpr();
- break;
- }
-
- bytecode.addOpcode(NEWARRAY);
- bytecode.add(atype);
- }
+ if (expr.getInitializer() != null)
+ throw new CompileError("array initializer is not supported");
+
+ int type = expr.getArrayType();
+ ASTList size = expr.getArraySize();
+ ASTList classname = expr.getClassName();
+ if (size.length() > 1) {
+ atMultiNewArray(type, classname, size);
+ return;
+ }
+
+ size.head().accept(this);
+ exprType = type;
+ arrayDim = 1;
+ if (type == CLASS) {
+ className = resolveClassName(classname);
+ bytecode.addAnewarray(jvmToJavaName(className));
+ }
+ else {
+ className = null;
+ int atype = 0;
+ switch (type) {
+ case BOOLEAN :
+ atype = T_BOOLEAN;
+ break;
+ case CHAR :
+ atype = T_CHAR;
+ break;
+ case FLOAT :
+ atype = T_FLOAT;
+ break;
+ case DOUBLE :
+ atype = T_DOUBLE;
+ break;
+ case BYTE :
+ atype = T_BYTE;
+ break;
+ case SHORT :
+ atype = T_SHORT;
+ break;
+ case INT :
+ atype = T_INT;
+ break;
+ case LONG :
+ atype = T_LONG;
+ break;
+ default :
+ badNewExpr();
+ break;
+ }
+
+ bytecode.addOpcode(NEWARRAY);
+ bytecode.add(atype);
+ }
}
private static void badNewExpr() throws CompileError {
- throw new CompileError("bad new expression");
+ throw new CompileError("bad new expression");
}
protected void atMultiNewArray(int type, ASTList classname, ASTList size)
- throws CompileError
+ throws CompileError
{
- int count, dim;
- dim = size.length();
- for (count = 0; size != null; size = size.tail()) {
- ASTree s = size.head();
- if (s == null)
- break; // int[][][] a = new int[3][4][];
-
- ++count;
- s.accept(this);
- if (exprType != INT)
- throw new CompileError("bad type for array size");
- }
-
- String desc;
- exprType = type;
- arrayDim = dim;
- if (type == CLASS) {
- className = resolveClassName(classname);
- desc = toJvmArrayName(className, dim);
- }
- else
- desc = toJvmTypeName(type, dim);
-
- bytecode.addMultiNewarray(desc, count);
+ int count, dim;
+ dim = size.length();
+ for (count = 0; size != null; size = size.tail()) {
+ ASTree s = size.head();
+ if (s == null)
+ break; // int[][][] a = new int[3][4][];
+
+ ++count;
+ s.accept(this);
+ if (exprType != INT)
+ throw new CompileError("bad type for array size");
+ }
+
+ String desc;
+ exprType = type;
+ arrayDim = dim;
+ if (type == CLASS) {
+ className = resolveClassName(classname);
+ desc = toJvmArrayName(className, dim);
+ }
+ else
+ desc = toJvmTypeName(type, dim);
+
+ bytecode.addMultiNewarray(desc, count);
}
protected void atMethodCall(Expr expr) throws CompileError {
- String mname = null;
- CtClass targetClass = null;
- ASTree method = expr.oprand1();
- ASTList args = (ASTList)expr.oprand2();
- boolean isStatic = false;
- boolean isSpecial = false;
-
- if (method instanceof Member) {
- mname = ((Member)method).get();
- targetClass = thisClass;
- bytecode.addAload(0); // this
- }
- else if (method instanceof Keyword) { // constructor
- isSpecial = true;
- mname = MethodInfo.nameInit; // <init>
- targetClass = thisClass;
- bytecode.addAload(0); // this
- if (((Keyword)method).get() == SUPER)
- targetClass = getSuperclass(targetClass);
- }
- else if (method instanceof Expr) {
- Expr e = (Expr)method;
- mname = ((Symbol)e.oprand2()).get();
- int op = e.getOperator();
- if (op == MEMBER) { // static method
- targetClass = lookupClass((ASTList)e.oprand1());
- isStatic = true;
- }
- else if (op == '.') {
- ASTree target = e.oprand1();
- if (target instanceof Keyword)
- if (((Keyword)target).get() == SUPER)
- isSpecial = true;
-
- try {
- target.accept(this);
- }
- catch (NoFieldException nfe) {
- if (nfe.getExpr() != target)
- throw nfe;
-
- // it should be a static method.
- exprType = CLASS;
- arrayDim = 0;
- className = nfe.getField(); // JVM-internal
- isStatic = true;
- }
-
- if (arrayDim > 0)
- targetClass = lookupClass2(javaLangObject);
- else if (exprType == CLASS /* && arrayDim == 0 */)
- targetClass = lookupClass(className);
- else
- badMethod();
- }
- else
- badMethod();
- }
- else
- fatal();
-
- atMethodCall2(targetClass, mname, args, isStatic, isSpecial);
+ String mname = null;
+ CtClass targetClass = null;
+ ASTree method = expr.oprand1();
+ ASTList args = (ASTList)expr.oprand2();
+ boolean isStatic = false;
+ boolean isSpecial = false;
+
+ if (method instanceof Member) {
+ mname = ((Member)method).get();
+ targetClass = thisClass;
+ bytecode.addAload(0); // this
+ }
+ else if (method instanceof Keyword) { // constructor
+ isSpecial = true;
+ mname = MethodInfo.nameInit; // <init>
+ targetClass = thisClass;
+ bytecode.addAload(0); // this
+ if (((Keyword)method).get() == SUPER)
+ targetClass = getSuperclass(targetClass);
+ }
+ else if (method instanceof Expr) {
+ Expr e = (Expr)method;
+ mname = ((Symbol)e.oprand2()).get();
+ int op = e.getOperator();
+ if (op == MEMBER) { // static method
+ targetClass = lookupClass((ASTList)e.oprand1());
+ isStatic = true;
+ }
+ else if (op == '.') {
+ ASTree target = e.oprand1();
+ if (target instanceof Keyword)
+ if (((Keyword)target).get() == SUPER)
+ isSpecial = true;
+
+ try {
+ target.accept(this);
+ }
+ catch (NoFieldException nfe) {
+ if (nfe.getExpr() != target)
+ throw nfe;
+
+ // it should be a static method.
+ exprType = CLASS;
+ arrayDim = 0;
+ className = nfe.getField(); // JVM-internal
+ isStatic = true;
+ }
+
+ if (arrayDim > 0)
+ targetClass = lookupClass2(javaLangObject);
+ else if (exprType == CLASS /* && arrayDim == 0 */)
+ targetClass = lookupClass(className);
+ else
+ badMethod();
+ }
+ else
+ badMethod();
+ }
+ else
+ fatal();
+
+ atMethodCall2(targetClass, mname, args, isStatic, isSpecial);
}
private static void badMethod() throws CompileError {
- throw new CompileError("bad method");
+ throw new CompileError("bad method");
}
private static CtClass getSuperclass(CtClass c) throws CompileError {
- try {
- return c.getSuperclass();
- }
- catch (NotFoundException e) {
- throw new CompileError("cannot find the super class of "
- + c.getName());
- }
+ try {
+ return c.getSuperclass();
+ }
+ catch (NotFoundException e) {
+ throw new CompileError("cannot find the super class of "
+ + c.getName());
+ }
}
public void atMethodCall2(CtClass targetClass, String mname,
- ASTList args, boolean isStatic, boolean isSpecial)
- throws CompileError
+ ASTList args, boolean isStatic, boolean isSpecial)
+ throws CompileError
{
- int nargs = atMethodArgsLength(args);
- int[] types = new int[nargs];
- int[] dims = new int[nargs];
- String[] cnames = new String[nargs];
-
- int stack = bytecode.getStackDepth();
-
- atMethodArgs(args, types, dims, cnames);
-
- // used by invokeinterface
- int count = bytecode.getStackDepth() - stack + 1;
-
- Object[] found = lookupMethod(targetClass, thisMethod, mname,
- types, dims, cnames, false);
- if (found == null) {
- String msg;
- if (mname.equals(MethodInfo.nameInit))
- msg = "constructor not found";
- else
- msg = "Method " + mname + " not found in "
- + targetClass.getName();
-
- throw new CompileError(msg);
- }
-
- CtClass declClass = (CtClass)found[0];
- MethodInfo minfo = (MethodInfo)found[1];
- String desc = minfo.getDescriptor();
- int acc = minfo.getAccessFlags();
-
- if (mname.equals(MethodInfo.nameInit)) {
- isSpecial = true;
- if (declClass != targetClass)
- throw new CompileError("no such a constructor");
- }
- else if ((acc & AccessFlag.PRIVATE) != 0) {
- isSpecial = true;
- if (declClass != targetClass)
- throw new CompileError("Method " + mname + "is private");
- }
-
- boolean popTarget = false;
- if ((acc & AccessFlag.STATIC) != 0) {
- if (!isStatic) {
- /* this method is static but the target object is
- on stack. It must be popped out.
- */
- isStatic = true;
- popTarget = true;
- }
-
- bytecode.addInvokestatic(declClass, mname, desc);
- }
- else if (isSpecial)
- bytecode.addInvokespecial(declClass, mname, desc);
- else if (declClass.isInterface())
- bytecode.addInvokeinterface(declClass, mname, desc, count);
- else
- bytecode.addInvokevirtual(declClass, mname, desc);
-
- setReturnType(desc, isStatic, popTarget);
+ int nargs = atMethodArgsLength(args);
+ int[] types = new int[nargs];
+ int[] dims = new int[nargs];
+ String[] cnames = new String[nargs];
+
+ int stack = bytecode.getStackDepth();
+
+ atMethodArgs(args, types, dims, cnames);
+
+ // used by invokeinterface
+ int count = bytecode.getStackDepth() - stack + 1;
+
+ Object[] found = lookupMethod(targetClass, thisMethod, mname,
+ types, dims, cnames, false);
+ if (found == null) {
+ String msg;
+ if (mname.equals(MethodInfo.nameInit))
+ msg = "constructor not found";
+ else
+ msg = "Method " + mname + " not found in "
+ + targetClass.getName();
+
+ throw new CompileError(msg);
+ }
+
+ CtClass declClass = (CtClass)found[0];
+ MethodInfo minfo = (MethodInfo)found[1];
+ String desc = minfo.getDescriptor();
+ int acc = minfo.getAccessFlags();
+
+ if (mname.equals(MethodInfo.nameInit)) {
+ isSpecial = true;
+ if (declClass != targetClass)
+ throw new CompileError("no such a constructor");
+ }
+ else if ((acc & AccessFlag.PRIVATE) != 0) {
+ isSpecial = true;
+ if (declClass != targetClass)
+ throw new CompileError("Method " + mname + "is private");
+ }
+
+ boolean popTarget = false;
+ if ((acc & AccessFlag.STATIC) != 0) {
+ if (!isStatic) {
+ /* this method is static but the target object is
+ on stack. It must be popped out.
+ */
+ isStatic = true;
+ popTarget = true;
+ }
+
+ bytecode.addInvokestatic(declClass, mname, desc);
+ }
+ else if (isSpecial)
+ bytecode.addInvokespecial(declClass, mname, desc);
+ else if (declClass.isInterface())
+ bytecode.addInvokeinterface(declClass, mname, desc, count);
+ else
+ bytecode.addInvokevirtual(declClass, mname, desc);
+
+ setReturnType(desc, isStatic, popTarget);
}
public int atMethodArgsLength(ASTList args) {
- return ASTList.length(args);
+ return ASTList.length(args);
}
public void atMethodArgs(ASTList args, int[] types, int[] dims,
- String[] cnames) throws CompileError {
- int i = 0;
- while (args != null) {
- ASTree a = args.head();
- a.accept(this);
- types[i] = exprType;
- dims[i] = arrayDim;
- cnames[i] = className;
- ++i;
- args = args.tail();
- }
+ String[] cnames) throws CompileError {
+ int i = 0;
+ while (args != null) {
+ ASTree a = args.head();
+ a.accept(this);
+ types[i] = exprType;
+ dims[i] = arrayDim;
+ cnames[i] = className;
+ ++i;
+ args = args.tail();
+ }
}
private void setReturnType(String desc, boolean isStatic,
- boolean popTarget)
- throws CompileError
+ boolean popTarget)
+ throws CompileError
{
- int i = desc.indexOf(')');
- if (i < 0)
- badMethod();
-
- char c = desc.charAt(++i);
- int dim = 0;
- while (c == '[') {
- ++dim;
- c = desc.charAt(++i);
- }
-
- arrayDim = dim;
- if (c == 'L') {
- int j = desc.indexOf(';', i + 1);
- if (j < 0)
- badMethod();
-
- exprType = CLASS;
- className = desc.substring(i + 1, j);
- }
- else {
- exprType = descToType(c);
- className = null;
- }
-
- int etype = exprType;
- if (isStatic) {
- if (popTarget) {
- if (is2word(etype, dim)) {
- bytecode.addOpcode(DUP2_X1);
- bytecode.addOpcode(POP2);
- bytecode.addOpcode(POP);
- }
- else if (etype == VOID)
- bytecode.addOpcode(POP);
- else {
- bytecode.addOpcode(SWAP);
- bytecode.addOpcode(POP);
- }
- }
- }
+ int i = desc.indexOf(')');
+ if (i < 0)
+ badMethod();
+
+ char c = desc.charAt(++i);
+ int dim = 0;
+ while (c == '[') {
+ ++dim;
+ c = desc.charAt(++i);
+ }
+
+ arrayDim = dim;
+ if (c == 'L') {
+ int j = desc.indexOf(';', i + 1);
+ if (j < 0)
+ badMethod();
+
+ exprType = CLASS;
+ className = desc.substring(i + 1, j);
+ }
+ else {
+ exprType = descToType(c);
+ className = null;
+ }
+
+ int etype = exprType;
+ if (isStatic) {
+ if (popTarget) {
+ if (is2word(etype, dim)) {
+ bytecode.addOpcode(DUP2_X1);
+ bytecode.addOpcode(POP2);
+ bytecode.addOpcode(POP);
+ }
+ else if (etype == VOID)
+ bytecode.addOpcode(POP);
+ else {
+ bytecode.addOpcode(SWAP);
+ bytecode.addOpcode(POP);
+ }
+ }
+ }
}
private Object[] lookupMethod(CtClass clazz, MethodInfo current,
- String methodName,
- int[] argTypes, int[] argDims,
- String[] argClassNames, boolean onlyExact)
- throws CompileError
+ String methodName,
+ int[] argTypes, int[] argDims,
+ String[] argClassNames, boolean onlyExact)
+ throws CompileError
{
- Object[] maybe = null;
-
- if (current != null)
- if (current.getName().equals(methodName)) {
- int res = compareSignature(current.getDescriptor(),
- argTypes, argDims, argClassNames);
- Object[] r = new Object[] { clazz, current };
- if (res == YES)
- return r;
- else if (res == MAYBE && maybe == null)
- maybe = r;
- }
-
- List list = clazz.getClassFile2().getMethods();
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
- if (minfo.getName().equals(methodName)) {
- int res = compareSignature(minfo.getDescriptor(),
- argTypes, argDims, argClassNames);
- Object[] r = new Object[] { clazz, minfo };
- if (res == YES)
- return r;
- else if (res == MAYBE && maybe == null)
- maybe = r;
- }
- }
-
- try {
- CtClass pclazz = clazz.getSuperclass();
- if (pclazz != null) {
- Object[] r = lookupMethod(pclazz, null, methodName, argTypes,
- argDims, argClassNames,
- (onlyExact || maybe != null));
- if (r != null)
- return r;
- }
- }
- catch (NotFoundException e) {}
-
- /* -- not necessary to search implemented interfaces.
- try {
- CtClass[] ifs = clazz.getInterfaces();
- int size = ifs.length;
- for (int i = 0; i < size; ++i) {
- Object[] r = lookupMethod(ifs[i], methodName, argTypes,
- argDims, argClassNames);
- if (r != null)
- return r;
- }
- }
- catch (NotFoundException e) {}
- */
-
- if (onlyExact)
- return null;
- else
- return maybe;
+ Object[] maybe = null;
+
+ if (current != null)
+ if (current.getName().equals(methodName)) {
+ int res = compareSignature(current.getDescriptor(),
+ argTypes, argDims, argClassNames);
+ Object[] r = new Object[] { clazz, current };
+ if (res == YES)
+ return r;
+ else if (res == MAYBE && maybe == null)
+ maybe = r;
+ }
+
+ List list = clazz.getClassFile2().getMethods();
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ if (minfo.getName().equals(methodName)) {
+ int res = compareSignature(minfo.getDescriptor(),
+ argTypes, argDims, argClassNames);
+ Object[] r = new Object[] { clazz, minfo };
+ if (res == YES)
+ return r;
+ else if (res == MAYBE && maybe == null)
+ maybe = r;
+ }
+ }
+
+ try {
+ CtClass pclazz = clazz.getSuperclass();
+ if (pclazz != null) {
+ Object[] r = lookupMethod(pclazz, null, methodName, argTypes,
+ argDims, argClassNames,
+ (onlyExact || maybe != null));
+ if (r != null)
+ return r;
+ }
+ }
+ catch (NotFoundException e) {}
+
+ /* -- not necessary to search implemented interfaces.
+ try {
+ CtClass[] ifs = clazz.getInterfaces();
+ int size = ifs.length;
+ for (int i = 0; i < size; ++i) {
+ Object[] r = lookupMethod(ifs[i], methodName, argTypes,
+ argDims, argClassNames);
+ if (r != null)
+ return r;
+ }
+ }
+ catch (NotFoundException e) {}
+ */
+
+ if (onlyExact)
+ return null;
+ else
+ return maybe;
}
private static final int YES = 2;
@@ -517,391 +506,391 @@ public class MemberCodeGen extends CodeGen {
* algorithm.
*/
private int compareSignature(String desc, int[] argTypes,
- int[] argDims, String[] argClassNames)
- throws CompileError
+ int[] argDims, String[] argClassNames)
+ throws CompileError
{
- int result = YES;
- int i = 1;
- int nArgs = argTypes.length;
- if (nArgs != Descriptor.numOfParameters(desc))
- return NO;
-
- int len = desc.length();
- for (int n = 0; i < len; ++n) {
- char c = desc.charAt(i++);
- if (c == ')')
- return (n == nArgs ? result : NO);
- else if (n >= nArgs)
- return NO;
-
- int dim = 0;
- while (c == '[') {
- ++dim;
- c = desc.charAt(i++);
- }
-
- if (argTypes[n] == NULL) {
- if (dim == 0 && c != 'L')
- return NO;
- }
- else if (argDims[n] != dim) {
- if (!(dim == 0 && c == 'L'
- && desc.startsWith("java/lang/Object;", i)))
- return NO;
-
- // if the thread reaches here, c must be 'L'.
- i = desc.indexOf(';', i) + 1;
- result = MAYBE;
- if (i <= 0)
- return NO; // invalid descriptor?
- }
- else if (c == 'L') { // not compare
- int j = desc.indexOf(';', i);
- if (j < 0 || argTypes[n] != CLASS)
- return NO;
-
- String cname = desc.substring(i, j);
- if (!cname.equals(argClassNames[n])) {
- CtClass clazz = lookupClass(argClassNames[n]);
- try {
- if (clazz.subtypeOf(lookupClass(cname)))
- result = MAYBE;
- else
- return NO;
- }
- catch (NotFoundException e) {
- result = MAYBE; // should be NO?
- }
- }
-
- i = j + 1;
- }
- else {
- int t = descToType(c);
- int at = argTypes[n];
- if (t != at)
- if (t == INT
- && (at == SHORT || at == BYTE || at == CHAR))
- result = MAYBE;
- else
- return NO;
- }
- }
-
- return NO;
+ int result = YES;
+ int i = 1;
+ int nArgs = argTypes.length;
+ if (nArgs != Descriptor.numOfParameters(desc))
+ return NO;
+
+ int len = desc.length();
+ for (int n = 0; i < len; ++n) {
+ char c = desc.charAt(i++);
+ if (c == ')')
+ return (n == nArgs ? result : NO);
+ else if (n >= nArgs)
+ return NO;
+
+ int dim = 0;
+ while (c == '[') {
+ ++dim;
+ c = desc.charAt(i++);
+ }
+
+ if (argTypes[n] == NULL) {
+ if (dim == 0 && c != 'L')
+ return NO;
+ }
+ else if (argDims[n] != dim) {
+ if (!(dim == 0 && c == 'L'
+ && desc.startsWith("java/lang/Object;", i)))
+ return NO;
+
+ // if the thread reaches here, c must be 'L'.
+ i = desc.indexOf(';', i) + 1;
+ result = MAYBE;
+ if (i <= 0)
+ return NO; // invalid descriptor?
+ }
+ else if (c == 'L') { // not compare
+ int j = desc.indexOf(';', i);
+ if (j < 0 || argTypes[n] != CLASS)
+ return NO;
+
+ String cname = desc.substring(i, j);
+ if (!cname.equals(argClassNames[n])) {
+ CtClass clazz = lookupClass(argClassNames[n]);
+ try {
+ if (clazz.subtypeOf(lookupClass(cname)))
+ result = MAYBE;
+ else
+ return NO;
+ }
+ catch (NotFoundException e) {
+ result = MAYBE; // should be NO?
+ }
+ }
+
+ i = j + 1;
+ }
+ else {
+ int t = descToType(c);
+ int at = argTypes[n];
+ if (t != at)
+ if (t == INT
+ && (at == SHORT || at == BYTE || at == CHAR))
+ result = MAYBE;
+ else
+ return NO;
+ }
+ }
+
+ return NO;
}
protected static int descToType(char c) throws CompileError {
- switch (c) {
- case 'Z' :
- return BOOLEAN;
- case 'C' :
- return CHAR;
- case 'B' :
- return BYTE;
- case 'S' :
- return SHORT;
- case 'I' :
- return INT;
- case 'J' :
- return LONG;
- case 'F' :
- return FLOAT;
- case 'D' :
- return DOUBLE;
- case 'V' :
- return VOID;
- case 'L' :
- case '[' :
- return CLASS;
- default :
- fatal();
- return VOID;
- }
+ switch (c) {
+ case 'Z' :
+ return BOOLEAN;
+ case 'C' :
+ return CHAR;
+ case 'B' :
+ return BYTE;
+ case 'S' :
+ return SHORT;
+ case 'I' :
+ return INT;
+ case 'J' :
+ return LONG;
+ case 'F' :
+ return FLOAT;
+ case 'D' :
+ return DOUBLE;
+ case 'V' :
+ return VOID;
+ case 'L' :
+ case '[' :
+ return CLASS;
+ default :
+ fatal();
+ return VOID;
+ }
}
protected void atFieldAssign(Expr expr, int op, ASTree left,
- ASTree right, boolean doDup) throws CompileError
+ ASTree right, boolean doDup) throws CompileError
{
- CtField f = fieldAccess(left);
- boolean is_static = resultStatic;
- if (op != '=' && !is_static)
- bytecode.addOpcode(DUP);
-
- int fi = atFieldRead(f, is_static, op == '=');
- int fType = exprType;
- int fDim = arrayDim;
- String cname = className;
-
- atAssignCore(expr, op, right, fType, fDim, cname);
-
- boolean is2w = is2word(fType, fDim);
- if (doDup) {
- int dup_code;
- if (is_static)
- dup_code = (is2w ? DUP2 : DUP);
- else
- dup_code = (is2w ? DUP2_X1 : DUP_X1);
-
- bytecode.addOpcode(dup_code);
- }
-
- if (is_static) {
- bytecode.add(PUTSTATIC);
- bytecode.growStack(is2w ? -2 : -1);
- }
- else {
- bytecode.add(PUTFIELD);
- bytecode.growStack(is2w ? -3 : -2);
- }
-
- bytecode.addIndex(fi);
- exprType = fType;
- arrayDim = fDim;
- className = cname;
+ CtField f = fieldAccess(left);
+ boolean is_static = resultStatic;
+ if (op != '=' && !is_static)
+ bytecode.addOpcode(DUP);
+
+ int fi = atFieldRead(f, is_static, op == '=');
+ int fType = exprType;
+ int fDim = arrayDim;
+ String cname = className;
+
+ atAssignCore(expr, op, right, fType, fDim, cname);
+
+ boolean is2w = is2word(fType, fDim);
+ if (doDup) {
+ int dup_code;
+ if (is_static)
+ dup_code = (is2w ? DUP2 : DUP);
+ else
+ dup_code = (is2w ? DUP2_X1 : DUP_X1);
+
+ bytecode.addOpcode(dup_code);
+ }
+
+ if (is_static) {
+ bytecode.add(PUTSTATIC);
+ bytecode.growStack(is2w ? -2 : -1);
+ }
+ else {
+ bytecode.add(PUTFIELD);
+ bytecode.growStack(is2w ? -3 : -2);
+ }
+
+ bytecode.addIndex(fi);
+ exprType = fType;
+ arrayDim = fDim;
+ className = cname;
}
/* overwritten in JvstCodeGen.
*/
public void atMember(Member mem) throws CompileError {
- atFieldRead(mem);
+ atFieldRead(mem);
}
protected void atFieldRead(ASTree expr) throws CompileError
{
- CtField f = fieldAccess(expr);
- boolean is_static = resultStatic;
- atFieldRead(f, is_static, false);
+ CtField f = fieldAccess(expr);
+ boolean is_static = resultStatic;
+ atFieldRead(f, is_static, false);
}
private int atFieldRead(CtField f, boolean isStatic, boolean noRead)
- throws CompileError
+ throws CompileError
{
- FieldInfo finfo = f.getFieldInfo2();
- String type = finfo.getDescriptor();
-
- int fi = addFieldrefInfo(f, finfo, type);
-
- int i = 0;
- char c = type.charAt(i);
- boolean is2byte = (c == 'J' || c == 'D');
- exprType = descToType(c);
- arrayDim = 0;
- if (c == '[') {
- i = 1;
- while ((c = type.charAt(i)) == '[')
- ++i;
-
- arrayDim = i;
- }
-
- if (c == 'L')
- className = type.substring(i + 1, type.indexOf(';', i + 1));
-
- if (noRead)
- return fi;
-
- if (isStatic) {
- bytecode.add(GETSTATIC);
- bytecode.growStack(is2byte ? 2 : 1);
- }
- else {
- bytecode.add(GETFIELD);
- bytecode.growStack(is2byte ? 1 : 0);
- }
-
- bytecode.addIndex(fi);
- return fi;
+ FieldInfo finfo = f.getFieldInfo2();
+ String type = finfo.getDescriptor();
+
+ int fi = addFieldrefInfo(f, finfo, type);
+
+ int i = 0;
+ char c = type.charAt(i);
+ boolean is2byte = (c == 'J' || c == 'D');
+ exprType = descToType(c);
+ arrayDim = 0;
+ if (c == '[') {
+ i = 1;
+ while ((c = type.charAt(i)) == '[')
+ ++i;
+
+ arrayDim = i;
+ }
+
+ if (c == 'L')
+ className = type.substring(i + 1, type.indexOf(';', i + 1));
+
+ if (noRead)
+ return fi;
+
+ if (isStatic) {
+ bytecode.add(GETSTATIC);
+ bytecode.growStack(is2byte ? 2 : 1);
+ }
+ else {
+ bytecode.add(GETFIELD);
+ bytecode.growStack(is2byte ? 1 : 0);
+ }
+
+ bytecode.addIndex(fi);
+ return fi;
}
protected int addFieldrefInfo(CtField f, FieldInfo finfo, String type) {
- ConstPool cp = bytecode.getConstPool();
- String cname = f.getDeclaringClass().getName();
- int ci = cp.addClassInfo(cname);
- String name = finfo.getName();
- return cp.addFieldrefInfo(ci, name, type);
+ ConstPool cp = bytecode.getConstPool();
+ String cname = f.getDeclaringClass().getName();
+ int ci = cp.addClassInfo(cname);
+ String name = finfo.getName();
+ return cp.addFieldrefInfo(ci, name, type);
}
protected void atFieldPlusPlus(int token, boolean isPost,
- ASTree oprand, Expr expr, boolean doDup)
- throws CompileError
+ ASTree oprand, Expr expr, boolean doDup)
+ throws CompileError
{
- CtField f = fieldAccess(oprand);
- boolean is_static = resultStatic;
- if (!is_static)
- bytecode.addOpcode(DUP);
-
- int fi = atFieldRead(f, is_static, false);
- int t = exprType;
- boolean is2w = is2word(t, arrayDim);
-
- int dup_code;
- if (is_static)
- dup_code = (is2w ? DUP2 : DUP);
- else
- dup_code = (is2w ? DUP2_X1 : DUP_X1);
-
- atPlusPlusCore(dup_code, doDup, token, isPost, expr);
-
- if (is_static) {
- bytecode.add(PUTSTATIC);
- bytecode.growStack(is2w ? -2 : -1);
- }
- else {
- bytecode.add(PUTFIELD);
- bytecode.growStack(is2w ? -3 : -2);
- }
-
- bytecode.addIndex(fi);
+ CtField f = fieldAccess(oprand);
+ boolean is_static = resultStatic;
+ if (!is_static)
+ bytecode.addOpcode(DUP);
+
+ int fi = atFieldRead(f, is_static, false);
+ int t = exprType;
+ boolean is2w = is2word(t, arrayDim);
+
+ int dup_code;
+ if (is_static)
+ dup_code = (is2w ? DUP2 : DUP);
+ else
+ dup_code = (is2w ? DUP2_X1 : DUP_X1);
+
+ atPlusPlusCore(dup_code, doDup, token, isPost, expr);
+
+ if (is_static) {
+ bytecode.add(PUTSTATIC);
+ bytecode.growStack(is2w ? -2 : -1);
+ }
+ else {
+ bytecode.add(PUTFIELD);
+ bytecode.growStack(is2w ? -3 : -2);
+ }
+
+ bytecode.addIndex(fi);
}
/* This method also returns a value in resultStatic.
*/
protected CtField fieldAccess(ASTree expr) throws CompileError {
- CtField f = null;
- boolean is_static = false;
- if (expr instanceof Member) {
- String name = ((Member)expr).get();
- try {
- f = thisClass.getField(name);
- }
- catch (NotFoundException e) {
- // EXPR might be part of a static member access?
- throw new NoFieldException(name, expr);
- }
-
- is_static = Modifier.isStatic(f.getModifiers());
- if (!is_static)
- if (inStaticMethod)
- throw new CompileError(
- "not available in a static method: " + name);
- else
- bytecode.addAload(0); // this
- }
- else if (expr instanceof Expr) {
- Expr e = (Expr)expr;
- int op = e.getOperator();
- if (op == MEMBER) {
- f = lookupField((ASTList)e.oprand1(), (Symbol)e.oprand2());
- is_static = true;
- }
- else if (op == '.') {
- try {
- e.oprand1().accept(this);
- if (exprType == CLASS && arrayDim == 0)
- f = lookupField(className, (Symbol)e.oprand2());
- else
- badLvalue();
-
- is_static = Modifier.isStatic(f.getModifiers());
- if (is_static)
- bytecode.addOpcode(POP);
- }
- catch (NoFieldException nfe) {
- if (nfe.getExpr() != e.oprand1())
- throw nfe;
-
- Symbol fname = (Symbol)e.oprand2();
- // it should be a static field.
- try {
- f = lookupField(nfe.getField(), fname);
- is_static = true;
- }
- catch (CompileError ce) {
- // EXPR might be part of a qualified class name.
- throw new NoFieldException(nfe.getField() + "/"
- + fname.get(), expr);
- }
- }
- }
- else
- badLvalue();
- }
- else
- badLvalue();
-
- resultStatic = is_static;
- return f;
+ CtField f = null;
+ boolean is_static = false;
+ if (expr instanceof Member) {
+ String name = ((Member)expr).get();
+ try {
+ f = thisClass.getField(name);
+ }
+ catch (NotFoundException e) {
+ // EXPR might be part of a static member access?
+ throw new NoFieldException(name, expr);
+ }
+
+ is_static = Modifier.isStatic(f.getModifiers());
+ if (!is_static)
+ if (inStaticMethod)
+ throw new CompileError(
+ "not available in a static method: " + name);
+ else
+ bytecode.addAload(0); // this
+ }
+ else if (expr instanceof Expr) {
+ Expr e = (Expr)expr;
+ int op = e.getOperator();
+ if (op == MEMBER) {
+ f = lookupField((ASTList)e.oprand1(), (Symbol)e.oprand2());
+ is_static = true;
+ }
+ else if (op == '.') {
+ try {
+ e.oprand1().accept(this);
+ if (exprType == CLASS && arrayDim == 0)
+ f = lookupField(className, (Symbol)e.oprand2());
+ else
+ badLvalue();
+
+ is_static = Modifier.isStatic(f.getModifiers());
+ if (is_static)
+ bytecode.addOpcode(POP);
+ }
+ catch (NoFieldException nfe) {
+ if (nfe.getExpr() != e.oprand1())
+ throw nfe;
+
+ Symbol fname = (Symbol)e.oprand2();
+ // it should be a static field.
+ try {
+ f = lookupField(nfe.getField(), fname);
+ is_static = true;
+ }
+ catch (CompileError ce) {
+ // EXPR might be part of a qualified class name.
+ throw new NoFieldException(nfe.getField() + "/"
+ + fname.get(), expr);
+ }
+ }
+ }
+ else
+ badLvalue();
+ }
+ else
+ badLvalue();
+
+ resultStatic = is_static;
+ return f;
}
private static void badLvalue() throws CompileError {
- throw new CompileError("bad l-value");
+ throw new CompileError("bad l-value");
}
public CtClass[] makeParamList(MethodDecl md) throws CompileError {
- CtClass[] params;
- ASTList plist = md.getParams();
- if (plist == null)
- params = new CtClass[0];
- else {
- int i = 0;
- params = new CtClass[plist.length()];
- while (plist != null) {
- params[i++] = lookupClass((Declarator)plist.head());
- plist = plist.tail();
- }
- }
-
- return params;
+ CtClass[] params;
+ ASTList plist = md.getParams();
+ if (plist == null)
+ params = new CtClass[0];
+ else {
+ int i = 0;
+ params = new CtClass[plist.length()];
+ while (plist != null) {
+ params[i++] = lookupClass((Declarator)plist.head());
+ plist = plist.tail();
+ }
+ }
+
+ return params;
}
public CtClass[] makeThrowsList(MethodDecl md) throws CompileError {
- CtClass[] clist;
- ASTList list = md.getThrows();
- if (list == null)
- return null;
- else {
- int i = 0;
- clist = new CtClass[list.length()];
- while (list != null) {
- clist[i++] = lookupClass((ASTList)list.head());
- list = list.tail();
- }
-
- return clist;
- }
+ CtClass[] clist;
+ ASTList list = md.getThrows();
+ if (list == null)
+ return null;
+ else {
+ int i = 0;
+ clist = new CtClass[list.length()];
+ while (list != null) {
+ clist[i++] = lookupClass((ASTList)list.head());
+ list = list.tail();
+ }
+
+ return clist;
+ }
}
public static int getModifiers(ASTList mods) {
- int m = 0;
- while (mods != null) {
- Keyword k = (Keyword)mods.head();
- mods = mods.tail();
- switch (k.get()) {
- case STATIC :
- m |= Modifier.STATIC;
- break;
- case FINAL :
- m |= Modifier.FINAL;
- break;
- case SYNCHRONIZED :
- m |= Modifier.SYNCHRONIZED;
- break;
- case ABSTRACT :
- m |= Modifier.ABSTRACT;
- break;
- case PUBLIC :
- m |= Modifier.PUBLIC;
- break;
- case PROTECTED :
- m |= Modifier.PROTECTED;
- break;
- case PRIVATE :
- m |= Modifier.PRIVATE;
- break;
- case VOLATILE :
- m |= Modifier.VOLATILE;
- break;
- case TRANSIENT :
- m |= Modifier.TRANSIENT;
- break;
- case STRICT :
- m |= Modifier.STRICT;
- break;
- }
- }
-
- return m;
+ int m = 0;
+ while (mods != null) {
+ Keyword k = (Keyword)mods.head();
+ mods = mods.tail();
+ switch (k.get()) {
+ case STATIC :
+ m |= Modifier.STATIC;
+ break;
+ case FINAL :
+ m |= Modifier.FINAL;
+ break;
+ case SYNCHRONIZED :
+ m |= Modifier.SYNCHRONIZED;
+ break;
+ case ABSTRACT :
+ m |= Modifier.ABSTRACT;
+ break;
+ case PUBLIC :
+ m |= Modifier.PUBLIC;
+ break;
+ case PROTECTED :
+ m |= Modifier.PROTECTED;
+ break;
+ case PRIVATE :
+ m |= Modifier.PRIVATE;
+ break;
+ case VOLATILE :
+ m |= Modifier.VOLATILE;
+ break;
+ case TRANSIENT :
+ m |= Modifier.TRANSIENT;
+ break;
+ case STRICT :
+ m |= Modifier.STRICT;
+ break;
+ }
+ }
+
+ return m;
}
/* Converts a class name into a JVM-internal representation.
@@ -910,136 +899,136 @@ public class MemberCodeGen extends CodeGen {
* For example, this converts Object into java/lang/Object.
*/
protected String resolveClassName(ASTList name) throws CompileError {
- if (name == null)
- return null;
- else
- return javaToJvmName(lookupClass(name).getName());
+ if (name == null)
+ return null;
+ else
+ return javaToJvmName(lookupClass(name).getName());
}
/* Expands a simple class name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
protected String resolveClassName(String jvmName) throws CompileError {
- if (jvmName == null)
- return null;
- else
- return javaToJvmName(lookupClass(jvmName).getName());
+ if (jvmName == null)
+ return null;
+ else
+ return javaToJvmName(lookupClass(jvmName).getName());
}
protected CtClass lookupClass(Declarator decl) throws CompileError {
- return lookupClass(decl.getType(), decl.getArrayDim(),
- decl.getClassName());
+ return lookupClass(decl.getType(), decl.getArrayDim(),
+ decl.getClassName());
}
protected CtClass lookupClass(int type, int dim, String classname)
- throws CompileError
+ throws CompileError
{
- String cname = "";
- CtClass clazz;
- switch (type) {
- case CLASS :
- clazz = lookupClass(classname);
- if (dim > 0)
- cname = clazz.getName();
- else
- return clazz;
-
- break;
- case BOOLEAN :
- cname = "boolean";
- break;
- case CHAR :
- cname = "char";
- break;
- case BYTE :
- cname = "byte";
- break;
- case SHORT :
- cname = "short";
- break;
- case INT :
- cname = "int";
- break;
- case LONG :
- cname = "long";
- break;
- case FLOAT :
- cname = "float";
- break;
- case DOUBLE :
- cname = "double";
- break;
- case VOID :
- cname = "void";
- break;
- default :
- fatal();
- }
-
- while (dim-- > 0)
- cname += "[]";
-
- return lookupClass2(cname);
+ String cname = "";
+ CtClass clazz;
+ switch (type) {
+ case CLASS :
+ clazz = lookupClass(classname);
+ if (dim > 0)
+ cname = clazz.getName();
+ else
+ return clazz;
+
+ break;
+ case BOOLEAN :
+ cname = "boolean";
+ break;
+ case CHAR :
+ cname = "char";
+ break;
+ case BYTE :
+ cname = "byte";
+ break;
+ case SHORT :
+ cname = "short";
+ break;
+ case INT :
+ cname = "int";
+ break;
+ case LONG :
+ cname = "long";
+ break;
+ case FLOAT :
+ cname = "float";
+ break;
+ case DOUBLE :
+ cname = "double";
+ break;
+ case VOID :
+ cname = "void";
+ break;
+ default :
+ fatal();
+ }
+
+ while (dim-- > 0)
+ cname += "[]";
+
+ return lookupClass2(cname);
}
protected CtClass lookupClass(ASTList name) throws CompileError {
- return lookupClass2(Declarator.astToClassName(name, '.'));
+ return lookupClass2(Declarator.astToClassName(name, '.'));
}
protected CtClass lookupClass(String jvmName) throws CompileError {
- return lookupClass2(jvmToJavaName(jvmName));
+ return lookupClass2(jvmToJavaName(jvmName));
}
/**
- * @param name a qualified class name. e.g. java.lang.String
+ * @param name a qualified class name. e.g. java.lang.String
*/
private CtClass lookupClass2(String name) throws CompileError {
- try {
- return classPool.get(name);
- }
- catch (NotFoundException e) {}
-
- try {
- if (name.indexOf('.') < 0)
- return classPool.get("java.lang." + name);
- }
- catch (NotFoundException e) {}
-
- throw new CompileError("no such class: " + name);
+ try {
+ return classPool.get(name);
+ }
+ catch (NotFoundException e) {}
+
+ try {
+ if (name.indexOf('.') < 0)
+ return classPool.get("java.lang." + name);
+ }
+ catch (NotFoundException e) {}
+
+ throw new CompileError("no such class: " + name);
}
public CtField lookupField(ASTList className, Symbol fieldName)
- throws CompileError
+ throws CompileError
{
- return lookupField2(Declarator.astToClassName(className, '.'),
- fieldName);
+ return lookupField2(Declarator.astToClassName(className, '.'),
+ fieldName);
}
public CtField lookupField(String className, Symbol fieldName)
- throws CompileError
+ throws CompileError
{
- return lookupField2(jvmToJavaName(className), fieldName);
+ return lookupField2(jvmToJavaName(className), fieldName);
}
/**
- * @param name a qualified class name. e.g. java.lang.String
+ * @param name a qualified class name. e.g. java.lang.String
*/
private CtField lookupField2(String className, Symbol fieldName)
- throws CompileError
+ throws CompileError
{
- CtClass cc = lookupClass(className);
- try {
- return cc.getField(fieldName.get());
- }
- catch (NotFoundException e) {}
- throw new CompileError("no such field: " + fieldName.get());
+ CtClass cc = lookupClass(className);
+ try {
+ return cc.getField(fieldName.get());
+ }
+ catch (NotFoundException e) {}
+ throw new CompileError("no such field: " + fieldName.get());
}
protected static String javaToJvmName(String classname) {
- return classname.replace('.', '/');
+ return classname.replace('.', '/');
}
protected static String jvmToJavaName(String classname) {
- return classname.replace('/', '.');
+ return classname.replace('/', '.');
}
}
diff --git a/src/main/javassist/compiler/NoFieldException.java b/src/main/javassist/compiler/NoFieldException.java
index a8102863..0f52311e 100644
--- a/src/main/javassist/compiler/NoFieldException.java
+++ b/src/main/javassist/compiler/NoFieldException.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import javassist.compiler.ast.ASTree;
@@ -34,9 +23,9 @@ public class NoFieldException extends CompileError {
/* NAME must be JVM-internal representation.
*/
public NoFieldException(String name, ASTree e) {
- super("no such field: " + name);
- fieldName = name;
- expr = e;
+ super("no such field: " + name);
+ fieldName = name;
+ expr = e;
}
/* The returned name should be JVM-internal representation.
diff --git a/src/main/javassist/compiler/Parser.java b/src/main/javassist/compiler/Parser.java
index 3039e5d1..1bc50aad 100644
--- a/src/main/javassist/compiler/Parser.java
+++ b/src/main/javassist/compiler/Parser.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import javassist.compiler.ast.*;
@@ -31,7 +20,7 @@ public final class Parser implements TokenId {
private Lex lex;
public Parser(Lex lex) {
- this.lex = lex;
+ this.lex = lex;
}
public boolean hasMore() { return lex.lookAhead() >= 0; }
@@ -40,40 +29,40 @@ public final class Parser implements TokenId {
* : method.declaration | field.declaration
*/
public ASTList parseMember(SymbolTable tbl) throws CompileError {
- ASTList mem = parseMember1(tbl);
- if (mem instanceof MethodDecl)
- return parseMethod2(tbl, (MethodDecl)mem);
- else
- return mem;
+ ASTList mem = parseMember1(tbl);
+ if (mem instanceof MethodDecl)
+ return parseMethod2(tbl, (MethodDecl)mem);
+ else
+ return mem;
}
/* A method body is not parsed.
*/
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);
+ 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);
}
/* field.declaration
@@ -82,22 +71,22 @@ public final class Parser implements TokenId {
* [ "=" expression ] ";"
*/
private FieldDecl parseField(SymbolTable tbl, ASTList mods,
- Declarator d) throws CompileError
+ Declarator d) throws CompileError
{
- ASTree expr = null;
- if (lex.lookAhead() == '=') {
- lex.get();
- expr = parseExpression(tbl);
- }
-
- int c = lex.get();
- if (c == ';')
- return new FieldDecl(mods, new ASTList(d, new ASTList(expr)));
- else if (c == ',')
- throw new CompileError(
- "only one field can be declared in one declaration", lex);
- else
- throw new SyntaxError(lex);
+ ASTree expr = null;
+ if (lex.lookAhead() == '=') {
+ lex.get();
+ expr = parseExpression(tbl);
+ }
+
+ int c = lex.get();
+ if (c == ';')
+ return new FieldDecl(mods, new ASTList(d, new ASTList(expr)));
+ else if (c == ',')
+ throw new CompileError(
+ "only one field can be declared in one declaration", lex);
+ else
+ throw new SyntaxError(lex);
}
/* method.declaration
@@ -111,60 +100,60 @@ public final class Parser implements TokenId {
* Note that a method body is not parsed.
*/
private MethodDecl parseMethod1(SymbolTable tbl, boolean isConstructor,
- ASTList mods, Declarator d)
- throws CompileError
+ ASTList mods, Declarator d)
+ throws CompileError
{
- if (lex.get() != '(')
- throw new SyntaxError(lex);
-
- ASTList parms = null;
- if (lex.lookAhead() != ')')
- while (true) {
- parms = ASTList.append(parms, parseFormalParam(tbl));
- int t = lex.lookAhead();
- if (t == ',')
- lex.get();
- else if (t == ')')
- break;
- }
-
- lex.get(); // ')'
- d.addArrayDim(parseArrayDimension());
- if (isConstructor && d.getArrayDim() > 0)
- throw new SyntaxError(lex);
-
- ASTList throwsList = null;
- if (lex.lookAhead() == THROWS) {
- lex.get();
- while (true) {
- throwsList = ASTList.append(throwsList, parseClassType(tbl));
- if (lex.lookAhead() == ',')
- lex.get();
- else
- break;
- }
- }
-
- return new MethodDecl(mods, new ASTList(d,
- ASTList.make(parms, throwsList, null)));
+ if (lex.get() != '(')
+ throw new SyntaxError(lex);
+
+ ASTList parms = null;
+ if (lex.lookAhead() != ')')
+ while (true) {
+ parms = ASTList.append(parms, parseFormalParam(tbl));
+ int t = lex.lookAhead();
+ if (t == ',')
+ lex.get();
+ else if (t == ')')
+ break;
+ }
+
+ lex.get(); // ')'
+ d.addArrayDim(parseArrayDimension());
+ if (isConstructor && d.getArrayDim() > 0)
+ throw new SyntaxError(lex);
+
+ ASTList throwsList = null;
+ if (lex.lookAhead() == THROWS) {
+ lex.get();
+ while (true) {
+ throwsList = ASTList.append(throwsList, parseClassType(tbl));
+ if (lex.lookAhead() == ',')
+ lex.get();
+ else
+ break;
+ }
+ }
+
+ return new MethodDecl(mods, new ASTList(d,
+ ASTList.make(parms, throwsList, null)));
}
/* Parses a method body.
*/
public MethodDecl parseMethod2(SymbolTable tbl, MethodDecl md)
- throws CompileError
+ throws CompileError
{
- Stmnt body = null;
- if (lex.lookAhead() == ';')
- lex.get();
- else {
- body = parseBlock(tbl);
- if (body == null)
- body = new Stmnt(BLOCK);
- }
-
- md.sublist(4).setHead(body);
- return md;
+ Stmnt body = null;
+ if (lex.lookAhead() == ';')
+ lex.get();
+ else {
+ body = parseBlock(tbl);
+ if (body == null)
+ body = new Stmnt(BLOCK);
+ }
+
+ md.sublist(4).setHead(body);
+ return md;
}
/* member.modifiers
@@ -173,233 +162,233 @@ public final class Parser implements TokenId {
* | VOLATILE | TRANSIENT | STRICT )*
*/
private ASTList parseMemberMods() {
- int t;
- ASTList list = null;
- while (true) {
- t = lex.lookAhead();
- if (t == ABSTRACT || t == FINAL || t == PUBLIC || t == PROTECTED
- || t == PRIVATE || t == SYNCHRONIZED || t == STATIC
- || t == VOLATILE || t == TRANSIENT || t == STRICT)
- list = new ASTList(new Keyword(lex.get()), list);
- else
- break;
- }
-
- return list;
+ int t;
+ ASTList list = null;
+ while (true) {
+ t = lex.lookAhead();
+ if (t == ABSTRACT || t == FINAL || t == PUBLIC || t == PROTECTED
+ || t == PRIVATE || t == SYNCHRONIZED || t == STATIC
+ || t == VOLATILE || t == TRANSIENT || t == STRICT)
+ list = new ASTList(new Keyword(lex.get()), list);
+ else
+ break;
+ }
+
+ return list;
}
/* formal.type : ( build-in-type | class.type ) array.dimension
*/
private Declarator parseFormalType(SymbolTable tbl) throws CompileError {
- int t = lex.lookAhead();
- if (isBuiltinType(t) || t == VOID) {
- lex.get(); // primitive type
- int dim = parseArrayDimension();
- return new Declarator(t, dim);
- }
- else {
- ASTList name = parseClassType(tbl);
- int dim = parseArrayDimension();
- return new Declarator(name, dim);
- }
+ int t = lex.lookAhead();
+ if (isBuiltinType(t) || t == VOID) {
+ lex.get(); // primitive type
+ int dim = parseArrayDimension();
+ return new Declarator(t, dim);
+ }
+ else {
+ ASTList name = parseClassType(tbl);
+ int dim = parseArrayDimension();
+ return new Declarator(name, dim);
+ }
}
private static boolean isBuiltinType(int t) {
- return (t == BOOLEAN || t == BYTE || t == CHAR || t == SHORT
- || t == INT || t == LONG || t == FLOAT || t == DOUBLE);
+ return (t == BOOLEAN || t == BYTE || t == CHAR || t == SHORT
+ || t == INT || t == LONG || t == FLOAT || t == DOUBLE);
}
/* formal.parameter : formal.type Identifier array.dimension
*/
private Declarator parseFormalParam(SymbolTable tbl)
- throws CompileError
+ 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;
+ 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;
}
/* statement : [ label ":" ]* labeled.statement
*
* labeled.statement
- * : block.statement
- * | if.statement
- * | while.statement
- * | do.statement
- * | for.statement
- * | switch.statement
- * | try.statement
- * | return.statement
- * | thorw.statement
- * | break.statement
- * | continue.statement
- * | declaration.or.expression
- * | ";"
+ * : block.statement
+ * | if.statement
+ * | while.statement
+ * | do.statement
+ * | for.statement
+ * | switch.statement
+ * | try.statement
+ * | return.statement
+ * | thorw.statement
+ * | break.statement
+ * | continue.statement
+ * | declaration.or.expression
+ * | ";"
*
* This method may return null (empty statement).
*/
public Stmnt parseStatement(SymbolTable tbl)
- throws CompileError
+ throws CompileError
{
- int t = lex.lookAhead();
- if (t == '{')
- return parseBlock(tbl);
- else if (t == ';') {
- lex.get();
- return new Stmnt(BLOCK); // empty statement
- }
- else if (t == Identifier && lex.lookAhead(1) == ':') {
- lex.get(); // Identifier
- String label = lex.getString();
- lex.get(); // ':'
- return Stmnt.make(LABEL, new Symbol(label), parseStatement(tbl));
- }
- else if (t == IF)
- return parseIf(tbl);
- else if (t == WHILE)
- return parseWhile(tbl);
- else if (t == DO)
- return parseDo(tbl);
- else if (t == FOR)
- return parseFor(tbl);
- else if (t == TRY)
- return parseTry(tbl);
- else if (t == SWITCH)
- return parseSwitch(tbl);
- else if (t == RETURN)
- return parseReturn(tbl);
- else if (t == THROW)
- return parseThrow(tbl);
- else if (t == BREAK)
- return parseBreak(tbl);
- else if (t == CONTINUE)
- return parseContinue(tbl);
- else
- return parseDeclarationOrExpression(tbl, false);
+ int t = lex.lookAhead();
+ if (t == '{')
+ return parseBlock(tbl);
+ else if (t == ';') {
+ lex.get();
+ return new Stmnt(BLOCK); // empty statement
+ }
+ else if (t == Identifier && lex.lookAhead(1) == ':') {
+ lex.get(); // Identifier
+ String label = lex.getString();
+ lex.get(); // ':'
+ return Stmnt.make(LABEL, new Symbol(label), parseStatement(tbl));
+ }
+ else if (t == IF)
+ return parseIf(tbl);
+ else if (t == WHILE)
+ return parseWhile(tbl);
+ else if (t == DO)
+ return parseDo(tbl);
+ else if (t == FOR)
+ return parseFor(tbl);
+ else if (t == TRY)
+ return parseTry(tbl);
+ else if (t == SWITCH)
+ return parseSwitch(tbl);
+ else if (t == RETURN)
+ return parseReturn(tbl);
+ else if (t == THROW)
+ return parseThrow(tbl);
+ else if (t == BREAK)
+ return parseBreak(tbl);
+ else if (t == CONTINUE)
+ return parseContinue(tbl);
+ else
+ return parseDeclarationOrExpression(tbl, false);
}
/* block.statement : "{" statement* "}"
*/
private Stmnt parseBlock(SymbolTable tbl) throws CompileError {
- if (lex.get() != '{')
- throw new SyntaxError(lex);
-
- Stmnt body = null;
- SymbolTable tbl2 = new SymbolTable(tbl);
- while (lex.lookAhead() != '}') {
- Stmnt s = parseStatement(tbl2);
- if (s != null)
- body = (Stmnt)ASTList.concat(body, new Stmnt(BLOCK, s));
- }
-
- lex.get(); // '}'
- if (body == null)
- return new Stmnt(BLOCK); // empty block
- else
- return body;
+ if (lex.get() != '{')
+ throw new SyntaxError(lex);
+
+ Stmnt body = null;
+ SymbolTable tbl2 = new SymbolTable(tbl);
+ while (lex.lookAhead() != '}') {
+ Stmnt s = parseStatement(tbl2);
+ if (s != null)
+ body = (Stmnt)ASTList.concat(body, new Stmnt(BLOCK, s));
+ }
+
+ lex.get(); // '}'
+ if (body == null)
+ return new Stmnt(BLOCK); // empty block
+ else
+ return body;
}
/* if.statement : IF "(" expression ")" statement
- * [ ELSE statement ]
+ * [ ELSE statement ]
*/
private Stmnt parseIf(SymbolTable tbl) throws CompileError {
- int t = lex.get(); // IF
- if (lex.get() != '(')
- throw new SyntaxError(lex);
-
- ASTree expr = parseExpression(tbl);
- if (lex.get() != ')')
- throw new SyntaxError(lex);
-
- Stmnt thenp = parseStatement(tbl);
- Stmnt elsep;
- if (lex.lookAhead() == ELSE) {
- lex.get();
- elsep = parseStatement(tbl);
- }
- else
- elsep = null;
-
- return new Stmnt(t, expr, new ASTList(thenp, new ASTList(elsep)));
+ int t = lex.get(); // IF
+ if (lex.get() != '(')
+ throw new SyntaxError(lex);
+
+ ASTree expr = parseExpression(tbl);
+ if (lex.get() != ')')
+ throw new SyntaxError(lex);
+
+ Stmnt thenp = parseStatement(tbl);
+ Stmnt elsep;
+ if (lex.lookAhead() == ELSE) {
+ lex.get();
+ elsep = parseStatement(tbl);
+ }
+ else
+ elsep = null;
+
+ return new Stmnt(t, expr, new ASTList(thenp, new ASTList(elsep)));
}
/* while.statement : WHILE "(" expression ")" statement
*/
private Stmnt parseWhile(SymbolTable tbl)
- throws CompileError
+ throws CompileError
{
- int t = lex.get(); // WHILE
- if (lex.get() != '(')
- throw new SyntaxError(lex);
+ int t = lex.get(); // WHILE
+ if (lex.get() != '(')
+ throw new SyntaxError(lex);
- ASTree expr = parseExpression(tbl);
- if (lex.get() != ')')
- throw new SyntaxError(lex);
+ ASTree expr = parseExpression(tbl);
+ if (lex.get() != ')')
+ throw new SyntaxError(lex);
- Stmnt body = parseStatement(tbl);
- return new Stmnt(t, expr, body);
+ Stmnt body = parseStatement(tbl);
+ return new Stmnt(t, expr, body);
}
/* do.statement : DO statement WHILE "(" expression ")" ";"
*/
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);
+ 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);
+ ASTree expr = parseExpression(tbl);
+ if (lex.get() != ')' || lex.get() != ';')
+ throw new SyntaxError(lex);
- return new Stmnt(t, expr, body);
+ return new Stmnt(t, expr, body);
}
/* for.statement : FOR "(" decl.or.expr expression ";" expression ")"
- * statement
+ * statement
*/
private Stmnt parseFor(SymbolTable tbl) throws CompileError {
- Stmnt expr1, expr3;
- ASTree expr2;
- int t = lex.get(); // FOR
+ Stmnt expr1, expr3;
+ ASTree expr2;
+ int t = lex.get(); // FOR
- SymbolTable tbl2 = new SymbolTable(tbl);
+ SymbolTable tbl2 = new SymbolTable(tbl);
- if (lex.get() != '(')
- throw new SyntaxError(lex);
+ if (lex.get() != '(')
+ throw new SyntaxError(lex);
- if (lex.lookAhead() == ';') {
- lex.get();
- expr1 = null;
- }
- else
- expr1 = parseDeclarationOrExpression(tbl2, true);
+ if (lex.lookAhead() == ';') {
+ lex.get();
+ expr1 = null;
+ }
+ else
+ expr1 = parseDeclarationOrExpression(tbl2, true);
- if (lex.lookAhead() == ';')
- expr2 = null;
- else
- expr2 = parseExpression(tbl2);
+ if (lex.lookAhead() == ';')
+ expr2 = null;
+ else
+ expr2 = parseExpression(tbl2);
- if (lex.get() != ';')
- throw new CompileError("; is missing", lex);
+ if (lex.get() != ';')
+ throw new CompileError("; is missing", lex);
- if (lex.lookAhead() == ')')
- expr3 = null;
- else
- expr3 = parseExprList(tbl2);
+ if (lex.lookAhead() == ')')
+ expr3 = null;
+ else
+ expr3 = parseExprList(tbl2);
- if (lex.get() != ')')
- throw new CompileError(") is missing", lex);
+ if (lex.get() != ')')
+ throw new CompileError(") is missing", lex);
- Stmnt body = parseStatement(tbl2);
- return new Stmnt(t, expr1, new ASTList(expr2,
- new ASTList(expr3, body)));
+ Stmnt body = parseStatement(tbl2);
+ return new Stmnt(t, expr1, new ASTList(expr2,
+ new ASTList(expr3, body)));
}
/* switch.statement : SWITCH "(" expression ")" "{" switch.block "}"
@@ -407,732 +396,732 @@ public final class Parser implements TokenId {
* swtich.block : ( switch.label* statement )*
*
* swtich.label : DEFAULT ":"
- * | CASE const.expression ":"
+ * | CASE const.expression ":"
*/
private Stmnt parseSwitch(SymbolTable tbl) throws CompileError {
- throw new CompileError("switch is not supported", lex);
+ throw new CompileError("switch is not supported", lex);
}
/* try.statement
* : TRY block.statement
- * [ CATCH "(" class.type Identifier ")" block.statement ]*
- * [ FINALLY block.statement ]*
+ * [ CATCH "(" class.type Identifier ")" block.statement ]*
+ * [ FINALLY block.statement ]*
*/
private Stmnt parseTry(SymbolTable tbl) throws CompileError {
- lex.get(); // TRY
- Stmnt block = parseBlock(tbl);
- ASTList catchList = null;
- while (lex.lookAhead() == CATCH) {
- lex.get(); // CATCH
- if (lex.get() != '(')
- throw new SyntaxError(lex);
-
- SymbolTable tbl2 = new SymbolTable(tbl);
- Declarator d = parseFormalParam(tbl2);
- if (d.getArrayDim() > 0 || d.getType() != CLASS)
- throw new SyntaxError(lex);
-
- if (lex.get() != ')')
- throw new SyntaxError(lex);
-
- Stmnt b = parseBlock(tbl2);
- catchList = ASTList.append(catchList, new Pair(d, b));
- }
-
- Stmnt finallyBlock = null;
- if (lex.lookAhead() == FINALLY) {
- lex.get(); // FINALLY
- finallyBlock = parseBlock(tbl);
- }
-
- return Stmnt.make(TRY, block, catchList, finallyBlock);
+ lex.get(); // TRY
+ Stmnt block = parseBlock(tbl);
+ ASTList catchList = null;
+ while (lex.lookAhead() == CATCH) {
+ lex.get(); // CATCH
+ if (lex.get() != '(')
+ throw new SyntaxError(lex);
+
+ SymbolTable tbl2 = new SymbolTable(tbl);
+ Declarator d = parseFormalParam(tbl2);
+ if (d.getArrayDim() > 0 || d.getType() != CLASS)
+ throw new SyntaxError(lex);
+
+ if (lex.get() != ')')
+ throw new SyntaxError(lex);
+
+ Stmnt b = parseBlock(tbl2);
+ catchList = ASTList.append(catchList, new Pair(d, b));
+ }
+
+ Stmnt finallyBlock = null;
+ if (lex.lookAhead() == FINALLY) {
+ lex.get(); // FINALLY
+ finallyBlock = parseBlock(tbl);
+ }
+
+ return Stmnt.make(TRY, block, catchList, finallyBlock);
}
/* return.statement : RETURN [ expression ] ";"
*/
private Stmnt parseReturn(SymbolTable tbl) throws CompileError {
- int t = lex.get(); // RETURN
- Stmnt s = new Stmnt(t);
- if (lex.lookAhead() != ';')
- s.setLeft(parseExpression(tbl));
+ 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);
+ if (lex.get() != ';')
+ throw new CompileError("; is missing", lex);
- return s;
+ return s;
}
/* throw.statement : THROW expression ";"
*/
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);
+ int t = lex.get(); // THROW
+ ASTree expr = parseExpression(tbl);
+ if (lex.get() != ';')
+ throw new CompileError("; is missing", lex);
- return new Stmnt(t, expr);
+ return new Stmnt(t, expr);
}
/* break.statement : BREAK [ Identifier ] ";"
*/
private Stmnt parseBreak(SymbolTable tbl)
- throws CompileError
+ throws CompileError
{
- return parseContinue(tbl);
+ return parseContinue(tbl);
}
/* continue.statement : CONTINUE [ Identifier ] ";"
*/
private Stmnt parseContinue(SymbolTable tbl)
- throws CompileError
+ throws CompileError
{
- int t = lex.get(); // CONTINUE
- Stmnt s = new Stmnt(t);
- int t2 = lex.get();
- if (t2 == Identifier) {
- s.setLeft(new Symbol(lex.getString()));
- t2 = lex.get();
- }
-
- if (t2 != ';')
- throw new CompileError("; is missing", lex);
-
- return s;
+ int t = lex.get(); // CONTINUE
+ Stmnt s = new Stmnt(t);
+ int t2 = lex.get();
+ if (t2 == Identifier) {
+ s.setLeft(new Symbol(lex.getString()));
+ t2 = lex.get();
+ }
+
+ if (t2 != ';')
+ throw new CompileError("; is missing", lex);
+
+ return s;
}
/* declaration.or.expression
* : [ FINAL ] built-in-type array.dimension declarators
* | [ FINAL ] class.type array.dimension declarators
* | expression ';'
- * | expr.list ';' if exprList is true
+ * | expr.list ';' if exprList is true
*
* Note: FINAL is currently ignored. This must be fixed
* in future.
*/
private Stmnt parseDeclarationOrExpression(SymbolTable tbl,
- boolean exprList)
- throws CompileError
+ boolean exprList)
+ throws CompileError
{
- int t = lex.lookAhead();
- while (t == FINAL) {
- lex.get();
- t = lex.lookAhead();
- }
-
- if (isBuiltinType(t)) {
- t = lex.get();
- int dim = parseArrayDimension();
- return parseDeclarators(tbl, new Declarator(t, dim));
- }
- else if (t == Identifier) {
- int i = nextIsClassType(0);
- if (i >= 0)
- if (lex.lookAhead(i) == Identifier) {
- ASTList name = parseClassType(tbl);
- int dim = parseArrayDimension();
- return parseDeclarators(tbl, new Declarator(name, dim));
- }
- }
-
- Stmnt expr;
- if (exprList)
- expr = parseExprList(tbl);
- else
- expr = new Stmnt(EXPR, parseExpression(tbl));
-
- if (lex.get() != ';')
- throw new CompileError("; is missing", lex);
-
- return expr;
+ int t = lex.lookAhead();
+ while (t == FINAL) {
+ lex.get();
+ t = lex.lookAhead();
+ }
+
+ if (isBuiltinType(t)) {
+ t = lex.get();
+ int dim = parseArrayDimension();
+ return parseDeclarators(tbl, new Declarator(t, dim));
+ }
+ else if (t == Identifier) {
+ int i = nextIsClassType(0);
+ if (i >= 0)
+ if (lex.lookAhead(i) == Identifier) {
+ ASTList name = parseClassType(tbl);
+ int dim = parseArrayDimension();
+ return parseDeclarators(tbl, new Declarator(name, dim));
+ }
+ }
+
+ Stmnt expr;
+ if (exprList)
+ expr = parseExprList(tbl);
+ else
+ expr = new Stmnt(EXPR, parseExpression(tbl));
+
+ if (lex.get() != ';')
+ throw new CompileError("; is missing", lex);
+
+ return expr;
}
/* expr.list : ( expression ',')* expression
*/
private Stmnt parseExprList(SymbolTable tbl) throws CompileError {
- Stmnt expr = null;
- for (;;) {
- Stmnt e = new Stmnt(EXPR, parseExpression(tbl));
- expr = (Stmnt)ASTList.concat(expr, new Stmnt(BLOCK, e));
- if (lex.lookAhead() == ',')
- lex.get();
- else
- return expr;
- }
+ Stmnt expr = null;
+ for (;;) {
+ Stmnt e = new Stmnt(EXPR, parseExpression(tbl));
+ expr = (Stmnt)ASTList.concat(expr, new Stmnt(BLOCK, e));
+ if (lex.lookAhead() == ',')
+ lex.get();
+ else
+ return expr;
+ }
}
/* declarators : declarator [ ',' declarator ]* ';'
*/
private Stmnt parseDeclarators(SymbolTable tbl, Declarator d)
- throws CompileError
+ throws CompileError
{
- Stmnt decl = null;
- for (;;) {
- decl = (Stmnt)ASTList.concat(decl,
- new Stmnt(DECL, parseDeclarator(tbl, d)));
- int t = lex.get();
- if (t == ';')
- return decl;
- else if (t != ',')
- throw new CompileError("; is missing", lex);
- }
+ Stmnt decl = null;
+ for (;;) {
+ decl = (Stmnt)ASTList.concat(decl,
+ new Stmnt(DECL, parseDeclarator(tbl, d)));
+ int t = lex.get();
+ if (t == ';')
+ return decl;
+ else if (t != ',')
+ throw new CompileError("; is missing", lex);
+ }
}
/* declarator : Identifier array.dimension [ '=' initializer ]
*/
private Declarator parseDeclarator(SymbolTable tbl, Declarator d)
- throws CompileError
+ 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;
+ 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;
}
/* initializer : expression | array.initializer
*/
private ASTree parseInitializer(SymbolTable tbl) throws CompileError {
- if (lex.lookAhead() == '{')
- return parseArrayInitializer(tbl);
- else
- return parseExpression(tbl);
+ if (lex.lookAhead() == '{')
+ return parseArrayInitializer(tbl);
+ else
+ return parseExpression(tbl);
}
/* array.initializer :
* '{' (( array.initializer | expression ) ',')* '}'
*/
private ASTree parseArrayInitializer(SymbolTable tbl)
- throws CompileError
+ throws CompileError
{
- lex.get(); // '{'
- throw new CompileError("array initializer is not supported", lex);
+ lex.get(); // '{'
+ throw new CompileError("array initializer is not supported", lex);
}
/* expression : conditional.expr
- * | conditional.expr assign.op expression (right-to-left)
+ * | conditional.expr assign.op expression (right-to-left)
*/
public ASTree parseExpression(SymbolTable tbl) throws CompileError {
- ASTree left = parseConditionalExpr(tbl);
- if (!isAssignOp(lex.lookAhead()))
- return left;
+ ASTree left = parseConditionalExpr(tbl);
+ if (!isAssignOp(lex.lookAhead()))
+ return left;
- int t = lex.get();
- ASTree right = parseExpression(tbl);
- return AssignExpr.makeAssign(t, left, right);
+ int t = lex.get();
+ ASTree right = parseExpression(tbl);
+ return AssignExpr.makeAssign(t, left, right);
}
private static boolean isAssignOp(int t) {
- return t == '=' || t == MOD_E || t == AND_E
- || t == MUL_E || t == PLUS_E || t == MINUS_E || t == DIV_E
- || t == EXOR_E || t == OR_E || t == LSHIFT_E
- || t == RSHIFT_E || t == ARSHIFT_E;
+ return t == '=' || t == MOD_E || t == AND_E
+ || t == MUL_E || t == PLUS_E || t == MINUS_E || t == DIV_E
+ || t == EXOR_E || t == OR_E || t == LSHIFT_E
+ || t == RSHIFT_E || t == ARSHIFT_E;
}
- /* conditional.expr (right-to-left)
- * : logical.or.expr [ '?' expression ':' conditional.expr ]
+ /* conditional.expr (right-to-left)
+ * : logical.or.expr [ '?' expression ':' conditional.expr ]
*/
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;
+ 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;
}
- /* logical.or.expr 10 (operator precedence)
+ /* logical.or.expr 10 (operator precedence)
* : logical.and.expr
- * | logical.or.expr OROR logical.and.expr left-to-right
+ * | logical.or.expr OROR logical.and.expr left-to-right
*
- * logical.and.expr 9
+ * logical.and.expr 9
* : inclusive.or.expr
* | logical.and.expr ANDAND inclusive.or.expr
*
- * inclusive.or.expr 8
+ * inclusive.or.expr 8
* : exclusive.or.expr
* | inclusive.or.expr "|" exclusive.or.expr
*
- * exclusive.or.expr 7
+ * exclusive.or.expr 7
* : and.expr
* | exclusive.or.expr "^" and.expr
*
- * and.expr 6
+ * and.expr 6
* : equality.expr
* | and.expr "&" equality.expr
*
- * equality.expr 5
+ * equality.expr 5
* : relational.expr
* | equality.expr (EQ | NEQ) relational.expr
*
- * relational.expr 4
+ * relational.expr 4
* : shift.expr
* | relational.expr (LE | GE | "<" | ">") shift.expr
* | relational.expr INSTANCEOF class.type ("[" "]")*
*
- * shift.expr 3
+ * shift.expr 3
* : additive.expr
* | shift.expr (LSHIFT | RSHIFT | ARSHIFT) additive.expr
*
- * additive.expr 2
+ * additive.expr 2
* : multiply.expr
* | additive.expr ("+" | "-") multiply.expr
*
- * multiply.expr 1
+ * multiply.expr 1
* : unary.expr
* | multiply.expr ("*" | "/" | "%") unary.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);
- }
+ 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 parseInstanceOf(SymbolTable tbl, ASTree expr)
- throws CompileError
+ throws CompileError
{
- int t = lex.lookAhead();
- if (isBuiltinType(t)) {
- lex.get(); // primitive type
- int dim = parseArrayDimension();
- return new InstanceOfExpr(t, dim, expr);
- }
- else {
- ASTList name = parseClassType(tbl);
- int dim = parseArrayDimension();
- return new InstanceOfExpr(name, dim, expr);
- }
+ int t = lex.lookAhead();
+ if (isBuiltinType(t)) {
+ lex.get(); // primitive type
+ int dim = parseArrayDimension();
+ return new InstanceOfExpr(t, dim, expr);
+ }
+ else {
+ ASTList name = parseClassType(tbl);
+ int dim = parseArrayDimension();
+ return new InstanceOfExpr(name, dim, expr);
+ }
}
private ASTree binaryExpr2(SymbolTable tbl, ASTree expr, int prec)
- throws CompileError
+ throws CompileError
{
- int t = lex.get();
- if (t == INSTANCEOF)
- return parseInstanceOf(tbl, expr);
-
- ASTree expr2 = parseUnaryExpr(tbl);
- for (;;) {
- int t2 = lex.lookAhead();
- int p2 = getOpPrecedence(t2);
- if (p2 != 0 && prec > p2)
- expr2 = binaryExpr2(tbl, expr2, p2);
- else
- return BinExpr.makeBin(t, expr, expr2);
- }
+ int t = lex.get();
+ if (t == INSTANCEOF)
+ return parseInstanceOf(tbl, expr);
+
+ ASTree expr2 = parseUnaryExpr(tbl);
+ for (;;) {
+ int t2 = lex.lookAhead();
+ int p2 = getOpPrecedence(t2);
+ if (p2 != 0 && prec > p2)
+ expr2 = binaryExpr2(tbl, expr2, p2);
+ else
+ return BinExpr.makeBin(t, expr, expr2);
+ }
}
// !"#$%&'( )*+,-./0 12345678 9:;<=>?
private static final int[] binaryOpPrecedence
- = { 0, 0, 0, 0, 1, 6, 0, 0,
- 0, 1, 2, 0, 2, 0, 1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 4, 0, 4, 0 };
+ = { 0, 0, 0, 0, 1, 6, 0, 0,
+ 0, 1, 2, 0, 2, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 4, 0, 4, 0 };
private int getOpPrecedence(int c) {
- if ('!' <= c && c <= '?')
- return binaryOpPrecedence[c - '!'];
- else if (c == '^')
- return 7;
- else if (c == '|')
- return 8;
- else if (c == ANDAND)
- return 9;
- else if (c == OROR)
- return 10;
- else if (c == EQ || c == NEQ)
- return 5;
- else if (c == LE || c == GE || c == INSTANCEOF)
- return 4;
- else if (c == LSHIFT || c == RSHIFT || c == ARSHIFT)
- return 3;
- else
- return 0; // not a binary operator
+ if ('!' <= c && c <= '?')
+ return binaryOpPrecedence[c - '!'];
+ else if (c == '^')
+ return 7;
+ else if (c == '|')
+ return 8;
+ else if (c == ANDAND)
+ return 9;
+ else if (c == OROR)
+ return 10;
+ else if (c == EQ || c == NEQ)
+ return 5;
+ else if (c == LE || c == GE || c == INSTANCEOF)
+ return 4;
+ else if (c == LSHIFT || c == RSHIFT || c == ARSHIFT)
+ return 3;
+ else
+ return 0; // not a binary operator
}
/* unary.expr : "++"|"--" unary.expr
- | "+"|"-" unary.expr
- | "!"|"~" unary.expr
- | cast.expr
- | postfix.expr
+ | "+"|"-" unary.expr
+ | "!"|"~" unary.expr
+ | cast.expr
+ | postfix.expr
unary.expr.not.plus.minus is a unary expression starting without
"+", "-", "++", or "--".
*/
private ASTree parseUnaryExpr(SymbolTable tbl) throws CompileError {
- int t;
- switch (lex.lookAhead()) {
- case '+' :
- case '-' :
- case PLUSPLUS :
- case MINUSMINUS :
- case '!' :
- case '~' :
- t = lex.get();
- return new Expr(t, parseUnaryExpr(tbl));
- case '(' :
- return parseCast(tbl);
- default :
- return parsePostfix(tbl);
- }
+ int t;
+ switch (lex.lookAhead()) {
+ case '+' :
+ case '-' :
+ case PLUSPLUS :
+ case MINUSMINUS :
+ case '!' :
+ case '~' :
+ t = lex.get();
+ return new Expr(t, parseUnaryExpr(tbl));
+ case '(' :
+ return parseCast(tbl);
+ default :
+ return parsePostfix(tbl);
+ }
}
/* cast.expr : "(" builtin.type ("[" "]")* ")" unary.expr
- | "(" class.type ("[" "]")* ")" unary.expr2
+ | "(" class.type ("[" "]")* ")" unary.expr2
unary.expr2 is a unary.expr begining with "(", NULL, StringL,
Identifier, THIS, SUPER, or NEW.
*/
private ASTree parseCast(SymbolTable tbl) throws CompileError {
- int t = lex.lookAhead(1);
- if (isBuiltinType(t)) {
- lex.get(); // '('
- lex.get(); // primitive type
- int dim = parseArrayDimension();
- if (lex.get() != ')')
- throw new CompileError(") is missing", lex);
-
- return new CastExpr(t, dim, parseUnaryExpr(tbl));
- }
- else if (t == Identifier && nextIsClassCast()) {
- lex.get(); // '('
- ASTList name = parseClassType(tbl);
- int dim = parseArrayDimension();
- if (lex.get() != ')')
- throw new CompileError(") is missing", lex);
-
- return new CastExpr(name, dim, parseUnaryExpr(tbl));
- }
- else
- return parsePostfix(tbl);
+ int t = lex.lookAhead(1);
+ if (isBuiltinType(t)) {
+ lex.get(); // '('
+ lex.get(); // primitive type
+ int dim = parseArrayDimension();
+ if (lex.get() != ')')
+ throw new CompileError(") is missing", lex);
+
+ return new CastExpr(t, dim, parseUnaryExpr(tbl));
+ }
+ else if (t == Identifier && nextIsClassCast()) {
+ lex.get(); // '('
+ ASTList name = parseClassType(tbl);
+ int dim = parseArrayDimension();
+ if (lex.get() != ')')
+ throw new CompileError(") is missing", lex);
+
+ return new CastExpr(name, dim, parseUnaryExpr(tbl));
+ }
+ else
+ return parsePostfix(tbl);
}
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;
+ 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;
}
private int nextIsClassType(int i) {
- int t;
- while (lex.lookAhead(++i) == '.')
- if (lex.lookAhead(++i) != Identifier)
- return -1;
+ int t;
+ while (lex.lookAhead(++i) == '.')
+ if (lex.lookAhead(++i) != Identifier)
+ return -1;
- while ((t = lex.lookAhead(i++)) == '[')
- if (lex.lookAhead(i++) != ']')
- return -1;
+ while ((t = lex.lookAhead(i++)) == '[')
+ if (lex.lookAhead(i++) != ']')
+ return -1;
- return i - 1;
+ return i - 1;
}
/* array.dimension : [ "[" "]" ]*
*/
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;
+ int arrayDim = 0;
+ while (lex.lookAhead() == '[') {
+ ++arrayDim;
+ lex.get();
+ if (lex.get() != ']')
+ throw new CompileError("] is missing", lex);
+ }
+
+ return arrayDim;
}
/* class.type : Identifier ( "." Identifier )*
*/
private ASTList parseClassType(SymbolTable tbl) throws CompileError {
- ASTList list = null;
- for (;;) {
- if (lex.get() != Identifier)
- throw new SyntaxError(lex);
-
- list = ASTList.append(list, new Symbol(lex.getString()));
- if (lex.lookAhead() == '.')
- lex.get();
- else
- break;
- }
-
- return list;
+ ASTList list = null;
+ for (;;) {
+ if (lex.get() != Identifier)
+ throw new SyntaxError(lex);
+
+ list = ASTList.append(list, new Symbol(lex.getString()));
+ if (lex.lookAhead() == '.')
+ lex.get();
+ else
+ break;
+ }
+
+ return list;
}
/* postfix.expr : number.literal
- * | primary.expr
- * | method.expr
- * | postfix.expr "++" | "--"
- * | postfix.expr "[" array.size "]"
- * | postfix.expr "." Identifier
- * | postfix.expr "#" Identifier
+ * | primary.expr
+ * | method.expr
+ * | postfix.expr "++" | "--"
+ * | postfix.expr "[" array.size "]"
+ * | postfix.expr "." Identifier
+ * | postfix.expr "#" Identifier
*
* "#" is not an operator of regular Java. It separates
* a class name and a member name in an expression for static member
* access. For example,
- * java.lang.Integer.toString(3) in regular Java
+ * java.lang.Integer.toString(3) in regular Java
* must be written like this:
- * java.lang.Integer#toString(3) for this compiler.
+ * java.lang.Integer#toString(3) for this compiler.
*/
private ASTree parsePostfix(SymbolTable tbl) throws CompileError {
- int token = lex.lookAhead();
- switch (token) {
- case LongConstant :
- case IntConstant :
- case CharConstant :
- lex.get();
- return new IntConst(lex.getLong(), token);
- case DoubleConstant :
- case FloatConstant :
- lex.get();
- return new DoubleConst(lex.getDouble(), token);
- default :
- break;
- }
-
- String str;
- ASTree index;
- ASTree expr = parsePrimaryExpr(tbl);
- int t;
- while (true) {
- switch (lex.lookAhead()) {
- case '(' :
- expr = parseMethodCall(tbl, expr);
- break;
- case '[' :
- index = parseArrayIndex(tbl);
- if (index == null)
- throw new SyntaxError(lex);
-
- expr = Expr.make(ARRAY, expr, index);
- break;
- case PLUSPLUS :
- case MINUSMINUS :
- t = lex.get();
- expr = Expr.make(t, null, expr);
- break;
- case '.' :
- lex.get();
- if (lex.get() != Identifier)
- throw new CompileError("missing member name", lex);
-
- expr = Expr.make('.', expr, new Member(lex.getString()));
- break;
- case '#' :
- lex.get();
- t = lex.get();
- if (t == CLASS)
- str = "class";
- else if (t == Identifier)
- str = lex.getString();
- else
- throw new CompileError("missing static member name", lex);
-
- expr = Expr.make(MEMBER, toClassName(expr, null),
- new Member(str));
- break;
- default :
- return expr;
- }
- }
+ int token = lex.lookAhead();
+ switch (token) {
+ case LongConstant :
+ case IntConstant :
+ case CharConstant :
+ lex.get();
+ return new IntConst(lex.getLong(), token);
+ case DoubleConstant :
+ case FloatConstant :
+ lex.get();
+ return new DoubleConst(lex.getDouble(), token);
+ default :
+ break;
+ }
+
+ String str;
+ ASTree index;
+ ASTree expr = parsePrimaryExpr(tbl);
+ int t;
+ while (true) {
+ switch (lex.lookAhead()) {
+ case '(' :
+ expr = parseMethodCall(tbl, expr);
+ break;
+ case '[' :
+ index = parseArrayIndex(tbl);
+ if (index == null)
+ throw new SyntaxError(lex);
+
+ expr = Expr.make(ARRAY, expr, index);
+ break;
+ case PLUSPLUS :
+ case MINUSMINUS :
+ t = lex.get();
+ expr = Expr.make(t, null, expr);
+ break;
+ case '.' :
+ lex.get();
+ if (lex.get() != Identifier)
+ throw new CompileError("missing member name", lex);
+
+ expr = Expr.make('.', expr, new Member(lex.getString()));
+ break;
+ case '#' :
+ lex.get();
+ t = lex.get();
+ if (t == CLASS)
+ str = "class";
+ else if (t == Identifier)
+ str = lex.getString();
+ else
+ throw new CompileError("missing static member name", lex);
+
+ expr = Expr.make(MEMBER, toClassName(expr, null),
+ new Member(str));
+ break;
+ default :
+ return expr;
+ }
+ }
}
/* method.call : method.expr "(" argument.list ")"
* method.expr : THIS | SUPER | Identifier
- * | postfix.expr "." Identifier
- * | postfix.expr "#" Identifier
+ * | postfix.expr "." Identifier
+ * | postfix.expr "#" Identifier
*/
private ASTree parseMethodCall(SymbolTable tbl, ASTree expr)
- throws CompileError
+ throws CompileError
{
- if (expr instanceof Keyword) {
- int token = ((Keyword)expr).get();
- if (token != THIS && token != SUPER)
- throw new SyntaxError(lex);
- }
- else if (expr instanceof Symbol) // Identifier
- ;
- else if (expr instanceof Expr) {
- int op = ((Expr)expr).getOperator();
- if (op != '.' && op != MEMBER)
- throw new SyntaxError(lex);
- }
-
- return Expr.make(CALL, expr, parseArgumentList(tbl));
+ if (expr instanceof Keyword) {
+ int token = ((Keyword)expr).get();
+ if (token != THIS && token != SUPER)
+ throw new SyntaxError(lex);
+ }
+ else if (expr instanceof Symbol) // Identifier
+ ;
+ else if (expr instanceof Expr) {
+ int op = ((Expr)expr).getOperator();
+ if (op != '.' && op != MEMBER)
+ throw new SyntaxError(lex);
+ }
+
+ return Expr.make(CALL, expr, parseArgumentList(tbl));
}
private ASTList toClassName(ASTree name, ASTList tail)
- throws CompileError
+ throws CompileError
{
- if (name instanceof Symbol)
- return new ASTList(name, tail);
- else if (name instanceof Expr) {
- Expr expr = (Expr)name;
- if (expr.getOperator() == '.')
- return toClassName(expr.oprand1(),
- new ASTList(expr.oprand2(), tail));
- }
-
- throw new CompileError("bad static member access", lex);
+ if (name instanceof Symbol)
+ return new ASTList(name, tail);
+ else if (name instanceof Expr) {
+ Expr expr = (Expr)name;
+ if (expr.getOperator() == '.')
+ return toClassName(expr.oprand1(),
+ new ASTList(expr.oprand2(), tail));
+ }
+
+ throw new CompileError("bad static member access", lex);
}
/* primary.expr : THIS | SUPER | TRUE | FALSE | NULL
- * | StringL
- * | Identifier
- * | NEW new.expr
- * | "(" expression ")"
+ * | StringL
+ * | Identifier
+ * | NEW new.expr
+ * | "(" expression ")"
*
* Identifier represents either a local variable name, a member name,
* or a class name.
*/
private ASTree parsePrimaryExpr(SymbolTable tbl) throws CompileError {
- int t;
- String name;
- Declarator decl;
- ASTree expr;
-
- switch (t = lex.get()) {
- case THIS :
- case SUPER :
- case TRUE :
- case FALSE :
- case NULL :
- return new Keyword(t);
- case Identifier :
- name = lex.getString();
- decl = tbl.lookup(name);
- if (decl == null)
- return new Member(name); // this or static member
- else
- return new Variable(name, decl); // local variable
- case StringL :
- return new StringL(lex.getString());
- case NEW :
- return parseNew(tbl);
- case '(' :
- expr = parseExpression(tbl);
- if (lex.get() == ')')
- return expr;
- else
- throw new CompileError(") is missing", lex);
- default :
- throw new SyntaxError(lex);
- }
+ int t;
+ String name;
+ Declarator decl;
+ ASTree expr;
+
+ switch (t = lex.get()) {
+ case THIS :
+ case SUPER :
+ case TRUE :
+ case FALSE :
+ case NULL :
+ return new Keyword(t);
+ case Identifier :
+ name = lex.getString();
+ decl = tbl.lookup(name);
+ if (decl == null)
+ return new Member(name); // this or static member
+ else
+ return new Variable(name, decl); // local variable
+ case StringL :
+ return new StringL(lex.getString());
+ case NEW :
+ return parseNew(tbl);
+ case '(' :
+ expr = parseExpression(tbl);
+ if (lex.get() == ')')
+ return expr;
+ else
+ throw new CompileError(") is missing", lex);
+ default :
+ throw new SyntaxError(lex);
+ }
}
/* new.expr : class.type "(" argument.list ")"
- * | class.type array.size [ array.initializer ]
- * | primitive.type array.size [ array.initializer ]
+ * | class.type array.size [ array.initializer ]
+ * | primitive.type array.size [ array.initializer ]
*/
private NewExpr parseNew(SymbolTable tbl) throws CompileError {
- ASTree init = null;
- int t = lex.lookAhead();
- if (isBuiltinType(t)) {
- lex.get();
- ASTList size = parseArraySize(tbl);
- if (lex.lookAhead() == '{')
- init = parseArrayInitializer(tbl);
-
- return new NewExpr(t, size, init);
- }
- else if (t == Identifier) {
- ASTList name = parseClassType(tbl);
- t = lex.lookAhead();
- if (t == '(') {
- ASTList args = parseArgumentList(tbl);
- return new NewExpr(name, args);
- }
- else if (t == '[') {
- ASTList size = parseArraySize(tbl);
- if (lex.lookAhead() == '{')
- init = parseArrayInitializer(tbl);
-
- return NewExpr.makeObjectArray(name, size, init);
- }
- }
-
- throw new SyntaxError(lex);
+ ASTree init = null;
+ int t = lex.lookAhead();
+ if (isBuiltinType(t)) {
+ lex.get();
+ ASTList size = parseArraySize(tbl);
+ if (lex.lookAhead() == '{')
+ init = parseArrayInitializer(tbl);
+
+ return new NewExpr(t, size, init);
+ }
+ else if (t == Identifier) {
+ ASTList name = parseClassType(tbl);
+ t = lex.lookAhead();
+ if (t == '(') {
+ ASTList args = parseArgumentList(tbl);
+ return new NewExpr(name, args);
+ }
+ else if (t == '[') {
+ ASTList size = parseArraySize(tbl);
+ if (lex.lookAhead() == '{')
+ init = parseArrayInitializer(tbl);
+
+ return NewExpr.makeObjectArray(name, size, init);
+ }
+ }
+
+ throw new SyntaxError(lex);
}
/* array.size : [ array.index ]*
*/
private ASTList parseArraySize(SymbolTable tbl) throws CompileError {
- ASTList list = null;
- while (lex.lookAhead() == '[')
- list = ASTList.append(list, parseArrayIndex(tbl));
+ ASTList list = null;
+ while (lex.lookAhead() == '[')
+ list = ASTList.append(list, parseArrayIndex(tbl));
- return list;
+ return list;
}
/* array.index : "[" [ expression ] "]"
*/
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;
- }
+ 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;
+ }
}
/* argument.list : "(" [ expression [ "," expression ]* ] ")"
*/
private ASTList parseArgumentList(SymbolTable tbl) throws CompileError {
- if (lex.get() != '(')
- throw new CompileError("( is missing", lex);
-
- ASTList list = null;
- if (lex.lookAhead() != ')')
- for (;;) {
- list = ASTList.append(list, parseExpression(tbl));
- if (lex.lookAhead() == ',')
- lex.get();
- else
- break;
- }
-
- if (lex.get() != ')')
- throw new CompileError(") is missing", lex);
-
- return list;
+ if (lex.get() != '(')
+ throw new CompileError("( is missing", lex);
+
+ ASTList list = null;
+ if (lex.lookAhead() != ')')
+ for (;;) {
+ list = ASTList.append(list, parseExpression(tbl));
+ if (lex.lookAhead() == ',')
+ lex.get();
+ else
+ break;
+ }
+
+ if (lex.get() != ')')
+ throw new CompileError(") is missing", lex);
+
+ return list;
}
}
diff --git a/src/main/javassist/compiler/ProceedHandler.java b/src/main/javassist/compiler/ProceedHandler.java
index a787223e..17759d76 100644
--- a/src/main/javassist/compiler/ProceedHandler.java
+++ b/src/main/javassist/compiler/ProceedHandler.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import javassist.bytecode.Bytecode;
@@ -36,5 +25,5 @@ import javassist.compiler.ast.ASTList;
*/
public interface ProceedHandler {
void doit(JvstCodeGen gen, Bytecode b, ASTList args)
- throws CompileError;
+ throws CompileError;
}
diff --git a/src/main/javassist/compiler/SymbolTable.java b/src/main/javassist/compiler/SymbolTable.java
index be318811..56134b49 100644
--- a/src/main/javassist/compiler/SymbolTable.java
+++ b/src/main/javassist/compiler/SymbolTable.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
import java.util.HashMap;
@@ -34,21 +23,21 @@ public final class SymbolTable extends HashMap {
public SymbolTable() { this(null); }
public SymbolTable(SymbolTable p) {
- super();
- parent = p;
+ super();
+ parent = p;
}
public SymbolTable getParent() { return parent; }
public Declarator lookup(String name) {
- Declarator found = (Declarator)get(name);
- if (found == null && parent != null)
- return parent.lookup(name);
- else
- return found;
+ Declarator found = (Declarator)get(name);
+ if (found == null && parent != null)
+ return parent.lookup(name);
+ else
+ return found;
}
public void append(String name, Declarator value) {
- put(name, value);
+ put(name, value);
}
}
diff --git a/src/main/javassist/compiler/SyntaxError.java b/src/main/javassist/compiler/SyntaxError.java
index f4c06d8f..cea7b962 100644
--- a/src/main/javassist/compiler/SyntaxError.java
+++ b/src/main/javassist/compiler/SyntaxError.java
@@ -1,32 +1,21 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
public class SyntaxError extends CompileError {
public SyntaxError(Lex l) {
- super("syntax error", l);
+ super("syntax error", l);
}
}
diff --git a/src/main/javassist/compiler/TokenId.java b/src/main/javassist/compiler/TokenId.java
index 8b78bf00..b0cd7acf 100644
--- a/src/main/javassist/compiler/TokenId.java
+++ b/src/main/javassist/compiler/TokenId.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler;
public interface TokenId {
@@ -34,7 +23,7 @@ public interface TokenId {
int CATCH = 305;
int CHAR = 306;
int CLASS = 307;
- int CONST = 308; // reserved keyword
+ int CONST = 308; // reserved keyword
int CONTINUE = 309;
int DEFAULT = 310;
int DO = 311;
@@ -45,7 +34,7 @@ public interface TokenId {
int FINALLY = 316;
int FLOAT = 317;
int FOR = 318;
- int GOTO = 319; // reserved keyword
+ int GOTO = 319; // reserved keyword
int IF = 320;
int IMPLEMENTS = 321;
int IMPORT = 322;
@@ -75,39 +64,39 @@ public interface TokenId {
int WHILE = 346;
int STRICT = 347;
- int NEQ = 350; // !=
- int MOD_E = 351; // %=
- int AND_E = 352; // &=
- int MUL_E = 353; // *=
- int PLUS_E = 354; // +=
- int MINUS_E = 355; // -=
- int DIV_E = 356; // /=
- int LE = 357; // <=
- int EQ = 358; // ==
- int GE = 359; // >=
- int EXOR_E = 360; // ^=
- int OR_E = 361; // |=
- int PLUSPLUS = 362; // ++
- int MINUSMINUS = 363; // --
- int LSHIFT = 364; // <<
- int LSHIFT_E = 365; // <<=
- int RSHIFT = 366; // >>
- int RSHIFT_E = 367; // >>=
- int OROR = 368; // ||
- int ANDAND = 369; // &&
- int ARSHIFT = 370; // >>>
- int ARSHIFT_E = 371; // >>>=
+ int NEQ = 350; // !=
+ int MOD_E = 351; // %=
+ int AND_E = 352; // &=
+ int MUL_E = 353; // *=
+ int PLUS_E = 354; // +=
+ int MINUS_E = 355; // -=
+ int DIV_E = 356; // /=
+ int LE = 357; // <=
+ int EQ = 358; // ==
+ int GE = 359; // >=
+ int EXOR_E = 360; // ^=
+ int OR_E = 361; // |=
+ int PLUSPLUS = 362; // ++
+ int MINUSMINUS = 363; // --
+ int LSHIFT = 364; // <<
+ int LSHIFT_E = 365; // <<=
+ int RSHIFT = 366; // >>
+ int RSHIFT_E = 367; // >>=
+ int OROR = 368; // ||
+ int ANDAND = 369; // &&
+ int ARSHIFT = 370; // >>>
+ int ARSHIFT_E = 371; // >>>=
// operators from NEQ to ARSHIFT_E
String opNames[] = { "!=", "%=", "&=", "*=", "+=", "-=", "/=",
- "<=", "==", ">=", "^=", "|=", "++", "--",
- "<<", "<<=", ">>", ">>=", "||", "&&", ">>>",
- ">>>=" };
+ "<=", "==", ">=", "^=", "|=", "++", "--",
+ "<<", "<<=", ">>", ">>=", "||", "&&", ">>>",
+ ">>>=" };
// operators from MOD_E to ARSHIFT_E
int assignOps[] = { '%', '&', '*', '+', '-', '/', 0, 0, 0,
- '^', '|', 0, 0, 0, LSHIFT, 0, RSHIFT, 0, 0, 0,
- ARSHIFT };
+ '^', '|', 0, 0, 0, LSHIFT, 0, RSHIFT, 0, 0, 0,
+ ARSHIFT };
int Identifier = 400;
int CharConstant = 401;
@@ -121,14 +110,14 @@ public interface TokenId {
int FALSE = 411;
int NULL = 412;
- int CALL = 'C'; // method call
- int ARRAY = 'A'; // array access
- int MEMBER = '#'; // static member access
+ int CALL = 'C'; // method call
+ int ARRAY = 'A'; // array access
+ int MEMBER = '#'; // static member access
- int EXPR = 'E'; // expression statement
- int LABEL = 'L'; // label statement
- int BLOCK = 'B'; // block statement
- int DECL = 'D'; // declaration statement
+ int EXPR = 'E'; // expression statement
+ int LABEL = 'L'; // label statement
+ int BLOCK = 'B'; // block statement
+ int DECL = 'D'; // declaration statement
int BadToken = 500;
}
diff --git a/src/main/javassist/compiler/ast/ASTList.java b/src/main/javassist/compiler/ast/ASTList.java
index 887a528a..9364a32d 100644
--- a/src/main/javassist/compiler/ast/ASTList.java
+++ b/src/main/javassist/compiler/ast/ASTList.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -36,17 +25,17 @@ public class ASTList extends ASTree {
private ASTList right;
public ASTList(ASTree _head, ASTList _tail) {
- left = _head;
- right = _tail;
+ left = _head;
+ right = _tail;
}
public ASTList(ASTree _head) {
- left = _head;
- right = null;
+ left = _head;
+ right = null;
}
public static ASTList make(ASTree e1, ASTree e2, ASTree e3) {
- return new ASTList(e1, new ASTList(e2, new ASTList(e3)));
+ return new ASTList(e1, new ASTList(e2, new ASTList(e3)));
}
public ASTree getLeft() { return left; }
@@ -56,7 +45,7 @@ public class ASTList extends ASTree {
public void setLeft(ASTree _left) { left = _left; }
public void setRight(ASTree _right) {
- right = (ASTList)_right;
+ right = (ASTList)_right;
}
/**
@@ -65,7 +54,7 @@ public class ASTList extends ASTree {
public ASTree head() { return left; }
public void setHead(ASTree _head) {
- left = _head;
+ left = _head;
}
/**
@@ -74,60 +63,60 @@ public class ASTList extends ASTree {
public ASTList tail() { return right; }
public void setTail(ASTList _tail) {
- right = _tail;
+ right = _tail;
}
public void accept(Visitor v) throws CompileError { v.atASTList(this); }
public String toString() {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append("(<");
- sbuf.append(getTag());
- sbuf.append('>');
- ASTList list = this;
- while (list != null) {
- sbuf.append(' ');
- ASTree a = list.left;
- sbuf.append(a == null ? "<null>" : a.toString());
- list = list.right;
- }
-
- sbuf.append(')');
- return sbuf.toString();
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append("(<");
+ sbuf.append(getTag());
+ sbuf.append('>');
+ ASTList list = this;
+ while (list != null) {
+ sbuf.append(' ');
+ ASTree a = list.left;
+ sbuf.append(a == null ? "<null>" : a.toString());
+ list = list.right;
+ }
+
+ sbuf.append(')');
+ return sbuf.toString();
}
/**
* Returns the number of the elements in this list.
*/
public int length() {
- return length(this);
+ return length(this);
}
public static int length(ASTList list) {
- if (list == null)
- return 0;
+ if (list == null)
+ return 0;
- int n = 0;
- while (list != null) {
- list = list.right;
- ++n;
- }
+ int n = 0;
+ while (list != null) {
+ list = list.right;
+ ++n;
+ }
- return n;
+ return n;
}
/**
* Returns a sub list of the list. The sub list begins with the
* n-th element of the list.
*
- * @param nth zero or more than zero.
+ * @param nth zero or more than zero.
*/
public ASTList sublist(int nth) {
- ASTList list = this;
- while (nth-- > 0)
- list = list.right;
+ ASTList list = this;
+ while (nth-- > 0)
+ list = list.right;
- return list;
+ return list;
}
/**
@@ -135,35 +124,35 @@ public class ASTList extends ASTree {
* list.
*/
public boolean subst(ASTree newObj, ASTree oldObj) {
- for (ASTList list = this; list != null; list = list.right)
- if (list.left == oldObj) {
- list.left = newObj;
- return true;
- }
+ for (ASTList list = this; list != null; list = list.right)
+ if (list.left == oldObj) {
+ list.left = newObj;
+ return true;
+ }
- return false;
+ return false;
}
/**
* Appends an object to a list.
*/
public static ASTList append(ASTList a, ASTree b) {
- return concat(a, new ASTList(b));
+ return concat(a, new ASTList(b));
}
/**
* Concatenates two lists.
*/
public static ASTList concat(ASTList a, ASTList b) {
- if (a == null)
- return b;
- else {
- ASTList list = a;
- while (list.right != null)
- list = list.right;
-
- list.right = b;
- return a;
- }
+ if (a == null)
+ return b;
+ else {
+ ASTList list = a;
+ while (list.right != null)
+ list = list.right;
+
+ list.right = b;
+ return a;
+ }
}
}
diff --git a/src/main/javassist/compiler/ast/ASTree.java b/src/main/javassist/compiler/ast/ASTree.java
index 72825142..85ecaf47 100644
--- a/src/main/javassist/compiler/ast/ASTree.java
+++ b/src/main/javassist/compiler/ast/ASTree.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import java.io.Serializable;
@@ -50,11 +39,11 @@ public abstract class ASTree implements Serializable {
public abstract void accept(Visitor v) throws CompileError;
public String toString() {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append('<');
- sbuf.append(getTag());
- sbuf.append('>');
- return sbuf.toString();
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append('<');
+ sbuf.append(getTag());
+ sbuf.append('>');
+ return sbuf.toString();
}
/**
@@ -62,7 +51,7 @@ public abstract class ASTree implements Serializable {
* <code>toString()</code>.
*/
protected String getTag() {
- String name = getClass().getName();
- return name.substring(name.lastIndexOf('.') + 1);
+ String name = getClass().getName();
+ return name.substring(name.lastIndexOf('.') + 1);
}
}
diff --git a/src/main/javassist/compiler/ast/AssignExpr.java b/src/main/javassist/compiler/ast/AssignExpr.java
index 0a062d46..ec3e59b7 100644
--- a/src/main/javassist/compiler/ast/AssignExpr.java
+++ b/src/main/javassist/compiler/ast/AssignExpr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -36,15 +25,15 @@ public class AssignExpr extends Expr {
*/
public AssignExpr(int op, ASTree _head, ASTList _tail) {
- super(op, _head, _tail);
+ super(op, _head, _tail);
}
public static AssignExpr makeAssign(int op, ASTree oprand1,
- ASTree oprand2) {
- return new AssignExpr(op, oprand1, new ASTList(oprand2));
+ ASTree oprand2) {
+ return new AssignExpr(op, oprand1, new ASTList(oprand2));
}
public void accept(Visitor v) throws CompileError {
- v.atAssignExpr(this);
+ v.atAssignExpr(this);
}
}
diff --git a/src/main/javassist/compiler/ast/BinExpr.java b/src/main/javassist/compiler/ast/BinExpr.java
index a8fdeb62..57bac5ef 100644
--- a/src/main/javassist/compiler/ast/BinExpr.java
+++ b/src/main/javassist/compiler/ast/BinExpr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -37,11 +26,11 @@ public class BinExpr extends Expr {
*/
public BinExpr(int op, ASTree _head, ASTList _tail) {
- super(op, _head, _tail);
+ super(op, _head, _tail);
}
public static BinExpr makeBin(int op, ASTree oprand1, ASTree oprand2) {
- return new BinExpr(op, oprand1, new ASTList(oprand2));
+ return new BinExpr(op, oprand1, new ASTList(oprand2));
}
public void accept(Visitor v) throws CompileError { v.atBinExpr(this); }
diff --git a/src/main/javassist/compiler/ast/CastExpr.java b/src/main/javassist/compiler/ast/CastExpr.java
index 7f8775cb..62fbc61c 100644
--- a/src/main/javassist/compiler/ast/CastExpr.java
+++ b/src/main/javassist/compiler/ast/CastExpr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.TokenId;
@@ -36,15 +25,15 @@ public class CastExpr extends ASTList implements TokenId {
protected int arrayDim;
public CastExpr(ASTList className, int dim, ASTree expr) {
- super(className, new ASTList(expr));
- castType = CLASS;
- arrayDim = dim;
+ super(className, new ASTList(expr));
+ castType = CLASS;
+ arrayDim = dim;
}
public CastExpr(int type, int dim, ASTree expr) {
- super(null, new ASTList(expr));
- castType = type;
- arrayDim = dim;
+ super(null, new ASTList(expr));
+ castType = type;
+ arrayDim = dim;
}
/* Returns CLASS, BOOLEAN, INT, or ...
diff --git a/src/main/javassist/compiler/ast/CondExpr.java b/src/main/javassist/compiler/ast/CondExpr.java
index d4a8a108..4451edc6 100644
--- a/src/main/javassist/compiler/ast/CondExpr.java
+++ b/src/main/javassist/compiler/ast/CondExpr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -32,7 +21,7 @@ import javassist.compiler.CompileError;
*/
public class CondExpr extends ASTList {
public CondExpr(ASTree cond, ASTree thenp, ASTree elsep) {
- super(cond, new ASTList(thenp, new ASTList(elsep)));
+ super(cond, new ASTList(thenp, new ASTList(elsep)));
}
public ASTree condExpr() { return head(); }
diff --git a/src/main/javassist/compiler/ast/Declarator.java b/src/main/javassist/compiler/ast/Declarator.java
index edeb839d..7361b92e 100644
--- a/src/main/javassist/compiler/ast/Declarator.java
+++ b/src/main/javassist/compiler/ast/Declarator.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.TokenId;
@@ -35,43 +24,43 @@ public class Declarator extends ASTList implements TokenId {
protected int varType;
protected int arrayDim;
protected int localVar;
- protected String qualifiedClass; // JVM-internal representation
+ protected String qualifiedClass; // JVM-internal representation
public Declarator(int type, int dim) {
- super(null);
- varType = type;
- arrayDim = dim;
- localVar = -1;
- qualifiedClass = null;
+ super(null);
+ varType = type;
+ arrayDim = dim;
+ localVar = -1;
+ qualifiedClass = null;
}
public Declarator(ASTList className, int dim) {
- super(null);
- varType = CLASS;
- arrayDim = dim;
- localVar = -1;
- qualifiedClass = astToClassName(className, '/');
+ super(null);
+ varType = CLASS;
+ arrayDim = dim;
+ localVar = -1;
+ qualifiedClass = astToClassName(className, '/');
}
/* For declaring a pre-defined? local variable.
*/
public Declarator(int type, String jvmClassName, int dim,
- int var, Symbol sym) {
- super(null);
- varType = type;
- arrayDim = dim;
- localVar = var;
- qualifiedClass = jvmClassName;
- setLeft(sym);
- append(this, null); // initializer
+ int var, Symbol sym) {
+ super(null);
+ varType = type;
+ arrayDim = dim;
+ localVar = var;
+ qualifiedClass = jvmClassName;
+ setLeft(sym);
+ append(this, null); // initializer
}
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);
- d.append(d, init);
- return d;
+ Declarator d = new Declarator(this.varType, this.arrayDim + dim);
+ d.qualifiedClass = this.qualifiedClass;
+ d.setLeft(sym);
+ d.append(d, init);
+ return d;
}
/* Returns CLASS, BOOLEAN, BYTE, CHAR, SHORT, INT, LONG, FLOAT,
@@ -92,11 +81,11 @@ public class Declarator extends ASTList implements TokenId {
public void setVariable(Symbol sym) { setLeft(sym); }
public ASTree getInitializer() {
- ASTList t = tail();
- if (t != null)
- return t.head();
- else
- return null;
+ ASTList t = tail();
+ if (t != null)
+ return t.head();
+ else
+ return null;
}
public void setLocalVar(int n) { localVar = n; }
@@ -106,23 +95,23 @@ public class Declarator extends ASTList implements TokenId {
public String getTag() { return "decl"; }
public void accept(Visitor v) throws CompileError {
- v.atDeclarator(this);
+ v.atDeclarator(this);
}
public static String astToClassName(ASTList name, char sep) {
- if (name == null)
- return null;
+ if (name == null)
+ return null;
- StringBuffer sbuf = new StringBuffer();
- for (;;) {
- sbuf.append(((Symbol)name.head()).get());
- name = name.tail();
- if (name == null)
- break;
+ StringBuffer sbuf = new StringBuffer();
+ for (;;) {
+ sbuf.append(((Symbol)name.head()).get());
+ name = name.tail();
+ if (name == null)
+ break;
- sbuf.append(sep);
- }
+ sbuf.append(sep);
+ }
- return sbuf.toString();
+ return sbuf.toString();
}
}
diff --git a/src/main/javassist/compiler/ast/DoubleConst.java b/src/main/javassist/compiler/ast/DoubleConst.java
index 459f030f..dcd91c58 100644
--- a/src/main/javassist/compiler/ast/DoubleConst.java
+++ b/src/main/javassist/compiler/ast/DoubleConst.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -45,6 +34,6 @@ public class DoubleConst extends ASTree {
public String toString() { return Double.toString(value); }
public void accept(Visitor v) throws CompileError {
- v.atDoubleConst(this);
+ v.atDoubleConst(this);
}
}
diff --git a/src/main/javassist/compiler/ast/Expr.java b/src/main/javassist/compiler/ast/Expr.java
index 1fecc9ce..0e345ef2 100644
--- a/src/main/javassist/compiler/ast/Expr.java
+++ b/src/main/javassist/compiler/ast/Expr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.TokenId;
@@ -41,17 +30,17 @@ public class Expr extends ASTList implements TokenId {
protected int operatorId;
public Expr(int op, ASTree _head, ASTList _tail) {
- super(_head, _tail);
- operatorId = op;
+ super(_head, _tail);
+ operatorId = op;
}
public Expr(int op, ASTree _head) {
- super(_head);
- operatorId = op;
+ super(_head);
+ operatorId = op;
}
public static Expr make(int op, ASTree oprand1, ASTree oprand2) {
- return new Expr(op, oprand1, new ASTList(oprand2));
+ return new Expr(op, oprand1, new ASTList(oprand2));
}
public int getOperator() { return operatorId; }
@@ -63,18 +52,18 @@ public class Expr extends ASTList implements TokenId {
public void accept(Visitor v) throws CompileError { v.atExpr(this); }
public String getName() {
- int id = operatorId;
- if (id < 128)
- return String.valueOf((char)id);
- else if (NEQ <= id && id <= ARSHIFT_E)
- return opNames[id - NEQ];
- else if (id == INSTANCEOF)
- return "instanceof";
- else
- return String.valueOf(id);
+ int id = operatorId;
+ if (id < 128)
+ return String.valueOf((char)id);
+ else if (NEQ <= id && id <= ARSHIFT_E)
+ return opNames[id - NEQ];
+ else if (id == INSTANCEOF)
+ return "instanceof";
+ else
+ return String.valueOf(id);
}
protected String getTag() {
- return "op:" + getName();
+ return "op:" + getName();
}
}
diff --git a/src/main/javassist/compiler/ast/FieldDecl.java b/src/main/javassist/compiler/ast/FieldDecl.java
index d57dd632..481552c0 100644
--- a/src/main/javassist/compiler/ast/FieldDecl.java
+++ b/src/main/javassist/compiler/ast/FieldDecl.java
@@ -1,35 +1,24 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
public class FieldDecl extends ASTList {
public FieldDecl(ASTree _head, ASTList _tail) {
- super(_head, _tail);
+ super(_head, _tail);
}
public ASTList getModifiers() { return (ASTList)getLeft(); }
@@ -39,6 +28,6 @@ public class FieldDecl extends ASTList {
public ASTree getInit() { return (ASTree)sublist(2).head(); }
public void accept(Visitor v) throws CompileError {
- v.atFieldDecl(this);
+ v.atFieldDecl(this);
}
}
diff --git a/src/main/javassist/compiler/ast/InstanceOfExpr.java b/src/main/javassist/compiler/ast/InstanceOfExpr.java
index 03d6bc1f..81195065 100644
--- a/src/main/javassist/compiler/ast/InstanceOfExpr.java
+++ b/src/main/javassist/compiler/ast/InstanceOfExpr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -32,18 +21,18 @@ import javassist.compiler.CompileError;
*/
public class InstanceOfExpr extends CastExpr {
public InstanceOfExpr(ASTList className, int dim, ASTree expr) {
- super(className, dim, expr);
+ super(className, dim, expr);
}
public InstanceOfExpr(int type, int dim, ASTree expr) {
- super(type, dim, expr);
+ super(type, dim, expr);
}
public String getTag() {
- return "instanceof:" + castType + ":" + arrayDim;
+ return "instanceof:" + castType + ":" + arrayDim;
}
public void accept(Visitor v) throws CompileError {
- v.atInstanceOfExpr(this);
+ v.atInstanceOfExpr(this);
}
}
diff --git a/src/main/javassist/compiler/ast/IntConst.java b/src/main/javassist/compiler/ast/IntConst.java
index 63ce70cb..12952c56 100644
--- a/src/main/javassist/compiler/ast/IntConst.java
+++ b/src/main/javassist/compiler/ast/IntConst.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -45,6 +34,6 @@ public class IntConst extends ASTree {
public String toString() { return Long.toString(value); }
public void accept(Visitor v) throws CompileError {
- v.atIntConst(this);
+ v.atIntConst(this);
}
}
diff --git a/src/main/javassist/compiler/ast/Keyword.java b/src/main/javassist/compiler/ast/Keyword.java
index 9e1798ec..864a2ce4 100644
--- a/src/main/javassist/compiler/ast/Keyword.java
+++ b/src/main/javassist/compiler/ast/Keyword.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -34,7 +23,7 @@ public class Keyword extends ASTree {
protected int tokenId;
public Keyword(int token) {
- tokenId = token;
+ tokenId = token;
}
public int get() { return tokenId; }
diff --git a/src/main/javassist/compiler/ast/Member.java b/src/main/javassist/compiler/ast/Member.java
index a4825874..fd7e86b9 100644
--- a/src/main/javassist/compiler/ast/Member.java
+++ b/src/main/javassist/compiler/ast/Member.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -32,7 +21,7 @@ import javassist.compiler.CompileError;
*/
public class Member extends Symbol {
public Member(String name) {
- super(name);
+ super(name);
}
public void accept(Visitor v) throws CompileError { v.atMember(this); }
diff --git a/src/main/javassist/compiler/ast/MethodDecl.java b/src/main/javassist/compiler/ast/MethodDecl.java
index 3c529014..b2e601fe 100644
--- a/src/main/javassist/compiler/ast/MethodDecl.java
+++ b/src/main/javassist/compiler/ast/MethodDecl.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -31,12 +20,12 @@ public class MethodDecl extends ASTList {
public static final String initName = "<init>";
public MethodDecl(ASTree _head, ASTList _tail) {
- super(_head, _tail);
+ super(_head, _tail);
}
public boolean isConstructor() {
- Symbol sym = getReturn().getVariable();
- return sym != null && initName.equals(sym.get());
+ Symbol sym = getReturn().getVariable();
+ return sym != null && initName.equals(sym.get());
}
public ASTList getModifiers() { return (ASTList)getLeft(); }
@@ -50,6 +39,6 @@ public class MethodDecl extends ASTList {
public Stmnt getBody() { return (Stmnt)sublist(4).head(); }
public void accept(Visitor v) throws CompileError {
- v.atMethodDecl(this);
+ v.atMethodDecl(this);
}
}
diff --git a/src/main/javassist/compiler/ast/NewExpr.java b/src/main/javassist/compiler/ast/NewExpr.java
index 33c721ed..bcb360dc 100644
--- a/src/main/javassist/compiler/ast/NewExpr.java
+++ b/src/main/javassist/compiler/ast/NewExpr.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.TokenId;
@@ -36,27 +25,27 @@ public class NewExpr extends ASTList implements TokenId {
protected int arrayType;
public NewExpr(ASTList className, ASTList args) {
- super(className, new ASTList(args));
- newArray = false;
- arrayType = CLASS;
+ super(className, new ASTList(args));
+ newArray = false;
+ arrayType = CLASS;
}
public NewExpr(int type, ASTList arraySize, ASTree init) {
- super(null, new ASTList(arraySize));
- newArray = true;
- arrayType = type;
- if (init != null)
- append(this, init);
+ super(null, new ASTList(arraySize));
+ newArray = true;
+ arrayType = type;
+ if (init != null)
+ append(this, init);
}
public static NewExpr makeObjectArray(ASTList className,
- ASTList arraySize, ASTree init) {
- NewExpr e = new NewExpr(className, arraySize);
- e.newArray = true;
- if (init != null)
- append(e, init);
+ ASTList arraySize, ASTree init) {
+ NewExpr e = new NewExpr(className, arraySize);
+ e.newArray = true;
+ if (init != null)
+ append(e, init);
- return e;
+ return e;
}
public boolean isArray() { return newArray; }
@@ -72,16 +61,16 @@ public class NewExpr extends ASTList implements TokenId {
public ASTList getArraySize() { return getArguments(); }
public ASTree getInitializer() {
- ASTree t = getRight().getRight();
- if (t == null)
- return null;
- else
- return t.getLeft();
+ ASTree t = getRight().getRight();
+ if (t == null)
+ return null;
+ else
+ return t.getLeft();
}
public void accept(Visitor v) throws CompileError { v.atNewExpr(this); }
protected String getTag() {
- return newArray ? "new[]" : "new";
+ return newArray ? "new[]" : "new";
}
}
diff --git a/src/main/javassist/compiler/ast/Pair.java b/src/main/javassist/compiler/ast/Pair.java
index 520207a8..7e46fe8b 100644
--- a/src/main/javassist/compiler/ast/Pair.java
+++ b/src/main/javassist/compiler/ast/Pair.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -35,20 +24,20 @@ public class Pair extends ASTree {
protected ASTree left, right;
public Pair(ASTree _left, ASTree _right) {
- left = _left;
- right = _right;
+ left = _left;
+ right = _right;
}
public void accept(Visitor v) throws CompileError { v.atPair(this); }
public String toString() {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append("(<Pair> ");
- sbuf.append(left == null ? "<null>" : left.toString());
- sbuf.append(" . ");
- sbuf.append(right == null ? "<null>" : right.toString());
- sbuf.append(')');
- return sbuf.toString();
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append("(<Pair> ");
+ sbuf.append(left == null ? "<null>" : left.toString());
+ sbuf.append(" . ");
+ sbuf.append(right == null ? "<null>" : right.toString());
+ sbuf.append(')');
+ return sbuf.toString();
}
public ASTree getLeft() { return left; }
diff --git a/src/main/javassist/compiler/ast/Stmnt.java b/src/main/javassist/compiler/ast/Stmnt.java
index c6b9a97e..b237e659 100644
--- a/src/main/javassist/compiler/ast/Stmnt.java
+++ b/src/main/javassist/compiler/ast/Stmnt.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.TokenId;
@@ -35,25 +24,25 @@ public class Stmnt extends ASTList implements TokenId {
protected int operatorId;
public Stmnt(int op, ASTree _head, ASTList _tail) {
- super(_head, _tail);
- operatorId = op;
+ super(_head, _tail);
+ operatorId = op;
}
public Stmnt(int op, ASTree _head) {
- super(_head);
- operatorId = op;
+ super(_head);
+ operatorId = op;
}
public Stmnt(int op) {
- this(op, null);
+ this(op, null);
}
public static Stmnt make(int op, ASTree oprand1, ASTree oprand2) {
- return new Stmnt(op, oprand1, new ASTList(oprand2));
+ return new Stmnt(op, oprand1, new ASTList(oprand2));
}
public static Stmnt make(int op, ASTree op1, ASTree op2, ASTree op3) {
- return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3)));
+ return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3)));
}
public void accept(Visitor v) throws CompileError { v.atStmnt(this); }
@@ -61,9 +50,9 @@ public class Stmnt extends ASTList implements TokenId {
public int getOperator() { return operatorId; }
protected String getTag() {
- if (operatorId < 128)
- return "stmnt:" + (char)operatorId;
- else
- return "stmnt:" + operatorId;
+ if (operatorId < 128)
+ return "stmnt:" + (char)operatorId;
+ else
+ return "stmnt:" + operatorId;
}
}
diff --git a/src/main/javassist/compiler/ast/StringL.java b/src/main/javassist/compiler/ast/StringL.java
index 5f173f50..5e99e5f0 100644
--- a/src/main/javassist/compiler/ast/StringL.java
+++ b/src/main/javassist/compiler/ast/StringL.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -34,7 +23,7 @@ public class StringL extends ASTree {
protected String text;
public StringL(String t) {
- text = t;
+ text = t;
}
public String get() { return text; }
diff --git a/src/main/javassist/compiler/ast/Symbol.java b/src/main/javassist/compiler/ast/Symbol.java
index c8e753bf..0d48ab8f 100644
--- a/src/main/javassist/compiler/ast/Symbol.java
+++ b/src/main/javassist/compiler/ast/Symbol.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -34,7 +23,7 @@ public class Symbol extends ASTree {
protected String identifier;
public Symbol(String sym) {
- identifier = sym;
+ identifier = sym;
}
public String get() { return identifier; }
diff --git a/src/main/javassist/compiler/ast/Variable.java b/src/main/javassist/compiler/ast/Variable.java
index 16112a99..63f9bee6 100644
--- a/src/main/javassist/compiler/ast/Variable.java
+++ b/src/main/javassist/compiler/ast/Variable.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;
@@ -34,14 +23,14 @@ public class Variable extends Symbol {
protected Declarator declarator;
public Variable(String sym, Declarator d) {
- super(sym);
- declarator = d;
+ super(sym);
+ declarator = d;
}
public Declarator getDeclarator() { return declarator; }
public String toString() {
- return identifier + ":" + declarator.getType();
+ return identifier + ":" + declarator.getType();
}
public void accept(Visitor v) throws CompileError { v.atVariable(this); }
diff --git a/src/main/javassist/compiler/ast/Visitor.java b/src/main/javassist/compiler/ast/Visitor.java
index 685713de..e7b4596c 100644
--- a/src/main/javassist/compiler/ast/Visitor.java
+++ b/src/main/javassist/compiler/ast/Visitor.java
@@ -1,28 +1,17 @@
/*
- * This file is part of the Javassist toolkit.
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * either http://www.mozilla.org/MPL/.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Javassist.
- *
- * The Initial Developer of the Original Code is Shigeru Chiba. Portions
- * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba.
- * All Rights Reserved.
- *
- * Contributor(s):
- *
- * The development of this software is supported in part by the PRESTO
- * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*/
-
package javassist.compiler.ast;
import javassist.compiler.CompileError;