1   
  2   
  3   
  4   
  5   
  6  """Contains few unrelated algorithms, which works on code creators tree""" 
  7   
  8  import re 
  9  from pygccxml import declarations 
 12      """Find all relevant code creators, which influennce on code generated by "me". 
 13       
 14      C++ allows to define aliases to namespaces. Py++ allows user to define aliases  
 15      to the namespace and will take this aliases into account when it generates  
 16      the code.  
 17       
 18      Example: 
 19       
 20        [a b c d e f g] 
 21               | 
 22               + [k l m] 
 23                    | 
 24                    + [y x] <-- we are here ( x ) 
 25                     
 26      return value is: [y,l,k,d,c,b,a] 
 27      """ 
 28      class impl: 
 29          def __init__( self, creator): 
 30              self._creator = creator 
  31           
 32          def _get_left_siblings( self, child ): 
 33              if not child or not child.parent: 
 34                  return [] 
 35              ids = map( id, child.parent.creators ) 
 36              child_index = ids.index( id( child ) ) 
 37              return child.parent.creators[:child_index] 
 38           
 39          def _get_definition_set( self, child ): 
 40              answer = [] 
 41              while child: 
 42                  answer.extend( self._get_left_siblings( child ) ) 
 43                  child = child.parent 
 44              return answer 
 45           
 46          def affect_creators(self): 
 47              return self._get_definition_set( self._creator ) 
 48      return impl( me ).affect_creators() 
 49   
 50  __RE_VALID_IDENTIFIER = re.compile( r"[_a-z]\w*", re.I | re.L | re.U ) 
 52      """Create valid name\\Python identifier from a string 
 53       
 54      As input this functions takes valid C++ name\identifier and replaces all invalid 
 55      characters.  
 56   
 57      Invalid characters are introduced by a template instantiation. 
 58      """ 
 59      global __RE_VALID_IDENTIFIER 
 60      match_found = __RE_VALID_IDENTIFIER.match(name) 
 61      if match_found and ( match_found.end() - match_found.start() == len(name) ): 
 62          return name 
 63      replace_table = { 
 64            '<'  : '_less_' 
 65          , '>'  : '_greater_' 
 66          , '::' : '_scope_' 
 67          , ','  : '_comma_' 
 68          , ' '  : '_' 
 69          , '\t' : '_' 
 70          , '*'  : '_ptr_' 
 71          , '&'  : '_ref_' 
 72          , '('  : '_obrace_' 
 73          , ')'  : '_cbrace_' 
 74          , '['  : '_o_sq_brace_' 
 75          , ']'  : '_c_sq_brace_' 
 76          , '='  : '_equal_' 
 77          , '.'  : '_dot_' 
 78          , '$'  : '_dollar_' 
 79      } 
 80      for orig, dest in replace_table.items(): 
 81          name = name.replace( orig, dest ) 
 82      return name 
  83   
 99       
101      """class-namespace, introduce few functions, which deals with functions 
102      registration order problem: http://www.language-binding.net/pyplusplus/documentation/functions/registration_order.html 
103      """ 
104       
105      @staticmethod 
132   
133      @staticmethod 
 150