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 CondExpr extends Expr 023 { 024 public /*@ non_null @*/ Expr test; 025 026 public /*@ non_null @*/ Expr thn; 027 028 public /*@ non_null @*/ Expr els; 029 030 //@ invariant locQuestion != javafe.util.Location.NULL; 031 public int locQuestion; 032 033 //@ invariant locColon != javafe.util.Location.NULL; 034 public int locColon; 035 036 public int getStartLoc() { return test.getStartLoc(); } 037 public int getEndLoc() { 038 int thenL = thn.getEndLoc(); 039 int elseL = els.getEndLoc(); 040 return Math.max(thenL, elseL); 041 } 042 043 044 // Generated boilerplate constructors: 045 046 /** 047 * Construct a raw CondExpr whose class invariant(s) have not 048 * yet been established. It is the caller's job to 049 * initialize the returned node's fields so that any 050 * class invariants hold. 051 */ 052 //@ requires I_will_establish_invariants_afterwards; 053 protected CondExpr() {} //@ nowarn Invariant,NonNullInit; 054 055 056 // Generated boilerplate methods: 057 058 public final int childCount() { 059 return 3; 060 } 061 062 public final Object childAt(int index) { 063 /*throws IndexOutOfBoundsException*/ 064 if (index < 0) 065 throw new IndexOutOfBoundsException("AST child index " + index); 066 int indexPre = index; 067 068 int sz; 069 070 if (index == 0) return this.test; 071 else index--; 072 073 if (index == 0) return this.thn; 074 else index--; 075 076 if (index == 0) return this.els; 077 else index--; 078 079 throw new IndexOutOfBoundsException("AST child index " + indexPre); 080 } //@ nowarn Exception; 081 082 public final String toString() { 083 return "[CondExpr" 084 + " test = " + this.test 085 + " thn = " + this.thn 086 + " els = " + this.els 087 + " locQuestion = " + this.locQuestion 088 + " locColon = " + this.locColon 089 + "]"; 090 } 091 092 public final int getTag() { 093 return TagConstants.CONDEXPR; 094 } 095 096 public final void accept(Visitor v) { v.visitCondExpr(this); } 097 098 public final Object accept(VisitorArgResult v, Object o) {return v.visitCondExpr(this, o); } 099 100 public void check() { 101 super.check(); 102 this.test.check(); 103 this.thn.check(); 104 this.els.check(); 105 } 106 107 //@ requires locQuestion != javafe.util.Location.NULL; 108 //@ requires locColon != javafe.util.Location.NULL; 109 //@ ensures \result != null; 110 public static CondExpr make(/*@ non_null @*/ Expr test, /*@ non_null @*/ Expr thn, /*@ non_null @*/ Expr els, int locQuestion, int locColon) { 111 //@ set I_will_establish_invariants_afterwards = true; 112 CondExpr result = new CondExpr(); 113 result.test = test; 114 result.thn = thn; 115 result.els = els; 116 result.locQuestion = locQuestion; 117 result.locColon = locColon; 118 return result; 119 } 120 }