Class Resolver

java.lang.Object
eu.bandm.tools.d2d2.base.Resolver

public final class Resolver extends Object
Changes an unresolved module into a resolved one.
Tactics are :
  1. local identifers have already been expanded (to module level scope) during the "load_uninstantiated" process. (The method {---- link ModuleRegistry#load_toplevel_module_from_stream(java.io.InputStream,String)} already has called {--- link Navigate.LocalReferenceNormalizer()#match(Module)}!!)
  2. here make first a Co-Rewriters copy of the module and all (recursively) imported modules, in their raw, uninstantiated state.
  3. Then resolve all D2d.References (via "set_resolved()"), thereby stacking and applying all module-level substitutions.
  4. Then re-write all expression-level substitutions.
  5. Normalize the resulting expression: (1) eliminate "#empty" references, (2) eliminate seq/alt/perm with zero or one sub-elements, (3) flatten all nested permutations.
  6. At last do some (more typechecking) analyses: calc first set and calc character sets. THIS COULD BE DISLOCATED TO ONE LEVEL ABOVE !?

Can stop processing after errors encountered.
returns != null iff no error encountered.
All errors are reported into a MessageReceiver, which has to be monitored by the calling level!

Only calling level is currently ModuleRegistry.
  • Field Details

  • Constructor Details

  • Method Details

    • error

      protected void error(Location<XMLDocumentIdentifier> loc, String txt)
    • error

      protected void error(Location<XMLDocumentIdentifier> loc, String txt, Object... obj)
    • warning

      protected void warning(Location<XMLDocumentIdentifier> loc, String txt)
    • hint

      protected void hint(Location<XMLDocumentIdentifier> loc, String txt)
    • log

      protected void log(String txt)
    • failure

      protected void failure(String txt)
    • resolve

      public Module resolve(Module unresolved)
      Gets an "unresolved" module and resolves all imports.
      For each import item:
      1. loads the raw module,
      2. apply all substitutions,
      3. and do this for all imported modules recursively.
      Then for all declarations process the defining expression:
      1. resolve all references
      2. expand all local substitutions and insertions
      3. (( perform TYPE CHECKING / SITLL MISSING FIXME ???))
      4. calculate the values of all character set expressions
      5. calculate the director map ".firsts" for later parsing.
    • findLoop

      protected boolean findLoop(Location<XMLDocumentIdentifier> loc, Module mod)
    • copyModule

      Module copyModule(ImportItem importingItem, Module mod)
      Import all modules and apply the replacements given with an "import" directive, whenever this refers to an second import statement IN the imported module. (A second kind of module-level substs, which operate on references, are executed when resolving those, see below.)
      Visiting starts with the (externally requested) top-level module and follows the import statements. "importingItem" is the item which caused the loading of the module "mod" which is the context of "item". "importingItem" is null only for all imports into the top-level module.
      item is an import statement in the module imported by the current importingItem. so look in importingItem, whether there is a substitution for the prefix of this importitem, and iff, then replace its target module accordingly. The front-end representation looks like ...
        module a
          import B from b ^ (C/D)
          import C from c 
        end module
        module b
          import D from d
          tags x = ... D:y ...
        end module
      
      .. which will produce a virtual module b', imported into a, with the contents
        module b'
          import D from c
          ...
       
      In this case "B from b" is the "importingItem", containing "(C/D)" as a replacement, and "D from d" is the "item" to process.
      NOTE that there could be a further replacement
          module top
            import A from a ^ (X/C)
            import X from x
            //etc. 
          end module
       
      In this case the item "C from c" in module a must be processed (and replaced by "C from x") BEFORE the descending into "B from b", which will replace "D from d" by "D from x".
    • moduleLevelReplacementError

      void moduleLevelReplacementError(Location<XMLDocumentIdentifier> loc, String pref)
    • liftFirstsToSeq

      public static void liftFirstsToSeq(Expression exp, Seq ns)
      All directors from "from" are lifted into the directory maps of "to", to point to the "from"-expression.