01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2006-2007 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.type;
20:
21: import java.io.IOException;
22:
23: /**
24: * Representation of a symbolic memory location. A variable reference
25: * has neither a base nor an offset.
26: *
27: * @author Robert Grimm
28: * @version $Revision: 1.3 $
29: */
30: public abstract class VariableReference extends Reference {
31:
32: /** The optional name. */
33: private final String name;
34:
35: /**
36: * Create a new anonymous variable reference.
37: *
38: * @param type The declared type.
39: */
40: public VariableReference(Type type) {
41: this (null, type);
42: }
43:
44: /**
45: * Create a new variable reference.
46: *
47: * @param name The declared name.
48: * @param type The declared type.
49: */
50: public VariableReference(String name, Type type) {
51: super (type);
52: this .name = name;
53:
54: // Adjust the type.
55: normalize();
56: }
57:
58: public boolean isVariable() {
59: return true;
60: }
61:
62: /**
63: * Determine whether this variable reference has a name.
64: *
65: * @return <code>true</code> if this variable reference has a name.
66: */
67: public boolean hasName() {
68: return null != name;
69: }
70:
71: /**
72: * Get this static reference's name.
73: *
74: * @return The name.
75: */
76: public String getName() {
77: return name;
78: }
79:
80: public void write(Appendable out) throws IOException {
81: if (null == name) {
82: out.append("<anon>");
83: } else {
84: out.append(name);
85: }
86: }
87:
88: }
|