Author: sebb
Date: Thu Jun 16 12:50:55 2011
New Revision: 1136411
URL: http://svn.apache.org/viewvc?rev=1136411&view=rev
Log:
Tab police
Modified:
jakarta/bcel/trunk/src/examples/Mini/ASTExpr.java
jakarta/bcel/trunk/src/examples/Mini/ASTFunAppl.java
jakarta/bcel/trunk/src/examples/Mini/ASTFunDecl.java
jakarta/bcel/trunk/src/examples/Mini/ASTIdent.java
jakarta/bcel/trunk/src/examples/Mini/ASTIfExpr.java
jakarta/bcel/trunk/src/examples/Mini/ASTLetExpr.java
jakarta/bcel/trunk/src/examples/Mini/ASTProgram.java
jakarta/bcel/trunk/src/examples/Mini/Environment.java
jakarta/bcel/trunk/src/examples/Mini/JJTMiniParserState.java
jakarta/bcel/trunk/src/examples/Mini/MiniC.java
jakarta/bcel/trunk/src/examples/Mini/SimpleNode.java
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTExpr.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTExpr.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTExpr.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTExpr.java Thu Jun 16 12:50:55 2011
@@ -164,13 +164,13 @@ implements MiniParserConstants, MiniPars
else {
// Compute expected type
if((kind == PLUS) || (kind == MINUS) || (kind == MULT) ||
- (kind == MOD) || (kind == DIV)) {
+ (kind == MOD) || (kind == DIV)) {
child_type = type = T_INT;
} else if((kind == AND) || (kind == OR)) {
child_type = type = T_BOOLEAN;
} else { // LEQ, GT, etc.
- child_type = T_INT;
- type = T_BOOLEAN;
+ child_type = T_INT;
+ type = T_BOOLEAN;
}
}
@@ -180,8 +180,8 @@ implements MiniParserConstants, MiniPars
if(t != child_type) {
MiniC.addError(exprs[i].getLine(), exprs[i].getColumn(),
- "Expression has not expected type " +
TYPE_NAMES[child_type] +
- " but " + TYPE_NAMES[t] + ".");
+ "Expression has not expected type " +
TYPE_NAMES[child_type] +
+ " but " + TYPE_NAMES[t] + ".");
}
is_simple = is_simple && exprs[i].isSimple();
@@ -223,23 +223,23 @@ implements MiniParserConstants, MiniPars
case MULT: ASTFunDecl.push(buf, _body_int + " * " + _body_int2); break;
case DIV: ASTFunDecl.push(buf, _body_int + " / " + _body_int2); break;
- case AND: ASTFunDecl.push(buf, toInt(toBool(_body_int) + " && " +
- toBool(_body_int2))); break;
+ case AND: ASTFunDecl.push(buf, toInt(toBool(_body_int) + " && " +
+ toBool(_body_int2))); break;
case OR: ASTFunDecl.push(buf, toInt(toBool(_body_int) + " || " +
- toBool(_body_int2))); break;
+ toBool(_body_int2))); break;
case EQ: ASTFunDecl.push(buf, toInt(_body_int + " == " + _body_int2));
- break;
+ break;
case LEQ: ASTFunDecl.push(buf, toInt(_body_int + " <= " + _body_int2));
- break;
+ break;
case GEQ: ASTFunDecl.push(buf, toInt(_body_int + " >= " + _body_int2));
- break;
+ break;
case NEQ: ASTFunDecl.push(buf, toInt(_body_int + " != " + _body_int2));
- break;
+ break;
case LT: ASTFunDecl.push(buf, toInt(_body_int + " < " + _body_int2));
- break;
+ break;
case GT: ASTFunDecl.push(buf, toInt(_body_int + " > " + _body_int2));
- break;
+ break;
default: System.err.println("Ooops");
}
@@ -256,8 +256,8 @@ implements MiniParserConstants, MiniPars
if(unop == MINUS) {
il.append(InstructionConstants.INEG);
} else { // == NOT
- il.append(new PUSH(cp, 1)); ASTFunDecl.push(); // Push TRUE
- il.append(InstructionConstants.IXOR); ASTFunDecl.pop();
+ il.append(new PUSH(cp, 1)); ASTFunDecl.push(); // Push TRUE
+ il.append(InstructionConstants.IXOR); ASTFunDecl.pop();
}
}
else { // Apply binary operand
@@ -273,7 +273,7 @@ implements MiniParserConstants, MiniPars
case AND: il.append(InstructionConstants.IAND); ASTFunDecl.pop();
break;
case OR: il.append(InstructionConstants.IOR); ASTFunDecl.pop();
break;
- /* Use negated operands */
+ /* Use negated operands */
case EQ: bh = il.append(new IF_ICMPNE(null)); ASTFunDecl.pop(2);
break;
case LEQ: bh = il.append(new IF_ICMPGT(null)); ASTFunDecl.pop(2);
break;
case GEQ: bh = il.append(new IF_ICMPLT(null)); ASTFunDecl.pop(2);
break;
@@ -285,14 +285,14 @@ implements MiniParserConstants, MiniPars
switch(kind) {
case EQ: case LEQ: case GEQ: case NEQ: case LT: case GT:
- BranchHandle g;
+ BranchHandle g;
- il.append(new PUSH(cp, 1));
- g = il.append(new GOTO(null));
- bh.setTarget(il.append(new PUSH(cp, 0)));
- g.setTarget(il.append(InstructionConstants.NOP)); // May be optimized
away later
- ASTFunDecl.push();
- break;
+ il.append(new PUSH(cp, 1));
+ g = il.append(new GOTO(null));
+ bh.setTarget(il.append(new PUSH(cp, 0)));
+ g.setTarget(il.append(InstructionConstants.NOP)); // May be optimized
away later
+ ASTFunDecl.push();
+ break;
default: break;
}
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTFunAppl.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTFunAppl.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTFunAppl.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTFunAppl.java Thu Jun 16 12:50:55
2011
@@ -85,23 +85,23 @@ public class ASTFunAppl extends ASTExpr
if(entry == null) {
MiniC.addError(name.getLine(), name.getColumn(),
- "Applying unknown function " + fname + ".");
+ "Applying unknown function " + fname + ".");
} else {
if(!(entry instanceof Function)) {
MiniC.addError(name.getLine(), name.getColumn(),
- "Applying non-function " + fname + ".");
+ "Applying non-function " + fname + ".");
} else {
- int len = (exprs != null)? exprs.length : 0;
- Function fun = (Function)entry;
+ int len = (exprs != null)? exprs.length : 0;
+ Function fun = (Function)entry;
- if(len != fun.getNoArgs()) {
+ if(len != fun.getNoArgs()) {
MiniC.addError(name.getLine(), name.getColumn(),
- "Function " + fname + " expects " + fun.getNoArgs() +
- " arguments, you supplied " + len + ".");
+ "Function " + fname + " expects " + fun.getNoArgs() +
+ " arguments, you supplied " + len + ".");
} else { // Adjust references
- function = fun;
- name = fun.getName();
- }
+ function = fun;
+ name = fun.getName();
+ }
}
}
@@ -132,19 +132,19 @@ public class ASTFunAppl extends ASTExpr
// Check arguments
if(exprs != null) {
for(int i=0; i < exprs.length; i++) { // length match checked in
previous pass
- int expect = args[i].getType(); // May be T_UNKNOWN
- int t_e = exprs[i].eval(expect); // May be T_UNKNOWN
+ int expect = args[i].getType(); // May be T_UNKNOWN
+ int t_e = exprs[i].eval(expect); // May be T_UNKNOWN
- if((expect != T_UNKNOWN) && (t_e != expect)) {
+ if((expect != T_UNKNOWN) && (t_e != expect)) {
MiniC.addError(exprs[i].getLine(), exprs[i].getColumn(),
- "Argument " + (i + 1) + " in application of " + fname +
- " is not of type " + TYPE_NAMES[expect] + " but " +
- TYPE_NAMES[t_e]);
+ "Argument " + (i + 1) + " in application of " + fname +
+ " is not of type " + TYPE_NAMES[expect] + " but " +
+ TYPE_NAMES[t_e]);
} else {
args[i].setType(t_e); // Update, may be identical
}
- is_simple = is_simple && exprs[i].isSimple(); // Check condition
+ is_simple = is_simple && exprs[i].isSimple(); // Check condition
}
}
@@ -171,7 +171,7 @@ public class ASTFunAppl extends ASTExpr
}
else { // Normal function
if(exprs != null) { // Output in reverse odrder
- for(int i = exprs.length - 1; i >= 0; i--) {
+ for(int i = exprs.length - 1; i >= 0; i--) {
exprs[i].code(buf);
}
}
@@ -180,12 +180,12 @@ public class ASTFunAppl extends ASTExpr
// Function call
if(exprs != null) {
- for(int i=0; i < exprs.length; i++) {
- call.append(ASTFunDecl.pop());
- if(i < exprs.length - 1) {
+ for(int i=0; i < exprs.length; i++) {
+ call.append(ASTFunDecl.pop());
+ if(i < exprs.length - 1) {
call.append(", ");
}
- }
+ }
}
call.append(")");
@@ -205,37 +205,37 @@ public class ASTFunAppl extends ASTExpr
if(fname.equals("READ")) {
il.append(new INVOKESTATIC(cp.addMethodref(class_name,
- "_readInt",
- "()I")));
+ "_readInt",
+ "()I")));
} else if(fname.equals("WRITE")) {
exprs[0].byte_code(il, method, cp);
ASTFunDecl.pop();
il.append(new INVOKESTATIC(cp.addMethodref(class_name,
- "_writeInt",
- "(I)I")));
+ "_writeInt",
+ "(I)I")));
}
else { // Normal function
int size = exprs.length;
Type[] argv = null;
if(exprs != null) {
- argv = new Type[size];
+ argv = new Type[size];
- for(int i=0; i < size; i++) {
- argv[i] = Type.INT;
- exprs[i].byte_code(il, method, cp);
- }
+ for(int i=0; i < size; i++) {
+ argv[i] = Type.INT;
+ exprs[i].byte_code(il, method, cp);
+ }
- //ASTFunDecl.push(size);
+ //ASTFunDecl.push(size);
}
ASTFunDecl.pop(size);
// Function call
il.append(new INVOKESTATIC(cp.addMethodref(class_name,
- fname,
-
Type.getMethodSignature(Type.INT,
-
argv))));
+ fname,
+
Type.getMethodSignature(Type.INT,
+
argv))));
}
ASTFunDecl.push();
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTFunDecl.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTFunDecl.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTFunDecl.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTFunDecl.java Thu Jun 16 12:50:55
2011
@@ -109,7 +109,7 @@ implements MiniParserTreeConstants, org.
if(entry != null) {
MiniC.addError(argv[i].getLine(), argv[i].getColumn(),
- "Redeclaration of " + entry + ".");
+ "Redeclaration of " + entry + ".");
} else {
env.put(new Variable(argv[i]));
}
@@ -138,8 +138,8 @@ implements MiniParserTreeConstants, org.
if((expected != T_UNKNOWN) && (type != expected)) {
MiniC.addError(line, column,
- "Function f ist not of type " + TYPE_NAMES[expected] +
- " as previously assumed, but " + TYPE_NAMES[type]);
+ "Function f ist not of type " + TYPE_NAMES[expected] +
+ " as previously assumed, but " + TYPE_NAMES[type]);
}
name.setType(type);
@@ -171,12 +171,12 @@ implements MiniParserTreeConstants, org.
}
else {
out.print(" public static final " + "int" + // type_names[type] +
- " " + fname + "(");
+ " " + fname + "(");
for(int i = 0; i < argv.length; i++) {
- out.print("int " + argv[i].getName());
-
- if(i < argv.length - 1) {
+ out.print("int " + argv[i].getName());
+
+ if(i < argv.length - 1) {
out.print(", ");
}
}
@@ -223,8 +223,8 @@ implements MiniParserTreeConstants, org.
if(fname.equals("main")) {
method = new MethodGen(ACC_STATIC | ACC_PUBLIC,
- Type.VOID, args, arg_names,
- "main", class_name, il, cp);
+ Type.VOID, args, arg_names,
+ "main", class_name, il, cp);
main = true;
} else if(fname.equals("READ") || fname.equals("WRITE")) { // Do nothing
@@ -236,18 +236,18 @@ implements MiniParserTreeConstants, org.
args = new Type[size];
for(int i = 0; i < size; i++) {
- args[i] = Type.INT;
- arg_names[i] = argv[i].getName();
+ args[i] = Type.INT;
+ arg_names[i] = argv[i].getName();
}
method = new MethodGen(ACC_STATIC | ACC_PRIVATE | ACC_FINAL,
- Type.INT, args, arg_names,
- fname, class_name, il, cp);
+ Type.INT, args, arg_names,
+ fname, class_name, il, cp);
LocalVariableGen[] lv = method.getLocalVariables();
for(int i = 0; i < size; i++) {
- Variable entry = (Variable)env.get(arg_names[i]);
- entry.setLocalVariable(lv[i]);
+ Variable entry = (Variable)env.get(arg_names[i]);
+ entry.setLocalVariable(lv[i]);
}
method.addException("java.io.IOException");
@@ -257,28 +257,28 @@ implements MiniParserTreeConstants, org.
body.byte_code(il, method, cp);
if(main) {
- ObjectType e_type = new ObjectType("java.lang.Exception");
- InstructionHandle start = il.getStart(), end, handler, end_handler;
- LocalVariableGen exc = method.addLocalVariable("$e",
- e_type,
- null, null);
- int slot = exc.getIndex();
-
- il.append(InstructionConstants.POP); pop(); // Remove last element on
stack
- end = il.append(InstructionConstants.RETURN); // Use instruction
constants, if possible
-
- // catch
- handler = il.append(new ASTORE(slot)); // save exception object
- il.append(new GETSTATIC(cp.addFieldref("java.lang.System", "err",
- "Ljava/io/PrintStream;")));
- il.append(new ALOAD(slot)); push(2);
- il.append(new INVOKEVIRTUAL(cp.addMethodref("java.io.PrintStream",
- "println",
- "(Ljava/lang/Object;)V")));
- pop(2);
- end_handler = il.append(InstructionConstants.RETURN);
- method.addExceptionHandler(start, end, handler, e_type);
- exc.setStart(handler); exc.setEnd(end_handler);
+ ObjectType e_type = new ObjectType("java.lang.Exception");
+ InstructionHandle start = il.getStart(), end, handler, end_handler;
+ LocalVariableGen exc = method.addLocalVariable("$e",
+ e_type,
+ null, null);
+ int slot = exc.getIndex();
+
+ il.append(InstructionConstants.POP); pop(); // Remove last element on
stack
+ end = il.append(InstructionConstants.RETURN); // Use instruction
constants, if possible
+
+ // catch
+ handler = il.append(new ASTORE(slot)); // save exception object
+ il.append(new GETSTATIC(cp.addFieldref("java.lang.System", "err",
+ "Ljava/io/PrintStream;")));
+ il.append(new ALOAD(slot)); push(2);
+ il.append(new INVOKEVIRTUAL(cp.addMethodref("java.io.PrintStream",
+ "println",
+ "(Ljava/lang/Object;)V")));
+ pop(2);
+ end_handler = il.append(InstructionConstants.RETURN);
+ method.addExceptionHandler(start, end, handler, e_type);
+ exc.setStart(handler); exc.setEnd(end_handler);
} else {
il.append(InstructionConstants.IRETURN); // Reuse object to save memory
}
@@ -297,9 +297,9 @@ implements MiniParserTreeConstants, org.
private static final InstructionFinder.CodeConstraint my_constraint =
new InstructionFinder.CodeConstraint() {
public boolean checkCode(InstructionHandle[] match) {
- BranchInstruction if_icmp =
(BranchInstruction)match[0].getInstruction();
- GOTO goto_ = (GOTO)match[2].getInstruction();
- return (if_icmp.getTarget() == match[3]) && (goto_.getTarget() ==
match[4]);
+ BranchInstruction if_icmp =
(BranchInstruction)match[0].getInstruction();
+ GOTO goto_ = (GOTO)match[2].getInstruction();
+ return (if_icmp.getTarget() == match[3]) && (goto_.getTarget() ==
match[4]);
}
};
@@ -328,21 +328,21 @@ implements MiniParserTreeConstants, org.
if_icmp.setTarget(ifeq.getTarget());
try {
- il.delete(match[1], match[4]);
+ il.delete(match[1], match[4]);
} catch(TargetLostException e) {
- InstructionHandle[] targets = e.getTargets();
+ InstructionHandle[] targets = e.getTargets();
- System.err.println(targets[0]);
+ System.err.println(targets[0]);
- for(int i=0; i < targets.length; i++) {
- InstructionTargeter[] targeters = targets[i].getTargeters();
+ for(int i=0; i < targets.length; i++) {
+ InstructionTargeter[] targeters = targets[i].getTargeters();
- for(int j=0; j < targeters.length; j++) {
+ for(int j=0; j < targeters.length; j++) {
if((targets[i] != match[4]) || (targeters[j] != match[2])) {
System.err.println("Ooops: " + e);
}
}
- }
+ }
}
}
}
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTIdent.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTIdent.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTIdent.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTIdent.java Thu Jun 16 12:50:55 2011
@@ -74,7 +74,7 @@ public class ASTIdent extends ASTExpr im
MiniC.addError(line, column, "Undeclared identifier " + name);
} else if(entry instanceof Function) {
MiniC.addError(line, column,
- "Function " + name + " used as an identifier.");
+ "Function " + name + " used as an identifier.");
} else {
reference = (Variable)entry;
}
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTIfExpr.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTIfExpr.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTIfExpr.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTIfExpr.java Thu Jun 16 12:50:55 2011
@@ -60,7 +60,7 @@ public class ASTIfExpr extends ASTExpr i
else_expr = (ASTExpr)children[2];
} else {
MiniC.addError(if_expr.getLine(), if_expr.getColumn(),
- "IF expression has no ELSE branch");
+ "IF expression has no ELSE branch");
}
children=null; // Throw away
@@ -93,16 +93,16 @@ public class ASTIfExpr extends ASTExpr i
if((if_type=if_expr.eval(T_BOOLEAN)) != T_BOOLEAN) {
MiniC.addError(if_expr.getLine(), if_expr.getColumn(),
- "IF expression is not of type boolean, but " +
- TYPE_NAMES[if_type] + ".");
+ "IF expression is not of type boolean, but " +
+ TYPE_NAMES[if_type] + ".");
}
then_type=then_expr.eval(expected);
if((expected != T_UNKNOWN) && (then_type != expected)) {
MiniC.addError(then_expr.getLine(), then_expr.getColumn(),
- "THEN expression is not of expected type " +
- TYPE_NAMES[expected] + " but " + TYPE_NAMES[then_type] +
".");
+ "THEN expression is not of expected type " +
+ TYPE_NAMES[expected] + " but " + TYPE_NAMES[then_type] +
".");
}
if(else_expr != null) {
@@ -110,11 +110,11 @@ public class ASTIfExpr extends ASTExpr i
if((expected != T_UNKNOWN) && (else_type != expected)) {
MiniC.addError(else_expr.getLine(), else_expr.getColumn(),
- "ELSE expression is not of expected type " +
- TYPE_NAMES[expected] + " but " + TYPE_NAMES[else_type] +
".");
+ "ELSE expression is not of expected type " +
+ TYPE_NAMES[expected] + " but " + TYPE_NAMES[else_type]
+ ".");
} else if(then_type == T_UNKNOWN) {
- then_type = else_type;
- then_expr.setType(else_type);
+ then_type = else_type;
+ then_expr.setType(else_type);
}
}
else {
@@ -124,8 +124,8 @@ public class ASTIfExpr extends ASTExpr i
if(then_type != else_type) {
MiniC.addError(line, column,
- "Type mismatch in THEN-ELSE: " +
- TYPE_NAMES[then_type] + " vs. " + TYPE_NAMES[else_type] +
".");
+ "Type mismatch in THEN-ELSE: " +
+ TYPE_NAMES[then_type] + " vs. " + TYPE_NAMES[else_type] +
".");
}
type = then_type;
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTLetExpr.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTLetExpr.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTLetExpr.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTLetExpr.java Thu Jun 16 12:50:55
2011
@@ -58,7 +58,7 @@ public class ASTLetExpr extends ASTExpr
*/
public void closeNode() {
int i, len_2 = children.length / 2; /* length must be a multiple of
- * two (ident = expr) + 1 (body expr) */
+ * two (ident = expr) + 1 (body expr)
*/
idents = new ASTIdent[len_2];
exprs = new ASTExpr[len_2];
@@ -91,7 +91,7 @@ public class ASTLetExpr extends ASTExpr
if(entry != null) {
MiniC.addError(id.getLine(), id.getColumn(),
- "Redeclaration of " + entry + ".");
+ "Redeclaration of " + entry + ".");
} else {
env.put(new Variable(id));
}
@@ -135,7 +135,7 @@ public class ASTLetExpr extends ASTExpr
exprs[i].code(buf);
buf.append(" " + TYPE_NAMES[t] + " " + ident + " = " +
- ASTFunDecl.pop() + ";\n");
+ ASTFunDecl.pop() + ";\n");
}
body.code(buf);
Modified: jakarta/bcel/trunk/src/examples/Mini/ASTProgram.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/ASTProgram.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/ASTProgram.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/ASTProgram.java Thu Jun 16 12:50:55
2011
@@ -118,28 +118,28 @@ implements MiniParserConstants, MiniPars
if(fun_decls != null) {
// Put function names into hash table aka. environment
for(int i=0; i < fun_decls.length; i++) {
- f = fun_decls[i];
- name = f.getName();
- fname = name.getName();
- fun = env.get(fname); // Lookup in env
-
- if(fun != null) {
+ f = fun_decls[i];
+ name = f.getName();
+ fname = name.getName();
+ fun = env.get(fname); // Lookup in env
+
+ if(fun != null) {
MiniC.addError(f.getLine(), f.getColumn(),
- "Redeclaration of " + fun + ".");
+ "Redeclaration of " + fun + ".");
} else {
env.put(new Function(name, null)); // `args' will be set by
FunDecl.traverse()
}
-
+
}
// Go for it
for(int i=0; i < fun_decls.length; i++) {
- fun_decls[i] = fun_decls[i].traverse((Environment)env.clone());
-
- // Look for `main' routine
- fname = fun_decls[i].getName().getName();
- if(fname.equals("main")) {
+ fun_decls[i] = fun_decls[i].traverse((Environment)env.clone());
+
+ // Look for `main' routine
+ fname = fun_decls[i].getName().getName();
+ if(fname.equals("main")) {
main = (Function)env.get(fname);
}
}
@@ -148,7 +148,7 @@ implements MiniParserConstants, MiniPars
MiniC.addError(0, 0, "You didn't declare a `main' function.");
} else if(main.getNoArgs() != 0) {
MiniC.addError(main.getLine(), main.getColumn(),
- "Main function has too many arguments declared.");
+ "Main function has too many arguments declared.");
}
}
@@ -165,12 +165,12 @@ implements MiniParserConstants, MiniPars
fun_decls[i].eval(pass);
if(pass == 3) { // Final check for unresolved types
- ASTIdent name = fun_decls[i].getName();
+ ASTIdent name = fun_decls[i].getName();
- if(name.getType() == T_UNKNOWN) {
+ if(name.getType() == T_UNKNOWN) {
MiniC.addError(name.getColumn(), name.getLine(),
- "Type of function " + name.getName() +
- " can not be determined (infinite recursion?).");
+ "Type of function " + name.getName() +
+ " can not be determined (infinite recursion?).");
}
}
}
@@ -186,14 +186,14 @@ implements MiniParserConstants, MiniPars
out.println("public final class " + name + " {");
out.println(" private static BufferedReader _in = new BufferedReader" +
- "(new InputStreamReader(System.in));\n");
+ "(new InputStreamReader(System.in));\n");
out.println(" private static final int _readInt() throws IOException {\n"
+
- " System.out.print(\"Please enter a number> \");\n" +
- " return Integer.parseInt(_in.readLine());\n }\n");
+ " System.out.print(\"Please enter a number> \");\n" +
+ " return Integer.parseInt(_in.readLine());\n }\n");
out.println(" private static final int _writeInt(int n) {\n" +
- " System.out.println(\"Result: \" + n);\n return 0;\n
}\n");
+ " System.out.println(\"Result: \" + n);\n return 0;\n
}\n");
for(int i=0; i < fun_decls.length; i++) {
fun_decls[i].code(out);
@@ -209,9 +209,9 @@ implements MiniParserConstants, MiniPars
/* private static BufferedReader _in;
*/
class_gen.addField(new Field(ACC_PRIVATE | ACC_STATIC,
- cp.addUtf8("_in"),
- cp.addUtf8("Ljava/io/BufferedReader;"),
- null, cp.getConstantPool()));
+ cp.addUtf8("_in"),
+ cp.addUtf8("Ljava/io/BufferedReader;"),
+ null, cp.getConstantPool()));
MethodGen method;
InstructionList il = new InstructionList();
@@ -222,27 +222,27 @@ implements MiniParserConstants, MiniPars
int _in = cp.addFieldref(class_name, "_in",
"Ljava/io/BufferedReader;");
int out = cp.addFieldref("java.lang.System", "out",
- "Ljava/io/PrintStream;");
+ "Ljava/io/PrintStream;");
il.append(new GETSTATIC(out));
il.append(new PUSH(cp, "Please enter a number> "));
il.append(new INVOKEVIRTUAL(cp.addMethodref("java.io.PrintStream",
- "print",
- "(Ljava/lang/String;)V")));
+ "print",
+ "(Ljava/lang/String;)V")));
il.append(new GETSTATIC(_in));
il.append(new INVOKEVIRTUAL(cp.addMethodref("java.io.BufferedReader",
- "readLine",
- "()Ljava/lang/String;")));
+ "readLine",
+ "()Ljava/lang/String;")));
il.append(new INVOKESTATIC(cp.addMethodref("java.lang.Integer",
- "parseInt",
- "(Ljava/lang/String;)I")));
+ "parseInt",
+ "(Ljava/lang/String;)I")));
il.append(InstructionConstants.IRETURN);
/* private static final int _readInt() throws IOException
*/
method = new MethodGen(ACC_STATIC | ACC_PRIVATE | ACC_FINAL,
- Type.INT, Type.NO_ARGS, null,
- "_readInt", class_name, il, cp);
+ Type.INT, Type.NO_ARGS, null,
+ "_readInt", class_name, il, cp);
method.addException("java.io.IOException");
@@ -259,27 +259,27 @@ implements MiniParserConstants, MiniPars
il.append(InstructionConstants.DUP);
il.append(new PUSH(cp, "Result: "));
il.append(new INVOKESPECIAL(cp.addMethodref("java.lang.StringBuffer",
- "<init>",
- "(Ljava/lang/String;)V")));
+ "<init>",
+ "(Ljava/lang/String;)V")));
il.append(new ILOAD(0));
il.append(new INVOKEVIRTUAL(cp.addMethodref("java.lang.StringBuffer",
- "append",
-
"(I)Ljava/lang/StringBuffer;")));
+ "append",
+
"(I)Ljava/lang/StringBuffer;")));
il.append(new INVOKEVIRTUAL(cp.addMethodref("java.lang.StringBuffer",
- "toString",
- "()Ljava/lang/String;")));
+ "toString",
+ "()Ljava/lang/String;")));
il.append(new INVOKEVIRTUAL(cp.addMethodref("java.io.PrintStream",
- "println",
- "(Ljava/lang/String;)V")));
+ "println",
+ "(Ljava/lang/String;)V")));
il.append(new PUSH(cp, 0));
il.append(InstructionConstants.IRETURN); // Reuse objects, if possible
method = new MethodGen(ACC_STATIC | ACC_PRIVATE | ACC_FINAL,
- Type.INT, args, argv,
- "_writeInt", class_name, il, cp);
+ Type.INT, args, argv,
+ "_writeInt", class_name, il, cp);
method.setMaxStack(4);
class_gen.addMethod(method.getMethod());
@@ -291,11 +291,11 @@ implements MiniParserConstants, MiniPars
il = new InstructionList();
il.append(new ALOAD(0)); // Push `this'
il.append(new INVOKESPECIAL(cp.addMethodref("java.lang.Object",
- "<init>", "()V")));
+ "<init>", "()V")));
il.append(new RETURN());
method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, null,
- "<init>", class_name, il, cp);
+ "<init>", class_name, il, cp);
method.setMaxStack(1);
class_gen.addMethod(method.getMethod());
@@ -309,16 +309,16 @@ implements MiniParserConstants, MiniPars
il.append(new NEW(cp.addClass("java.io.InputStreamReader")));
il.append(InstructionConstants.DUP);
il.append(new GETSTATIC(cp.addFieldref("java.lang.System", "in",
- "Ljava/io/InputStream;")));
+ "Ljava/io/InputStream;")));
il.append(new INVOKESPECIAL(cp.addMethodref("java.io.InputStreamReader",
- "<init>",
"(Ljava/io/InputStream;)V")));
+ "<init>",
"(Ljava/io/InputStream;)V")));
il.append(new INVOKESPECIAL(cp.addMethodref("java.io.BufferedReader",
- "<init>",
"(Ljava/io/Reader;)V")));
+ "<init>",
"(Ljava/io/Reader;)V")));
il.append(new PUTSTATIC(_in));
il.append(InstructionConstants.RETURN); // Reuse instruction constants
method = new MethodGen(ACC_STATIC, Type.VOID, Type.NO_ARGS, null,
- "<clinit>", class_name, il, cp);
+ "<clinit>", class_name, il, cp);
method.setMaxStack(5);
class_gen.addMethod(method.getMethod());
Modified: jakarta/bcel/trunk/src/examples/Mini/Environment.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/Environment.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/Environment.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/Environment.java Thu Jun 16 12:50:55
2011
@@ -76,12 +76,12 @@ public class Environment implements Clon
table[hash] = v = new Vector(SLOTS);
} else {
try {
- int index = lookup(v, key);
+ int index = lookup(v, key);
- if(index >= 0) {
- v.setElementAt(obj, index); // Overwrite
- return;
- }
+ if(index >= 0) {
+ v.setElementAt(obj, index); // Overwrite
+ return;
+ }
} catch(ArrayIndexOutOfBoundsException e) {}
}
@@ -132,8 +132,8 @@ public class Environment implements Clon
int index = lookup(v, key);
if(index >= 0) {
- elements--; // Count
- v.removeElementAt(index);
+ elements--; // Count
+ v.removeElementAt(index);
}
} catch(ArrayIndexOutOfBoundsException e) {}
}
@@ -159,16 +159,16 @@ public class Environment implements Clon
for(int i=0; i < size; i++) {
if(table[i] != null) {
- copy[i] = (Vector)table[i].clone(); // Copies references
+ copy[i] = (Vector)table[i].clone(); // Copies references
- /*
- int len = table[i].size();
+ /*
+ int len = table[i].size();
- copy[i] = new Vector(len);
- try {
- for(int j=0; j < len; j++)
- copy[i].addElement(table[i].elementAt(j));
- } catch(ArrayIndexOutOfBoundsException e) {}*/
+ copy[i] = new Vector(len);
+ try {
+ for(int j=0; j < len; j++)
+ copy[i].addElement(table[i].elementAt(j));
+ } catch(ArrayIndexOutOfBoundsException e) {}*/
}
}
@@ -194,12 +194,12 @@ public class Environment implements Clon
for(int i=0; i < size; i++) {
if((v = table[i]) != null) {
- int len = v.size();
- try {
- for(int j=0; j < len; j++) {
+ int len = v.size();
+ try {
+ for(int j=0; j < len; j++) {
entries[k++] = (EnvEntry)v.elementAt(j);
}
- } catch(ArrayIndexOutOfBoundsException e) {}
+ } catch(ArrayIndexOutOfBoundsException e) {}
}
}
Modified: jakarta/bcel/trunk/src/examples/Mini/JJTMiniParserState.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/JJTMiniParserState.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/JJTMiniParserState.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/JJTMiniParserState.java Thu Jun 16
12:50:55 2011
@@ -23,8 +23,8 @@ class JJTMiniParserState {
private java.util.Stack nodes;
private java.util.Stack marks;
- private int sp; // number of nodes on stack
- private int mk; // current mark
+ private int sp; // number of nodes on stack
+ private int mk; // current mark
private boolean node_created;
JJTMiniParserState() {
@@ -125,9 +125,9 @@ class JJTMiniParserState {
int a = nodeArity();
mk = ((Integer)marks.pop()).intValue();
while (a-- > 0) {
- Node c = popNode();
- c.jjtSetParent(n);
- n.jjtAddChild(c, a);
+ Node c = popNode();
+ c.jjtSetParent(n);
+ n.jjtAddChild(c, a);
}
n.jjtClose();
pushNode(n);
Modified: jakarta/bcel/trunk/src/examples/Mini/MiniC.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/MiniC.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/MiniC.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/MiniC.java Thu Jun 16 12:50:55 2011
@@ -29,7 +29,7 @@ public class MiniC implements org.apache
private static Vector warnings = null;
private static String file = null;
private static int pass = 0;
-
+
public static void main(String[] argv) {
String[] file_name = new String[argv.length];
int files=0;
@@ -41,66 +41,66 @@ public class MiniC implements org.apache
/* Parse command line arguments.
*/
for(int i=0; i < argv.length; i++) {
- if(argv[i].charAt(0) == '-') { // command line switch
- if(argv[i].equals("-java")) {
+ if(argv[i].charAt(0) == '-') { // command line switch
+ if(argv[i].equals("-java")) {
byte_code=false;
} else if(argv[i].equals("-bytecode")) {
byte_code=true;
} else {
throw new Exception("Unknown option: " + argv[i]);
}
- }
- else { // add file name to list
- file_name[files++] = argv[i];
- }
+ }
+ else { // add file name to list
+ file_name[files++] = argv[i];
+ }
}
-
+
if(files == 0) {
System.err.println("Nothing to compile.");
}
for(int j=0; j < files; j++) {
- errors = new Vector();
- warnings = new Vector();
- pass = 0;
+ errors = new Vector();
+ warnings = new Vector();
+ pass = 0;
- if(j == 0) {
+ if(j == 0) {
parser = new MiniParser(new java.io.FileInputStream(file_name[0]));
} else {
parser.ReInit(new java.io.FileInputStream(file_name[j]));
}
- int index = file_name[j].lastIndexOf('.');
- if(index > 0) {
+ int index = file_name[j].lastIndexOf('.');
+ if(index > 0) {
base_name = file_name[j].substring(0, index);
} else {
base_name = file_name[j];
}
- if((index = base_name.lastIndexOf(File.separatorChar)) > 0) {
+ if((index = base_name.lastIndexOf(File.separatorChar)) > 0) {
base_name = base_name.substring(index + 1);
}
- file = file_name[j];
+ file = file_name[j];
- System.out.println("Parsing ...");
+ System.out.println("Parsing ...");
parser.Program();
ASTProgram program = (ASTProgram)parser.jjtree.rootNode();
- System.out.println("Pass 1: Optimizing parse tree ...");
+ System.out.println("Pass 1: Optimizing parse tree ...");
pass = 1;
program = program.traverse();
// program.dump(">");
- if(errors.size() == 0) {
- System.out.println("Pass 2: Type checking (I) ...");
- program.eval(pass=2);
- }
-
- if(errors.size() == 0) {
- System.out.println("Pass 3: Type checking (II) ...");
- program.eval(pass=3);
- }
+ if(errors.size() == 0) {
+ System.out.println("Pass 2: Type checking (I) ...");
+ program.eval(pass=2);
+ }
+
+ if(errors.size() == 0) {
+ System.out.println("Pass 3: Type checking (II) ...");
+ program.eval(pass=3);
+ }
for(int i=0; i < errors.size(); i++) {
System.out.println(errors.elementAt(i));
@@ -110,41 +110,41 @@ public class MiniC implements org.apache
System.out.println(warnings.elementAt(i));
}
- if(errors.size() == 0) {
- if(byte_code) {
- System.out.println("Pass 5: Generating byte code ...");
- ClassGen class_gen = new ClassGen(base_name, "java.lang.Object",
- file_name[j],
- ACC_PUBLIC | ACC_FINAL |
- ACC_SUPER, null);
- ConstantPoolGen cp = class_gen.getConstantPool();
-
- program.byte_code(class_gen, cp);
- JavaClass clazz = class_gen.getJavaClass();
- clazz.dump(base_name + ".class");
- }
- else {
- System.out.println("Pass 5: Generating Java code ...");
- PrintWriter out = new PrintWriter(new FileOutputStream(base_name +
".java"));
- program.code(out, base_name);
- out.close();
-
- System.out.println("Pass 6: Compiling Java code ...");
-
- String[] args = { "javac", base_name + ".java" };
- //sun.tools.javac.Main compiler = new
sun.tools.javac.Main(System.err, "javac");
- try {
- Process p = Runtime.getRuntime().exec(args);
- p.waitFor();
- } catch(Exception e) {System.out.println(e); }
-
- //compiler.compile(args);
- }
- }
+ if(errors.size() == 0) {
+ if(byte_code) {
+ System.out.println("Pass 5: Generating byte code ...");
+ ClassGen class_gen = new ClassGen(base_name, "java.lang.Object",
+ file_name[j],
+ ACC_PUBLIC | ACC_FINAL |
+ ACC_SUPER, null);
+ ConstantPoolGen cp = class_gen.getConstantPool();
+
+ program.byte_code(class_gen, cp);
+ JavaClass clazz = class_gen.getJavaClass();
+ clazz.dump(base_name + ".class");
+ }
+ else {
+ System.out.println("Pass 5: Generating Java code ...");
+ PrintWriter out = new PrintWriter(new FileOutputStream(base_name +
".java"));
+ program.code(out, base_name);
+ out.close();
+
+ System.out.println("Pass 6: Compiling Java code ...");
+
+ String[] args = { "javac", base_name + ".java" };
+ //sun.tools.javac.Main compiler = new
sun.tools.javac.Main(System.err, "javac");
+ try {
+ Process p = Runtime.getRuntime().exec(args);
+ p.waitFor();
+ } catch(Exception e) {System.out.println(e); }
+
+ //compiler.compile(args);
+ }
+ }
- if((errors.size() > 0) || (warnings.size() > 0)) {
+ if((errors.size() > 0) || (warnings.size() > 0)) {
System.out.println(errors.size() + " errors and " + warnings.size() +
- " warnings.");
+ " warnings.");
}
}
} catch(Exception e) { e.printStackTrace(); }
@@ -154,13 +154,13 @@ public class MiniC implements org.apache
final static void addError(int line, int column, String err) {
if(pass != 2) {
errors.addElement(file + ":" + fillup(line, 3) + "," + fillup(column,
2) +
- ": " + err);
+ ": " + err);
}
}
final static void addWarning(int line, int column, String err) {
warnings.addElement("Warning: " + file + ":" + fillup(line, 3) + "," +
- fillup(column, 3) + ": " + err);
+ fillup(column, 3) + ": " + err);
}
final static String fillup(int n, int len) {
Modified: jakarta/bcel/trunk/src/examples/Mini/SimpleNode.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/examples/Mini/SimpleNode.java?rev=1136411&r1=1136410&r2=1136411&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/examples/Mini/SimpleNode.java (original)
+++ jakarta/bcel/trunk/src/examples/Mini/SimpleNode.java Thu Jun 16 12:50:55
2011
@@ -87,10 +87,10 @@ public abstract class SimpleNode impleme
System.out.println(toString(prefix));
if (children != null) {
for (int i = 0; i < children.length; ++i) {
- SimpleNode n = (SimpleNode)children[i];
- if (n != null) {
- n.dump(prefix + " ");
- }
+ SimpleNode n = (SimpleNode)children[i];
+ if (n != null) {
+ n.dump(prefix + " ");
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]