|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectxtc.type.AST
public abstract class AST
Common type operations for Rats! ASTs.
This class supports two views on a grammar's generic AST. The first view is dynamically typed, with all generic AST nodes represented by the canonical node type. The second view is statically typed, with all generic AST nodes represented by tuples organized into variants. Either way, this class supports the following types:VoidT.UnitT.InternalT with name
"char".InternalT with name
"string".InternalT with name
"token".InternalT
with name "node".VariantT with
TupleT elements.InternalT
with name "formatting".InternalT with name
"list".InternalT with name
"action".Constants.ATT_NODE attribute; the
dynamically typed node representing generic productions also has
the Constants.ATT_GENERIC attribute.
In addition to generic ASTs, this class also supports
user-defined types, which must be represented by types that are not
listed above.
Concrete subclasses specify the mapping between strings and
types. For mapping internal representations back to strings, the
void type has name "void", the unit type has name "unit", and the
wildcard has name "?".
| Nested Class Summary | |
|---|---|
static class |
AST.MetaData
The metadata for a grammar's statically typed nodes. |
| Field Summary | |
|---|---|
static Type |
ACTION
The canonical parameterized action type. |
static Type |
ANY
The canonical any type. |
static Type |
CHAR
The canonical character reference type. |
protected Map<String,Type> |
externToIntern
The map from strings to type representations. |
static Type |
FORMATTING
The canonical formatting node type. |
static Type |
GENERIC
The canonical dynamically typed generic node type. |
protected List<String> |
importedModules
The list of imported module names. |
protected Map<String,String> |
importedTypes
The map from simple type names to fully qualified type names. |
static Set<String> |
INTERNAL
The set of internal type names. |
protected Map<String,String> |
internToExtern
The map from internal type names to external types. |
static Type |
LIST
The canonical parameterized list type. |
static Type |
NODE
The canonical dynamically typed node type. |
static Type |
NULL_NODE
The canonical null node type. |
protected Map<String,String> |
originalNames
The map from unqualified variant names to original names. |
static Type |
STRING
The canonical string type. |
static Type |
TOKEN
The canonical token type. |
protected Map<String,TupleT> |
tuples
The map from tuple names to tuple types. |
protected Map<String,List<VariantT>> |
tupleVariants
The map from tuple names to variants containing the tuples. |
protected Map<String,Set<String>> |
variantNodes
The map from variant names to nodes. |
protected Map<String,VariantT> |
variants
The map from variant names to variant types. |
static Type |
VOID
The canonical void type, which is VoidT.TYPE. |
static Type |
WILD_ACTION
The canonical action instantiated with a wildcard element type. |
static Type |
WILD_LIST
The canonical list instantiated with a wildcard element type. |
| Constructor Summary | |
|---|---|
AST()
Create a new instance. |
|
| Method Summary | |
|---|---|
static Type |
actionOf(Type element)
Create a new action type. |
void |
add(TupleT tuple,
VariantT variant)
Add the specified tuple type to the specified variant type. |
Type |
combine(TupleT tuple1,
TupleT tuple2,
boolean flatten,
boolean strict)
Combine the specified tuple types into a consistent type. |
Type |
concretize(Type type,
Type concrete)
Ensure that the specified type is concrete. |
void |
concretizeTuples(VariantT variant,
Type concrete)
Concretize the specified variant type's tuples. |
String |
extern(Type type)
Convert the specified type to a string. |
protected abstract String |
externAction(Type type)
Convert the specified action type to a string. |
protected abstract String |
externList(Type type)
Convert the specified list type to a string. |
protected abstract String |
externUser(Type type)
Convert the specified user-defined type to a string. |
Type |
flatten(TupleT tuple,
boolean strict)
Flatten the specified tuple type. |
static Type |
getArgument(Type type)
Get the specified instantiated type's only argument. |
AST.MetaData |
getMetaData(VariantT variant)
Determine the metadata for the specified variant. |
Constants.FuzzyBoolean |
hasLocation(Type type)
Determine whether instances of the specified type have a source location. |
protected abstract Constants.FuzzyBoolean |
hasLocationUser(Type type)
Determine whether instances of the specified user-defined type have a source location. |
boolean |
hasTuple(String name)
Determine whether a tuple type with the specified name has been created before. |
boolean |
hasVariant(String name)
Determine whether a variant type with the specified name has been created before. |
void |
importModule(String module)
Import the specified module. |
void |
importType(String qualified,
String simple)
Import the specified type. |
abstract void |
initialize(boolean hasNode,
boolean hasToken,
boolean hasFormatting,
boolean hasAction)
Initialize the mapping between external and internal representations. |
Type |
intern(String s)
Convert the specified string representation of a type into the type. |
protected abstract Type |
internAction(String s)
Convert the specified string representation of an action type into the type. |
protected abstract Type |
internList(String s)
Convert the specified string representation of a list type into the type. |
protected abstract Type |
internUser(String s)
Convert the specified string representation of a user-defined type into its internal representation. |
static boolean |
isAction(Type type)
Determine whether the specified type is an action. |
static boolean |
isAny(Type type)
Determine whether the specified type is the any type. |
static boolean |
isChar(Type type)
Determine whether the specified type is a character. |
static boolean |
isDynamicNode(Type type)
Determine whether the specified type is a dynamically typed node. |
static boolean |
isFormatting(Type type)
Determine whether the specified type is a formatting node. |
abstract boolean |
isGenericNode(String s)
Determine whether the specified string represents the generic node type. |
static boolean |
isGenericNode(Type type)
Determine whether the specified type is a generic node. |
static boolean |
isList(Type type)
Determine whether the specified type is a list. |
boolean |
isMonomorphic(String name)
Determine whether the tuple type with the specified name has been created before and is monomorphic. |
static boolean |
isNode(Type type)
Determine whether the specified type is a node. |
static boolean |
isNullNode(Type type)
Determine whether the specified type is a null node. |
static boolean |
isOptional(Type type)
Determine whether the specified type is optional. |
static boolean |
isStaticNode(Type type)
Determine whether the specified type is a statically typed node. |
static boolean |
isString(Type type)
Determine whether the specified type is a string. |
static boolean |
isToken(Type type)
Determine whether the specified type is a token. |
static boolean |
isUser(Type type)
Determine whether the specified type is user-defined. |
static boolean |
isVariable(Type type)
Determine whether the specified type is variable. |
abstract boolean |
isVoid(String s)
Determine whether the specified string represents the void type. |
static boolean |
isVoid(Type type)
Determine whether the specified type is the void type. |
static Type |
listOf(Type element)
Create a new list type. |
static Type |
markOptional(Type type)
Mark the specified type as optional. |
static Type |
markVariable(Type type)
Mark the specified type as variable. |
boolean |
overlap(VariantT v1,
VariantT v2)
Determine whether the specified variants overlap. |
void |
print(Type type,
Printer printer,
boolean refIsDecl,
boolean qualified,
String module)
Print the specified type. |
String |
toOriginal(VariantT variant)
Get the original name for the specified variant. |
TupleT |
toTuple(String name)
Get the tuple type with the specified name. |
TupleT |
toTuple(VariantT variant)
Get the polymorphic tuple for the specified variant. |
VariantT |
toVariant(String name,
boolean poly)
Get the variant type with the specified name. |
String |
toVariantName(String name)
Convert the specified production's name into a variant name. |
List<VariantT> |
toVariants(TupleT tuple)
Get the specified tuple's variants. |
Type |
unify(Type t1,
Type t2,
boolean strict)
Unify the specified types. |
protected Type |
unify(VariantT v1,
VariantT v2)
Unify the specified statically typed nodes. |
protected abstract Type |
unifyUser(Type t1,
Type t2,
boolean strict)
Unify the specified user-defined types. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Set<String> INTERNAL
public static final Type VOID
VoidT.TYPE.
public static final Type ANY
public static final Type CHAR
public static final Type STRING
public static final Type TOKEN
public static final Type NODE
public static final Type NULL_NODE
public static final Type GENERIC
public static final Type FORMATTING
public static final Type LIST
public static final Type WILD_LIST
public static final Type ACTION
public static final Type WILD_ACTION
protected final Map<String,Type> externToIntern
protected final Map<String,String> internToExtern
protected final List<String> importedModules
protected final Map<String,String> importedTypes
protected final Map<String,VariantT> variants
protected final Map<String,Set<String>> variantNodes
protected final Map<String,String> originalNames
protected final Map<String,TupleT> tuples
protected final Map<String,List<VariantT>> tupleVariants
| Constructor Detail |
|---|
public AST()
initialize(boolean,boolean,boolean,boolean)| Method Detail |
|---|
public abstract void initialize(boolean hasNode,
boolean hasToken,
boolean hasFormatting,
boolean hasAction)
externToIntern
and internToExtern data structures.
hasNode - Flag to indicate use of built-in nodes.hasToken - Flag to indicate use of tokens.hasFormatting - Flag to indicate use of formatting.hasAction - Flag to indicate use of actions.public void importModule(String module)
importedModules. The specified
module name must end with the appropriate separator.
module - The module name.
public void importType(String qualified,
String simple)
importedTypes.
qualified - The fully qualified name.simple - The simple name.public abstract boolean isVoid(String s)
s - The type as a string.
true if the string represents the void type.public abstract boolean isGenericNode(String s)
s - The type as a string.
true if the string represents the generic
node type.public Type intern(String s)
internList(String), internAction(String), and internUser(String) for list,
action, and user-defined types, respectively.
s - The type as a string.
IllegalArgumentException - Signals that the string
representation is not a valid type.protected abstract Type internList(String s)
s - The list type as a string.
ErrorT.TYPE if the string does not
represent a list.protected abstract Type internAction(String s)
s - The action type as a string.
ErrorT.TYPE if the string does not
represent an action.protected abstract Type internUser(String s)
s - The user-defined type as a string.
IllegalArgumentException - Signals that the string
representation is not a valid type.public String extern(Type type)
externList(Type), externAction(Type), and
externUser(Type) for list, action, and user-defined
types, respectively.
type - The type.
protected abstract String externList(Type type)
type - The list type.
protected abstract String externAction(Type type)
type - The action type.
protected abstract String externUser(Type type)
type - The user-defined type.
public Constants.FuzzyBoolean hasLocation(Type type)
hasLocationUser(Type)
for user-defined types.
type - The type.
protected abstract Constants.FuzzyBoolean hasLocationUser(Type type)
type - The type.
public static boolean isOptional(Type type)
type - The type.
true if the specified type is optional.public static boolean isVariable(Type type)
type - The type.
true if the specified type is variable.public static boolean isVoid(Type type)
type - The type.
true if the type is the void type.public static boolean isAny(Type type)
type - The type.
true if the type is the any type.public static boolean isChar(Type type)
type - The type.
true if the type is a character.public static boolean isString(Type type)
type - The type.
true if the type is a string.public static boolean isToken(Type type)
type - The type.
true if the type is a token.public static boolean isNode(Type type)
type - The type.
true if the type is a node.public static boolean isDynamicNode(Type type)
type - The type.
true if the type is a dynamically typed
node.public static boolean isNullNode(Type type)
type - The type.
true if the type is a null node.public static boolean isStaticNode(Type type)
type - The type.
true if the type is a statically typed node.public static boolean isGenericNode(Type type)
type - The type.
true if the type is a generic node.public static boolean isFormatting(Type type)
type - The type.
true if the type is a formatting node.public static boolean isList(Type type)
type - The type.
true if the type is a list.public static boolean isAction(Type type)
type - The type.
true if the type is an action.public static Type getArgument(Type type)
type - The instantiated type.
public static boolean isUser(Type type)
type - The type.
true if the type is a user-defined type.public static Type markOptional(Type type)
type - The type.
public static Type markVariable(Type type)
type - The type.
public String toVariantName(String name)
name - The production's name.
public boolean hasVariant(String name)
toVariant(String,boolean) before.
name - The name in camel case.
true if a variant type with the name exists.toVariantName(String)
public VariantT toVariant(String name,
boolean poly)
Constants.ATT_NODE attribute.
name - The name in camel case.poly - The flag for whether the variant is polymorphic.
toVariantName(String)public String toOriginal(VariantT variant)
toVariant(String,boolean).
variant - The variant.
public boolean hasTuple(String name)
name - The name.
true if a tuple type with the name exists.public boolean isMonomorphic(String name)
name - The name.
true if a tuple type with the name exists
and is monomorphic.public TupleT toTuple(String name)
name - The name.
public void add(TupleT tuple,
VariantT variant)
toTuple(String) or toTuple(VariantT). The specified
variant must have been created with toVariant(String,boolean).
tuple - The tuple.variant - The variant.public List<VariantT> toVariants(TupleT tuple)
toTuple(String) or toTuple(VariantT). It must have
been added to any variants with add(TupleT,VariantT).
tuple - The tuple.
public TupleT toTuple(VariantT variant)
toVariant(String,boolean).
variant - The variant.
public boolean overlap(VariantT v1,
VariantT v2)
toVariant(String,boolean).
v1 - The first variant.v2 - The second variant.
true if the two variants overlap.public AST.MetaData getMetaData(VariantT variant)
variant - The variant.
public static Type listOf(Type element)
element - The element type.
public static Type actionOf(Type element)
element - The element type.
public Type unify(Type t1,
Type t2,
boolean strict)
unify(VariantT,VariantT) for statically typed nodes and to
unifyUser(Type,Type,boolean) for user-defined types.
t1 - The first type.t2 - The second type.strict - The flag for strict unification.
ErrorT.TYPE if the two types
do not unify.
protected Type unify(VariantT v1,
VariantT v2)
v1 - The first variant.v2 - The second variant.
protected abstract Type unifyUser(Type t1,
Type t2,
boolean strict)
t1 - The first user-defined type.t2 - The second user-defined type.strict - The flag for strict unification.
ErrorT.TYPE if the two types
do not unify.
public Type flatten(TupleT tuple,
boolean strict)
tuple - The tuple type.strict - The flag for strict unification.
ErrorT.TYPE if types
cannot be unified.
public Type combine(TupleT tuple1,
TupleT tuple2,
boolean flatten,
boolean strict)
tuple1 - The first tuple.tuple2 - The second tuple.flatten - The flag for flattening lists.strict - The flag for strict unification.
ErrorT.TYPE if the two
tuple types cannot be combined into a consistent type.
public Type concretize(Type type,
Type concrete)
type - The type.concrete - The concrete replacement for wildcards.
concretizeTuples(VariantT,Type)
public void concretizeTuples(VariantT variant,
Type concrete)
variant - The variant.concrete - The concrete replacement for wildcards.concretize(Type,Type)
public void print(Type type,
Printer printer,
boolean refIsDecl,
boolean qualified,
String module)
printer - The printer.type - The type.refIsDecl - The flag for whether a variant type reference
also is a declaration.qualified - The flag for printing qualified names.module - The current module name, which may be null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||