org.extendj.ast.RelationalExpr Maven / Gradle / Ivy
/* 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 org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import org.jastadd.util.*;
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.io.BufferedInputStream;
import java.io.DataInputStream;
/**
* @ast node
* @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:265
* @astdecl RelationalExpr : Binary;
* @production RelationalExpr : {@link Binary};
*/
public abstract class RelationalExpr extends Binary implements Cloneable {
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1168
*/
public void createBCode(CodeGeneration gen) { emitBooleanCondition(gen); }
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1313
*/
public void branchTrue(CodeGeneration gen, int target) {
// Branch when true.
if (isConstant()) {
if (isTrue()) {
gen.GOTO(target);
}
} else {
TypeDecl type = getLeftOperand().type();
if (type.isNumericType()) {
type = binaryNumericPromotedType();
getLeftOperand().createBCode(gen);
getLeftOperand().emitCastTo(gen, type); // Binary numeric promotion.
getRightOperand().createBCode(gen);
getRightOperand().emitCastTo(gen, type); // Binary numeric promotion.
} else {
getLeftOperand().createBCode(gen);
getRightOperand().createBCode(gen);
}
compareBranch(gen, target, type);
}
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1424
*/
public void branchFalse(CodeGeneration gen, int target) {
// Branch when false.
if (isConstant()) {
if (isFalse()) {
gen.GOTO(target);
}
} else {
TypeDecl type = getLeftOperand().type();
if (type.isNumericType()) {
type = binaryNumericPromotedType();
getLeftOperand().createBCode(gen);
getLeftOperand().emitCastTo(gen, type); // Binary numeric promotion.
getRightOperand().createBCode(gen);
getRightOperand().emitCastTo(gen, type); // Binary numeric promotion.
} else {
getLeftOperand().createBCode(gen);
getRightOperand().createBCode(gen);
}
compareNotBranch(gen, target, type);
}
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1446
*/
public void compareBranch(CodeGeneration gen, int label, TypeDecl typeDecl) {
throw new Error("compareBranch not implemented for " + getClass().getName());
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1474
*/
public void compareNotBranch(CodeGeneration gen, int label, TypeDecl typeDecl) {
throw new Error("compareNotBranch not implemented for " + getClass().getName());
}
/**
* @declaredat ASTNode:1
*/
public RelationalExpr() {
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[2];
}
/**
* @declaredat ASTNode:13
*/
@ASTNodeAnnotation.Constructor(
name = {"LeftOperand", "RightOperand"},
type = {"Expr", "Expr"},
kind = {"Child", "Child"}
)
public RelationalExpr(Expr p0, Expr p1) {
setChild(p0, 0);
setChild(p1, 1);
}
/** @apilevel low-level
* @declaredat ASTNode:23
*/
protected int numChildren() {
return 2;
}
/**
* @apilevel internal
* @declaredat ASTNode:29
*/
public boolean mayHaveRewrite() {
return false;
}
/** @apilevel internal
* @declaredat ASTNode:33
*/
public void flushAttrCache() {
super.flushAttrCache();
type_reset();
}
/** @apilevel internal
* @declaredat ASTNode:38
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:42
*/
public RelationalExpr clone() throws CloneNotSupportedException {
RelationalExpr node = (RelationalExpr) super.clone();
return node;
}
/**
* 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:53
*/
@Deprecated
public abstract RelationalExpr fullCopy();
/**
* 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:61
*/
public abstract RelationalExpr treeCopyNoTransform();
/**
* 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:69
*/
public abstract RelationalExpr treeCopy();
/**
* Replaces the LeftOperand child.
* @param node The new node to replace the LeftOperand child.
* @apilevel high-level
*/
public void setLeftOperand(Expr node) {
setChild(node, 0);
}
/**
* Retrieves the LeftOperand child.
* @return The current node used as the LeftOperand child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="LeftOperand")
public Expr getLeftOperand() {
return (Expr) getChild(0);
}
/**
* Retrieves the LeftOperand child.
* This method does not invoke AST transformations.
* @return The current node used as the LeftOperand child.
* @apilevel low-level
*/
public Expr getLeftOperandNoTransform() {
return (Expr) getChildNoTransform(0);
}
/**
* Replaces the RightOperand child.
* @param node The new node to replace the RightOperand child.
* @apilevel high-level
*/
public void setRightOperand(Expr node) {
setChild(node, 1);
}
/**
* Retrieves the RightOperand child.
* @return The current node used as the RightOperand child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="RightOperand")
public Expr getRightOperand() {
return (Expr) getChild(1);
}
/**
* Retrieves the RightOperand child.
* This method does not invoke AST transformations.
* @return The current node used as the RightOperand child.
* @apilevel low-level
*/
public Expr getRightOperandNoTransform() {
return (Expr) getChildNoTransform(1);
}
/** @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 = typeBoolean();
if (state().inCircle()) {
type_computed = state().cycle();
} else {
type_computed = ASTState.NON_CYCLE;
}
return type_value;
}
/**
* @attribute syn
* @aspect TypeCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:280
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:280")
public Collection typeProblems() {
{
Collection problems = new LinkedList();
if (!getLeftOperand().type().isNumericType()) {
problems.add(errorf("%s is not numeric", getLeftOperand().type().typeName()));
}
if (!getRightOperand().type().isNumericType()) {
problems.add(errorf("%s is not numeric", getRightOperand().type().typeName()));
}
return problems;
}
}
/** @apilevel internal */
public ASTNode rewriteTo() {
return super.rewriteTo();
}
/** @apilevel internal */
public boolean canRewrite() {
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:277
{
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);
for (Problem value : typeProblems()) {
collection.add(value);
}
}
}