001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */
002    package org.extendj.ast;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.Set;
007    import java.util.Collections;
008    import java.util.Collection;
009    import java.util.ArrayList;
010    import beaver.*;
011    import java.util.*;
012    import java.io.ByteArrayOutputStream;
013    import java.io.PrintStream;
014    import java.lang.reflect.InvocationTargetException;
015    import java.lang.reflect.Method;
016    import org.jastadd.util.*;
017    import java.util.zip.*;
018    import java.io.*;
019    import org.jastadd.util.PrettyPrintable;
020    import org.jastadd.util.PrettyPrinter;
021    import java.io.FileNotFoundException;
022    import java.io.BufferedInputStream;
023    import java.io.DataInputStream;
024    /**
025     * @ast node
026     * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:182
027     * @production InstanceOfExpr : {@link Expr} ::= <span class="component">{@link Expr}</span> <span class="component">TypeAccess:{@link Access}</span>;
028    
029     */
030    public class InstanceOfExpr extends Expr implements Cloneable {
031      /**
032       * @aspect Java4PrettyPrint
033       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:211
034       */
035      public void prettyPrint(PrettyPrinter out) {
036        out.print(getExpr());
037        out.print(" instanceof ");
038        out.print(getTypeAccess());
039      }
040      /**
041       * @aspect TypeCheck
042       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:276
043       */
044      public void refined_TypeCheck_InstanceOfExpr_typeCheck() {
045        TypeDecl relationalExpr = getExpr().type();
046        TypeDecl referenceType = getTypeAccess().type();
047        if (!relationalExpr.isUnknown()) {
048          if (!relationalExpr.isReferenceType() && !relationalExpr.isNull()) {
049            error("The relational expression in instance of must be reference or null type");
050          }
051          if (!referenceType.isReferenceType()) {
052            error("The reference expression in instance of must be reference type");
053          }
054          if (!relationalExpr.castingConversionTo(referenceType)) {
055            errorf("The type %s of the relational expression %s can not be cast into the type %s",
056                relationalExpr.typeName(), getExpr().prettyPrint(), referenceType.typeName());
057          }
058          if (getExpr().isTypeAccess()) {
059            errorf("The relational expression %s must not be a type name", getExpr().prettyPrint());
060          }
061        }
062      }
063      /**
064       * @aspect CreateBCode
065       * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1354
066       */
067      public void createBCode(CodeGeneration gen) {
068        getExpr().createBCode(gen);
069        gen.emitInstanceof(getTypeAccess().type());
070      }
071      /**
072       * @declaredat ASTNode:1
073       */
074      public InstanceOfExpr() {
075        super();
076      }
077      /**
078       * Initializes the child array to the correct size.
079       * Initializes List and Opt nta children.
080       * @apilevel internal
081       * @ast method
082       * @declaredat ASTNode:10
083       */
084      public void init$Children() {
085        children = new ASTNode[2];
086      }
087      /**
088       * @declaredat ASTNode:13
089       */
090      public InstanceOfExpr(Expr p0, Access p1) {
091        setChild(p0, 0);
092        setChild(p1, 1);
093      }
094      /**
095       * @apilevel low-level
096       * @declaredat ASTNode:20
097       */
098      protected int numChildren() {
099        return 2;
100      }
101      /**
102       * @apilevel internal
103       * @declaredat ASTNode:26
104       */
105      public boolean mayHaveRewrite() {
106        return false;
107      }
108      /**
109       * @apilevel internal
110       * @declaredat ASTNode:32
111       */
112      public void flushAttrCache() {
113        super.flushAttrCache();
114        type_reset();
115      }
116      /**
117       * @apilevel internal
118       * @declaredat ASTNode:39
119       */
120      public void flushCollectionCache() {
121        super.flushCollectionCache();
122      }
123      /**
124       * @apilevel internal
125       * @declaredat ASTNode:45
126       */
127      public void flushRewriteCache() {
128        super.flushRewriteCache();
129      }
130      /**
131       * @apilevel internal
132       * @declaredat ASTNode:51
133       */
134      public InstanceOfExpr clone() throws CloneNotSupportedException {
135        InstanceOfExpr node = (InstanceOfExpr) super.clone();
136        return node;
137      }
138      /**
139       * @apilevel internal
140       * @declaredat ASTNode:58
141       */
142      public InstanceOfExpr copy() {
143        try {
144          InstanceOfExpr node = (InstanceOfExpr) clone();
145          node.parent = null;
146          if (children != null) {
147            node.children = (ASTNode[]) children.clone();
148          }
149          return node;
150        } catch (CloneNotSupportedException e) {
151          throw new Error("Error: clone not supported for " + getClass().getName());
152        }
153      }
154      /**
155       * Create a deep copy of the AST subtree at this node.
156       * The copy is dangling, i.e. has no parent.
157       * @return dangling copy of the subtree at this node
158       * @apilevel low-level
159       * @deprecated Please use treeCopy or treeCopyNoTransform instead
160       * @declaredat ASTNode:77
161       */
162      @Deprecated
163      public InstanceOfExpr fullCopy() {
164        return treeCopyNoTransform();
165      }
166      /**
167       * Create a deep copy of the AST subtree at this node.
168       * The copy is dangling, i.e. has no parent.
169       * @return dangling copy of the subtree at this node
170       * @apilevel low-level
171       * @declaredat ASTNode:87
172       */
173      public InstanceOfExpr treeCopyNoTransform() {
174        InstanceOfExpr tree = (InstanceOfExpr) copy();
175        if (children != null) {
176          for (int i = 0; i < children.length; ++i) {
177            ASTNode child = (ASTNode) children[i];
178            if (child != null) {
179              child = child.treeCopyNoTransform();
180              tree.setChild(child, i);
181            }
182          }
183        }
184        return tree;
185      }
186      /**
187       * Create a deep copy of the AST subtree at this node.
188       * The subtree of this node is traversed to trigger rewrites before copy.
189       * The copy is dangling, i.e. has no parent.
190       * @return dangling copy of the subtree at this node
191       * @apilevel low-level
192       * @declaredat ASTNode:107
193       */
194      public InstanceOfExpr treeCopy() {
195        doFullTraversal();
196        return treeCopyNoTransform();
197      }
198      /**
199       * @apilevel internal
200       * @declaredat ASTNode:114
201       */
202      protected boolean is$Equal(ASTNode node) {
203        return super.is$Equal(node);    
204      }
205      /**
206       * Replaces the Expr child.
207       * @param node The new node to replace the Expr child.
208       * @apilevel high-level
209       */
210      public void setExpr(Expr node) {
211        setChild(node, 0);
212      }
213      /**
214       * Retrieves the Expr child.
215       * @return The current node used as the Expr child.
216       * @apilevel high-level
217       */
218      @ASTNodeAnnotation.Child(name="Expr")
219      public Expr getExpr() {
220        return (Expr) getChild(0);
221      }
222      /**
223       * Retrieves the Expr child.
224       * <p><em>This method does not invoke AST transformations.</em></p>
225       * @return The current node used as the Expr child.
226       * @apilevel low-level
227       */
228      public Expr getExprNoTransform() {
229        return (Expr) getChildNoTransform(0);
230      }
231      /**
232       * Replaces the TypeAccess child.
233       * @param node The new node to replace the TypeAccess child.
234       * @apilevel high-level
235       */
236      public void setTypeAccess(Access node) {
237        setChild(node, 1);
238      }
239      /**
240       * Retrieves the TypeAccess child.
241       * @return The current node used as the TypeAccess child.
242       * @apilevel high-level
243       */
244      @ASTNodeAnnotation.Child(name="TypeAccess")
245      public Access getTypeAccess() {
246        return (Access) getChild(1);
247      }
248      /**
249       * Retrieves the TypeAccess child.
250       * <p><em>This method does not invoke AST transformations.</em></p>
251       * @return The current node used as the TypeAccess child.
252       * @apilevel low-level
253       */
254      public Access getTypeAccessNoTransform() {
255        return (Access) getChildNoTransform(1);
256      }
257      /**
258       * @aspect GenericsTypeCheck
259       * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:447
260       */
261       
262      public void typeCheck() {
263        refined_TypeCheck_InstanceOfExpr_typeCheck();
264        if (!getTypeAccess().type().isReifiable()) {
265          error("right-hand side of instanceof expression must denote a reifiable type");
266        }
267      }
268      /**
269       * @attribute syn
270       * @aspect ConstantExpression
271       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:254
272       */
273      @ASTNodeAnnotation.Attribute
274      public boolean isConstant() {
275        boolean isConstant_value = false;
276    
277        return isConstant_value;
278      }
279      /**
280       * @attribute syn
281       * @aspect DA
282       * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:375
283       */
284      @ASTNodeAnnotation.Attribute
285      public boolean isDAafterFalse(Variable v) {
286        boolean isDAafterFalse_Variable_value = isDAafter(v);
287    
288        return isDAafterFalse_Variable_value;
289      }
290      /**
291       * @attribute syn
292       * @aspect DA
293       * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:374
294       */
295      @ASTNodeAnnotation.Attribute
296      public boolean isDAafterTrue(Variable v) {
297        boolean isDAafterTrue_Variable_value = isDAafter(v);
298    
299        return isDAafterTrue_Variable_value;
300      }
301      /**
302       * @attribute syn
303       * @aspect DA
304       * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:259
305       */
306      @ASTNodeAnnotation.Attribute
307      public boolean isDAafter(Variable v) {
308        boolean isDAafter_Variable_value = getExpr().isDAafter(v);
309    
310        return isDAafter_Variable_value;
311      }
312      /**
313       * @attribute syn
314       * @aspect DU
315       * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:783
316       */
317      @ASTNodeAnnotation.Attribute
318      public boolean isDUafter(Variable v) {
319        boolean isDUafter_Variable_value = getExpr().isDUafter(v);
320    
321        return isDUafter_Variable_value;
322      }
323      /**
324       * @apilevel internal
325       */
326      protected boolean type_computed = false;
327      /**
328       * @apilevel internal
329       */
330      protected TypeDecl type_value;
331      /**
332       * @apilevel internal
333       */
334      private void type_reset() {
335        type_computed = false;
336        type_value = null;
337      }
338      /**
339       * @attribute syn
340       * @aspect TypeAnalysis
341       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302
342       */
343      @ASTNodeAnnotation.Attribute
344      public TypeDecl type() {
345        ASTNode$State state = state();
346        if (type_computed) {
347          return type_value;
348        }
349        boolean intermediate = state.INTERMEDIATE_VALUE;
350        state.INTERMEDIATE_VALUE = false;
351        int num = state.boundariesCrossed;
352        boolean isFinal = this.is$Final();
353        type_value = typeBoolean();
354        if (isFinal && num == state().boundariesCrossed) {
355          type_computed = true;
356        } else {
357        }
358        state.INTERMEDIATE_VALUE |= intermediate;
359    
360        return type_value;
361      }
362      /**
363       * @attribute syn
364       * @aspect PreciseRethrow
365       * @declaredat /home/jesper/git/extendj/java7/frontend/PreciseRethrow.jrag:149
366       */
367      @ASTNodeAnnotation.Attribute
368      public boolean modifiedInScope(Variable var) {
369        boolean modifiedInScope_Variable_value = getExpr().modifiedInScope(var);
370    
371        return modifiedInScope_Variable_value;
372      }
373      /**
374       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
375       * @apilevel internal
376       */
377      public NameType Define_nameType(ASTNode caller, ASTNode child) {
378        if (caller == getTypeAccessNoTransform()) {
379          // @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:116
380          return NameType.TYPE_NAME;
381        }
382        else {
383          return getParent().Define_nameType(this, caller);
384        }
385      }
386      protected boolean canDefine_nameType(ASTNode caller, ASTNode child) {
387        return true;
388      }
389      /**
390       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:196
391       * @apilevel internal
392       */
393      public boolean Define_assignmentContext(ASTNode caller, ASTNode child) {
394        if (caller == getExprNoTransform()) {
395          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:252
396          return false;
397        }
398        else {
399          return getParent().Define_assignmentContext(this, caller);
400        }
401      }
402      protected boolean canDefine_assignmentContext(ASTNode caller, ASTNode child) {
403        return true;
404      }
405      /**
406       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:197
407       * @apilevel internal
408       */
409      public boolean Define_invocationContext(ASTNode caller, ASTNode child) {
410        if (caller == getExprNoTransform()) {
411          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:253
412          return false;
413        }
414        else {
415          return getParent().Define_invocationContext(this, caller);
416        }
417      }
418      protected boolean canDefine_invocationContext(ASTNode caller, ASTNode child) {
419        return true;
420      }
421      /**
422       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:198
423       * @apilevel internal
424       */
425      public boolean Define_castContext(ASTNode caller, ASTNode child) {
426        if (caller == getExprNoTransform()) {
427          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:254
428          return false;
429        }
430        else {
431          return getParent().Define_castContext(this, caller);
432        }
433      }
434      protected boolean canDefine_castContext(ASTNode caller, ASTNode child) {
435        return true;
436      }
437      /**
438       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:199
439       * @apilevel internal
440       */
441      public boolean Define_stringContext(ASTNode caller, ASTNode child) {
442        if (caller == getExprNoTransform()) {
443          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:255
444          return false;
445        }
446        else {
447          return getParent().Define_stringContext(this, caller);
448        }
449      }
450      protected boolean canDefine_stringContext(ASTNode caller, ASTNode child) {
451        return true;
452      }
453      /**
454       * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:200
455       * @apilevel internal
456       */
457      public boolean Define_numericContext(ASTNode caller, ASTNode child) {
458        if (caller == getExprNoTransform()) {
459          // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:256
460          return false;
461        }
462        else {
463          return getParent().Define_numericContext(this, caller);
464        }
465      }
466      protected boolean canDefine_numericContext(ASTNode caller, ASTNode child) {
467        return true;
468      }
469      /**
470       * @apilevel internal
471       */
472      public ASTNode rewriteTo() {
473        return super.rewriteTo();
474      }
475    }