public abstract class AST
extends java.lang.Object
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 "?".| Modifier and Type | Class and Description |
|---|---|
static class |
AST.MetaData
The metadata for a grammar's statically typed nodes.
|
| Modifier and Type | Field and Description |
|---|---|
static Type |
ACTION
The canonical parameterized action type.
|
static Type |
ANY
The canonical any type.
|
static Type |
CHAR
The canonical character reference type.
|
protected java.util.Map<java.lang.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 java.util.List<java.lang.String> |
importedModules
The list of imported module names.
|
protected java.util.Map<java.lang.String,java.lang.String> |
importedTypes
The map from simple type names to fully qualified type names.
|
static java.util.Set<java.lang.String> |
INTERNAL
The set of internal type names.
|
protected java.util.Map<java.lang.String,java.lang.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 java.util.Map<java.lang.String,java.lang.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 java.util.Map<java.lang.String,TupleT> |
tuples
The map from tuple names to tuple types.
|
protected java.util.Map<java.lang.String,java.util.List<VariantT>> |
tupleVariants
The map from tuple names to variants containing the tuples.
|
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
variantNodes
The map from variant names to nodes.
|
protected java.util.Map<java.lang.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 and Description |
|---|
AST()
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
java.lang.String |
extern(Type type)
Convert the specified type to a string.
|
protected abstract java.lang.String |
externAction(Type type)
Convert the specified action type to a string.
|
protected abstract java.lang.String |
externList(Type type)
Convert the specified list type to a string.
|
protected abstract java.lang.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(java.lang.String name)
Determine whether a tuple type with the specified name has been
created before.
|
boolean |
hasVariant(java.lang.String name)
Determine whether a variant type with the specified name has been
created before.
|
void |
importModule(java.lang.String module)
Import the specified module.
|
void |
importType(java.lang.String qualified,
java.lang.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(java.lang.String s)
Convert the specified string representation of a type into the
type.
|
protected abstract Type |
internAction(java.lang.String s)
Convert the specified string representation of an action type
into the type.
|
protected abstract Type |
internList(java.lang.String s)
Convert the specified string representation of a list type into
the type.
|
protected abstract Type |
internUser(java.lang.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(java.lang.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(java.lang.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(java.lang.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,
java.lang.String module)
Print the specified type.
|
java.lang.String |
toOriginal(VariantT variant)
Get the original name for the specified variant.
|
TupleT |
toTuple(java.lang.String name)
Get the tuple type with the specified name.
|
TupleT |
toTuple(VariantT variant)
Get the polymorphic tuple for the specified variant.
|
VariantT |
toVariant(java.lang.String name,
boolean poly)
Get the variant type with the specified name.
|
java.lang.String |
toVariantName(java.lang.String name)
Convert the specified production's name into a variant name.
|
java.util.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.
|
public static final java.util.Set<java.lang.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 java.util.Map<java.lang.String,Type> externToIntern
protected final java.util.Map<java.lang.String,java.lang.String> internToExtern
protected final java.util.List<java.lang.String> importedModules
protected final java.util.Map<java.lang.String,java.lang.String> importedTypes
protected final java.util.Map<java.lang.String,VariantT> variants
protected final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> variantNodes
protected final java.util.Map<java.lang.String,java.lang.String> originalNames
protected final java.util.Map<java.lang.String,TupleT> tuples
protected final java.util.Map<java.lang.String,java.util.List<VariantT>> tupleVariants
public AST()
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(java.lang.String module)
importedModules. The specified
module name must end with the appropriate separator.module - The module name.public void importType(java.lang.String qualified,
java.lang.String simple)
importedTypes.qualified - The fully qualified name.simple - The simple name.public abstract boolean isVoid(java.lang.String s)
s - The type as a string.true if the string represents the void type.public abstract boolean isGenericNode(java.lang.String s)
s - The type as a string.true if the string represents the generic
node type.public Type intern(java.lang.String s)
internList(String), internAction(String), and internUser(String) for list,
action, and user-defined types, respectively.s - The type as a string.java.lang.IllegalArgumentException - Signals that the string
representation is not a valid type.protected abstract Type internList(java.lang.String s)
s - The list type as a string.ErrorT.TYPE if the string does not
represent a list.protected abstract Type internAction(java.lang.String s)
s - The action type as a string.ErrorT.TYPE if the string does not
represent an action.protected abstract Type internUser(java.lang.String s)
s - The user-defined type as a string.java.lang.IllegalArgumentException - Signals that the string
representation is not a valid type.public java.lang.String extern(Type type)
externList(Type), externAction(Type), and
externUser(Type) for list, action, and user-defined
types, respectively.type - The type.protected abstract java.lang.String externList(Type type)
type - The list type.protected abstract java.lang.String externAction(Type type)
type - The action type.protected abstract java.lang.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 java.lang.String toVariantName(java.lang.String name)
name - The production's name.public boolean hasVariant(java.lang.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(java.lang.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 java.lang.String toOriginal(VariantT variant)
toVariant(String,boolean).variant - The variant.public boolean hasTuple(java.lang.String name)
name - The name.true if a tuple type with the name exists.public boolean isMonomorphic(java.lang.String name)
name - The name.true if a tuple type with the name exists
and is monomorphic.public TupleT toTuple(java.lang.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 java.util.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, java.lang.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.Copyright © 2014. All Rights Reserved.