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 package Mini; 19 import org.apache.bcel.generic.LocalVariableGen; 20 21 /** 22 * Represents a variable declared in a LET expression or a FUN declaration. 23 * 24 * @version $Id$ 25 */ 26 public class Variable implements EnvEntry { 27 private ASTIdent name; // Reference to the original declaration 28 private boolean reserved; // Is a key word? 29 30 private int line, column; // Extracted from name.getToken() 31 private String var_name; // Short for name.getName() 32 private LocalVariableGen local_var; // local var associated with this variable 33 Variable(ASTIdent name)34 public Variable(ASTIdent name) { 35 this(name, false); 36 } 37 Variable(ASTIdent name, boolean reserved)38 public Variable(ASTIdent name, boolean reserved) { 39 this.name = name; 40 this.reserved = reserved; 41 42 var_name = name.getName(); 43 line = name.getLine(); 44 column = name.getColumn(); 45 } 46 47 @Override toString()48 public String toString() { 49 if(!reserved) { 50 return var_name + " declared at line " + line + ", column " + column; 51 } else { 52 return var_name + " <reserved key word>"; 53 } 54 } 55 getName()56 public ASTIdent getName() { return name; } getHashKey()57 public String getHashKey() { return var_name; } getLine()58 public int getLine() { return line; } getColumn()59 public int getColumn() { return column; } getType()60 public int getType() { return name.getType(); } 61 setLocalVariable(LocalVariableGen local_var)62 void setLocalVariable(LocalVariableGen local_var) { 63 this.local_var = local_var; 64 } getLocalVariable()65 LocalVariableGen getLocalVariable() { return local_var; } 66 } 67 68