1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 /* Generated By:JJTree: Do not edit this line. ASTInteger.java */ 19 /* JJT: 0.3pre1 */ 20 21 package Mini; 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.InstructionList; 24 import org.apache.bcel.generic.MethodGen; 25 import org.apache.bcel.generic.PUSH; 26 27 /** 28 * 29 * @version $Id$ 30 */ 31 public class ASTInteger extends ASTExpr { 32 private int value; 33 34 // Generated methods ASTInteger(int id)35 ASTInteger(int id) { 36 super(id); 37 } 38 ASTInteger(MiniParser p, int id)39 ASTInteger(MiniParser p, int id) { 40 super(p, id); 41 } 42 jjtCreate(MiniParser p, int id)43 public static Node jjtCreate(MiniParser p, int id) { 44 return new ASTInteger(p, id); 45 } 46 47 // closeNode, dump inherited from Expr 48 49 /** 50 * @return identifier and line/column number of appearance 51 */ 52 @Override toString()53 public String toString() { 54 return super.toString() + " = " + value; 55 } 56 57 /** 58 * Overrides ASTExpr.traverse() 59 */ 60 @Override traverse(Environment env)61 public ASTExpr traverse(Environment env) { 62 this.env = env; 63 return this; // Nothing to reduce/traverse here 64 } 65 66 /** 67 * Second pass 68 * Overrides AstExpr.eval() 69 * @return type of expression 70 */ 71 @Override eval(int expected)72 public int eval(int expected) { 73 is_simple = true; // (Very) simple expression, always true 74 75 return type = T_INT; 76 } 77 78 /** 79 * Fourth pass, produce Java code. 80 */ 81 @Override code(StringBuffer buf)82 public void code(StringBuffer buf) { 83 ASTFunDecl.push(buf, "" + value); 84 } 85 86 /** 87 * Fifth pass, produce Java byte code. 88 */ 89 @Override byte_code(InstructionList il, MethodGen method, ConstantPoolGen cp)90 public void byte_code(InstructionList il, MethodGen method, ConstantPoolGen cp) { 91 il.append(new PUSH(cp, value)); ASTFunDecl.push(); 92 } 93 setValue(int value)94 void setValue(int value) { this.value = value; } getValue()95 int getValue() { return value; } 96 } 97