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 /**
024 * We represent [C.]this.
025 *
026 * <p> classPrefix holds C if present, and null otherwise.
027 *
028 * @note classPrefix will hold a <em>**TypeSig**</em> instead of a
029 * TypeName if we have been inferred. (The inferred field specifies
030 * whether or not we have been inferred.)
031 */
032
033 public class ThisExpr extends Expr
034 {
035 public Type classPrefix;
036
037
038 //@ invariant loc != javafe.util.Location.NULL;
039 public int loc;
040
041
042 //* Were we inferred by the disambiguation code?
043 public boolean inferred = false;
044
045 /*@ public represents startLoc <- (classPrefix != null && classPrefix instanceof TypeName)
046 @ ? classPrefix.getStartLoc() : loc;
047 @*/
048 public /*@ pure @*/ int getStartLoc() {
049 if (classPrefix != null && classPrefix instanceof TypeName)
050 return classPrefix.getStartLoc();
051 return loc;
052 }
053
054 //@ also public normal_behavior
055 //@ ensures \result == Location.inc(loc, 3);
056 public /*@ pure @*/ int getEndLoc() { return Location.inc(loc, 3); }
057
058
059 // Generated boilerplate constructors:
060
061 //@ ensures this.classPrefix == classPrefix;
062 //@ ensures this.loc == loc;
063 protected ThisExpr(Type classPrefix, int loc) {
064 super();
065 this.classPrefix = classPrefix;
066 this.loc = loc;
067 }
068
069 // Generated boilerplate methods:
070
071 public final int childCount() {
072 return 1;
073 }
074
075 public final Object childAt(int index) {
076 /*throws IndexOutOfBoundsException*/
077 if (index < 0)
078 throw new IndexOutOfBoundsException("AST child index " + index);
079 int indexPre = index;
080
081 int sz;
082
083 if (index == 0) return this.classPrefix;
084 else index--;
085
086 throw new IndexOutOfBoundsException("AST child index " + indexPre);
087 } //@ nowarn Exception;
088
089 public final /*@non_null*/String toString() {
090 return "[ThisExpr"
091 + " classPrefix = " + this.classPrefix
092 + " loc = " + this.loc
093 + "]";
094 }
095
096 public final int getTag() {
097 return TagConstants.THISEXPR;
098 }
099
100 public final void accept(Visitor v) { v.visitThisExpr(this); }
101
102 public final Object accept(VisitorArgResult v, Object o) {return v.visitThisExpr(this, o); }
103
104 public void check() {
105 super.check();
106 if (this.classPrefix != null)
107 this.classPrefix.check();
108 }
109
110 //@ requires loc != javafe.util.Location.NULL;
111 //@ ensures \result != null;
112 public static ThisExpr make(Type classPrefix, int loc) {
113 ThisExpr result = new ThisExpr(classPrefix, loc);
114 return result;
115 }
116 }