Skip to content

Rebinding

slepher edited this page Sep 25, 2019 · 9 revisions

Usage

-include_lib("erlando/include/rebinding.hrl").

-rebinding_all(Opts).
-rebinding_fun(FAs).
-rebinding_fun({FAs, Opts}).

FAs = FA | [FA...].
FA = F | F/A.
Opts = Opt | [Opt...] | #{OptKey => OptValue}.
Opt = OptKey | {OptKey, OptValue}.
#{OptKey => OptValue} = #{debug => true | false}.

Rebinding Attributes

   -rebinding_all -rebinding_fun defines rebinding scope.
   -rebinding_all meaning rebinding scope is all function.
   -rebinding_fun meaning rebinding scope is in functions mentioned.
   rebinding options is avaliable in scope mentioned.
   rebinding option debug means print code after rebinding rules applied.
   if neither -rebinding_fun nor -rebinding_all is used, rebinding scope is all function and rebinding options is [].

Types

  • Rebinding Scope Groups
    • Case/If/Try-Catch/Receive
    • Function Call Arguments
  • Rebinding Scopes
    • Function Clause - shadowed:true
    • Named Function - shadowed:true
    • List/BitString Comprehension - shadowed:true
    • List/BitString Comprehension Generate Pattern - shadowed:true
    • Case/If/Try-Catch/Receive Clause - shadowed:false
    • Function Call Argument - shadowed:false
  • Rebinding Pattern Variable Group
    • Function Patterns
    • Case/If/Try-Catch/Receive Clause Pattern
    • Match Left Pattern
    • List/BitString Comprehension Generate Pattern
  • Rebinding Pattern Variable
    • Function Pattern Variable - function_clause
    • Case/If/Try-Catch/Receive Clause Pattern Variable - match_clause
    • Match Left Pattern Variable - match_left
    • New Syntax: Left Pattern Variable with Oprator + Before - pinned_match_left
    • List/BitString Comprehension Generate Pattern Variable - comprehension_generate

Rebinding Strategy

  • Rebinding Scope Group
    • Entry
      • push scope variables to scope stack
      • empty scope varialbes
    • Exit
      • merge scope group variables to local variables
  • Rebinding Scope
    • entry
      • push local variables to variables stack
      • push local renames to renames stack
      • emtpy local variables
      • empty local renames
    • exit
      • shadowed:false
        • merge local variables to scope variables
      • shadowed:true
        • no extra changes
      • global variables regenerate from full variables stack
      • local variables from pop variables stack
      • global renames regenerate by full renames stack
      • local renames regenerate from pop renames stack
  • Rebinding Pattern Variable Group
    • entry
      • clear pattern variables
    • exit
      • clear pattern variables
  • Rebinding Pattern Variable
    • function_clause | match_left | comprehension_generate
      • exists in pattern variables
        • rename by global renames
      • not exists in pattern variables
        • exists in global variables
          • generate a new variable name
          • update global renames by new variable name
          • update local renames by new variable name
          • insert new variable name to local variables
          • insert new variable name to global variables
        • not exists in global variables
          • variable local variables
          • insert variable name to local variables
          • insert variable name to global variables
    • pinned_match_left | match_clause
      • rename by global renames
Clone this wiki locally