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 /** 023 * Represents an ExplicitConstructorInvocation. 024 * <p> Only occurs as the first Stmt in a ConstructorDecl. 025 * <p> Name resolution sets the decl field to the callee. 026 */ 027 028 public class ConstructorInvocation extends Stmt 029 { 030 /** 031 * superCall is true implies call is "super(...)", 032 * superCall is false implies call is "this(...)". 033 */ 034 public boolean superCall; 035 036 037 /** 038 * The enclosing instance is the object expression before a super 039 * call ( <enclosingInstance>.super(...) ). This field may be null 040 * if there is no such expression. 041 * 042 * @note If the supertype in question is an inner class, then the 043 * type checker will infer a [<C>.]this expression if no expression 044 * is present and place it in this slot. (See ThisExpr for how to 045 * distinguish inferred this expressions.)<p> 046 */ 047 public Expr enclosingInstance; 048 049 050 //@ invariant enclosingInstance != null && superCall ==> locDot != Location.NULL; 051 public int locDot; 052 053 054 //@ invariant locKeyword != javafe.util.Location.NULL; 055 public int locKeyword; 056 057 //@ invariant locOpenParen != javafe.util.Location.NULL; 058 public int locOpenParen; 059 060 061 public /*@ non_null @*/ ExprVec args; 062 063 064 public ConstructorDecl decl; 065 066 private void postCheck() { 067 if (decl != null) { 068 // Any invariants here...??? 069 } 070 } 071 072 public int getStartLoc() { 073 if (enclosingInstance == null) return locKeyword; 074 else return enclosingInstance.getStartLoc(); 075 } 076 077 public int getEndLoc() { 078 if (args.size()<1) 079 return super.getEndLoc(); 080 081 return args.elementAt(args.size()-1).getEndLoc(); 082 } 083 084 //@ requires enclosingInstance != null && superCall ==> locDot != Location.NULL; 085 // 086 //@ requires locKeyword != javafe.util.Location.NULL; 087 //@ requires locOpenParen != javafe.util.Location.NULL; 088 //@ ensures \result != null; 089 public static ConstructorInvocation make(boolean superCall, 090 Expr enclosingInstance, 091 int locDot, 092 int locKeyword, 093 int locOpenParen, 094 /*@ non_null @*/ ExprVec args) { 095 //@ set I_will_establish_invariants_afterwards = true; 096 ConstructorInvocation result = new ConstructorInvocation(); 097 result.superCall = superCall; 098 result.enclosingInstance = enclosingInstance; 099 result.locDot = locDot; 100 result.locKeyword = locKeyword; 101 result.locOpenParen = locOpenParen; 102 result.args = args; 103 return result; 104 } 105 106 107 // Generated boilerplate constructors: 108 109 /** 110 * Construct a raw ConstructorInvocation whose class invariant(s) have not 111 * yet been established. It is the caller's job to 112 * initialize the returned node's fields so that any 113 * class invariants hold. 114 */ 115 //@ requires I_will_establish_invariants_afterwards; 116 protected ConstructorInvocation() {} //@ nowarn Invariant,NonNullInit; 117 118 119 // Generated boilerplate methods: 120 121 public final int childCount() { 122 int sz = 0; 123 if (this.args != null) sz += this.args.size(); 124 return sz + 1; 125 } 126 127 public final Object childAt(int index) { 128 /*throws IndexOutOfBoundsException*/ 129 if (index < 0) 130 throw new IndexOutOfBoundsException("AST child index " + index); 131 int indexPre = index; 132 133 int sz; 134 135 if (index == 0) return this.enclosingInstance; 136 else index--; 137 138 sz = (this.args == null ? 0 : this.args.size()); 139 if (0 <= index && index < sz) 140 return this.args.elementAt(index); 141 else index -= sz; 142 143 throw new IndexOutOfBoundsException("AST child index " + indexPre); 144 } //@ nowarn Exception; 145 146 public final String toString() { 147 return "[ConstructorInvocation" 148 + " superCall = " + this.superCall 149 + " enclosingInstance = " + this.enclosingInstance 150 + " locDot = " + this.locDot 151 + " locKeyword = " + this.locKeyword 152 + " locOpenParen = " + this.locOpenParen 153 + " args = " + this.args 154 + "]"; 155 } 156 157 public final int getTag() { 158 return TagConstants.CONSTRUCTORINVOCATION; 159 } 160 161 public final void accept(Visitor v) { v.visitConstructorInvocation(this); } 162 163 public final Object accept(VisitorArgResult v, Object o) {return v.visitConstructorInvocation(this, o); } 164 165 public void check() { 166 super.check(); 167 if (this.enclosingInstance != null) 168 this.enclosingInstance.check(); 169 for(int i = 0; i < this.args.size(); i++) 170 this.args.elementAt(i).check(); 171 postCheck(); 172 } 173 174 }