All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.extendj.ast.MinusExpr Maven / Gradle / Ivy

There is a newer version: 8.1.2
Show newest version
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.0 */
package org.extendj.ast;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.ArrayList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.zip.*;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.jastadd.util.*;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import beaver.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
/**
 * @ast node
 * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:229
 * @astdecl MinusExpr : Unary;
 * @production MinusExpr : {@link Unary};

 */
public class MinusExpr extends Unary implements Cloneable {
  /**
   * @aspect CodeGeneration
   * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:461
   */
  void emitOperation(CodeGeneration gen)  { type().neg(gen); }
  /**
   * @declaredat ASTNode:1
   */
  public MinusExpr() {
    super();
  }
  /**
   * Initializes the child array to the correct size.
   * Initializes List and Opt nta children.
   * @apilevel internal
   * @ast method
   * @declaredat ASTNode:10
   */
  public void init$Children() {
    children = new ASTNode[1];
  }
  /**
   * @declaredat ASTNode:13
   */
  @ASTNodeAnnotation.Constructor(
    name = {"Operand"},
    type = {"Expr"},
    kind = {"Child"}
  )
  public MinusExpr(Expr p0) {
    setChild(p0, 0);
  }
  /** @apilevel low-level 
   * @declaredat ASTNode:22
   */
  protected int numChildren() {
    return 1;
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:28
   */
  public boolean mayHaveRewrite() {
    return true;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:32
   */
  public void flushAttrCache() {
    super.flushAttrCache();
    rewrittenNode_reset();
    type_reset();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:38
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:42
   */
  public MinusExpr clone() throws CloneNotSupportedException {
    MinusExpr node = (MinusExpr) super.clone();
    return node;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:47
   */
  public MinusExpr copy() {
    try {
      MinusExpr node = (MinusExpr) clone();
      node.parent = null;
      if (children != null) {
        node.children = (ASTNode[]) children.clone();
      }
      return node;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " + getClass().getName());
    }
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @deprecated Please use treeCopy or treeCopyNoTransform instead
   * @declaredat ASTNode:66
   */
  @Deprecated
  public MinusExpr fullCopy() {
    return treeCopyNoTransform();
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @declaredat ASTNode:76
   */
  public MinusExpr treeCopyNoTransform() {
    MinusExpr tree = (MinusExpr) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) children[i];
        if (child != null) {
          child = child.treeCopyNoTransform();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The subtree of this node is traversed to trigger rewrites before copy.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @declaredat ASTNode:96
   */
  public MinusExpr treeCopy() {
    MinusExpr tree = (MinusExpr) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) getChild(i);
        if (child != null) {
          child = child.treeCopy();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:110
   */
  protected boolean is$Equal(ASTNode node) {
    return super.is$Equal(node);    
  }
  /**
   * Replaces the Operand child.
   * @param node The new node to replace the Operand child.
   * @apilevel high-level
   */
  public void setOperand(Expr node) {
    setChild(node, 0);
  }
  /**
   * Retrieves the Operand child.
   * @return The current node used as the Operand child.
   * @apilevel high-level
   */
  @ASTNodeAnnotation.Child(name="Operand")
  public Expr getOperand() {
    return (Expr) getChild(0);
  }
  /**
   * Retrieves the Operand child.
   * 

This method does not invoke AST transformations.

* @return The current node used as the Operand child. * @apilevel low-level */ public Expr getOperandNoTransform() { return (Expr) getChildNoTransform(0); } /** @apilevel internal */ private void type_reset() { type_computed = null; type_value = null; } /** @apilevel internal */ protected ASTState.Cycle type_computed = null; /** @apilevel internal */ protected TypeDecl type_value; /** * @attribute syn * @aspect TypeAnalysis * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:296 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="TypeAnalysis", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:296") public TypeDecl type() { ASTState state = state(); if (type_computed == ASTState.NON_CYCLE || type_computed == state().cycle()) { return type_value; } type_value = getOperand().type().unaryNumericPromotion(); if (state().inCircle()) { type_computed = state().cycle(); } else { type_computed = ASTState.NON_CYCLE; } return type_value; } /** * @attribute syn * @aspect PrettyPrintUtil * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:317 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="PrettyPrintUtil", declaredAt="/home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:317") public String printPreOp() { String printPreOp_value = "-"; return printPreOp_value; } /** * @attribute syn * @aspect ConstantExpression * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:32 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="ConstantExpression", declaredAt="/home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:32") public Constant constant() { Constant constant_value = type().minus(getOperand().constant()); return constant_value; } /** * @attribute syn * @aspect ConstantExpression * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:383 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="ConstantExpression", declaredAt="/home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:383") public boolean isConstant() { boolean isConstant_value = getOperand().isConstant(); return isConstant_value; } /** @apilevel internal */ public ASTNode rewriteTo() { // Declared at /home/jesper/git/extendj/java4/frontend/UnaryMinusRewrite.jrag:38 if (getOperand() instanceof IntegerLiteral && ((IntegerLiteral) getOperand()).isDecimal() && getOperand().isPositive()) { return rewriteRule0(); } // Declared at /home/jesper/git/extendj/java4/frontend/UnaryMinusRewrite.jrag:48 if (getOperand() instanceof LongLiteral && ((LongLiteral) getOperand()).isDecimal() && getOperand().isPositive()) { return rewriteRule1(); } return super.rewriteTo(); } /** * @declaredat /home/jesper/git/extendj/java4/frontend/UnaryMinusRewrite.jrag:38 * @apilevel internal */ private IntegerLiteral rewriteRule0() { { IntegerLiteral original = (IntegerLiteral) getOperand(); return new IntegerLiteral("-" + original.getLITERAL()); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/UnaryMinusRewrite.jrag:48 * @apilevel internal */ private LongLiteral rewriteRule1() { { LongLiteral original = (LongLiteral) getOperand(); return new LongLiteral("-" + original.getLITERAL()); } } /** @apilevel internal */ public boolean canRewrite() { // Declared at /home/jesper/git/extendj/java4/frontend/UnaryMinusRewrite.jrag:38 if (getOperand() instanceof IntegerLiteral && ((IntegerLiteral) getOperand()).isDecimal() && getOperand().isPositive()) { return true; } // Declared at /home/jesper/git/extendj/java4/frontend/UnaryMinusRewrite.jrag:48 if (getOperand() instanceof LongLiteral && ((LongLiteral) getOperand()).isDecimal() && getOperand().isPositive()) { return true; } return false; } /** @apilevel internal */ protected void collect_contributors_CompilationUnit_problems(CompilationUnit _root, java.util.Map> _map) { // @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:383 if (!getOperand().type().isNumericType()) { { java.util.Set contributors = _map.get(_root); if (contributors == null) { contributors = new java.util.LinkedHashSet(); _map.put((ASTNode) _root, contributors); } contributors.add(this); } } super.collect_contributors_CompilationUnit_problems(_root, _map); } /** @apilevel internal */ protected void contributeTo_CompilationUnit_problems(LinkedList collection) { super.contributeTo_CompilationUnit_problems(collection); if (!getOperand().type().isNumericType()) { collection.add(error("unary minus only operates on numeric types")); } } /** @apilevel internal */ private void rewrittenNode_reset() { rewrittenNode_computed = false; rewrittenNode_initialized = false; rewrittenNode_value = null; rewrittenNode_cycle = null; } /** @apilevel internal */ protected ASTState.Cycle rewrittenNode_cycle = null; /** @apilevel internal */ protected boolean rewrittenNode_computed = false; /** @apilevel internal */ protected ASTNode rewrittenNode_value; /** @apilevel internal */ protected boolean rewrittenNode_initialized = false; @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true, isNTA=true) @ASTNodeAnnotation.Source(aspect="", declaredAt=":0") public ASTNode rewrittenNode() { if (rewrittenNode_computed) { return rewrittenNode_value; } ASTState state = state(); if (!rewrittenNode_initialized) { rewrittenNode_initialized = true; rewrittenNode_value = this; if (rewrittenNode_value != null) { rewrittenNode_value.setParent(getParent()); } } if (!state.inCircle() || state.calledByLazyAttribute()) { state.enterCircle(); do { rewrittenNode_cycle = state.nextCycle(); ASTNode new_rewrittenNode_value = rewrittenNode_value.rewriteTo(); if (new_rewrittenNode_value != rewrittenNode_value || new_rewrittenNode_value.canRewrite()) { state.setChangeInCycle(); } rewrittenNode_value = new_rewrittenNode_value; if (rewrittenNode_value != null) { rewrittenNode_value.setParent(getParent()); } } while (state.testAndClearChangeInCycle()); rewrittenNode_computed = true; state.leaveCircle(); } else if (rewrittenNode_cycle != state.cycle()) { rewrittenNode_cycle = state.cycle(); ASTNode new_rewrittenNode_value = rewrittenNode_value.rewriteTo(); if (new_rewrittenNode_value != rewrittenNode_value || new_rewrittenNode_value.canRewrite()) { state.setChangeInCycle(); } rewrittenNode_value = new_rewrittenNode_value; if (rewrittenNode_value != null) { rewrittenNode_value.setParent(getParent()); } } else { } return rewrittenNode_value; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy