001 // -*- mode: java -*-
002 /* Copyright 2000, 2001, Compaq Computer Corporation */
003
004 /* IF THIS IS A JAVA FILE, DO NOT EDIT IT!
005
006 Most Java files in this directory which are part of the Javafe AST
007 are automatically generated using the astgen comment (see
008 ESCTools/Javafe/astgen) from the input file 'hierarchy.h'. If you
009 wish to modify AST classes or introduce new ones, modify
010 'hierarchy.j.'
011 */
012
013 package javafe.ast;
014
015 import javafe.util.Assert;
016 import javafe.util.Location;
017 import javafe.util.ErrorSet;
018
019 // Convention: unless otherwise noted, integer fields named "loc" refer
020 // to the location of the first character of the syntactic unit
021
022
023 public class SimpleName extends Name
024 {
025 public /*@ non_null @*/ Identifier id;
026
027
028 //@ invariant loc != javafe.util.Location.NULL;
029 public int loc;
030
031
032 //@ invariant length == 1;
033
034 /**
035 * @return a String representation of <code>this</code> in Java's
036 * syntax.
037 */
038 public /*@non_null*/ String printName() {
039 return id.toString();
040 }
041
042 public boolean equals(Object other) {
043 if (other instanceof SimpleName)
044 return id == ((SimpleName)other).id;
045 else
046 return false;
047 }
048
049 public /*@non_null*/ Name prefix(int len) {
050 Assert.precondition(len == 1);
051 return make(id, loc);
052 }
053
054 /** Return a hash code for <code>this</code> such that two
055 <code>Name</code>s that are <code>equals</code> have the same hash
056 code.
057 */
058 public int hashCode() {
059 return id.hashCode();
060 }
061
062 /**
063 * @return the first <code>len</code> identifiers in
064 * <code>this</code> in an array. Requires that <code>len</code> be
065 * between 0 and length of <code>this</code> inclusive.
066 */
067 public String[] toStrings(int len) {
068 Assert.precondition(len == 0 || len == 1);
069 if (len == 0) return emptyStringArray;
070 String[] result = { id.toString() };
071 return result;
072 }
073
074 /** Return the number of identifiers in <code>this</code>. */
075 public int size() { return 1; }
076
077 /** Return the ith identifier of <code>this</code>. */
078 public /*@non_null*/ Identifier identifierAt(int i) {
079 if (i != 0) throw new ArrayIndexOutOfBoundsException();
080 return id;
081 }
082
083 /** Return the location of the ith identifier of <code>this</code>. */
084 public int locIdAt(int i) {
085 if (i != 0) throw new ArrayIndexOutOfBoundsException();
086 return loc;
087 }
088
089 /** Return the location of the dot after the ith identifier of
090 <code>this</code>.
091 */
092 public int locDotAfter(int i) {
093 throw new ArrayIndexOutOfBoundsException();
094 }
095
096 //@ public represents startLoc <- loc;
097 public /*@ pure @*/ int getStartLoc() { return loc; }
098
099
100 // Generated boilerplate constructors:
101
102 //@ ensures this.id == id;
103 //@ ensures this.loc == loc;
104 protected SimpleName(/*@ non_null @*/ Identifier id, int loc) {
105 super();
106 this.id = id;
107 this.loc = loc;
108 }
109
110 // Generated boilerplate methods:
111
112 public final int childCount() {
113 return 1;
114 }
115
116 public final Object childAt(int index) {
117 /*throws IndexOutOfBoundsException*/
118 if (index < 0)
119 throw new IndexOutOfBoundsException("AST child index " + index);
120 int indexPre = index;
121
122 int sz;
123
124 if (index == 0) return this.id;
125 else index--;
126
127 throw new IndexOutOfBoundsException("AST child index " + indexPre);
128 } //@ nowarn Exception;
129
130 public final /*@non_null*/String toString() {
131 return "[SimpleName"
132 + " id = " + this.id
133 + " loc = " + this.loc
134 + "]";
135 }
136
137 public final int getTag() {
138 return TagConstants.SIMPLENAME;
139 }
140
141 public final void accept(Visitor v) { v.visitSimpleName(this); }
142
143 public final Object accept(VisitorArgResult v, Object o) {return v.visitSimpleName(this, o); }
144
145 public void check() {
146 super.check();
147 if (this.id == null) throw new RuntimeException();
148 }
149
150 //@ requires loc != javafe.util.Location.NULL;
151 //@ ensures \result != null;
152 public static SimpleName make(/*@ non_null @*/ Identifier id, int loc) {
153 SimpleName result = new SimpleName(id, loc);
154 return result;
155 }
156 }