01: // Copyright (c) 2005 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.expr;
05:
06: import gnu.mapping.*;
07:
08: /** A common super-type for ReferenceExpa and SetExp.
09: * Contains shared information about the variable that is accessed. */
10:
11: public abstract class AccessExp extends Expression {
12: /** The name of the variable to set - either a String or a Symbol. */
13: Object symbol;
14: /** If non-null, the local Declaration this refers to. */
15: Declaration binding;
16:
17: public String string_name() {
18: return symbol.toString();
19: }
20:
21: public final String getName() {
22: return symbol instanceof Symbol ? ((Symbol) symbol).getName()
23: : symbol.toString();
24: }
25:
26: /** Return a simple name, or null if the name has a non-empty namespace. */
27: public final String getSimpleName() {
28: if (symbol instanceof String)
29: return (String) symbol;
30: Symbol sym;
31: if (symbol instanceof Symbol
32: && (sym = (Symbol) symbol).hasEmptyNamespace())
33: return sym.getLocalName();
34: return null;
35: }
36:
37: public final Object getSymbol() {
38: return symbol;
39: }
40:
41: /** If non-null, the local Declaration this refers to. */
42: public final Declaration getBinding() {
43: return binding;
44: }
45:
46: public final void setBinding(Declaration decl) {
47: binding = decl;
48: }
49:
50: /** If binding has a non-static field and no base, use this instead of base.
51: * This is mainly used for aliases of imported module declarations. */
52: private Declaration context;
53:
54: public final Declaration contextDecl() {
55: return context;
56: }
57:
58: public final void setContextDecl(Declaration decl) {
59: context = decl;
60: }
61: }
|