org.extendj.ast.ASTState Maven / Gradle / Ivy
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 class
* @declaredat ASTState:34
*/
public class ASTState extends java.lang.Object {
/**
* This class stores an attribute value tagged with an iteration ID for
* a circular evaluation.
*
* @apilevel internal
*/
protected static class CircularValue {
Object value;
Cycle cycle;
}
/**
* Instances of this class are used to uniquely identify circular evaluation iterations.
* These iteration ID objects are created for each new fixed-point iteration in
* a circular evaluation.
*
* @apilevel internal
*/
protected static class Cycle {
}
/**
* The iteration ID used outside of circular evaluation.
*
* This is the iteration ID when no circular evaluation is ongoing.
*/
public static final Cycle NON_CYCLE = new Cycle();
/**
* Tracks the state of the current circular evaluation. This class defines a
* stack structure where the next element on the stack is pointed to by the
* {@code next} field.
*
* @apilevel internal
*/
protected static class CircleState {
final CircleState next;
boolean change = false;
/** Evaluation depth of lazy attributes. */
int lazyAttribute = 0;
/** Cycle ID of the latest cycle in this circular evaluation. */
Cycle cycle = NON_CYCLE;
protected CircleState(CircleState next) {
this.next = next;
}
}
/** Sentinel circle state representing non-circular evaluation. */
private static final CircleState CIRCLE_BOTTOM = new CircleState(null);
/**
* Current circular state.
* @apilevel internal
*/
private CircleState circle = CIRCLE_BOTTOM;
/** @apilevel internal */
protected boolean inCircle() {
return circle != CIRCLE_BOTTOM;
}
/** @apilevel internal */
protected boolean calledByLazyAttribute() {
return circle.lazyAttribute > 0;
}
/** @apilevel internal */
protected void enterLazyAttribute() {
circle.lazyAttribute += 1;
}
/** @apilevel internal */
protected void leaveLazyAttribute() {
circle.lazyAttribute -= 1;
}
/** @apilevel internal */
protected void enterCircle() {
CircleState next = new CircleState(circle);
circle = next;
}
/**
* Maps circular attribute to last evaluated cycle index.
* @apilevel internal
*/
private java.util.Map