org.extendj.ast.CastExpr 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/java4/grammar/Java.ast:261
* @astdecl CastExpr : Expr ::= TypeAccess:Access Expr;
* @production CastExpr : {@link Expr} ::= TypeAccess:{@link Access} {@link Expr};
*/
public class CastExpr extends Expr implements Cloneable {
/**
* @aspect Java4PrettyPrint
* @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:130
*/
public void prettyPrint(PrettyPrinter out) {
out.print("(");
out.print(getTypeAccess());
out.print(") ");
out.print(getExpr());
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1022
*/
public void createBCode(CodeGeneration gen) {
getExpr().createBCode(gen);
getExpr().emitCastTo(gen, type());
}
/**
* @declaredat ASTNode:1
*/
public CastExpr() {
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 = {"TypeAccess", "Expr"},
type = {"Access", "Expr"},
kind = {"Child", "Child"}
)
public CastExpr(Access 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();
unassignedAfter_Variable_reset();
}
/** @apilevel internal
* @declaredat ASTNode:39
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:43
*/
public CastExpr clone() throws CloneNotSupportedException {
CastExpr node = (CastExpr) super.clone();
return node;
}
/** @apilevel internal
* @declaredat ASTNode:48
*/
public CastExpr copy() {
try {
CastExpr node = (CastExpr) 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 CastExpr 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 CastExpr treeCopyNoTransform() {
CastExpr tree = (CastExpr) 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 CastExpr treeCopy() {
CastExpr tree = (CastExpr) 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 TypeAccess child.
* @param node The new node to replace the TypeAccess child.
* @apilevel high-level
*/
public void setTypeAccess(Access node) {
setChild(node, 0);
}
/**
* Retrieves the TypeAccess child.
* @return The current node used as the TypeAccess child.
* @apilevel high-level
*/
@ASTNodeAnnotation.Child(name="TypeAccess")
public Access getTypeAccess() {
return (Access) getChild(0);
}
/**
* Retrieves the TypeAccess child.
* This method does not invoke AST transformations.
* @return The current node used as the TypeAccess child.
* @apilevel low-level
*/
public Access getTypeAccessNoTransform() {
return (Access) getChildNoTransform(0);
}
/**
* Replaces the Expr child.
* @param node The new node to replace the Expr child.
* @apilevel high-level
*/
public void setExpr(Expr node) {
setChild(node, 1);
}
/**
* 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(1);
}
/**
* 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(1);
}
/**
* @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().cast(getExpr().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 = getExpr().isConstant()
&& (getTypeAccess().type().isPrimitive() || getTypeAccess().type().isString());
return isConstant_value;
}
/**
* @attribute syn
* @aspect AccessTypes
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:56
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="AccessTypes", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:56")
public boolean isSuperAccess() {
boolean isSuperAccess_value = getExpr().isSuperAccess();
return isSuperAccess_value;
}
/**
* @attribute syn
* @aspect AccessTypes
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:62
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="AccessTypes", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:62")
public boolean isThisAccess() {
boolean isThisAccess_value = getExpr().isThisAccess();
return isThisAccess_value;
}
/**
* Test if an expression contains an unresolved parse name.
* @attribute syn
* @aspect NameResolution
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:555
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="NameResolution", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:555")
public boolean containsParseName() {
boolean containsParseName_value = getTypeAccess().containsParseName() || getExpr().containsParseName();
return containsParseName_value;
}
/** @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:295
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeAnalysis", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:295")
public TypeDecl type() {
ASTState state = state();
if (type_computed == ASTState.NON_CYCLE || type_computed == state().cycle()) {
return type_value;
}
type_value = getTypeAccess().type();
if (state().inCircle()) {
type_computed = state().cycle();
} else {
type_computed = ASTState.NON_CYCLE;
}
return type_value;
}
/**
* @attribute syn
* @aspect TypeHierarchyCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:240
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeHierarchyCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:240")
public boolean staticContextQualifier() {
boolean staticContextQualifier_value = getExpr().staticContextQualifier();
return staticContextQualifier_value;
}
/**
* @attribute syn
* @aspect DefiniteAssignment
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:268
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="DefiniteAssignment", declaredAt="/home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:268")
public boolean assignedAfter(Variable v) {
boolean assignedAfter_Variable_value = getExpr().assignedAfter(v);
return assignedAfter_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:899")
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 = getExpr().unassignedAfter(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 = getExpr().unassignedAfter(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;
}
}
/**
* @attribute syn
* @aspect TypeCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:357
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:357")
public Collection typeProblems() {
{
Collection problems = new LinkedList();
TypeDecl expr = getExpr().type();
TypeDecl type = getTypeAccess().type();
if (!expr.isUnknown()) {
if (!expr.castingConversionTo(type)) {
problems.add(errorf("%s can not be cast into %s", expr.typeName(), type.typeName()));
}
if (!getTypeAccess().isTypeAccess()) {
problems.add(errorf("%s is not a type access in cast expression",
getTypeAccess().prettyPrint()));
}
}
return problems;
}
}
/**
* @attribute syn
* @aspect PreciseRethrow
* @declaredat /home/jesper/git/extendj/java7/frontend/PreciseRethrow.jrag:145
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="PreciseRethrow", declaredAt="/home/jesper/git/extendj/java7/frontend/PreciseRethrow.jrag:145")
public boolean modifiedInScope(Variable var) {
boolean modifiedInScope_Variable_value = getExpr().modifiedInScope(var);
return modifiedInScope_Variable_value;
}
/**
* @attribute syn
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1150
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="CreateBCode", declaredAt="/home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1150")
public boolean canBeTrue() {
boolean canBeTrue_value = getExpr().canBeTrue();
return canBeTrue_value;
}
/**
* @attribute syn
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1162
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="CreateBCode", declaredAt="/home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1162")
public boolean canBeFalse() {
boolean canBeFalse_value = getExpr().canBeFalse();
return canBeFalse_value;
}
/**
* @attribute inh
* @aspect SuppressWarnings
* @declaredat /home/jesper/git/extendj/java7/frontend/SuppressWarnings.jrag:37
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="SuppressWarnings", declaredAt="/home/jesper/git/extendj/java7/frontend/SuppressWarnings.jrag:37")
public boolean withinSuppressWarnings(String annot) {
boolean withinSuppressWarnings_String_value = getParent().Define_withinSuppressWarnings(this, null, annot);
return withinSuppressWarnings_String_value;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
* @apilevel internal
*/
public NameType Define_nameType(ASTNode _callerNode, ASTNode _childNode) {
if (getTypeAccessNoTransform() != null && _callerNode == getTypeAccess()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:111
return NameType.TYPE_NAME;
}
else {
return getParent().Define_nameType(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute nameType
*/
protected boolean canDefine_nameType(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @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:42
return type();
}
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:326
return false;
}
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:327
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:328
return true;
}
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:329
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:330
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;
}
/** @apilevel internal */
protected void collect_contributors_CompilationUnit_problems(CompilationUnit _root, java.util.Map> _map) {
// @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:355
{
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/java7/frontend/UncheckedConversion.jrag:56
if (!withinSuppressWarnings("unchecked")) {
{
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);
}
if (!withinSuppressWarnings("unchecked")) {
for (Problem value : uncheckedConversionWarnings(getExpr().type(), getTypeAccess().type())) {
collection.add(value);
}
}
}
}