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

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

/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.0 */
package org.extendj.ast;
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.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
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;
import java.util.LinkedHashSet;
import java.util.*;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import java.util.zip.*;
import java.io.*;
import org.jastadd.util.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
/**
 * @ast node
 * @declaredat /home/jesper/git/extendj/java8/grammar/Lambda.ast:13
 * @astdecl ExprLambdaBody : LambdaBody ::= Expr;
 * @production ExprLambdaBody : {@link LambdaBody} ::= {@link Expr};

 */
public class ExprLambdaBody extends LambdaBody implements Cloneable {
  /**
   * @aspect Java8PrettyPrint
   * @declaredat /home/jesper/git/extendj/java8/frontend/PrettyPrint.jadd:67
   */
  public void prettyPrint(PrettyPrinter out) {
    out.print(getExpr());
  }
  /**
   * @aspect PrettyPrintUtil8
   * @declaredat /home/jesper/git/extendj/java8/frontend/PrettyPrintUtil.jadd:75
   */
  @Override public String toString() {
    return getExprNoTransform().toString();
  }
  /**
   * @aspect LambdaToClass
   * @declaredat /home/jesper/git/extendj/java8/frontend/LambdaAnonymousDecl.jrag:92
   */
  protected Block toBlock() {
    List stmtList = new List();
    Expr expr = getExpr().treeCopyNoTransform();
    boolean voidType;
    FunctionDescriptor fd = enclosingLambda().targetInterface().functionDescriptor();
    if (fd.method.hasValue()) {
      voidType = fd.method.get().type().isVoid();
    } else {
      voidType = false;
    }
    if (voidType) {
      // Return type is void: insert ExprStmt in list.
      stmtList.add(new ExprStmt(expr));
    } else {
      // Otherwise, insert return statement.
      stmtList.add(new ReturnStmt(expr));
    }
    return new Block(stmtList);
  }
  /**
   * @declaredat ASTNode:1
   */
  public ExprLambdaBody() {
    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 = {"Expr"},
    type = {"Expr"},
    kind = {"Child"}
  )
  public ExprLambdaBody(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 false;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:32
   */
  public void flushAttrCache() {
    super.flushAttrCache();
    congruentTo_FunctionDescriptor_reset();
    isBlockBody_reset();
    isExprBody_reset();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:39
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:43
   */
  public ExprLambdaBody clone() throws CloneNotSupportedException {
    ExprLambdaBody node = (ExprLambdaBody) super.clone();
    return node;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:48
   */
  public ExprLambdaBody copy() {
    try {
      ExprLambdaBody node = (ExprLambdaBody) 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:67
   */
  @Deprecated
  public ExprLambdaBody 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:77
   */
  public ExprLambdaBody treeCopyNoTransform() {
    ExprLambdaBody tree = (ExprLambdaBody) 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:97
   */
  public ExprLambdaBody treeCopy() {
    ExprLambdaBody tree = (ExprLambdaBody) 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:111
   */
  protected boolean is$Equal(ASTNode node) {
    return super.is$Equal(node);    
  }
  /**
   * Replaces the Expr child.
   * @param node The new node to replace the Expr child.
   * @apilevel high-level
   */
  public void setExpr(Expr node) {
    setChild(node, 0);
  }
  /**
   * Retrieves the Expr child.
   * @return The current node used as the Expr child.
   * @apilevel high-level
   */
  @ASTNodeAnnotation.Child(name="Expr")
  public Expr getExpr() {
    return (Expr) getChild(0);
  }
  /**
   * Retrieves the Expr child.
   * 

This method does not invoke AST transformations.

* @return The current node used as the Expr child. * @apilevel low-level */ public Expr getExprNoTransform() { return (Expr) getChildNoTransform(0); } /** @apilevel internal */ private void congruentTo_FunctionDescriptor_reset() { congruentTo_FunctionDescriptor_computed = null; congruentTo_FunctionDescriptor_values = null; } /** @apilevel internal */ protected java.util.Map congruentTo_FunctionDescriptor_values; /** @apilevel internal */ protected java.util.Map congruentTo_FunctionDescriptor_computed; /** * @attribute syn * @aspect LambdaExpr * @declaredat /home/jesper/git/extendj/java8/frontend/LambdaExpr.jrag:89 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="LambdaExpr", declaredAt="/home/jesper/git/extendj/java8/frontend/LambdaExpr.jrag:89") public boolean congruentTo(FunctionDescriptor fd) { Object _parameters = fd; if (congruentTo_FunctionDescriptor_computed == null) congruentTo_FunctionDescriptor_computed = new java.util.HashMap(4); if (congruentTo_FunctionDescriptor_values == null) congruentTo_FunctionDescriptor_values = new java.util.HashMap(4); ASTState state = state(); if (congruentTo_FunctionDescriptor_values.containsKey(_parameters) && congruentTo_FunctionDescriptor_computed.containsKey(_parameters) && (congruentTo_FunctionDescriptor_computed.get(_parameters) == ASTState.NON_CYCLE || congruentTo_FunctionDescriptor_computed.get(_parameters) == state().cycle())) { return (Boolean) congruentTo_FunctionDescriptor_values.get(_parameters); } boolean congruentTo_FunctionDescriptor_value = congruentTo_compute(fd); if (state().inCircle()) { congruentTo_FunctionDescriptor_values.put(_parameters, congruentTo_FunctionDescriptor_value); congruentTo_FunctionDescriptor_computed.put(_parameters, state().cycle()); } else { congruentTo_FunctionDescriptor_values.put(_parameters, congruentTo_FunctionDescriptor_value); congruentTo_FunctionDescriptor_computed.put(_parameters, ASTState.NON_CYCLE); } return congruentTo_FunctionDescriptor_value; } /** @apilevel internal */ private boolean congruentTo_compute(FunctionDescriptor fd) { if (fd.method.hasValue()) { if (fd.method.get().type().isVoid()) { return getExpr().stmtCompatible(); } else { return getExpr().assignConversionTo(fd.method.get().type()); } } else { return false; } } /** * @attribute syn * @aspect PreciseRethrow * @declaredat /home/jesper/git/extendj/java8/frontend/EffectivelyFinal.jrag:43 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="PreciseRethrow", declaredAt="/home/jesper/git/extendj/java8/frontend/EffectivelyFinal.jrag:43") public boolean modifiedInScope(Variable var) { boolean modifiedInScope_Variable_value = getExpr().modifiedInScope(var); return modifiedInScope_Variable_value; } /** @apilevel internal */ private void isBlockBody_reset() { isBlockBody_computed = null; } /** @apilevel internal */ protected ASTState.Cycle isBlockBody_computed = null; /** @apilevel internal */ protected boolean isBlockBody_value; /** * @attribute syn * @aspect LambdaBody * @declaredat /home/jesper/git/extendj/java8/frontend/LambdaBody.jrag:29 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="LambdaBody", declaredAt="/home/jesper/git/extendj/java8/frontend/LambdaBody.jrag:29") public boolean isBlockBody() { ASTState state = state(); if (isBlockBody_computed == ASTState.NON_CYCLE || isBlockBody_computed == state().cycle()) { return isBlockBody_value; } isBlockBody_value = false; if (state().inCircle()) { isBlockBody_computed = state().cycle(); } else { isBlockBody_computed = ASTState.NON_CYCLE; } return isBlockBody_value; } /** @apilevel internal */ private void isExprBody_reset() { isExprBody_computed = null; } /** @apilevel internal */ protected ASTState.Cycle isExprBody_computed = null; /** @apilevel internal */ protected boolean isExprBody_value; /** * @attribute syn * @aspect LambdaBody * @declaredat /home/jesper/git/extendj/java8/frontend/LambdaBody.jrag:30 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="LambdaBody", declaredAt="/home/jesper/git/extendj/java8/frontend/LambdaBody.jrag:30") public boolean isExprBody() { ASTState state = state(); if (isExprBody_computed == ASTState.NON_CYCLE || isExprBody_computed == state().cycle()) { return isExprBody_value; } isExprBody_value = true; if (state().inCircle()) { isExprBody_computed = state().cycle(); } else { isExprBody_computed = ASTState.NON_CYCLE; } return isExprBody_value; } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:31 * @apilevel internal */ public TypeDecl Define_targetType(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:127 { TypeDecl decl = enclosingLambda().targetType(); if (decl.isNull()) { return unknownType(); } else if (!(decl instanceof InterfaceDecl)) { return unknownType(); } else { InterfaceDecl iDecl = (InterfaceDecl) decl; if (!iDecl.isFunctional()) { return unknownType(); } else { FunctionDescriptor fd = iDecl.functionDescriptor(); if (fd.method.hasValue()) { return fd.method.get().type(); } else { return unknownType(); } } } } } else { return getParent().Define_targetType(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:31 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute targetType */ protected boolean canDefine_targetType(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:235 * @apilevel internal */ public boolean Define_assignmentContext(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:247 return true; } else { return getParent().Define_assignmentContext(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:235 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute assignmentContext */ protected boolean canDefine_assignmentContext(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:236 * @apilevel internal */ public boolean Define_invocationContext(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:248 return false; } else { return getParent().Define_invocationContext(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:236 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute invocationContext */ protected boolean canDefine_invocationContext(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:237 * @apilevel internal */ public boolean Define_castContext(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:249 return false; } else { return getParent().Define_castContext(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:237 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute castContext */ protected boolean canDefine_castContext(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:238 * @apilevel internal */ public boolean Define_stringContext(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:250 return false; } else { return getParent().Define_stringContext(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:238 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute stringContext */ protected boolean canDefine_stringContext(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:239 * @apilevel internal */ public boolean Define_numericContext(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:251 return false; } else { return getParent().Define_numericContext(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:239 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute numericContext */ protected boolean canDefine_numericContext(ASTNode _callerNode, ASTNode _childNode) { return true; } /** @apilevel internal */ public ASTNode rewriteTo() { return super.rewriteTo(); } /** @apilevel internal */ public boolean canRewrite() { return false; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy