001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 1997-1999 Raja Vallee-Rai
003: * Copyright (C) 2004 Ondrej Lhotak
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the
017: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
018: * Boston, MA 02111-1307, USA.
019: */
020:
021: /*
022: * Modified by the Sable Research Group and others 1997-1999.
023: * See the 'credits' file distributed with Soot for the complete list of
024: * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
025: */
026:
027: package soot.jimple;
028:
029: import soot.tagkit.*;
030: import soot.*;
031: import soot.baf.*;
032: import soot.util.*;
033: import java.util.*;
034:
035: public class StaticFieldRef implements FieldRef, ConvertToBaf {
036:
037: protected SootFieldRef fieldRef;
038:
039: protected StaticFieldRef(SootFieldRef fieldRef) {
040: if (!fieldRef.isStatic())
041: throw new RuntimeException("wrong static-ness");
042: this .fieldRef = fieldRef;
043: }
044:
045: public Object clone() {
046: return new StaticFieldRef(fieldRef);
047: }
048:
049: public String toString() {
050: return fieldRef.getSignature();
051: }
052:
053: public void toString(UnitPrinter up) {
054: up.fieldRef(fieldRef);
055: }
056:
057: public SootFieldRef getFieldRef() {
058: return fieldRef;
059: }
060:
061: public void setFieldRef(SootFieldRef fieldRef) {
062: this .fieldRef = fieldRef;
063: }
064:
065: public SootField getField() {
066: return fieldRef.resolve();
067: }
068:
069: public List getUseBoxes() {
070: return AbstractUnit.emptyList;
071: }
072:
073: public Type getType() {
074: return fieldRef.type();
075: }
076:
077: public void apply(Switch sw) {
078: ((RefSwitch) sw).caseStaticFieldRef(this );
079: }
080:
081: public boolean equivTo(Object o) {
082: if (o instanceof StaticFieldRef)
083: return ((StaticFieldRef) o).getField().equals(getField());
084:
085: return false;
086: }
087:
088: public int equivHashCode() {
089: return getField().equivHashCode();
090: }
091:
092: public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
093: Unit u = Baf.v().newStaticGetInst(fieldRef);
094: out.add(u);
095:
096: Iterator it = context.getCurrentUnit().getTags().iterator();
097: while (it.hasNext()) {
098: u.addTag((Tag) it.next());
099: }
100: }
101: }
|