Class Navigate.LocalReferenceNormalizer

java.lang.Object
eu.bandm.tools.d2d2.model.MATCH_ONLY_00
eu.bandm.tools.d2d2.model.SinglePhase
eu.bandm.tools.d2d2.base.Navigate.LocalReferenceNormalizer
Enclosing class:
Navigate

public static class Navigate.LocalReferenceNormalizer extends SinglePhase
Replaces hard every referring identifier which is local to some declared object by the normalized identifier, as valid on module level.

It does remove only syntactic sugar, namely an abbreviated way of writing for a compound identifier. Any non-compound reference text (= written without any dot) appearing in the expression of a definition is searched for in the local defs of this definition, and then in the local siblings of this definition.

(This is the same strategy when resolving relative module names.)

So the following transformation applies:

       def b =  ___                            def b =  ___
       def a =  ___ b ___                      def a =  ___ a.b ___          
       with local tags b = _ c _ d      =====> with local tags b = ___ a.b.c _ a.d
                  with local tags c = __ d __         with local tags c = __ a.d __
                       end local                                end local
                  tags d = _ d _                          tags d = _ a.d _
            end local                               end local
  
No nesting is supported: only simple identifiers are compared with the names of the local definitions on the same level. So NO replacement happens for "b.c" in
       def a =  ___ b.c  ___
         with local tags b = ___ ____ 
           with local tags c = ___ b ___
  
Nor is there any replacement in the last argument of an explicit substitution expression, because this means an identifier as a textual component, not a reference to a definition:
       def a =  ___ (@c)^(x/b) ___      
         with local tags b = ___ b ___ 
  
This normalization must be done before any substitution is applied, because these operate on normalized but unresolved identifiers, simply replacing text. Therefore the textual representation of all references must be normalized, independently from the (later) resolution process.

This must be taken into consideration when writing replacement clauses:

       def a =  ___ b  ___      
         with local tags b = ___
   DOES REPLACE:                   DOES NOT REPLACE:
       def x = @a ^(z/a.b)              def x = @a ^(z/b)       
  

Currently this normalization called once for each loaded uninstantiated Module out of ModuleRegistry.load_toplevel_module_from_stream(..)

  • Field Details

    • regexpLocals

      @Opt protected @Opt TagsRegExp regexpLocals
      The lowest definition to search for locals.
    • someLocals

      protected boolean someLocals
      Whether there are some local definitions, somewhere in the hierarchy.
  • Constructor Details

    • LocalReferenceNormalizer

      public LocalReferenceNormalizer()
  • Method Details

    • action

      public void action(Module mod)
      Service entry point for normalizing all references in an uninstantiated module.
      Overrides:
      action in class SinglePhase
    • action

      public void action(Subst x)
      Do not normalize the x in "a^(b/x)".
      Overrides:
      action in class SinglePhase
    • action

      public void action(CharsRegExp x)
      Chars Reg Exp do not have local defs.
      Overrides:
      action in class SinglePhase
    • action

      public void action(TagsRegExp x)
      Apply normalization to the expression value of a Tags Reg Exp and to its local definitions.
      Overrides:
      action in class SinglePhase
    • action

      public void action(Reference ref)
      Compound ids like "A.b" will not be replaced because they are never entered as keys in a directory of definitions (neither module-wide nor local).

      Does currently not recognize mixtures of locally meant prefix plus explicit qualification, like

         tags a =   b.c 
              with local tags b = // ...
                  with local tags c = // ...
                  end local 
              end local
       
      Overrides:
      action in class SinglePhase