org.extendj.ast.SwitchStmt Maven / Gradle / Ivy
The newest version!
/* 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/java4/grammar/Java.ast:335
* @astdecl SwitchStmt : BranchTargetStmt ::= Expr Block;
* @production SwitchStmt : {@link BranchTargetStmt} ::= {@link Expr} {@link Block};
*/
public class SwitchStmt extends BranchTargetStmt implements Cloneable {
/**
* @aspect Java4PrettyPrint
* @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:573
*/
public void prettyPrint(PrettyPrinter out) {
out.print("switch (");
out.print(getExpr());
out.print(") ");
out.print(getBlock());
}
/**
* @return label to be used as default target in switch bytecode instruction
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1601
*/
private int defaultLabel() {
DefaultCase defaultCase = defaultCase();
if (defaultCase != null) {
return defaultCase.label();
} else {
return end_label();
}
}
/**
* @declaredat ASTNode:1
*/
public SwitchStmt() {
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 = {"Expr", "Block"},
type = {"Expr", "Block"},
kind = {"Child", "Child"}
)
public SwitchStmt(Expr p0, Block 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();
canCompleteNormally_reset();
assignedAfter_Variable_reset();
unassignedAfter_Variable_reset();
unassignedAfterLastStmt_Variable_reset();
caseMap_reset();
defaultCase_reset();
end_label_reset();
enumIndexExpr_reset();
typeInt_reset();
typeLong_reset();
}
/** @apilevel internal
* @declaredat ASTNode:47
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:51
*/
public SwitchStmt clone() throws CloneNotSupportedException {
SwitchStmt node = (SwitchStmt) super.clone();
return node;
}
/** @apilevel internal
* @declaredat ASTNode:56
*/
public SwitchStmt copy() {
try {
SwitchStmt node = (SwitchStmt) 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:75
*/
@Deprecated
public SwitchStmt 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:85
*/
public SwitchStmt treeCopyNoTransform() {
SwitchStmt tree = (SwitchStmt) 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:105
*/
public SwitchStmt treeCopy() {
SwitchStmt tree = (SwitchStmt) 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:119
*/
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);
}
/**
* Replaces the Block child.
* @param node The new node to replace the Block child.
* @apilevel high-level
*/
public void setBlock(Block node) {
setChild(node, 1);
}
/**
* Retrieves the Block child.
* @return The current node used as the Block child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="Block")
public Block getBlock() {
return (Block) getChild(1);
}
/**
* Retrieves the Block child.
* This method does not invoke AST transformations.
* @return The current node used as the Block child.
* @apilevel low-level
*/
public Block getBlockNoTransform() {
return (Block) getChildNoTransform(1);
}
/**
* @aspect AutoBoxingCodegen
* @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:207
*/
public void createBCode(CodeGeneration gen) {
super.createBCode(gen);
int cond_label = gen.constantPool().newLabel();
int switch_label = gen.constantPool().newLabel();
ArrayList cases = new ArrayList();
if (getExpr().type().isEnumDecl()) {
enumIndexExpr().createBCode(gen);
Map enumIndices = hostType().enumIndices(getExpr().type());
for (ConstCase cc : constCases()) {
cases.add(new EnumLabel(enumIndices.get((EnumConstant) cc.getValue().varDecl()), cc));
}
} else {
getExpr().createBCode(gen);
if (getExpr().type().isReferenceType()) {
getExpr().type().emitUnboxingOperation(gen);
}
for (ConstCase cc : constCases()) {
cases.add(new CaseLabel(cc));
}
}
gen.SWITCH(cases, defaultLabel());
getBlock().createBCode(gen);
gen.addLabel(end_label());
}
/**
* @attribute syn
* @aspect UnreachableStatements
* @declaredat /home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:96
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="UnreachableStatements", declaredAt="/home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:96")
public boolean lastStmtCanCompleteNormally() {
boolean lastStmtCanCompleteNormally_value = getBlock().canCompleteNormally();
return lastStmtCanCompleteNormally_value;
}
/**
* @attribute syn
* @aspect UnreachableStatements
* @declaredat /home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:98
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="UnreachableStatements", declaredAt="/home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:98")
public boolean noStmts() {
{
for (int i = 0; i < getBlock().getNumStmt(); i++) {
if (!(getBlock().getStmt(i) instanceof Case)) {
return false;
}
}
return true;
}
}
/**
* @attribute syn
* @aspect UnreachableStatements
* @declaredat /home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:107
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="UnreachableStatements", declaredAt="/home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:107")
public boolean noStmtsAfterLastLabel() {
boolean noStmtsAfterLastLabel_value = getBlock().getNumStmt() > 0
&& getBlock().getStmt(getBlock().getNumStmt()-1) instanceof Case;
return noStmtsAfterLastLabel_value;
}
/**
* @attribute syn
* @aspect UnreachableStatements
* @declaredat /home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:111
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="UnreachableStatements", declaredAt="/home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:111")
public boolean noDefaultLabel() {
{
for (int i = 0; i < getBlock().getNumStmt(); i++) {
if (getBlock().getStmt(i) instanceof DefaultCase) {
return false;
}
}
return true;
}
}
/** @apilevel internal */
private void canCompleteNormally_reset() {
canCompleteNormally_computed = null;
}
/** @apilevel internal */
protected ASTState.Cycle canCompleteNormally_computed = null;
/** @apilevel internal */
protected boolean canCompleteNormally_value;
/**
* @attribute syn
* @aspect UnreachableStatements
* @declaredat /home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:50
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="UnreachableStatements", declaredAt="/home/jesper/git/extendj/java4/frontend/UnreachableStatements.jrag:50")
public boolean canCompleteNormally() {
ASTState state = state();
if (canCompleteNormally_computed == ASTState.NON_CYCLE || canCompleteNormally_computed == state().cycle()) {
return canCompleteNormally_value;
}
canCompleteNormally_value = lastStmtCanCompleteNormally() || noStmts()
|| noStmtsAfterLastLabel()
|| noDefaultLabel() || reachableBreak();
if (state().inCircle()) {
canCompleteNormally_computed = state().cycle();
} else {
canCompleteNormally_computed = ASTState.NON_CYCLE;
}
return canCompleteNormally_value;
}
/**
* @return true
if this statement is a potential
* branch target of the given branch statement.
* @attribute syn
* @aspect BranchTarget
* @declaredat /home/jesper/git/extendj/java4/frontend/BranchTarget.jrag:215
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="BranchTarget", declaredAt="/home/jesper/git/extendj/java4/frontend/BranchTarget.jrag:215")
public boolean potentialTargetOf(Stmt branch) {
boolean potentialTargetOf_Stmt_value = branch.canBranchTo(this);
return potentialTargetOf_Stmt_value;
}
/** @apilevel internal */
private void assignedAfter_Variable_reset() {
assignedAfter_Variable_values = null;
}
protected java.util.Map assignedAfter_Variable_values;
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true)
@ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:264")
public boolean assignedAfter(Variable v) {
Object _parameters = v;
if (assignedAfter_Variable_values == null) assignedAfter_Variable_values = new java.util.HashMap(4);
ASTState.CircularValue _value;
if (assignedAfter_Variable_values.containsKey(_parameters)) {
Object _cache = assignedAfter_Variable_values.get(_parameters);
if (!(_cache instanceof ASTState.CircularValue)) {
return (Boolean) _cache;
} else {
_value = (ASTState.CircularValue) _cache;
}
} else {
_value = new ASTState.CircularValue();
assignedAfter_Variable_values.put(_parameters, _value);
_value.value = true;
}
ASTState state = state();
if (!state.inCircle() || state.calledByLazyAttribute()) {
state.enterCircle();
boolean new_assignedAfter_Variable_value;
do {
_value.cycle = state.nextCycle();
new_assignedAfter_Variable_value = assignedAfter_compute(v);
if (((Boolean)_value.value) != new_assignedAfter_Variable_value) {
state.setChangeInCycle();
_value.value = new_assignedAfter_Variable_value;
}
} while (state.testAndClearChangeInCycle());
assignedAfter_Variable_values.put(_parameters, new_assignedAfter_Variable_value);
state.leaveCircle();
return new_assignedAfter_Variable_value;
} else if (_value.cycle != state.cycle()) {
_value.cycle = state.cycle();
boolean new_assignedAfter_Variable_value = assignedAfter_compute(v);
if (((Boolean)_value.value) != new_assignedAfter_Variable_value) {
state.setChangeInCycle();
_value.value = new_assignedAfter_Variable_value;
}
return new_assignedAfter_Variable_value;
} else {
return (Boolean) _value.value;
}
}
/** @apilevel internal */
private boolean assignedAfter_compute(Variable v) {
if (!(!noDefaultLabel() || getExpr().assignedAfter(v))) {
return false;
}
if (!(!switchLabelEndsBlock() || getExpr().assignedAfter(v))) {
return false;
}
if (!assignedAfterLastStmt(v)) {
return false;
}
for (BreakStmt stmt : targetBreaks()) {
if (!stmt.assignedAfterReachedFinallyBlocks(v)) {
return false;
}
}
return true;
}
/**
* @attribute syn
* @aspect DefiniteAssignment
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:708
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:708")
public boolean assignedAfterLastStmt(Variable v) {
boolean assignedAfterLastStmt_Variable_value = getBlock().assignedAfter(v);
return assignedAfterLastStmt_Variable_value;
}
/** @apilevel internal */
private void unassignedAfter_Variable_reset() {
unassignedAfter_Variable_values = null;
}
protected java.util.Map unassignedAfter_Variable_values;
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true)
@ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:895")
public boolean unassignedAfter(Variable v) {
Object _parameters = v;
if (unassignedAfter_Variable_values == null) unassignedAfter_Variable_values = new java.util.HashMap(4);
ASTState.CircularValue _value;
if (unassignedAfter_Variable_values.containsKey(_parameters)) {
Object _cache = unassignedAfter_Variable_values.get(_parameters);
if (!(_cache instanceof ASTState.CircularValue)) {
return (Boolean) _cache;
} else {
_value = (ASTState.CircularValue) _cache;
}
} else {
_value = new ASTState.CircularValue();
unassignedAfter_Variable_values.put(_parameters, _value);
_value.value = true;
}
ASTState state = state();
if (!state.inCircle() || state.calledByLazyAttribute()) {
state.enterCircle();
boolean new_unassignedAfter_Variable_value;
do {
_value.cycle = state.nextCycle();
new_unassignedAfter_Variable_value = unassignedAfter_compute(v);
if (((Boolean)_value.value) != new_unassignedAfter_Variable_value) {
state.setChangeInCycle();
_value.value = new_unassignedAfter_Variable_value;
}
} while (state.testAndClearChangeInCycle());
unassignedAfter_Variable_values.put(_parameters, new_unassignedAfter_Variable_value);
state.leaveCircle();
return new_unassignedAfter_Variable_value;
} else if (_value.cycle != state.cycle()) {
_value.cycle = state.cycle();
boolean new_unassignedAfter_Variable_value = unassignedAfter_compute(v);
if (((Boolean)_value.value) != new_unassignedAfter_Variable_value) {
state.setChangeInCycle();
_value.value = new_unassignedAfter_Variable_value;
}
return new_unassignedAfter_Variable_value;
} else {
return (Boolean) _value.value;
}
}
/** @apilevel internal */
private boolean unassignedAfter_compute(Variable v) {
if (!(!noDefaultLabel() || getExpr().unassignedAfter(v))) {
return false;
}
if (!(!switchLabelEndsBlock() || getExpr().unassignedAfter(v))) {
return false;
}
if (!unassignedAfterLastStmt(v)) {
return false;
}
for (BreakStmt stmt : targetBreaks()) {
if (!stmt.unassignedAfterReachedFinallyBlocks(v)) {
return false;
}
}
return true;
}
/** @apilevel internal */
private void unassignedAfterLastStmt_Variable_reset() {
unassignedAfterLastStmt_Variable_values = null;
}
protected java.util.Map unassignedAfterLastStmt_Variable_values;
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN, isCircular=true)
@ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:1378")
public boolean unassignedAfterLastStmt(Variable v) {
Object _parameters = v;
if (unassignedAfterLastStmt_Variable_values == null) unassignedAfterLastStmt_Variable_values = new java.util.HashMap(4);
ASTState.CircularValue _value;
if (unassignedAfterLastStmt_Variable_values.containsKey(_parameters)) {
Object _cache = unassignedAfterLastStmt_Variable_values.get(_parameters);
if (!(_cache instanceof ASTState.CircularValue)) {
return (Boolean) _cache;
} else {
_value = (ASTState.CircularValue) _cache;
}
} else {
_value = new ASTState.CircularValue();
unassignedAfterLastStmt_Variable_values.put(_parameters, _value);
_value.value = true;
}
ASTState state = state();
if (!state.inCircle() || state.calledByLazyAttribute()) {
state.enterCircle();
boolean new_unassignedAfterLastStmt_Variable_value;
do {
_value.cycle = state.nextCycle();
new_unassignedAfterLastStmt_Variable_value = getBlock().unassignedAfter(v);
if (((Boolean)_value.value) != new_unassignedAfterLastStmt_Variable_value) {
state.setChangeInCycle();
_value.value = new_unassignedAfterLastStmt_Variable_value;
}
} while (state.testAndClearChangeInCycle());
unassignedAfterLastStmt_Variable_values.put(_parameters, new_unassignedAfterLastStmt_Variable_value);
state.leaveCircle();
return new_unassignedAfterLastStmt_Variable_value;
} else if (_value.cycle != state.cycle()) {
_value.cycle = state.cycle();
boolean new_unassignedAfterLastStmt_Variable_value = getBlock().unassignedAfter(v);
if (((Boolean)_value.value) != new_unassignedAfterLastStmt_Variable_value) {
state.setChangeInCycle();
_value.value = new_unassignedAfterLastStmt_Variable_value;
}
return new_unassignedAfterLastStmt_Variable_value;
} else {
return (Boolean) _value.value;
}
}
/**
* @attribute syn
* @aspect DefiniteUnassignment
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:1381
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="DefiniteUnassignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:1381")
public boolean switchLabelEndsBlock() {
boolean switchLabelEndsBlock_value = getBlock().getNumStmt() > 0
&& getBlock().getStmt(getBlock().getNumStmt()-1) instanceof ConstCase;
return switchLabelEndsBlock_value;
}
/** @apilevel internal */
private void caseMap_reset() {
caseMap_computed = null;
caseMap_value = null;
}
/** @apilevel internal */
protected ASTState.Cycle caseMap_computed = null;
/** @apilevel internal */
protected Map