Skip to content

Rebinding

slepher edited this page Oct 12, 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
  • Extra Rebinding Scope Groups in strict mode
    • Function Call Arguments
    • Tuple
    • List
    • Map
    • Map Update
    • Record
    • Record Update
    • Oprator
  • 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 - nonfun_clause - shadowed:false
  • Extra Rebinding Scopes in strict mode
    • Function Call Argument - funcall_argument - shadowed:false
    • Tuple Member - expression_member - shadowed:false
    • List Member - expression_member - shadowed:false
    • Map Member - expression_member - shadowed:false
    • Map Update Member - expression_member - shadowed:false
    • Record Member - expression_member - shadowed:false
    • Record Update Member - expression_member - shadowed:false
    • Oprator Member - expression_member - 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
      • push scope renames to scope stack
      • empty scope varialbes
      • empty scope renames
    • Exit
      • merge scope group variables to local variables
      • merge scope renames variables to local renames
  • Rebinding Scope
    • entry
      • push local variables to variables stack
      • push local renames to renames stack
      • emtpy local variables
      • empty local renames
    • exit
      • nonfun_clause
        • merge local variables to scope variables
        • 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
      • funcall_argument
        • merge local variables to scope variables
        • merge local renames to scope renames
        • global variables regenerate from full variables stack
        • local variables from pop variables stack
      • shadowed:true
        • 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 | match_clause (while clause_pinned is false).
      • 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 (while clause_pinned is true) | pinned_match_clause.
      • rename by global renames
Clone this wiki locally