001 /* Copyright 2000, 2001, Compaq Computer Corporation */ 002 003 /* IF THIS IS A JAVA FILE, DO NOT EDIT IT! 004 005 Most Java files in this directory which are part of the Javafe AST 006 are automatically generated using the astgen comment (see 007 ESCTools/Javafe/astgen) from the input file 'hierarchy.h'. If you 008 wish to modify AST classes or introduce new ones, modify 009 'hierarchy.j.' 010 */ 011 012 package javafe.ast; 013 014 import javafe.util.Assert; 015 import javafe.util.Location; 016 import javafe.util.ErrorSet; 017 018 // Convention: unless otherwise noted, integer fields named "loc" refer 019 // to the location of the first character of the syntactic unit 020 021 022 public class SimpleName extends Name 023 { 024 public /*@ non_null @*/ Identifier id; 025 026 027 //@ invariant loc != javafe.util.Location.NULL; 028 public int loc; 029 030 031 //@ invariant length == 1; 032 033 /** 034 * @return a String representation of <code>this</code> in Java's 035 * syntax. 036 */ 037 public String printName() { 038 return id.toString(); 039 } 040 041 public boolean equals(Object other) { 042 if (other instanceof SimpleName) 043 return id == ((SimpleName)other).id; 044 else 045 return false; 046 } 047 048 public Name prefix(int len) { 049 Assert.precondition(len == 1); 050 return make(id, loc); 051 } 052 053 /** Return a hash code for <code>this</code> such that two 054 <code>Name</code>s that are <code>equals</code> have the same hash 055 code. 056 */ 057 public int hashCode() { 058 return id.hashCode(); 059 } 060 061 /** 062 * @return the first <code>len</code> identifiers in 063 * <code>this</code> in an array. Requires that <code>len</code> be 064 * between 0 and length of <code>this</code> inclusive. 065 */ 066 public String[] toStrings(int len) { 067 Assert.precondition(len == 0 || len == 1); 068 if (len == 0) return emptyStringArray; 069 String[] result = { id.toString() }; 070 return result; 071 } 072 073 /** Return the number of identifiers in <code>this</code>. */ 074 public int size() { return 1; } 075 076 /** Return the ith identifier of <code>this</code>. */ 077 public Identifier identifierAt(int i) { 078 if (i != 0) throw new ArrayIndexOutOfBoundsException(); 079 return id; 080 } 081 082 /** Return the location of the ith identifier of <code>this</code>. */ 083 public int locIdAt(int i) { 084 if (i != 0) throw new ArrayIndexOutOfBoundsException(); 085 return loc; 086 } 087 088 /** Return the location of the dot after the ith identifier of 089 <code>this</code>. 090 */ 091 public int locDotAfter(int i) { 092 throw new ArrayIndexOutOfBoundsException(); 093 } 094 095 public int getStartLoc() { return loc; } 096 097 098 // Generated boilerplate constructors: 099 100 /** 101 * Construct a raw SimpleName whose class invariant(s) have not 102 * yet been established. It is the caller's job to 103 * initialize the returned node's fields so that any 104 * class invariants hold. 105 */ 106 //@ requires I_will_establish_invariants_afterwards; 107 protected SimpleName() {} //@ nowarn Invariant,NonNullInit; 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 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 //@ set I_will_establish_invariants_afterwards = true; 154 SimpleName result = new SimpleName(); 155 result.id = id; 156 result.loc = loc; 157 return result; 158 } 159 }