org.extendj.ast.ConstCase 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:298
* @astdecl ConstCase : Case ::= Value:Expr;
* @production ConstCase : {@link Case} ::= Value:{@link Expr};
*/
public class ConstCase extends Case implements Cloneable {
/**
* @aspect Java4PrettyPrint
* @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:243
*/
public void prettyPrint(PrettyPrinter out) {
out.print("case ");
out.print(getValue());
out.print(":");
}
/**
* @declaredat ASTNode:1
*/
public ConstCase() {
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 = {"Value"},
type = {"Expr"},
kind = {"Child"}
)
public ConstCase(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();
}
/** @apilevel internal
* @declaredat ASTNode:36
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:40
*/
public ConstCase clone() throws CloneNotSupportedException {
ConstCase node = (ConstCase) super.clone();
return node;
}
/** @apilevel internal
* @declaredat ASTNode:45
*/
public ConstCase copy() {
try {
ConstCase node = (ConstCase) 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:64
*/
@Deprecated
public ConstCase 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:74
*/
public ConstCase treeCopyNoTransform() {
ConstCase tree = (ConstCase) 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:94
*/
public ConstCase treeCopy() {
ConstCase tree = (ConstCase) 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:108
*/
protected boolean is$Equal(ASTNode node) {
return super.is$Equal(node);
}
/**
* Replaces the Value child.
* @param node The new node to replace the Value child.
* @apilevel high-level
*/
public void setValue(Expr node) {
setChild(node, 0);
}
/**
* Retrieves the Value child.
* @return The current node used as the Value child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="Value")
public Expr getValue() {
return (Expr) getChild(0);
}
/**
* Retrieves the Value child.
* This method does not invoke AST transformations.
* @return The current node used as the Value child.
* @apilevel low-level
*/
public Expr getValueNoTransform() {
return (Expr) getChildNoTransform(0);
}
/**
* @aspect NameCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/NameCheck.jrag:667
*/
private boolean refined_NameCheck_ConstCase_constValue_Case(Case c)
{
if (!(c instanceof ConstCase) || !getValue().isConstant()) {
return false;
}
if (!getValue().type().assignableToInt()
|| !((ConstCase) c).getValue().type().assignableToInt()) {
return false;
}
return getValue().constant().intValue() == ((ConstCase) c).getValue().constant().intValue();
}
/**
* @attribute syn
* @aspect NameCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/NameCheck.jrag:574
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="NameCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/NameCheck.jrag:574")
public Collection nameProblems() {
{
if (getValue().isConstant() && previousCase(this) != this) {
return Collections.singletonList(errorf(
"constant expression %s is multiply declared in two case statements",
getValue().prettyPrint()));
}
return Collections.emptyList();
}
}
/**
* @return {@code true} if this case label has the same constant value as
* the argument case label.
* @attribute syn
* @aspect NameCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/NameCheck.jrag:665
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="NameCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/NameCheck.jrag:665")
public boolean constValue(Case c) {
{
if (switchType().isEnumDecl()) {
if (!(c instanceof ConstCase) || !getValue().isConstant()) {
return false;
}
return getValue().varDecl() == ((ConstCase) c).getValue().varDecl();
} else {
return refined_NameCheck_ConstCase_constValue_Case(c);
}
}
}
/**
* @attribute syn
* @aspect TypeCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:470
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:470")
public Collection typeProblems() {
{
Collection problems = new LinkedList();
boolean isEnumConstant = getValue().isEnumConstant();
if (switchType().isEnumDecl() && !isEnumConstant) {
problems.add(error("Unqualified enumeration constant required"));
} else {
TypeDecl type = getValue().type();
if (!type.assignConversionTo(switchType(), getValue())) {
problems.add(error("Constant expression must be assignable to Expression"));
}
if (!getValue().isConstant() && !type.isUnknown() && !isEnumConstant) {
problems.add(error("Switch expression must be constant"));
}
}
return problems;
}
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/EnhancedFor.jrag:138
* @apilevel internal
*/
public SimpleSet Define_lookupVariable(ASTNode _callerNode, ASTNode _childNode, String name) {
if (getValueNoTransform() != null && _callerNode == getValue()) {
// @declaredat /home/jesper/git/extendj/java5/frontend/Enums.jrag:644
return switchType().isEnumDecl()
? switchType().memberFields(name)
: lookupVariable(name);
}
else {
return getParent().Define_lookupVariable(this, _callerNode, name);
}
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/EnhancedFor.jrag:138
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute lookupVariable
*/
protected boolean canDefine_lookupVariable(ASTNode _callerNode, ASTNode _childNode, String name) {
return true;
}
/** @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/NameCheck.jrag:572
{
java.util.Set contributors = _map.get(_root);
if (contributors == null) {
contributors = new java.util.LinkedHashSet();
_map.put((ASTNode) _root, contributors);
}
contributors.add(this);
}
// @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:468
{
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 : nameProblems()) {
collection.add(value);
}
for (Problem value : typeProblems()) {
collection.add(value);
}
}
}