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 * Represents various kinds of unary expressions.
025 * The tag is one of the constants:
026 * ADD SUB NOT BITNOT INC DEC POSTFIXINC POSTFIXDEC
027 * defined in OperatorTags.
028 */
029
030 public class UnaryExpr extends Expr
031 {
032 /*@ invariant (op == TagConstants.UNARYADD || op == TagConstants.UNARYSUB
033 || op == TagConstants.NOT || op == TagConstants.BITNOT
034 || op == TagConstants.INC || op == TagConstants.DEC
035 || op == TagConstants.POSTFIXINC || op == TagConstants.POSTFIXDEC); */
036 public int op;
037
038
039 public /*@ non_null @*/ Expr expr;
040
041 //@ invariant locOp != javafe.util.Location.NULL;
042 public int locOp;
043
044
045 public final int getTag() { return op; }
046
047 private void postCheck() {
048 boolean goodtag =
049 (op == TagConstants.UNARYADD || op == TagConstants.UNARYSUB
050 || op == TagConstants.NOT || op == TagConstants.BITNOT
051 || op == TagConstants.INC || op == TagConstants.DEC
052 || op == TagConstants.POSTFIXINC || op == TagConstants.POSTFIXDEC);
053 Assert.notFalse(goodtag);
054 }
055 //@ public represents startLoc <- Math.min(expr.getStartLoc(), locOp);
056 public /*@ pure @*/ int getStartLoc() {
057 int le = expr.getStartLoc();
058 return le < locOp ? le : locOp;
059 }
060
061 //@ also public normal_behavior
062 //@ ensures \result == Math.max(expr.getStartLoc(), locOp);
063 public /*@ pure @*/ int getEndLoc() {
064 int le = expr.getEndLoc();
065 return le < locOp ? locOp : le;
066 }
067
068 /*@ requires (op == TagConstants.UNARYADD || op == TagConstants.UNARYSUB
069 || op == TagConstants.NOT || op == TagConstants.BITNOT
070 || op == TagConstants.INC || op == TagConstants.DEC
071 || op == TagConstants.POSTFIXINC || op == TagConstants.POSTFIXDEC); */
072 //
073 //@ requires locOp != javafe.util.Location.NULL;
074 public static /*@non_null*/ UnaryExpr make(int op, /*@ non_null @*/ Expr expr, int locOp) {
075 UnaryExpr result = new UnaryExpr(op, expr, locOp);
076 return result;
077 }
078
079
080 // Generated boilerplate constructors:
081
082 //@ ensures this.op == op;
083 //@ ensures this.expr == expr;
084 //@ ensures this.locOp == locOp;
085 protected UnaryExpr(int op, /*@ non_null @*/ Expr expr, int locOp) {
086 super();
087 this.op = op;
088 this.expr = expr;
089 this.locOp = locOp;
090 }
091
092 // Generated boilerplate methods:
093
094 public final int childCount() {
095 return 1;
096 }
097
098 public final Object childAt(int index) {
099 /*throws IndexOutOfBoundsException*/
100 if (index < 0)
101 throw new IndexOutOfBoundsException("AST child index " + index);
102 int indexPre = index;
103
104 int sz;
105
106 if (index == 0) return this.expr;
107 else index--;
108
109 throw new IndexOutOfBoundsException("AST child index " + indexPre);
110 } //@ nowarn Exception;
111
112 public final /*@non_null*/String toString() {
113 return "[UnaryExpr"
114 + " op = " + this.op
115 + " expr = " + this.expr
116 + " locOp = " + this.locOp
117 + "]";
118 }
119
120 public final void accept(Visitor v) { v.visitUnaryExpr(this); }
121
122 public final Object accept(VisitorArgResult v, Object o) {return v.visitUnaryExpr(this, o); }
123
124 public void check() {
125 super.check();
126 this.expr.check();
127 postCheck();
128 }
129
130 }