public class Resolver3 extends Rewrite
resolveAllPublics()
.
resolvedModule
ist self-contained: All Definitions rewritten
from imported modules are cloned to definitions contained directly therein;
as NAME they get the original name prepended by the complete import prefix path.
resolveAllPublics() | | | | V createNewInstance(..) ^ V / Clone the definition object, | Call rewriting match(..) for the | RegExp = def.value. | | | | | V | | | action(Subst/Insertion) | =update rewriting contexts | V | | rewriteFields([div. constructors]) | =rewrite expression objects, filling | fields with rewrite of sub-expr | V | rewriteFields(Reference) | () Apply local rewrites and | visit target expression recursively | () or else apply import level rewrites | and visit target expr. recursively | () or else restore "frozen @" replacement context | and visit again. | () otherwise: | | | V | visitPossiblyImportedDef(..) | V | | loadImportedModule() | V | visitDefinition(..) | () if instance for this combination (of rawDef and importContext) | does NOT exist: | create a new Instance and start its rewriting. | on return: if ".cyclic" is not set: set ".complete" | // now an instance exists: | () if instance is not "bound()": memorize a classifcation request | () if !.complete and insert mode then set .cyclic | () if insertMode && !cyclic: rewrite reference to | rewritten contents/expression | () if insertMode && cyclic: rewrite reference to | "@ x" combination, "x" the rewritten definition | () else store rewritten instance as reference's ".resolved" | (The results are stored in two maps : | "reference2rawDef" and "reference2importContext".) | | | | | | | | \ V \ processWaitingReferences() \ V \ ->processWaitingReference(..) /\ creates a new Instance object, which / \ is either its own class, or related to another / \ Instance of the same raw def as its representative / \ (hypothetically or confirmed). | \ | | | \V | | createNewInstance(..) | V | equivalent(ref's def, old instantiation of same def) | V | (new Equivalence()).match() \ V \ descend(Reference) \----------------Central object is
Resolver3.Instance
which is built for every found combination of
Definition
and Resolver3.ImportContext
.
(Additionally Instances will be needed for combinations of local substitution,
insert operation and recursive call as in "@x^(a/b)" with "x=...x...".
This is done by the methods createNewInstance(ImportContext,Definition,Reference)
and newHypothesis(Instance)
.
The former also does the CLONING of the Definition
object and the rewriting
of the expression. (The latter only creates a new Instance object reflecting the
hypothesis of being equivalent with the method's argument.)
Resolver3.Instance
, which is an "equivalence class", i.e. its own representative.
During this, each expression value is visited with the rewriting method
of this class, and all rewriting directives (local and coming with module imports)
are applied.
As a result, all reached Reference
s are attributed by the maps
reference2rawDef
and reference2importContext
, reflecting the result
of applying all rewrite directives. Resolver3.Instance
is addressed globally by a "characteristic pair"
of raw definition and import context.
Additionally a reached reference is entered in the set waitingForEquivalence
,
iff there is no Resolver3.Instance
yet for this combination, or only one with a failed
hypothesis.
processWaitingReference(Reference)
: Resolver3.Instance
exists,
nothing is done.Resolver3.Instance
is created. Every already existing Resolver3.Instance
for the same raw definition, which is an equivalence class, i.e. its own
representative, is tested against the import context of the critical reference
by calling equivalent(Definition,Definition)
.Instance.hypothesisConfirmed()
is called
on this hypothesis, making it a permanent fact.Instance.setIsClass()
.
Resolver3.Equivalence
goes from the two
definitions to the two expressions, and visits them pairwise. Resolver3.DifferenceFound
.Reference
s are reached, first processWaitingReference(Reference)
is called for both of them recursively, and then the representatives of the two
resulting Instance objects are compared.Resolver3.Instance
which is currently under test against some equivalence class has
been stored in currentHypothesis
. So, whenever an Resolver3.Instance
(=x) is reached
which is itself hypothetical, the dependency is memorized by adding "currentHypothesis"
to "x.requiredBy" and setting "currentHypothesis.requires=true" (This is for optimization
/object reuse only).
Reference
(from Resolver3.Instance.reprRef
is re-entered into
waitingForEquivalence
.
Modifier and Type | Class and Description |
---|---|
protected class |
Resolver3.Binding<T>
Stack frame which memorizes a particular single rewriting clause, mapping an identifier
to an expression.
|
protected class |
Resolver3.DifferenceFound |
class |
Resolver3.DistributeSolutions
Adjusts alle reachable references to point to the representative of its
equivalence class: by the pointer ".resolved" to the rewritten Definition object,
as well as by "sourceText" to the compound name.
|
protected class |
Resolver3.Equivalence |
protected class |
Resolver3.FlattenContext
Stack frame which memorizes the situation when parsing an "insert operator" = "@".
|
static class |
Resolver3.Formatter_showingResolution |
protected class |
Resolver3.ImportContext
Stack frames which represent dynamic import situations.
|
protected class |
Resolver3.Instance
The parametrized instance of one particular d2d model
Definition . |
Modifier and Type | Field and Description |
---|---|
protected @Opt String |
currentDefinitionName
The name of the definition (local to its containing module), the expression of
which is currently rewritten.
|
protected Resolver3.FlattenContext |
currentFlattenContext
Top of the stack of
Resolver3.FlattenContext s. |
protected @Opt ImportItem |
currentLexicalImportItem
The ImportItem when an expression is rewritten like "a" in
"import A from modA ^(a/b)".
|
protected Resolver3.Binding<Expression> |
currentLocalSubsts
Stack of bindings representing the nesting of local substitution expressions
of form
exp^(a/b) . |
protected Resolver3.DifferenceFound |
differenceFound |
protected CheckedMap_RD<String,Definition> |
emptyLocals
A constant map which contains NO local definitions, used as the value of
"localDefs" when a definition is cloned/instantiated.
|
protected Resolver3.ImportContext |
importContextForDefs
Where to look for the definition, meant by some particular reference value.
|
protected Resolver3.ImportContext |
importContextForRews
Where to look for rewrite instructions coming with the "ImportItem",
when rewriting references.
|
protected Map<Definition,Map<Resolver3.ImportContext,Resolver3.Instance>> |
instances
Maps indexed by the raw (=source level) definitions.
|
protected ModuleRegistry |
moduleRegistry
Where imported raw modules are loaded from.
|
protected MessageTee<SimpleMessage<XMLDocumentIdentifier>> |
msg |
protected MessageCounter<SimpleMessage<XMLDocumentIdentifier>> |
msgcount |
protected Map<Reference,Resolver3.ImportContext> |
reference2importContext
Central result of the rewriting process, which maps rewritten Reference objects
to the import context (=module import prefix chain=rewriting context) of the
finally meant definition.
|
protected Map<Reference,Definition> |
reference2rawDef
Central result of the rewriting process, which maps rewritten Reference objects
to the definition in the "raw" source module which is meant.
|
protected ResolvedModule |
resolvedModule
Output data: the result of the resolution process.
|
protected Resolver3.ImportContext |
rootImportContext
A synthetic/pseudo import context, to fulfill the role of "importContext" for the
top-level module, which is indeed NOT imported.
|
protected Module |
rootModule
Input data: the source module to be resolved.
|
static String |
rootModuleExpandedSuffix |
static String |
rootModuleSymbolicName |
protected boolean |
unify
Whether unification shall be used for minimization of instantiated definitions.
|
protected Set<Reference> |
waitingForEquivalence
Set of all references which have not yet been classified for equivalence.
|
_visitor_debug_stream, partial
Constructor and Description |
---|
Resolver3(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msgoutput,
ModuleRegistry moduleRegistry,
Module rootModule)
Central service providing method.
|
Modifier and Type | Method and Description |
---|---|
void |
action(Insertion ins)
Insert a new
Resolver3.FlattenContext on top of the stack of flatten contexts,
then descend into the sub-expression. |
void |
action(Perm x) |
void |
action(Subst subst)
Simply insert a new
Resolver3.Binding on top of the stack of local substs,
then descend into the sub-expression. |
protected Resolver3.Instance |
createNewInstance(Resolver3.ImportContext ic,
Definition raw,
@Opt Reference reprRef)
Central routine for processing a new instantiation of a particular definition
in a particular import context.
In case of XRegExp : Calls the main class visitor methods for applying
all rewriting expressions to the def's value. |
void |
dumpInstances() |
protected boolean |
equivalent(Definition def1,
Definition def2) |
protected boolean |
equivalent(Expression exp1,
Expression exp2) |
protected void |
error(Location<XMLDocumentIdentifier> loc,
String txt,
Object... obj) |
protected <T> @Opt Resolver3.Binding<T> |
findBinding(@Opt Resolver3.Binding<T> binding,
String id)
Is called with
currentLocalSubsts ; iterate through the chain of Resolver3.Binding . |
protected @Opt Resolver3.Instance |
findInstance(Definition raw,
Resolver3.ImportContext ic) |
protected Map<Resolver3.ImportContext,Resolver3.Instance> |
findInstances(Definition raw) |
protected @Opt Resolver3.ImportContext |
loadImportedModule(Location<XMLDocumentIdentifier> loc,
Resolver3.ImportContext ic,
String pref)
Load the imported module referred to in the
ImportItem with the
given name, and create and store a new Resolver3.ImportContext , if not yet done. |
protected Resolver3.Instance |
processWaitingReference(Reference ref)
Process one reference which has not yet been classified, but
already been resolved (i.e.
|
protected void |
processWaitingReferences()
Main service provider entry point to process all reachable references.
|
@Opt Module |
resolveAllPublics()
Central service providing method.
|
@Opt Module |
resolveAllPublics(boolean unify)
Central service providing method.
|
protected void |
rewriteFields(Alt clone)
Rewrite all sub-expessions; propagate "all are empty" upwards, or
replace singleton-alternative by its only member.
|
protected void |
rewriteFields(CharBinary clone)
Rewrite all sub-expessions; propagate "all are empty" upwards, or
replace singleton expression by its only member.
|
protected void |
rewriteFields(CharSetConst clone)
Simply clones.
|
protected void |
rewriteFields(GrUnary clone)
Rewrite the sub-expression; propagate "empty" upwards.
|
protected void |
rewriteFields(ParseParticle clone)
Rewrite sub-expression and propagate "empty" upwards.
|
protected void |
rewriteFields(Perm clone)
Rewrite all sub-expessions; propagate "all are empty" upwards, or
replace singleton-permutation by its only member.
|
void |
rewriteFields(Reference ref)
Central rewriting method: for one particular reference, apply local rewrite,
module import rewrite and inlining-expansion, in this sequential order.
|
protected void |
rewriteFields(Seq clone)
Rewrite all sub-expessions; propagate "all are empty" upwards, or
replace singleton-sequence by its only member.
|
protected void |
rewriteFields(StringConst clone)
Simply clones.
|
protected void |
switchModuleRest(Location<XMLDocumentIdentifier> loc,
String... prefs)
Skip the first id in compound id, since it has just been processed and caused a
module import context switch, and continue to resolve the rest, if any.
|
protected void |
visitDefinition(Location<XMLDocumentIdentifier> loc,
String... prefs)
We are currently rewriting a reference (the on-stock produced
clone is
currentReference ) and resolving it, and have finally applied
all rewritings of all levels and reached a reference text, one identifier or
more than one identifiers, joined by Chars.STRING_NAMING_LEVEL_SEPARATOR . |
protected void |
visitPossiblyImportedDefinition(Location<XMLDocumentIdentifier> loc,
String... prefs)
After all substitutions have been applied: find the source text meant by a reference.
|
protected void |
visitPossiblyImportedDefinition(Location<XMLDocumentIdentifier> loc,
String id) |
protected void |
warning(Location<XMLDocumentIdentifier> loc,
String txt,
Object... obj) |
action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, breakLoop, breakLoop, breakLoop, breakLoop, breakLoop, getResult, isMulti, lookUp, putToCache, revert, rewrite_typed, rewrite, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, rewriteFields, substitute_empty, substitute, useCache
_visitor_trace, action, action, action, action, foreignObject, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, nomatch
protected final MessageTee<SimpleMessage<XMLDocumentIdentifier>> msg
protected final MessageCounter<SimpleMessage<XMLDocumentIdentifier>> msgcount
protected final ModuleRegistry moduleRegistry
protected final Module rootModule
protected final Resolver3.ImportContext rootImportContext
protected final ResolvedModule resolvedModule
protected boolean unify
public static final String rootModuleSymbolicName
public static final String rootModuleExpandedSuffix
protected final CheckedMap_RD<String,Definition> emptyLocals
protected Resolver3.Binding<Expression> currentLocalSubsts
exp^(a/b)
.protected Resolver3.ImportContext importContextForRews
createNewInstance(ImportContext,Definition,Reference)
to the definition's import context,
before starting the rewrite of the definitions's expression.importContextForDefs
,
where that definition has been found.Resolver3.FlattenContext
is applied to a reference, it is
among the reconstructed context state.
(This is the only situation when it differs from importContextForDefs
, because
a verbatim, non-rewritten reference to a definition is meant in the same ImportContext
as the original definition currently under flattening, not in the ImportContext containing
the "@ A.B.x" statement.)protected Resolver3.ImportContext importContextForDefs
createNewInstance(ImportContext,Definition,Reference)
to the definition's import context.visitPossiblyImportedDefinition(Location, String...)
resolves the import
prefices.@Opt protected @Opt String currentDefinitionName
@Opt protected @Opt ImportItem currentLexicalImportItem
protected Resolver3.FlattenContext currentFlattenContext
Resolver3.FlattenContext
s. Pushed onto when an insert operator
is rewritten; popped from (in two steps) when a Reference
is reached by
this Rewriter and all other rewrite directives do not match.protected Map<Definition,Map<Resolver3.ImportContext,Resolver3.Instance>> instances
findInstances(Definition)
and by
findInstance(Definition, ImportContext)
; written only by
createNewInstance(ImportContext,Definition,Reference)
.protected Map<Reference,Definition> reference2rawDef
protected Map<Reference,Resolver3.ImportContext> reference2importContext
Resolver3.DistributeSolutions
the results are entered into ".resolved"protected Set<Reference> waitingForEquivalence
createNewInstance(ImportContext,Definition,Reference)
visitDefinition(Location,String...)
. ((FIXME REALLY !?!??))protected final Resolver3.DifferenceFound differenceFound
public Resolver3(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msgoutput, ModuleRegistry moduleRegistry, Module rootModule)
resolveAllPublics()
must be called.
(Can only by used once.)@Opt public @Opt Module resolveAllPublics()
@Opt public @Opt Module resolveAllPublics(boolean unify)
protected void error(Location<XMLDocumentIdentifier> loc, String txt, Object... obj)
protected void warning(Location<XMLDocumentIdentifier> loc, String txt, Object... obj)
@Opt protected <T> @Opt Resolver3.Binding<T> findBinding(@Opt @Opt Resolver3.Binding<T> binding, String id)
currentLocalSubsts
; iterate through the chain of Resolver3.Binding
.public void dumpInstances()
protected Map<Resolver3.ImportContext,Resolver3.Instance> findInstances(Definition raw)
@Opt protected @Opt Resolver3.Instance findInstance(Definition raw, Resolver3.ImportContext ic)
protected Resolver3.Instance createNewInstance(Resolver3.ImportContext ic, Definition raw, @Opt @Opt Reference reprRef)
XRegExp
: Calls the main class visitor methods for applying
all rewriting expressions to the def's value.
(During this, more Reference
s may be added to waitingForEquivalence
.)
Resolver3.Instance
object.processWaitingReference(Reference)
and NOT made own class,
but first made hypothetically equivalent with all other class-like instances first.newHypothesis(Instance)
, possibly reusing the object structure physically.public void action(Subst subst)
Resolver3.Binding
on top of the stack of local substs,
then descend into the sub-expression. Remove the binding on return.public void action(Insertion ins)
Resolver3.FlattenContext
on top of the stack of flatten contexts,
then descend into the sub-expression. Remove the binding on return.protected void rewriteFields(GrUnary clone)
rewriteFields
in class Rewrite
protected void rewriteFields(Alt clone)
rewriteFields
in class Rewrite
protected void rewriteFields(Perm clone)
rewriteFields
in class Rewrite
protected void rewriteFields(Seq clone)
rewriteFields
in class Rewrite
protected void rewriteFields(CharBinary clone)
rewriteFields
in class Rewrite
protected void rewriteFields(ParseParticle clone)
rewriteFields
in class Rewrite
protected void rewriteFields(CharSetConst clone)
rewriteFields
in class Rewrite
protected void rewriteFields(StringConst clone)
rewriteFields
in class Rewrite
public void rewriteFields(Reference ref)
rewriteFields
in class Rewrite
protected void visitPossiblyImportedDefinition(Location<XMLDocumentIdentifier> loc, String id)
protected void visitPossiblyImportedDefinition(Location<XMLDocumentIdentifier> loc, String... prefs)
visitDefinition(Location, String...)
.importContextForDef
and the caches of loaded raw modules.protected void switchModuleRest(Location<XMLDocumentIdentifier> loc, String... prefs)
@Opt protected @Opt Resolver3.ImportContext loadImportedModule(Location<XMLDocumentIdentifier> loc, Resolver3.ImportContext ic, String pref)
ImportItem
with the
given name, and create and store a new Resolver3.ImportContext
, if not yet done.ic
- the import context from which the module is importedpref
- the source text prefix of the import.protected void visitDefinition(Location<XMLDocumentIdentifier> loc, String... prefs)
currentReference
) and resolving it, and have finally applied
all rewritings of all levels and reached a reference text, one identifier or
more than one identifiers, joined by Chars.STRING_NAMING_LEVEL_SEPARATOR
.
importContextForDefs
.protected void processWaitingReferences()
waitingForEquivalence
and calls
processWaitingReference(Reference)
. Processing means resolving all substitutions
and classifying the adressed (rewritten) Definition into equivalence classes.
#createNewInstance(ImportContext,Definition.Reference)
, namely
when visiting the definion's expression. This is called initially by
resolveAllPublics(boolean)
and recursively during processing by
processWaitingReference(Reference)
.protected Resolver3.Instance processWaitingReference(Reference ref)
reference2rawDef
and reference2importContext
have been set, etc.)Resolver3.Instance
object (which is not a failed hypothesis)
then do nothing.
Otherwise test equivalence with all Instances of the same raw definition, which
are own equivalence classes. For this, a hypothetical equivalence is constructed
and equivalent(Definition,Definition)
is called. If this succeeds, the
hypothesis is confirmed. If all these fail, the Instance is made an equivalence class
on its own.protected boolean equivalent(Definition def1, Definition def2)
protected boolean equivalent(Expression exp1, Expression exp2)
see also the complete user documentation .