001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.tree;
022:
023: import EDU.purdue.cs.bloat.editor.*;
024:
025: /**
026: * LocalExpr represents an expression that accesses a variable in a method's
027: * local variable table. Note that during register allocation the index becomes
028: * the color that the LocalExpr (variable) is assigned.
029: *
030: * @see Tree#newStackLocal
031: * @see Tree#newLocal(Type)
032: */
033: public class LocalExpr extends VarExpr implements LeafExpr {
034: boolean fromStack;
035:
036: /**
037: * Constructor.
038: *
039: * @param index
040: * Index into the local variable table for this expression.
041: * @param fromStack
042: * Is the local allocated on the stack?
043: * @param type
044: * The type of this expression
045: */
046: public LocalExpr(final int index, final boolean fromStack,
047: final Type type) {
048: super (index, type);
049: this .fromStack = fromStack;
050: }
051:
052: /**
053: * Constructor. LocalExpr is not allocated on the stack.
054: *
055: * @param index
056: * Index into the local variable table for this expression.
057: * @param type
058: * The type of this expression.
059: */
060: public LocalExpr(final int index, final Type type) {
061: this (index, false, type);
062: }
063:
064: public boolean fromStack() {
065: return fromStack;
066: }
067:
068: /**
069: * Returns true if the type of this expression is a return address.
070: */
071: public boolean isReturnAddress() {
072: return type().equals(Type.ADDRESS);
073: }
074:
075: public void visitForceChildren(final TreeVisitor visitor) {
076: }
077:
078: public void visit(final TreeVisitor visitor) {
079: visitor.visitLocalExpr(this );
080: }
081:
082: /**
083: * @param other
084: * The other expression to compare against.
085: */
086: public boolean equalsExpr(final Expr other) {
087: return (other instanceof LocalExpr)
088: && ((LocalExpr) other).type.simple().equals(
089: type.simple())
090: && (((LocalExpr) other).fromStack == fromStack)
091: && (((LocalExpr) other).index == index);
092: }
093:
094: public int exprHashCode() {
095: return 13 + (fromStack ? 0 : 1) + index
096: + type.simple().hashCode();
097: }
098:
099: public Object clone() {
100: return copyInto(new LocalExpr(index, fromStack, type));
101: }
102:
103: }
|