org.extendj.ast.Access 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 java.io.BufferedInputStream;
import java.io.DataInputStream;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.jastadd.util.*;
import java.io.File;
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;
/**
* An abstract access.
* Concrete subclasses include field, method, and type access.
* @ast node
* @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:69
* @astdecl Access : Expr;
* @production Access : {@link Expr};
*/
public abstract class Access extends Expr implements Cloneable {
/**
* Used by the parser to build a method access from a parsed, potentially qualified, name.
* @aspect QualifiedNames
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:451
*/
public Access buildMethodAccess(List arguments) {
throw new Error("Can not build method access from access of type "
+ getClass().getSimpleName());
}
/**
* @aspect QualifiedNames
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:474
*/
public Access addArrayDims(List list) {
Access a = this;
for (int i = 0; i < list.getNumChildNoTransform(); i++) {
Dims dims = (Dims) list.getChildNoTransform(i);
Opt opt = dims.getExprOpt();
if (opt.getNumChildNoTransform() == 1) {
a = new ArrayTypeWithSizeAccess(a, (Expr) opt.getChildNoTransform(0));
} else {
a = new ArrayTypeAccess(a);
}
a.setStart(dims.start());
a.setEnd(dims.end());
}
return a;
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:627
*/
protected void emitLoadLocalInNestedClass(CodeGeneration gen, Variable v) {
if (inExplicitConstructorInvocation() && enclosingBodyDecl() instanceof ConstructorDecl) {
ConstructorDecl c = (ConstructorDecl) enclosingBodyDecl();
v.type().emitLoadLocal(gen, c.localIndexOfEnclosingVariable(v));
} else {
String classname = hostType().constantPoolName();
String name = "val$" + v.name();
int index = gen.constantPool().addFieldref(classname, name, v.type());
gen.ALOAD(0, hostType());
gen.GETFIELD(index, v.type());
}
}
/**
* Generate bytecode to push on the stack the qualifier to access the variable v.
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:643
*/
protected void createLoadQualifier(CodeGeneration gen, Variable v) {
if (v.isField()) {
if (hasPrevExpr()) {
// Load explicit qualifier.
prevExpr().createBCode(gen);
// Pop qualifier stack element for class variables.
// This qualifier must be computed to ensure side effects are evaluated.
if (!prevExpr().isTypeAccess() && v.isClassVariable()) {
gen.POP(prevExpr().type());
} else {
prevExpr().emitCastTo(gen, fieldQualifierType());
}
} else if (v.isInstanceVariable()) {
emitThis(gen, fieldQualifierType());
}
}
}
/**
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:750
*/
public void emitThis(CodeGeneration gen, TypeDecl targetDecl) {
if (targetDecl == hostType()) {
gen.ALOAD(0, hostType());
} else {
TypeDecl enclosing = hostType();
if (inExplicitConstructorInvocation()) {
gen.ALOAD(1, enclosing.enclosing());
enclosing = enclosing.enclosing();
} else {
gen.ALOAD(0, enclosing);
}
while (enclosing != targetDecl) {
String classname = enclosing.constantPoolName();
enclosing = enclosing.enclosingType();
int index = gen.constantPool().addFieldref(classname, "this$0", enclosing);
gen.GETFIELD(index, enclosing);
}
}
}
/**
* @declaredat ASTNode:1
*/
public Access() {
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() {
}
/** @apilevel low-level
* @declaredat ASTNode:13
*/
protected int numChildren() {
return 0;
}
/**
* @apilevel internal
* @declaredat ASTNode:19
*/
public boolean mayHaveRewrite() {
return false;
}
/** @apilevel internal
* @declaredat ASTNode:23
*/
public void flushAttrCache() {
super.flushAttrCache();
type_reset();
}
/** @apilevel internal
* @declaredat ASTNode:28
*/
public void flushCollectionCache() {
super.flushCollectionCache();
}
/** @apilevel internal
* @declaredat ASTNode:32
*/
public Access clone() throws CloneNotSupportedException {
Access node = (Access) 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:43
*/
@Deprecated
public abstract Access 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:51
*/
public abstract Access 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:59
*/
public abstract Access treeCopy();
/**
* @attribute syn
* @aspect QualifiedNames
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:164
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="QualifiedNames", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:164")
public boolean isQualified() {
boolean isQualified_value = hasPrevExpr();
return isQualified_value;
}
/**
* @attribute syn
* @aspect QualifiedNames
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:167
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="QualifiedNames", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:167")
public Expr qualifier() {
Expr qualifier_value = prevExpr();
return qualifier_value;
}
/**
* @attribute syn
* @aspect QualifiedNames
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:174
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="QualifiedNames", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:174")
public Access lastAccess() {
Access lastAccess_value = this;
return lastAccess_value;
}
/**
* @attribute syn
* @aspect QualifiedNames
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:184
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="QualifiedNames", declaredAt="/home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:184")
public boolean hasPrevExpr() {
boolean hasPrevExpr_value = isRightChildOfDot();
return hasPrevExpr_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: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 = unknownType();
if (state().inCircle()) {
type_computed = state().cycle();
} else {
type_computed = ASTState.NON_CYCLE;
}
return type_value;
}
/**
* 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() {
{
switch (nameType()) {
case PACKAGE_NAME:
return NameType.PACKAGE_NAME;
case TYPE_NAME:
case PACKAGE_OR_TYPE_NAME:
return NameType.PACKAGE_OR_TYPE_NAME;
case AMBIGUOUS_NAME:
case EXPRESSION_NAME:
return NameType.AMBIGUOUS_NAME;
case NOT_CLASSIFIED:
default:
return NameType.NOT_CLASSIFIED;
}
}
}
/**
* Find the outermost qualified expression this access.
*
* If this is not a qualified access, then this access is returned.
*
*
For example, if {@code unqualifiedScope()} is evaluated for the {@code
* MethodAccess} inside the expression {@code Dot(FieldAccess,
* Dot(FieldAccess, MethodAcceess))}, then the outermost {@code Dot} is the
* unqualified scope of the {@code MethodAccess}.
* @attribute syn
* @aspect LookupMethod
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:87
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="LookupMethod", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:87")
public Expr unqualifiedScope() {
Expr unqualifiedScope_value = isQualified() ? nestedScope() : this;
return unqualifiedScope_value;
}
/**
* @return {@code true} if this access is a method call of a non-static method.
* @attribute syn
* @aspect GenerateClassfile
* @declaredat /home/jesper/git/extendj/java4/backend/GenerateClassfile.jrag:418
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="GenerateClassfile", declaredAt="/home/jesper/git/extendj/java4/backend/GenerateClassfile.jrag:418")
public boolean isInstanceMethodAccess() {
boolean isInstanceMethodAccess_value = false;
return isInstanceMethodAccess_value;
}
/**
* @attribute syn
* @aspect InnerClasses
* @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:57
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InnerClasses", declaredAt="/home/jesper/git/extendj/java4/backend/InnerClasses.jrag:57")
public TypeDecl fieldQualifierType() {
{
throw new Error("Can not evaluate fieldQualifierType() on node of type "
+ getClass().getSimpleName());
}
}
/**
* @attribute syn
* @aspect InnerClasses
* @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:135
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InnerClasses", declaredAt="/home/jesper/git/extendj/java4/backend/InnerClasses.jrag:135")
public TypeDecl superConstructorQualifier(TypeDecl targetEnclosingType) {
{
TypeDecl enclosing = hostType();
while (!enclosing.instanceOf(targetEnclosingType)) {
enclosing = enclosing.enclosingType();
}
return enclosing;
}
}
/**
* @attribute syn
* @aspect InnerClasses
* @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:394
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InnerClasses", declaredAt="/home/jesper/git/extendj/java4/backend/InnerClasses.jrag:394")
public boolean requiresAccessor() {
{
throw new Error("Can not evaluate requiresAccessor() on node of type "
+ getClass().getSimpleName());
}
}
/**
* @attribute syn
* @aspect CodeGeneration
* @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:38
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="CodeGeneration", declaredAt="/home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:38")
public int sourceLineNumber() {
int sourceLineNumber_value = findFirstSourceLineNumber();
return sourceLineNumber_value;
}
/**
* @attribute inh
* @aspect TypeScopePropagation
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:325
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="TypeScopePropagation", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupType.jrag:325")
public TypeDecl unknownType() {
TypeDecl unknownType_value = getParent().Define_unknownType(this, null);
return unknownType_value;
}
/**
* Find the outermost qualified expression of a qualified access.
*
*
It is an error if this attribute is evaluated on an unqualified
* access.
*
* @throws UnsupportedOperationException if evaluated on an unqualified
* access.
* @attribute inh
* @aspect LookupMethod
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:98
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="LookupMethod", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:98")
public Expr nestedScope() {
Expr nestedScope_value = getParent().Define_nestedScope(this, null);
return nestedScope_value;
}
/**
* @attribute inh
* @aspect VariableScopePropagation
* @declaredat /home/jesper/git/extendj/java4/frontend/LookupVariable.jrag:355
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="VariableScopePropagation", declaredAt="/home/jesper/git/extendj/java4/frontend/LookupVariable.jrag:355")
public Variable unknownField() {
Variable unknownField_value = getParent().Define_unknownField(this, null);
return unknownField_value;
}
/**
* @attribute inh
* @aspect CreateBCode
* @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:625
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH)
@ASTNodeAnnotation.Source(aspect="CreateBCode", declaredAt="/home/jesper/git/extendj/java4/backend/CreateBCode.jrag:625")
public boolean inExplicitConstructorInvocation() {
boolean inExplicitConstructorInvocation_value = getParent().Define_inExplicitConstructorInvocation(this, null);
return inExplicitConstructorInvocation_value;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:86
* @apilevel internal
*/
public boolean Define_isLeftChildOfDot(ASTNode _callerNode, ASTNode _childNode) {
int childIndex = this.getIndexOfChild(_callerNode);
return false;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:86
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute isLeftChildOfDot
*/
protected boolean canDefine_isLeftChildOfDot(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:101
* @apilevel internal
*/
public boolean Define_isRightChildOfDot(ASTNode _callerNode, ASTNode _childNode) {
int childIndex = this.getIndexOfChild(_callerNode);
return false;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:101
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute isRightChildOfDot
*/
protected boolean canDefine_isRightChildOfDot(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:118
* @apilevel internal
*/
public Expr Define_prevExpr(ASTNode _callerNode, ASTNode _childNode) {
int childIndex = this.getIndexOfChild(_callerNode);
return prevExprError();
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:118
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute prevExpr
*/
protected boolean canDefine_prevExpr(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:142
* @apilevel internal
*/
public Access Define_nextAccess(ASTNode _callerNode, ASTNode _childNode) {
int childIndex = this.getIndexOfChild(_callerNode);
return nextAccessError();
}
/**
* @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:142
* @apilevel internal
* @return {@code true} if this node has an equation for the inherited attribute nextAccess
*/
protected boolean canDefine_nextAccess(ASTNode _callerNode, ASTNode _childNode) {
return true;
}
/** @apilevel internal */
public ASTNode rewriteTo() {
return super.rewriteTo();
}
/** @apilevel internal */
public boolean canRewrite() {
return false;
}
}