org.extendj.ast.ArrayAccess 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;
/**
* An array type access.
*
* Array accesses only occur as suffixes to another qualifying expression,
* possibly including other array accesses. The last array access will be the
* innermost nested expression in a Dot chain starting with the array itself.
* @ast node
* @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:127
* @astdecl ArrayAccess : Access ::= Expr;
* @production ArrayAccess : {@link Access} ::= {@link Expr};
*/
public class ArrayAccess extends Access implements Cloneable {
/**
* @aspect Java4PrettyPrint
* @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:35
*/
public void prettyPrint(PrettyPrinter out) {
out.print("[");
out.print(getExpr());
out.print("]");
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:498
*/
public void createPushAssignmentResult(CodeGeneration gen) {
gen.DUP_X2(type());
}
/**
* @aspect CodeGeneration
* @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:254
*/
public void emitStore(CodeGeneration gen) {
type().emitArrayStore(gen);
}
/**
* @declaredat ASTNode:1
*/
public ArrayAccess() {
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 ArrayAccess(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();
type_reset();
unassignedAfter_Variable_reset();
}
/** @apilevel internal
* @declaredat ASTNode:38
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:42
*/
public ArrayAccess clone() throws CloneNotSupportedException {
ArrayAccess node = (ArrayAccess) super.clone();
return node;
}
/** @apilevel internal
* @declaredat ASTNode:47
*/
public ArrayAccess copy() {
try {
ArrayAccess node = (ArrayAccess) 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:66
*/
@Deprecated
public ArrayAccess 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:76
*/
public ArrayAccess treeCopyNoTransform() {
ArrayAccess tree = (ArrayAccess) 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:96
*/
public ArrayAccess treeCopy() {
ArrayAccess tree = (ArrayAccess) 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:110
*/
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);
}
/**
* @aspect AutoBoxingCodegen
* @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:443
*/
public void createAssignSimpleLoadDest(CodeGeneration gen) {
prevExpr().createBCode(gen);
prevExpr().emitCastTo(gen, type().arrayType());
getExpr().createBCode(gen);
getExpr().emitCastTo(gen, typeInt());
}
/**
* @aspect AutoBoxingCodegen
* @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:450
*/
public void createAssignLoadDest(CodeGeneration gen) {
prevExpr().createBCode(gen);
prevExpr().emitCastTo(gen, type().arrayType());
gen.DUP();
getExpr().createBCode(gen);
getExpr().emitCastTo(gen, typeInt());
gen.DUP_X1(typeInt());
type().emitArrayLoad(gen);
}
/**
* @aspect AutoBoxingCodegen
* @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:435
*/
public void createBCode(CodeGeneration gen) {
prevExpr().createBCode(gen);
prevExpr().emitCastTo(gen, type().arrayType());
getExpr().createBCode(gen);
getExpr().emitCastTo(gen, typeInt());
type().emitArrayLoad(gen);
}
/**
* Defines the expected kind of name for the left hand side in a qualified
* expression.
* @attribute syn
* @aspect SyntacticClassification
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:60
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="SyntacticClassification", declaredAt="/home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:60")
public NameType predNameType() {
NameType predNameType_value = NameType.EXPRESSION_NAME;
return predNameType_value;
}
/**
* @attribute syn
* @aspect AccessTypes
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:72
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="AccessTypes", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:72")
public boolean isArrayAccess() {
boolean isArrayAccess_value = true;
return isArrayAccess_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 = isQualified() ? qualifier().type().componentType() : unknownType();
if (state().inCircle()) {
type_computed = state().cycle();
} else {
type_computed = ASTState.NON_CYCLE;
}
return type_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:33
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:33")
public boolean isVariable() {
boolean isVariable_value = true;
return isVariable_value;
}
/**
* @attribute syn
* @aspect TypeCheck
* @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:176
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="TypeCheck", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:176")
public Collection typeProblems() {
{
Collection problems = new LinkedList();
if (isQualified() && !qualifier().type().isArrayDecl() && !qualifier().type().isUnknown()) {
problems.add(errorf("the type %s of the indexed element is not an array",
qualifier().type().name()));
}
if (!getExpr().type().unaryNumericPromotion().isInt() || !getExpr().type().isIntegralType()) {
problems.add(errorf("array index must be int after unary numeric promotion which %s is not",
getExpr().type().typeName()));
}
return problems;
}
}
/**
* @attribute inh
* @aspect TypeAnalysis
* @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:303
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="TypeAnalysis", declaredAt="/home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:303")
public TypeDecl unknownType() {
TypeDecl unknownType_value = getParent().Define_unknownType(this, null);
return unknownType_value;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
* @apilevel internal
*/
public NameType Define_nameType(ASTNode _callerNode, ASTNode _childNode) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:141
return NameType.EXPRESSION_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/java4/frontend/LookupType.jrag:113
* @apilevel internal
*/
public boolean Define_hasPackage(ASTNode _callerNode, ASTNode _childNode, String packageName) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:120
return unqualifiedScope().hasPackage(packageName);
}
else {
return getParent().Define_hasPackage(this, _callerNode, packageName);
}
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:113
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute hasPackage
*/
protected boolean canDefine_hasPackage(ASTNode _callerNode, ASTNode _childNode, String packageName) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:231
* @apilevel internal
*/
public SimpleSet Define_lookupType(ASTNode _callerNode, ASTNode _childNode, String name) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:389
return unqualifiedScope().lookupType(name);
}
else {
return getParent().Define_lookupType(this, _callerNode, name);
}
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:231
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute lookupType
*/
protected boolean canDefine_lookupType(ASTNode _callerNode, ASTNode _childNode, String name) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java5/frontend/EnhancedFor.jrag:138
* @apilevel internal
*/
public SimpleSet Define_lookupVariable(ASTNode _callerNode, ASTNode _childNode, String name) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/LookupVariable.jrag:248
return unqualifiedScope().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;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:34
* @apilevel internal
*/
public boolean Define_isDest(ASTNode _callerNode, ASTNode _childNode) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:53
return false;
}
else {
return getParent().Define_isDest(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:34
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute isDest
*/
protected boolean canDefine_isDest(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:44
* @apilevel internal
*/
public boolean Define_isSource(ASTNode _callerNode, ASTNode _childNode) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:54
return true;
}
else {
return getParent().Define_isSource(this, _callerNode);
}
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:44
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute isSource
*/
protected boolean canDefine_isSource(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:116
* @apilevel internal
*/
public Collection Define_lookupMethod(ASTNode _callerNode, ASTNode _childNode, String name) {
if (getExprNoTransform() != null && _callerNode == getExpr()) {
// @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:132
return unqualifiedScope().lookupMethod(name);
}
else {
return getParent().Define_lookupMethod(this, _callerNode, name);
}
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:116
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute lookupMethod
*/
protected boolean canDefine_lookupMethod(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/TypeCheck.jrag:174
{
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);
}
}
}