proxygen
cpp.ast.AstBuilder Class Reference
Inheritance diagram for cpp.ast.AstBuilder:

Public Member Functions

def __init__ (self, token_stream, filename, in_class='', visibility=None, namespace_stack=[])
 
def HandleError (self, msg, token)
 
def Generate (self)
 
def GetScope (self)
 
def GetName (self, seq=None)
 
def GetMethod (self, modifiers, templated_types)
 
def handle_bool (self)
 
def handle_char (self)
 
def handle_int (self)
 
def handle_long (self)
 
def handle_short (self)
 
def handle_double (self)
 
def handle_float (self)
 
def handle_void (self)
 
def handle_wchar_t (self)
 
def handle_unsigned (self)
 
def handle_signed (self)
 
def handle_struct (self)
 
def handle_union (self)
 
def handle_enum (self)
 
def handle_auto (self)
 
def handle_register (self)
 
def handle_const (self)
 
def handle_inline (self)
 
def handle_extern (self)
 
def handle_static (self)
 
def handle_virtual (self)
 
def handle_volatile (self)
 
def handle_mutable (self)
 
def handle_public (self)
 
def handle_protected (self)
 
def handle_private (self)
 
def handle_friend (self)
 
def handle_static_cast (self)
 
def handle_const_cast (self)
 
def handle_dynamic_cast (self)
 
def handle_reinterpret_cast (self)
 
def handle_new (self)
 
def handle_delete (self)
 
def handle_typedef (self)
 
def handle_typeid (self)
 
def handle_typename (self)
 
def handle_template (self)
 
def handle_true (self)
 
def handle_false (self)
 
def handle_asm (self)
 
def handle_class (self)
 
def handle_namespace (self)
 
def handle_using (self)
 
def handle_explicit (self)
 
def handle_this (self)
 
def handle_operator (self)
 
def handle_sizeof (self)
 
def handle_case (self)
 
def handle_switch (self)
 
def handle_default (self)
 
def handle_if (self)
 
def handle_else (self)
 
def handle_return (self)
 
def handle_goto (self)
 
def handle_try (self)
 
def handle_catch (self)
 
def handle_throw (self)
 
def handle_while (self)
 
def handle_do (self)
 
def handle_for (self)
 
def handle_break (self)
 
def handle_continue (self)
 
def __init__ (self, token_stream, filename, in_class='', visibility=None, namespace_stack=[])
 
def HandleError (self, msg, token)
 
def Generate (self)
 
def GetScope (self)
 
def GetName (self, seq=None)
 
def GetMethod (self, modifiers, templated_types)
 
def handle_bool (self)
 
def handle_char (self)
 
def handle_int (self)
 
def handle_long (self)
 
def handle_short (self)
 
def handle_double (self)
 
def handle_float (self)
 
def handle_void (self)
 
def handle_wchar_t (self)
 
def handle_unsigned (self)
 
def handle_signed (self)
 
def handle_struct (self)
 
def handle_union (self)
 
def handle_enum (self)
 
def handle_auto (self)
 
def handle_register (self)
 
def handle_const (self)
 
def handle_inline (self)
 
def handle_extern (self)
 
def handle_static (self)
 
def handle_virtual (self)
 
def handle_volatile (self)
 
def handle_mutable (self)
 
def handle_public (self)
 
def handle_protected (self)
 
def handle_private (self)
 
def handle_friend (self)
 
def handle_static_cast (self)
 
def handle_const_cast (self)
 
def handle_dynamic_cast (self)
 
def handle_reinterpret_cast (self)
 
def handle_new (self)
 
def handle_delete (self)
 
def handle_typedef (self)
 
def handle_typeid (self)
 
def handle_typename (self)
 
def handle_template (self)
 
def handle_true (self)
 
def handle_false (self)
 
def handle_asm (self)
 
def handle_class (self)
 
def handle_namespace (self)
 
def handle_using (self)
 
def handle_explicit (self)
 
def handle_this (self)
 
def handle_operator (self)
 
def handle_sizeof (self)
 
def handle_case (self)
 
def handle_switch (self)
 
def handle_default (self)
 
def handle_if (self)
 
def handle_else (self)
 
def handle_return (self)
 
def handle_goto (self)
 
def handle_try (self)
 
def handle_catch (self)
 
def handle_throw (self)
 
def handle_while (self)
 
def handle_do (self)
 
def handle_for (self)
 
def handle_break (self)
 
def handle_continue (self)
 
def __init__ (self, token_stream, filename, in_class='', visibility=None, namespace_stack=[])
 
def HandleError (self, msg, token)
 
def Generate (self)
 
def GetScope (self)
 
def GetName (self, seq=None)
 
def GetMethod (self, modifiers, templated_types)
 
def handle_bool (self)
 
def handle_char (self)
 
def handle_int (self)
 
def handle_long (self)
 
def handle_short (self)
 
def handle_double (self)
 
def handle_float (self)
 
def handle_void (self)
 
def handle_wchar_t (self)
 
def handle_unsigned (self)
 
def handle_signed (self)
 
def handle_struct (self)
 
def handle_union (self)
 
def handle_enum (self)
 
def handle_auto (self)
 
def handle_register (self)
 
def handle_const (self)
 
def handle_inline (self)
 
def handle_extern (self)
 
def handle_static (self)
 
def handle_virtual (self)
 
def handle_volatile (self)
 
def handle_mutable (self)
 
def handle_public (self)
 
def handle_protected (self)
 
def handle_private (self)
 
def handle_friend (self)
 
def handle_static_cast (self)
 
def handle_const_cast (self)
 
def handle_dynamic_cast (self)
 
def handle_reinterpret_cast (self)
 
def handle_new (self)
 
def handle_delete (self)
 
def handle_typedef (self)
 
def handle_typeid (self)
 
def handle_typename (self)
 
def handle_template (self)
 
def handle_true (self)
 
def handle_false (self)
 
def handle_asm (self)
 
def handle_class (self)
 
def handle_namespace (self)
 
def handle_using (self)
 
def handle_explicit (self)
 
def handle_this (self)
 
def handle_operator (self)
 
def handle_sizeof (self)
 
def handle_case (self)
 
def handle_switch (self)
 
def handle_default (self)
 
def handle_if (self)
 
def handle_else (self)
 
def handle_return (self)
 
def handle_goto (self)
 
def handle_try (self)
 
def handle_catch (self)
 
def handle_throw (self)
 
def handle_while (self)
 
def handle_do (self)
 
def handle_for (self)
 
def handle_break (self)
 
def handle_continue (self)
 

Public Attributes

 tokens
 
 filename
 
 token_queue
 
 namespace_stack
 
 in_class
 
 in_class_name_only
 
 visibility
 
 in_function
 
 current_token
 
 converter
 

Private Member Functions

def _CreateVariable (self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
 
def _GenerateOne (self, token)
 
def _GetTokensUpTo (self, expected_token_type, expected_token)
 
def _GetVarTokensUpTo (self, expected_token_type, expected_tokens)
 
def _IgnoreUpTo (self, token_type, token)
 
def _SkipIf0Blocks (self)
 
def _GetMatchingChar (self, open_paren, close_paren, GetNextToken=None)
 
def _GetParameters (self)
 
def _GetNextToken (self)
 
def _AddBackToken (self, token)
 
def _AddBackTokens (self, tokens)
 
def _GetMethod (self, return_type_and_name, modifiers, templated_types, get_paren)
 
def _GetReturnTypeAndClassName (self, token_seq)
 
def _GetNestedType (self, ctor)
 
def _GetTemplatedTypes (self)
 
def _GetBases (self)
 
def _GetClass (self, class_type, visibility, templated_types)
 
def _CreateVariable (self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
 
def _GenerateOne (self, token)
 
def _GetTokensUpTo (self, expected_token_type, expected_token)
 
def _GetVarTokensUpTo (self, expected_token_type, expected_tokens)
 
def _IgnoreUpTo (self, token_type, token)
 
def _SkipIf0Blocks (self)
 
def _GetMatchingChar (self, open_paren, close_paren, GetNextToken=None)
 
def _GetParameters (self)
 
def _GetNextToken (self)
 
def _AddBackToken (self, token)
 
def _AddBackTokens (self, tokens)
 
def _GetMethod (self, return_type_and_name, modifiers, templated_types, get_paren)
 
def _GetReturnTypeAndClassName (self, token_seq)
 
def _GetNestedType (self, ctor)
 
def _GetTemplatedTypes (self)
 
def _GetBases (self)
 
def _GetClass (self, class_type, visibility, templated_types)
 
def _CreateVariable (self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
 
def _GenerateOne (self, token)
 
def _GetTokensUpTo (self, expected_token_type, expected_token)
 
def _GetVarTokensUpTo (self, expected_token_type, expected_tokens)
 
def _IgnoreUpTo (self, token_type, token)
 
def _SkipIf0Blocks (self)
 
def _GetMatchingChar (self, open_paren, close_paren, GetNextToken=None)
 
def _GetParameters (self)
 
def _GetNextToken (self)
 
def _AddBackToken (self, token)
 
def _AddBackTokens (self, tokens)
 
def _GetMethod (self, return_type_and_name, modifiers, templated_types, get_paren)
 
def _GetReturnTypeAndClassName (self, token_seq)
 
def _GetNestedType (self, ctor)
 
def _GetTemplatedTypes (self)
 
def _GetBases (self)
 
def _GetClass (self, class_type, visibility, templated_types)
 

Private Attributes

 _handling_typedef
 

Detailed Description

Definition at line 676 of file ast.py.

Constructor & Destructor Documentation

def cpp.ast.AstBuilder.__init__ (   self,
  token_stream,
  filename,
  in_class = '',
  visibility = None,
  namespace_stack = [] 
)

Definition at line 678 of file ast.py.

678  namespace_stack=[]):
679  self.tokens = token_stream
680  self.filename = filename
681  # TODO(nnorwitz): use a better data structure (deque) for the queue.
682  # Switching directions of the "queue" improved perf by about 25%.
683  # Using a deque should be even better since we access from both sides.
684  self.token_queue = []
685  self.namespace_stack = namespace_stack[:]
686  self.in_class = in_class
687  if in_class is None:
688  self.in_class_name_only = None
689  else:
690  self.in_class_name_only = in_class.split('::')[-1]
691  self.visibility = visibility
692  self.in_function = False
693  self.current_token = None
694  # Keep the state whether we are currently handling a typedef or not.
695  self._handling_typedef = False
696 
698 
def cpp.ast.AstBuilder.__init__ (   self,
  token_stream,
  filename,
  in_class = '',
  visibility = None,
  namespace_stack = [] 
)

Definition at line 678 of file ast.py.

References cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.converter, cpp.ast.AstBuilder.current_token, cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, cpp.ast.AstBuilder.in_class_name_only, cpp.ast.AstBuilder.in_function, cpp.ast.TypeConverter.namespace_stack, cpp.ast.AstBuilder.namespace_stack, cpp.ast.AstBuilder.token_queue, cpp.ast.AstBuilder.tokens, and cpp.ast.AstBuilder.visibility.

678  namespace_stack=[]):
679  self.tokens = token_stream
680  self.filename = filename
681  # TODO(nnorwitz): use a better data structure (deque) for the queue.
682  # Switching directions of the "queue" improved perf by about 25%.
683  # Using a deque should be even better since we access from both sides.
684  self.token_queue = []
685  self.namespace_stack = namespace_stack[:]
686  self.in_class = in_class
687  if in_class is None:
688  self.in_class_name_only = None
689  else:
690  self.in_class_name_only = in_class.split('::')[-1]
691  self.visibility = visibility
692  self.in_function = False
693  self.current_token = None
694  # Keep the state whether we are currently handling a typedef or not.
695  self._handling_typedef = False
696 
698 
def cpp.ast.AstBuilder.__init__ (   self,
  token_stream,
  filename,
  in_class = '',
  visibility = None,
  namespace_stack = [] 
)

Definition at line 678 of file ast.py.

References cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.converter, cpp.ast.AstBuilder.current_token, cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, cpp.ast.AstBuilder.in_class_name_only, cpp.ast.AstBuilder.in_function, cpp.ast.TypeConverter.namespace_stack, cpp.ast.AstBuilder.namespace_stack, cpp.ast.AstBuilder.token_queue, cpp.ast.AstBuilder.tokens, and cpp.ast.AstBuilder.visibility.

678  namespace_stack=[]):
679  self.tokens = token_stream
680  self.filename = filename
681  # TODO(nnorwitz): use a better data structure (deque) for the queue.
682  # Switching directions of the "queue" improved perf by about 25%.
683  # Using a deque should be even better since we access from both sides.
684  self.token_queue = []
685  self.namespace_stack = namespace_stack[:]
686  self.in_class = in_class
687  if in_class is None:
688  self.in_class_name_only = None
689  else:
690  self.in_class_name_only = in_class.split('::')[-1]
691  self.visibility = visibility
692  self.in_function = False
693  self.current_token = None
694  # Keep the state whether we are currently handling a typedef or not.
695  self._handling_typedef = False
696 
698 

Member Function Documentation

def cpp.ast.AstBuilder._AddBackToken (   self,
  token 
)
private

Definition at line 910 of file ast.py.

Referenced by cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder.handle_namespace(), cpp.ast.AstBuilder.handle_struct(), and cpp.ast.AstBuilder.handle_template().

910  def _AddBackToken(self, token):
911  if token.whence == tokenize.WHENCE_STREAM:
912  token.whence = tokenize.WHENCE_QUEUE
913  self.token_queue.insert(0, token)
914  else:
915  assert token.whence == tokenize.WHENCE_QUEUE, token
916  self.token_queue.append(token)
917 
def _AddBackToken(self, token)
Definition: ast.py:910
def cpp.ast.AstBuilder._AddBackToken (   self,
  token 
)
private

Definition at line 910 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken().

910  def _AddBackToken(self, token):
911  if token.whence == tokenize.WHENCE_STREAM:
912  token.whence = tokenize.WHENCE_QUEUE
913  self.token_queue.insert(0, token)
914  else:
915  assert token.whence == tokenize.WHENCE_QUEUE, token
916  self.token_queue.append(token)
917 
def _AddBackToken(self, token)
Definition: ast.py:910
def cpp.ast.AstBuilder._AddBackToken (   self,
  token 
)
private

Definition at line 910 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken().

910  def _AddBackToken(self, token):
911  if token.whence == tokenize.WHENCE_STREAM:
912  token.whence = tokenize.WHENCE_QUEUE
913  self.token_queue.insert(0, token)
914  else:
915  assert token.whence == tokenize.WHENCE_QUEUE, token
916  self.token_queue.append(token)
917 
def _AddBackToken(self, token)
Definition: ast.py:910
def cpp.ast.AstBuilder._AddBackTokens (   self,
  tokens 
)
private

Definition at line 918 of file ast.py.

References cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.reversed(), and cpp.ast.AstBuilder.token_queue.

918  def _AddBackTokens(self, tokens):
919  if tokens:
920  if tokens[-1].whence == tokenize.WHENCE_STREAM:
921  for token in tokens:
922  token.whence = tokenize.WHENCE_QUEUE
923  self.token_queue[:0] = reversed(tokens)
924  else:
925  assert tokens[-1].whence == tokenize.WHENCE_QUEUE, tokens
926  self.token_queue.extend(reversed(tokens))
927 
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def reversed(seq)
Definition: ast.py:52
def cpp.ast.AstBuilder._AddBackTokens (   self,
  tokens 
)
private

Definition at line 918 of file ast.py.

References cpp.ast.reversed(), and cpp.ast.AstBuilder.token_queue.

Referenced by cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder.handle_namespace(), cpp.ast.AstBuilder.handle_struct(), and cpp.ast.AstBuilder.handle_template().

918  def _AddBackTokens(self, tokens):
919  if tokens:
920  if tokens[-1].whence == tokenize.WHENCE_STREAM:
921  for token in tokens:
922  token.whence = tokenize.WHENCE_QUEUE
923  self.token_queue[:0] = reversed(tokens)
924  else:
925  assert tokens[-1].whence == tokenize.WHENCE_QUEUE, tokens
926  self.token_queue.extend(reversed(tokens))
927 
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def reversed(seq)
Definition: ast.py:52
def cpp.ast.AstBuilder._AddBackTokens (   self,
  tokens 
)
private

Definition at line 918 of file ast.py.

References cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.reversed(), and cpp.ast.AstBuilder.token_queue.

918  def _AddBackTokens(self, tokens):
919  if tokens:
920  if tokens[-1].whence == tokenize.WHENCE_STREAM:
921  for token in tokens:
922  token.whence = tokenize.WHENCE_QUEUE
923  self.token_queue[:0] = reversed(tokens)
924  else:
925  assert tokens[-1].whence == tokenize.WHENCE_QUEUE, tokens
926  self.token_queue.extend(reversed(tokens))
927 
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def reversed(seq)
Definition: ast.py:52
def cpp.ast.AstBuilder._CreateVariable (   self,
  pos_token,
  name,
  type_name,
  type_modifiers,
  ref_pointer_name_seq,
  templated_types,
  value = None 
)
private

Definition at line 728 of file ast.py.

References cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

728  ref_pointer_name_seq, templated_types, value=None):
729  reference = '&' in ref_pointer_name_seq
730  pointer = '*' in ref_pointer_name_seq
731  array = '[' in ref_pointer_name_seq
732  var_type = Type(pos_token.start, pos_token.end, type_name,
733  templated_types, type_modifiers,
734  reference, pointer, array)
735  return VariableDeclaration(pos_token.start, pos_token.end,
736  name, var_type, value, self.namespace_stack)
737 
def cpp.ast.AstBuilder._CreateVariable (   self,
  pos_token,
  name,
  type_name,
  type_modifiers,
  ref_pointer_name_seq,
  templated_types,
  value = None 
)
private

Definition at line 728 of file ast.py.

References cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

728  ref_pointer_name_seq, templated_types, value=None):
729  reference = '&' in ref_pointer_name_seq
730  pointer = '*' in ref_pointer_name_seq
731  array = '[' in ref_pointer_name_seq
732  var_type = Type(pos_token.start, pos_token.end, type_name,
733  templated_types, type_modifiers,
734  reference, pointer, array)
735  return VariableDeclaration(pos_token.start, pos_token.end,
736  name, var_type, value, self.namespace_stack)
737 
def cpp.ast.AstBuilder._CreateVariable (   self,
  pos_token,
  name,
  type_name,
  type_modifiers,
  ref_pointer_name_seq,
  templated_types,
  value = None 
)
private

Definition at line 728 of file ast.py.

References cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

Referenced by cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder.Generate(), and cpp.ast.AstBuilder.handle_struct().

728  ref_pointer_name_seq, templated_types, value=None):
729  reference = '&' in ref_pointer_name_seq
730  pointer = '*' in ref_pointer_name_seq
731  array = '[' in ref_pointer_name_seq
732  var_type = Type(pos_token.start, pos_token.end, type_name,
733  templated_types, type_modifiers,
734  reference, pointer, array)
735  return VariableDeclaration(pos_token.start, pos_token.end,
736  name, var_type, value, self.namespace_stack)
737 
def cpp.ast.AstBuilder._GenerateOne (   self,
  token 
)
private

Definition at line 738 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._GetVarTokensUpTo(), cpp.ast.AstBuilder._SkipIf0Blocks(), folly.enumerate(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, cpp.ast.AstBuilder.in_class_name_only, join, and folly::detail::distributed_mutex.strip().

Referenced by cpp.ast.AstBuilder._GenerateOne(), and cpp.ast.AstBuilder.Generate().

738  def _GenerateOne(self, token):
739  if token.token_type == tokenize.NAME:
740  if (keywords.IsKeyword(token.name) and
741  not keywords.IsBuiltinType(token.name)):
742  method = getattr(self, 'handle_' + token.name)
743  return method()
744  elif token.name == self.in_class_name_only:
745  # The token name is the same as the class, must be a ctor if
746  # there is a paren. Otherwise, it's the return type.
747  # Peek ahead to get the next token to figure out which.
748  next = self._GetNextToken()
749  self._AddBackToken(next)
750  if next.token_type == tokenize.SYNTAX and next.name == '(':
751  return self._GetMethod([token], FUNCTION_CTOR, None, True)
752  # Fall through--handle like any other method.
753 
754  # Handle data or function declaration/definition.
755  syntax = tokenize.SYNTAX
756  temp_tokens, last_token = \
757  self._GetVarTokensUpTo(syntax, '(', ';', '{', '[')
758  temp_tokens.insert(0, token)
759  if last_token.name == '(':
760  # If there is an assignment before the paren,
761  # this is an expression, not a method.
762  expr = bool([e for e in temp_tokens if e.name == '='])
763  if expr:
764  new_temp = self._GetTokensUpTo(tokenize.SYNTAX, ';')
765  temp_tokens.append(last_token)
766  temp_tokens.extend(new_temp)
767  last_token = tokenize.Token(tokenize.SYNTAX, ';', 0, 0)
768 
769  if last_token.name == '[':
770  # Handle array, this isn't a method, unless it's an operator.
771  # TODO(nnorwitz): keep the size somewhere.
772  # unused_size = self._GetTokensUpTo(tokenize.SYNTAX, ']')
773  temp_tokens.append(last_token)
774  if temp_tokens[-2].name == 'operator':
775  temp_tokens.append(self._GetNextToken())
776  else:
777  temp_tokens2, last_token = \
778  self._GetVarTokensUpTo(tokenize.SYNTAX, ';')
779  temp_tokens.extend(temp_tokens2)
780 
781  if last_token.name == ';':
782  # Handle data, this isn't a method.
783  parts = self.converter.DeclarationToParts(temp_tokens, True)
784  (name, type_name, templated_types, modifiers, default,
785  unused_other_tokens) = parts
786 
787  t0 = temp_tokens[0]
788  names = [t.name for t in temp_tokens]
789  if templated_types:
790  start, end = self.converter.GetTemplateIndices(names)
791  names = names[:start] + names[end:]
792  default = ''.join([t.name for t in default])
793  return self._CreateVariable(t0, name, type_name, modifiers,
794  names, templated_types, default)
795  if last_token.name == '{':
796  self._AddBackTokens(temp_tokens[1:])
797  self._AddBackToken(last_token)
798  method_name = temp_tokens[0].name
799  method = getattr(self, 'handle_' + method_name, None)
800  if not method:
801  # Must be declaring a variable.
802  # TODO(nnorwitz): handle the declaration.
803  return None
804  return method()
805  return self._GetMethod(temp_tokens, 0, None, False)
806  elif token.token_type == tokenize.SYNTAX:
807  if token.name == '~' and self.in_class:
808  # Must be a dtor (probably not in method body).
809  token = self._GetNextToken()
810  # self.in_class can contain A::Name, but the dtor will only
811  # be Name. Make sure to compare against the right value.
812  if (token.token_type == tokenize.NAME and
813  token.name == self.in_class_name_only):
814  return self._GetMethod([token], FUNCTION_DTOR, None, True)
815  # TODO(nnorwitz): handle a lot more syntax.
816  elif token.token_type == tokenize.PREPROCESSOR:
817  # TODO(nnorwitz): handle more preprocessor directives.
818  # token starts with a #, so remove it and strip whitespace.
819  name = token.name[1:].lstrip()
820  if name.startswith('include'):
821  # Remove "include".
822  name = name[7:].strip()
823  assert name
824  # Handle #include <newline> "header-on-second-line.h".
825  if name.startswith('\\'):
826  name = name[1:].strip()
827  assert name[0] in '<"', token
828  assert name[-1] in '>"', token
829  system = name[0] == '<'
830  filename = name[1:-1]
831  return Include(token.start, token.end, filename, system)
832  if name.startswith('define'):
833  # Remove "define".
834  name = name[6:].strip()
835  assert name
836  value = ''
837  for i, c in enumerate(name):
838  if c.isspace():
839  value = name[i:].lstrip()
840  name = name[:i]
841  break
842  return Define(token.start, token.end, name, value)
843  if name.startswith('if') and name[2:3].isspace():
844  condition = name[3:].strip()
845  if condition.startswith('0') or condition.startswith('(0)'):
846  self._SkipIf0Blocks()
847  return None
848 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
std::uint64_t strip(std::chrono::nanoseconds t)
def _GenerateOne(self, token)
Definition: ast.py:738
detail::RangeEnumerator< Range > enumerate(Range &&r)
Definition: Enumerate.h:167
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _SkipIf0Blocks(self)
Definition: ast.py:865
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder._GenerateOne (   self,
  token 
)
private

Definition at line 738 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._GetVarTokensUpTo(), cpp.ast.AstBuilder._SkipIf0Blocks(), folly.enumerate(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, cpp.ast.AstBuilder.in_class_name_only, join, and folly::detail::distributed_mutex.strip().

738  def _GenerateOne(self, token):
739  if token.token_type == tokenize.NAME:
740  if (keywords.IsKeyword(token.name) and
741  not keywords.IsBuiltinType(token.name)):
742  method = getattr(self, 'handle_' + token.name)
743  return method()
744  elif token.name == self.in_class_name_only:
745  # The token name is the same as the class, must be a ctor if
746  # there is a paren. Otherwise, it's the return type.
747  # Peek ahead to get the next token to figure out which.
748  next = self._GetNextToken()
749  self._AddBackToken(next)
750  if next.token_type == tokenize.SYNTAX and next.name == '(':
751  return self._GetMethod([token], FUNCTION_CTOR, None, True)
752  # Fall through--handle like any other method.
753 
754  # Handle data or function declaration/definition.
755  syntax = tokenize.SYNTAX
756  temp_tokens, last_token = \
757  self._GetVarTokensUpTo(syntax, '(', ';', '{', '[')
758  temp_tokens.insert(0, token)
759  if last_token.name == '(':
760  # If there is an assignment before the paren,
761  # this is an expression, not a method.
762  expr = bool([e for e in temp_tokens if e.name == '='])
763  if expr:
764  new_temp = self._GetTokensUpTo(tokenize.SYNTAX, ';')
765  temp_tokens.append(last_token)
766  temp_tokens.extend(new_temp)
767  last_token = tokenize.Token(tokenize.SYNTAX, ';', 0, 0)
768 
769  if last_token.name == '[':
770  # Handle array, this isn't a method, unless it's an operator.
771  # TODO(nnorwitz): keep the size somewhere.
772  # unused_size = self._GetTokensUpTo(tokenize.SYNTAX, ']')
773  temp_tokens.append(last_token)
774  if temp_tokens[-2].name == 'operator':
775  temp_tokens.append(self._GetNextToken())
776  else:
777  temp_tokens2, last_token = \
778  self._GetVarTokensUpTo(tokenize.SYNTAX, ';')
779  temp_tokens.extend(temp_tokens2)
780 
781  if last_token.name == ';':
782  # Handle data, this isn't a method.
783  parts = self.converter.DeclarationToParts(temp_tokens, True)
784  (name, type_name, templated_types, modifiers, default,
785  unused_other_tokens) = parts
786 
787  t0 = temp_tokens[0]
788  names = [t.name for t in temp_tokens]
789  if templated_types:
790  start, end = self.converter.GetTemplateIndices(names)
791  names = names[:start] + names[end:]
792  default = ''.join([t.name for t in default])
793  return self._CreateVariable(t0, name, type_name, modifiers,
794  names, templated_types, default)
795  if last_token.name == '{':
796  self._AddBackTokens(temp_tokens[1:])
797  self._AddBackToken(last_token)
798  method_name = temp_tokens[0].name
799  method = getattr(self, 'handle_' + method_name, None)
800  if not method:
801  # Must be declaring a variable.
802  # TODO(nnorwitz): handle the declaration.
803  return None
804  return method()
805  return self._GetMethod(temp_tokens, 0, None, False)
806  elif token.token_type == tokenize.SYNTAX:
807  if token.name == '~' and self.in_class:
808  # Must be a dtor (probably not in method body).
809  token = self._GetNextToken()
810  # self.in_class can contain A::Name, but the dtor will only
811  # be Name. Make sure to compare against the right value.
812  if (token.token_type == tokenize.NAME and
813  token.name == self.in_class_name_only):
814  return self._GetMethod([token], FUNCTION_DTOR, None, True)
815  # TODO(nnorwitz): handle a lot more syntax.
816  elif token.token_type == tokenize.PREPROCESSOR:
817  # TODO(nnorwitz): handle more preprocessor directives.
818  # token starts with a #, so remove it and strip whitespace.
819  name = token.name[1:].lstrip()
820  if name.startswith('include'):
821  # Remove "include".
822  name = name[7:].strip()
823  assert name
824  # Handle #include <newline> "header-on-second-line.h".
825  if name.startswith('\\'):
826  name = name[1:].strip()
827  assert name[0] in '<"', token
828  assert name[-1] in '>"', token
829  system = name[0] == '<'
830  filename = name[1:-1]
831  return Include(token.start, token.end, filename, system)
832  if name.startswith('define'):
833  # Remove "define".
834  name = name[6:].strip()
835  assert name
836  value = ''
837  for i, c in enumerate(name):
838  if c.isspace():
839  value = name[i:].lstrip()
840  name = name[:i]
841  break
842  return Define(token.start, token.end, name, value)
843  if name.startswith('if') and name[2:3].isspace():
844  condition = name[3:].strip()
845  if condition.startswith('0') or condition.startswith('(0)'):
846  self._SkipIf0Blocks()
847  return None
848 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
std::uint64_t strip(std::chrono::nanoseconds t)
def _GenerateOne(self, token)
Definition: ast.py:738
detail::RangeEnumerator< Range > enumerate(Range &&r)
Definition: Enumerate.h:167
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _SkipIf0Blocks(self)
Definition: ast.py:865
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder._GenerateOne (   self,
  token 
)
private

Definition at line 738 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._GetVarTokensUpTo(), cpp.ast.AstBuilder._SkipIf0Blocks(), folly.enumerate(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, cpp.ast.AstBuilder.in_class_name_only, join, and folly::detail::distributed_mutex.strip().

738  def _GenerateOne(self, token):
739  if token.token_type == tokenize.NAME:
740  if (keywords.IsKeyword(token.name) and
741  not keywords.IsBuiltinType(token.name)):
742  method = getattr(self, 'handle_' + token.name)
743  return method()
744  elif token.name == self.in_class_name_only:
745  # The token name is the same as the class, must be a ctor if
746  # there is a paren. Otherwise, it's the return type.
747  # Peek ahead to get the next token to figure out which.
748  next = self._GetNextToken()
749  self._AddBackToken(next)
750  if next.token_type == tokenize.SYNTAX and next.name == '(':
751  return self._GetMethod([token], FUNCTION_CTOR, None, True)
752  # Fall through--handle like any other method.
753 
754  # Handle data or function declaration/definition.
755  syntax = tokenize.SYNTAX
756  temp_tokens, last_token = \
757  self._GetVarTokensUpTo(syntax, '(', ';', '{', '[')
758  temp_tokens.insert(0, token)
759  if last_token.name == '(':
760  # If there is an assignment before the paren,
761  # this is an expression, not a method.
762  expr = bool([e for e in temp_tokens if e.name == '='])
763  if expr:
764  new_temp = self._GetTokensUpTo(tokenize.SYNTAX, ';')
765  temp_tokens.append(last_token)
766  temp_tokens.extend(new_temp)
767  last_token = tokenize.Token(tokenize.SYNTAX, ';', 0, 0)
768 
769  if last_token.name == '[':
770  # Handle array, this isn't a method, unless it's an operator.
771  # TODO(nnorwitz): keep the size somewhere.
772  # unused_size = self._GetTokensUpTo(tokenize.SYNTAX, ']')
773  temp_tokens.append(last_token)
774  if temp_tokens[-2].name == 'operator':
775  temp_tokens.append(self._GetNextToken())
776  else:
777  temp_tokens2, last_token = \
778  self._GetVarTokensUpTo(tokenize.SYNTAX, ';')
779  temp_tokens.extend(temp_tokens2)
780 
781  if last_token.name == ';':
782  # Handle data, this isn't a method.
783  parts = self.converter.DeclarationToParts(temp_tokens, True)
784  (name, type_name, templated_types, modifiers, default,
785  unused_other_tokens) = parts
786 
787  t0 = temp_tokens[0]
788  names = [t.name for t in temp_tokens]
789  if templated_types:
790  start, end = self.converter.GetTemplateIndices(names)
791  names = names[:start] + names[end:]
792  default = ''.join([t.name for t in default])
793  return self._CreateVariable(t0, name, type_name, modifiers,
794  names, templated_types, default)
795  if last_token.name == '{':
796  self._AddBackTokens(temp_tokens[1:])
797  self._AddBackToken(last_token)
798  method_name = temp_tokens[0].name
799  method = getattr(self, 'handle_' + method_name, None)
800  if not method:
801  # Must be declaring a variable.
802  # TODO(nnorwitz): handle the declaration.
803  return None
804  return method()
805  return self._GetMethod(temp_tokens, 0, None, False)
806  elif token.token_type == tokenize.SYNTAX:
807  if token.name == '~' and self.in_class:
808  # Must be a dtor (probably not in method body).
809  token = self._GetNextToken()
810  # self.in_class can contain A::Name, but the dtor will only
811  # be Name. Make sure to compare against the right value.
812  if (token.token_type == tokenize.NAME and
813  token.name == self.in_class_name_only):
814  return self._GetMethod([token], FUNCTION_DTOR, None, True)
815  # TODO(nnorwitz): handle a lot more syntax.
816  elif token.token_type == tokenize.PREPROCESSOR:
817  # TODO(nnorwitz): handle more preprocessor directives.
818  # token starts with a #, so remove it and strip whitespace.
819  name = token.name[1:].lstrip()
820  if name.startswith('include'):
821  # Remove "include".
822  name = name[7:].strip()
823  assert name
824  # Handle #include <newline> "header-on-second-line.h".
825  if name.startswith('\\'):
826  name = name[1:].strip()
827  assert name[0] in '<"', token
828  assert name[-1] in '>"', token
829  system = name[0] == '<'
830  filename = name[1:-1]
831  return Include(token.start, token.end, filename, system)
832  if name.startswith('define'):
833  # Remove "define".
834  name = name[6:].strip()
835  assert name
836  value = ''
837  for i, c in enumerate(name):
838  if c.isspace():
839  value = name[i:].lstrip()
840  name = name[:i]
841  break
842  return Define(token.start, token.end, name, value)
843  if name.startswith('if') and name[2:3].isspace():
844  condition = name[3:].strip()
845  if condition.startswith('0') or condition.startswith('(0)'):
846  self._SkipIf0Blocks()
847  return None
848 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
std::uint64_t strip(std::chrono::nanoseconds t)
def _GenerateOne(self, token)
Definition: ast.py:738
detail::RangeEnumerator< Range > enumerate(Range &&r)
Definition: Enumerate.h:167
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _SkipIf0Blocks(self)
Definition: ast.py:865
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder._GetBases (   self)
private

Definition at line 1457 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder.GetName().

1457  def _GetBases(self):
1458  # Get base classes.
1459  bases = []
1460  while 1:
1461  token = self._GetNextToken()
1462  assert token.token_type == tokenize.NAME, token
1463  # TODO(nnorwitz): store kind of inheritance...maybe.
1464  if token.name not in ('public', 'protected', 'private'):
1465  # If inheritance type is not specified, it is private.
1466  # Just put the token back so we can form a name.
1467  # TODO(nnorwitz): it would be good to warn about this.
1468  self._AddBackToken(token)
1469  else:
1470  # Check for virtual inheritance.
1471  token = self._GetNextToken()
1472  if token.name != 'virtual':
1473  self._AddBackToken(token)
1474  else:
1475  # TODO(nnorwitz): store that we got virtual for this base.
1476  pass
1477  base, next_token = self.GetName()
1478  bases_ast = self.converter.ToType(base)
1479  assert len(bases_ast) == 1, bases_ast
1480  bases.append(bases_ast[0])
1481  assert next_token.token_type == tokenize.SYNTAX, next_token
1482  if next_token.name == '{':
1483  token = next_token
1484  break
1485  # Support multiple inheritance.
1486  assert next_token.name == ',', next_token
1487  return bases, token
1488 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetBases(self)
Definition: ast.py:1457
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetBases (   self)
private

Definition at line 1457 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder.GetName().

1457  def _GetBases(self):
1458  # Get base classes.
1459  bases = []
1460  while 1:
1461  token = self._GetNextToken()
1462  assert token.token_type == tokenize.NAME, token
1463  # TODO(nnorwitz): store kind of inheritance...maybe.
1464  if token.name not in ('public', 'protected', 'private'):
1465  # If inheritance type is not specified, it is private.
1466  # Just put the token back so we can form a name.
1467  # TODO(nnorwitz): it would be good to warn about this.
1468  self._AddBackToken(token)
1469  else:
1470  # Check for virtual inheritance.
1471  token = self._GetNextToken()
1472  if token.name != 'virtual':
1473  self._AddBackToken(token)
1474  else:
1475  # TODO(nnorwitz): store that we got virtual for this base.
1476  pass
1477  base, next_token = self.GetName()
1478  bases_ast = self.converter.ToType(base)
1479  assert len(bases_ast) == 1, bases_ast
1480  bases.append(bases_ast[0])
1481  assert next_token.token_type == tokenize.SYNTAX, next_token
1482  if next_token.name == '{':
1483  token = next_token
1484  break
1485  # Support multiple inheritance.
1486  assert next_token.name == ',', next_token
1487  return bases, token
1488 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetBases(self)
Definition: ast.py:1457
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetBases (   self)
private

Definition at line 1457 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder.GetName().

Referenced by cpp.ast.AstBuilder._GetBases(), and cpp.ast.AstBuilder._GetClass().

1457  def _GetBases(self):
1458  # Get base classes.
1459  bases = []
1460  while 1:
1461  token = self._GetNextToken()
1462  assert token.token_type == tokenize.NAME, token
1463  # TODO(nnorwitz): store kind of inheritance...maybe.
1464  if token.name not in ('public', 'protected', 'private'):
1465  # If inheritance type is not specified, it is private.
1466  # Just put the token back so we can form a name.
1467  # TODO(nnorwitz): it would be good to warn about this.
1468  self._AddBackToken(token)
1469  else:
1470  # Check for virtual inheritance.
1471  token = self._GetNextToken()
1472  if token.name != 'virtual':
1473  self._AddBackToken(token)
1474  else:
1475  # TODO(nnorwitz): store that we got virtual for this base.
1476  pass
1477  base, next_token = self.GetName()
1478  bases_ast = self.converter.ToType(base)
1479  assert len(bases_ast) == 1, bases_ast
1480  bases.append(bases_ast[0])
1481  assert next_token.token_type == tokenize.SYNTAX, next_token
1482  if next_token.name == '{':
1483  token = next_token
1484  break
1485  # Support multiple inheritance.
1486  assert next_token.name == ',', next_token
1487  return bases, token
1488 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetBases(self)
Definition: ast.py:1457
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetClass (   self,
  class_type,
  visibility,
  templated_types 
)
private

Definition at line 1489 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.HandleError(), join, bm.list, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

1489  def _GetClass(self, class_type, visibility, templated_types):
1490  class_name = None
1491  class_token = self._GetNextToken()
1492  if class_token.token_type != tokenize.NAME:
1493  assert class_token.token_type == tokenize.SYNTAX, class_token
1494  token = class_token
1495  else:
1496  # Skip any macro (e.g. storage class specifiers) after the
1497  # 'class' keyword.
1498  next_token = self._GetNextToken()
1499  if next_token.token_type == tokenize.NAME:
1500  self._AddBackToken(next_token)
1501  else:
1502  self._AddBackTokens([class_token, next_token])
1503  name_tokens, token = self.GetName()
1504  class_name = ''.join([t.name for t in name_tokens])
1505  bases = None
1506  if token.token_type == tokenize.SYNTAX:
1507  if token.name == ';':
1508  # Forward declaration.
1509  return class_type(class_token.start, class_token.end,
1510  class_name, None, templated_types, None,
1511  self.namespace_stack)
1512  if token.name in '*&':
1513  # Inline forward declaration. Could be method or data.
1514  name_token = self._GetNextToken()
1515  next_token = self._GetNextToken()
1516  if next_token.name == ';':
1517  # Handle data
1518  modifiers = ['class']
1519  return self._CreateVariable(class_token, name_token.name,
1520  class_name,
1521  modifiers, token.name, None)
1522  else:
1523  # Assume this is a method.
1524  tokens = (class_token, token, name_token, next_token)
1525  self._AddBackTokens(tokens)
1526  return self.GetMethod(FUNCTION_NONE, None)
1527  if token.name == ':':
1528  bases, token = self._GetBases()
1529 
1530  body = None
1531  if token.token_type == tokenize.SYNTAX and token.name == '{':
1532  assert token.token_type == tokenize.SYNTAX, token
1533  assert token.name == '{', token
1534 
1535  ast = AstBuilder(self.GetScope(), self.filename, class_name,
1536  visibility, self.namespace_stack)
1537  body = list(ast.Generate())
1538 
1539  if not self._handling_typedef:
1540  token = self._GetNextToken()
1541  if token.token_type != tokenize.NAME:
1542  assert token.token_type == tokenize.SYNTAX, token
1543  assert token.name == ';', token
1544  else:
1545  new_class = class_type(class_token.start, class_token.end,
1546  class_name, bases, None,
1547  body, self.namespace_stack)
1548 
1549  modifiers = []
1550  return self._CreateVariable(class_token,
1551  token.name, new_class,
1552  modifiers, token.name, None)
1553  else:
1554  if not self._handling_typedef:
1555  self.HandleError('non-typedef token', token)
1556  self._AddBackToken(token)
1557 
1558  return class_type(class_token.start, class_token.end, class_name,
1559  bases, templated_types, body, self.namespace_stack)
1560 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def _GetBases(self)
Definition: ast.py:1457
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def GetScope(self)
Definition: ast.py:902
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder._GetClass (   self,
  class_type,
  visibility,
  templated_types 
)
private

Definition at line 1489 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.HandleError(), join, bm.list, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

1489  def _GetClass(self, class_type, visibility, templated_types):
1490  class_name = None
1491  class_token = self._GetNextToken()
1492  if class_token.token_type != tokenize.NAME:
1493  assert class_token.token_type == tokenize.SYNTAX, class_token
1494  token = class_token
1495  else:
1496  # Skip any macro (e.g. storage class specifiers) after the
1497  # 'class' keyword.
1498  next_token = self._GetNextToken()
1499  if next_token.token_type == tokenize.NAME:
1500  self._AddBackToken(next_token)
1501  else:
1502  self._AddBackTokens([class_token, next_token])
1503  name_tokens, token = self.GetName()
1504  class_name = ''.join([t.name for t in name_tokens])
1505  bases = None
1506  if token.token_type == tokenize.SYNTAX:
1507  if token.name == ';':
1508  # Forward declaration.
1509  return class_type(class_token.start, class_token.end,
1510  class_name, None, templated_types, None,
1511  self.namespace_stack)
1512  if token.name in '*&':
1513  # Inline forward declaration. Could be method or data.
1514  name_token = self._GetNextToken()
1515  next_token = self._GetNextToken()
1516  if next_token.name == ';':
1517  # Handle data
1518  modifiers = ['class']
1519  return self._CreateVariable(class_token, name_token.name,
1520  class_name,
1521  modifiers, token.name, None)
1522  else:
1523  # Assume this is a method.
1524  tokens = (class_token, token, name_token, next_token)
1525  self._AddBackTokens(tokens)
1526  return self.GetMethod(FUNCTION_NONE, None)
1527  if token.name == ':':
1528  bases, token = self._GetBases()
1529 
1530  body = None
1531  if token.token_type == tokenize.SYNTAX and token.name == '{':
1532  assert token.token_type == tokenize.SYNTAX, token
1533  assert token.name == '{', token
1534 
1535  ast = AstBuilder(self.GetScope(), self.filename, class_name,
1536  visibility, self.namespace_stack)
1537  body = list(ast.Generate())
1538 
1539  if not self._handling_typedef:
1540  token = self._GetNextToken()
1541  if token.token_type != tokenize.NAME:
1542  assert token.token_type == tokenize.SYNTAX, token
1543  assert token.name == ';', token
1544  else:
1545  new_class = class_type(class_token.start, class_token.end,
1546  class_name, bases, None,
1547  body, self.namespace_stack)
1548 
1549  modifiers = []
1550  return self._CreateVariable(class_token,
1551  token.name, new_class,
1552  modifiers, token.name, None)
1553  else:
1554  if not self._handling_typedef:
1555  self.HandleError('non-typedef token', token)
1556  self._AddBackToken(token)
1557 
1558  return class_type(class_token.start, class_token.end, class_name,
1559  bases, templated_types, body, self.namespace_stack)
1560 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def _GetBases(self)
Definition: ast.py:1457
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def GetScope(self)
Definition: ast.py:902
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder._GetClass (   self,
  class_type,
  visibility,
  templated_types 
)
private

Definition at line 1489 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.HandleError(), join, bm.list, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

Referenced by cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder.handle_class(), cpp.ast.AstBuilder.handle_struct(), and cpp.ast.AstBuilder.handle_template().

1489  def _GetClass(self, class_type, visibility, templated_types):
1490  class_name = None
1491  class_token = self._GetNextToken()
1492  if class_token.token_type != tokenize.NAME:
1493  assert class_token.token_type == tokenize.SYNTAX, class_token
1494  token = class_token
1495  else:
1496  # Skip any macro (e.g. storage class specifiers) after the
1497  # 'class' keyword.
1498  next_token = self._GetNextToken()
1499  if next_token.token_type == tokenize.NAME:
1500  self._AddBackToken(next_token)
1501  else:
1502  self._AddBackTokens([class_token, next_token])
1503  name_tokens, token = self.GetName()
1504  class_name = ''.join([t.name for t in name_tokens])
1505  bases = None
1506  if token.token_type == tokenize.SYNTAX:
1507  if token.name == ';':
1508  # Forward declaration.
1509  return class_type(class_token.start, class_token.end,
1510  class_name, None, templated_types, None,
1511  self.namespace_stack)
1512  if token.name in '*&':
1513  # Inline forward declaration. Could be method or data.
1514  name_token = self._GetNextToken()
1515  next_token = self._GetNextToken()
1516  if next_token.name == ';':
1517  # Handle data
1518  modifiers = ['class']
1519  return self._CreateVariable(class_token, name_token.name,
1520  class_name,
1521  modifiers, token.name, None)
1522  else:
1523  # Assume this is a method.
1524  tokens = (class_token, token, name_token, next_token)
1525  self._AddBackTokens(tokens)
1526  return self.GetMethod(FUNCTION_NONE, None)
1527  if token.name == ':':
1528  bases, token = self._GetBases()
1529 
1530  body = None
1531  if token.token_type == tokenize.SYNTAX and token.name == '{':
1532  assert token.token_type == tokenize.SYNTAX, token
1533  assert token.name == '{', token
1534 
1535  ast = AstBuilder(self.GetScope(), self.filename, class_name,
1536  visibility, self.namespace_stack)
1537  body = list(ast.Generate())
1538 
1539  if not self._handling_typedef:
1540  token = self._GetNextToken()
1541  if token.token_type != tokenize.NAME:
1542  assert token.token_type == tokenize.SYNTAX, token
1543  assert token.name == ';', token
1544  else:
1545  new_class = class_type(class_token.start, class_token.end,
1546  class_name, bases, None,
1547  body, self.namespace_stack)
1548 
1549  modifiers = []
1550  return self._CreateVariable(class_token,
1551  token.name, new_class,
1552  modifiers, token.name, None)
1553  else:
1554  if not self._handling_typedef:
1555  self.HandleError('non-typedef token', token)
1556  self._AddBackToken(token)
1557 
1558  return class_type(class_token.start, class_token.end, class_name,
1559  bases, templated_types, body, self.namespace_stack)
1560 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def _GetBases(self)
Definition: ast.py:1457
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def GetScope(self)
Definition: ast.py:902
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder._GetMatchingChar (   self,
  open_paren,
  close_paren,
  GetNextToken = None 
)
private

Definition at line 880 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken().

Referenced by cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetParameters(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder.GetName(), and cpp.ast.AstBuilder.GetScope().

880  def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None):
881  if GetNextToken is None:
882  GetNextToken = self._GetNextToken
883  # Assumes the current token is open_paren and we will consume
884  # and return up to the close_paren.
885  count = 1
886  token = GetNextToken()
887  while 1:
888  if token.token_type == tokenize.SYNTAX:
889  if token.name == open_paren:
890  count += 1
891  elif token.name == close_paren:
892  count -= 1
893  if count == 0:
894  break
895  yield token
896  token = GetNextToken()
897  yield token
898 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetMatchingChar (   self,
  open_paren,
  close_paren,
  GetNextToken = None 
)
private

Definition at line 880 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), and cpp.ast.AstBuilder._GetNextToken().

880  def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None):
881  if GetNextToken is None:
882  GetNextToken = self._GetNextToken
883  # Assumes the current token is open_paren and we will consume
884  # and return up to the close_paren.
885  count = 1
886  token = GetNextToken()
887  while 1:
888  if token.token_type == tokenize.SYNTAX:
889  if token.name == open_paren:
890  count += 1
891  elif token.name == close_paren:
892  count -= 1
893  if count == 0:
894  break
895  yield token
896  token = GetNextToken()
897  yield token
898 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetMatchingChar (   self,
  open_paren,
  close_paren,
  GetNextToken = None 
)
private

Definition at line 880 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), and cpp.ast.AstBuilder._GetNextToken().

880  def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None):
881  if GetNextToken is None:
882  GetNextToken = self._GetNextToken
883  # Assumes the current token is open_paren and we will consume
884  # and return up to the close_paren.
885  count = 1
886  token = GetNextToken()
887  while 1:
888  if token.token_type == tokenize.SYNTAX:
889  if token.name == open_paren:
890  count += 1
891  elif token.name == close_paren:
892  count -= 1
893  if count == 0:
894  break
895  yield token
896  token = GetNextToken()
897  yield token
898 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetMethod (   self,
  return_type_and_name,
  modifiers,
  templated_types,
  get_paren 
)
private

Definition at line 960 of file ast.py.

References cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetParameters(), cpp.ast.AstBuilder._GetReturnTypeAndClassName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.HandleError(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, bm.list, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

Referenced by cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder.GetMethod(), and cpp.ast.AstBuilder.handle_struct().

960  get_paren):
961  template_portion = None
962  if get_paren:
963  token = self._GetNextToken()
964  assert token.token_type == tokenize.SYNTAX, token
965  if token.name == '<':
966  # Handle templatized dtors.
967  template_portion = [token]
968  template_portion.extend(self._GetMatchingChar('<', '>'))
969  token = self._GetNextToken()
970  assert token.token_type == tokenize.SYNTAX, token
971  assert token.name == '(', token
972 
973  name = return_type_and_name.pop()
974  # Handle templatized ctors.
975  if name.name == '>':
976  index = 1
977  while return_type_and_name[index].name != '<':
978  index += 1
979  template_portion = return_type_and_name[index:] + [name]
980  del return_type_and_name[index:]
981  name = return_type_and_name.pop()
982  elif name.name == ']':
983  rt = return_type_and_name
984  assert rt[-1].name == '[', return_type_and_name
985  assert rt[-2].name == 'operator', return_type_and_name
986  name_seq = return_type_and_name[-2:]
987  del return_type_and_name[-2:]
988  name = tokenize.Token(tokenize.NAME, 'operator[]',
989  name_seq[0].start, name.end)
990  # Get the open paren so _GetParameters() below works.
991  unused_open_paren = self._GetNextToken()
992 
993  # TODO(nnorwitz): store template_portion.
994  return_type = return_type_and_name
995  indices = name
996  if return_type:
997  indices = return_type[0]
998 
999  # Force ctor for templatized ctors.
1000  if name.name == self.in_class and not modifiers:
1001  modifiers |= FUNCTION_CTOR
1002  parameters = list(self._GetParameters())
1003  del parameters[-1] # Remove trailing ')'.
1004 
1005  # Handling operator() is especially weird.
1006  if name.name == 'operator' and not parameters:
1007  token = self._GetNextToken()
1008  assert token.name == '(', token
1009  parameters = list(self._GetParameters())
1010  del parameters[-1] # Remove trailing ')'.
1011 
1012  token = self._GetNextToken()
1013  while token.token_type == tokenize.NAME:
1014  modifier_token = token
1015  token = self._GetNextToken()
1016  if modifier_token.name == 'const':
1017  modifiers |= FUNCTION_CONST
1018  elif modifier_token.name == '__attribute__':
1019  # TODO(nnorwitz): handle more __attribute__ details.
1020  modifiers |= FUNCTION_ATTRIBUTE
1021  assert token.name == '(', token
1022  # Consume everything between the (parens).
1023  unused_tokens = list(self._GetMatchingChar('(', ')'))
1024  token = self._GetNextToken()
1025  elif modifier_token.name == 'throw':
1026  modifiers |= FUNCTION_THROW
1027  assert token.name == '(', token
1028  # Consume everything between the (parens).
1029  unused_tokens = list(self._GetMatchingChar('(', ')'))
1030  token = self._GetNextToken()
1031  elif modifier_token.name == 'override':
1032  modifiers |= FUNCTION_OVERRIDE
1033  elif modifier_token.name == modifier_token.name.upper():
1034  # HACK(nnorwitz): assume that all upper-case names
1035  # are some macro we aren't expanding.
1036  modifiers |= FUNCTION_UNKNOWN_ANNOTATION
1037  else:
1038  self.HandleError('unexpected token', modifier_token)
1039 
1040  assert token.token_type == tokenize.SYNTAX, token
1041  # Handle ctor initializers.
1042  if token.name == ':':
1043  # TODO(nnorwitz): anything else to handle for initializer list?
1044  while token.name != ';' and token.name != '{':
1045  token = self._GetNextToken()
1046 
1047  # Handle pointer to functions that are really data but look
1048  # like method declarations.
1049  if token.name == '(':
1050  if parameters[0].name == '*':
1051  # name contains the return type.
1052  name = parameters.pop()
1053  # parameters contains the name of the data.
1054  modifiers = [p.name for p in parameters]
1055  # Already at the ( to open the parameter list.
1056  function_parameters = list(self._GetMatchingChar('(', ')'))
1057  del function_parameters[-1] # Remove trailing ')'.
1058  # TODO(nnorwitz): store the function_parameters.
1059  token = self._GetNextToken()
1060  assert token.token_type == tokenize.SYNTAX, token
1061  assert token.name == ';', token
1062  return self._CreateVariable(indices, name.name, indices.name,
1063  modifiers, '', None)
1064  # At this point, we got something like:
1065  # return_type (type::*name_)(params);
1066  # This is a data member called name_ that is a function pointer.
1067  # With this code: void (sq_type::*field_)(string&);
1068  # We get: name=void return_type=[] parameters=sq_type ... field_
1069  # TODO(nnorwitz): is return_type always empty?
1070  # TODO(nnorwitz): this isn't even close to being correct.
1071  # Just put in something so we don't crash and can move on.
1072  real_name = parameters[-1]
1073  modifiers = [p.name for p in self._GetParameters()]
1074  del modifiers[-1] # Remove trailing ')'.
1075  return self._CreateVariable(indices, real_name.name, indices.name,
1076  modifiers, '', None)
1077 
1078  if token.name == '{':
1079  body = list(self.GetScope())
1080  del body[-1] # Remove trailing '}'.
1081  else:
1082  body = None
1083  if token.name == '=':
1084  token = self._GetNextToken()
1085 
1086  if token.name == 'default' or token.name == 'delete':
1087  # Ignore explicitly defaulted and deleted special members
1088  # in C++11.
1089  token = self._GetNextToken()
1090  else:
1091  # Handle pure-virtual declarations.
1092  assert token.token_type == tokenize.CONSTANT, token
1093  assert token.name == '0', token
1094  modifiers |= FUNCTION_PURE_VIRTUAL
1095  token = self._GetNextToken()
1096 
1097  if token.name == '[':
1098  # TODO(nnorwitz): store tokens and improve parsing.
1099  # template <typename T, size_t N> char (&ASH(T (&seq)[N]))[N];
1100  tokens = list(self._GetMatchingChar('[', ']'))
1101  token = self._GetNextToken()
1102 
1103  assert token.name == ';', (token, return_type_and_name, parameters)
1104 
1105  # Looks like we got a method, not a function.
1106  if len(return_type) > 2 and return_type[-1].name == '::':
1107  return_type, in_class = \
1108  self._GetReturnTypeAndClassName(return_type)
1109  return Method(indices.start, indices.end, name.name, in_class,
1110  return_type, parameters, modifiers, templated_types,
1111  body, self.namespace_stack)
1112  return Function(indices.start, indices.end, name.name, return_type,
1113  parameters, modifiers, templated_types, body,
1114  self.namespace_stack)
1115 
def _GetReturnTypeAndClassName(self, token_seq)
Definition: ast.py:1116
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def GetScope(self)
Definition: ast.py:902
def _GetNextToken(self)
Definition: ast.py:905
def _GetParameters(self)
Definition: ast.py:899
def cpp.ast.AstBuilder._GetMethod (   self,
  return_type_and_name,
  modifiers,
  templated_types,
  get_paren 
)
private

Definition at line 960 of file ast.py.

References cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetParameters(), cpp.ast.AstBuilder._GetReturnTypeAndClassName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.HandleError(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, bm.list, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

960  get_paren):
961  template_portion = None
962  if get_paren:
963  token = self._GetNextToken()
964  assert token.token_type == tokenize.SYNTAX, token
965  if token.name == '<':
966  # Handle templatized dtors.
967  template_portion = [token]
968  template_portion.extend(self._GetMatchingChar('<', '>'))
969  token = self._GetNextToken()
970  assert token.token_type == tokenize.SYNTAX, token
971  assert token.name == '(', token
972 
973  name = return_type_and_name.pop()
974  # Handle templatized ctors.
975  if name.name == '>':
976  index = 1
977  while return_type_and_name[index].name != '<':
978  index += 1
979  template_portion = return_type_and_name[index:] + [name]
980  del return_type_and_name[index:]
981  name = return_type_and_name.pop()
982  elif name.name == ']':
983  rt = return_type_and_name
984  assert rt[-1].name == '[', return_type_and_name
985  assert rt[-2].name == 'operator', return_type_and_name
986  name_seq = return_type_and_name[-2:]
987  del return_type_and_name[-2:]
988  name = tokenize.Token(tokenize.NAME, 'operator[]',
989  name_seq[0].start, name.end)
990  # Get the open paren so _GetParameters() below works.
991  unused_open_paren = self._GetNextToken()
992 
993  # TODO(nnorwitz): store template_portion.
994  return_type = return_type_and_name
995  indices = name
996  if return_type:
997  indices = return_type[0]
998 
999  # Force ctor for templatized ctors.
1000  if name.name == self.in_class and not modifiers:
1001  modifiers |= FUNCTION_CTOR
1002  parameters = list(self._GetParameters())
1003  del parameters[-1] # Remove trailing ')'.
1004 
1005  # Handling operator() is especially weird.
1006  if name.name == 'operator' and not parameters:
1007  token = self._GetNextToken()
1008  assert token.name == '(', token
1009  parameters = list(self._GetParameters())
1010  del parameters[-1] # Remove trailing ')'.
1011 
1012  token = self._GetNextToken()
1013  while token.token_type == tokenize.NAME:
1014  modifier_token = token
1015  token = self._GetNextToken()
1016  if modifier_token.name == 'const':
1017  modifiers |= FUNCTION_CONST
1018  elif modifier_token.name == '__attribute__':
1019  # TODO(nnorwitz): handle more __attribute__ details.
1020  modifiers |= FUNCTION_ATTRIBUTE
1021  assert token.name == '(', token
1022  # Consume everything between the (parens).
1023  unused_tokens = list(self._GetMatchingChar('(', ')'))
1024  token = self._GetNextToken()
1025  elif modifier_token.name == 'throw':
1026  modifiers |= FUNCTION_THROW
1027  assert token.name == '(', token
1028  # Consume everything between the (parens).
1029  unused_tokens = list(self._GetMatchingChar('(', ')'))
1030  token = self._GetNextToken()
1031  elif modifier_token.name == 'override':
1032  modifiers |= FUNCTION_OVERRIDE
1033  elif modifier_token.name == modifier_token.name.upper():
1034  # HACK(nnorwitz): assume that all upper-case names
1035  # are some macro we aren't expanding.
1036  modifiers |= FUNCTION_UNKNOWN_ANNOTATION
1037  else:
1038  self.HandleError('unexpected token', modifier_token)
1039 
1040  assert token.token_type == tokenize.SYNTAX, token
1041  # Handle ctor initializers.
1042  if token.name == ':':
1043  # TODO(nnorwitz): anything else to handle for initializer list?
1044  while token.name != ';' and token.name != '{':
1045  token = self._GetNextToken()
1046 
1047  # Handle pointer to functions that are really data but look
1048  # like method declarations.
1049  if token.name == '(':
1050  if parameters[0].name == '*':
1051  # name contains the return type.
1052  name = parameters.pop()
1053  # parameters contains the name of the data.
1054  modifiers = [p.name for p in parameters]
1055  # Already at the ( to open the parameter list.
1056  function_parameters = list(self._GetMatchingChar('(', ')'))
1057  del function_parameters[-1] # Remove trailing ')'.
1058  # TODO(nnorwitz): store the function_parameters.
1059  token = self._GetNextToken()
1060  assert token.token_type == tokenize.SYNTAX, token
1061  assert token.name == ';', token
1062  return self._CreateVariable(indices, name.name, indices.name,
1063  modifiers, '', None)
1064  # At this point, we got something like:
1065  # return_type (type::*name_)(params);
1066  # This is a data member called name_ that is a function pointer.
1067  # With this code: void (sq_type::*field_)(string&);
1068  # We get: name=void return_type=[] parameters=sq_type ... field_
1069  # TODO(nnorwitz): is return_type always empty?
1070  # TODO(nnorwitz): this isn't even close to being correct.
1071  # Just put in something so we don't crash and can move on.
1072  real_name = parameters[-1]
1073  modifiers = [p.name for p in self._GetParameters()]
1074  del modifiers[-1] # Remove trailing ')'.
1075  return self._CreateVariable(indices, real_name.name, indices.name,
1076  modifiers, '', None)
1077 
1078  if token.name == '{':
1079  body = list(self.GetScope())
1080  del body[-1] # Remove trailing '}'.
1081  else:
1082  body = None
1083  if token.name == '=':
1084  token = self._GetNextToken()
1085 
1086  if token.name == 'default' or token.name == 'delete':
1087  # Ignore explicitly defaulted and deleted special members
1088  # in C++11.
1089  token = self._GetNextToken()
1090  else:
1091  # Handle pure-virtual declarations.
1092  assert token.token_type == tokenize.CONSTANT, token
1093  assert token.name == '0', token
1094  modifiers |= FUNCTION_PURE_VIRTUAL
1095  token = self._GetNextToken()
1096 
1097  if token.name == '[':
1098  # TODO(nnorwitz): store tokens and improve parsing.
1099  # template <typename T, size_t N> char (&ASH(T (&seq)[N]))[N];
1100  tokens = list(self._GetMatchingChar('[', ']'))
1101  token = self._GetNextToken()
1102 
1103  assert token.name == ';', (token, return_type_and_name, parameters)
1104 
1105  # Looks like we got a method, not a function.
1106  if len(return_type) > 2 and return_type[-1].name == '::':
1107  return_type, in_class = \
1108  self._GetReturnTypeAndClassName(return_type)
1109  return Method(indices.start, indices.end, name.name, in_class,
1110  return_type, parameters, modifiers, templated_types,
1111  body, self.namespace_stack)
1112  return Function(indices.start, indices.end, name.name, return_type,
1113  parameters, modifiers, templated_types, body,
1114  self.namespace_stack)
1115 
def _GetReturnTypeAndClassName(self, token_seq)
Definition: ast.py:1116
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def GetScope(self)
Definition: ast.py:902
def _GetNextToken(self)
Definition: ast.py:905
def _GetParameters(self)
Definition: ast.py:899
def cpp.ast.AstBuilder._GetMethod (   self,
  return_type_and_name,
  modifiers,
  templated_types,
  get_paren 
)
private

Definition at line 960 of file ast.py.

References cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetParameters(), cpp.ast.AstBuilder._GetReturnTypeAndClassName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.HandleError(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, bm.list, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

960  get_paren):
961  template_portion = None
962  if get_paren:
963  token = self._GetNextToken()
964  assert token.token_type == tokenize.SYNTAX, token
965  if token.name == '<':
966  # Handle templatized dtors.
967  template_portion = [token]
968  template_portion.extend(self._GetMatchingChar('<', '>'))
969  token = self._GetNextToken()
970  assert token.token_type == tokenize.SYNTAX, token
971  assert token.name == '(', token
972 
973  name = return_type_and_name.pop()
974  # Handle templatized ctors.
975  if name.name == '>':
976  index = 1
977  while return_type_and_name[index].name != '<':
978  index += 1
979  template_portion = return_type_and_name[index:] + [name]
980  del return_type_and_name[index:]
981  name = return_type_and_name.pop()
982  elif name.name == ']':
983  rt = return_type_and_name
984  assert rt[-1].name == '[', return_type_and_name
985  assert rt[-2].name == 'operator', return_type_and_name
986  name_seq = return_type_and_name[-2:]
987  del return_type_and_name[-2:]
988  name = tokenize.Token(tokenize.NAME, 'operator[]',
989  name_seq[0].start, name.end)
990  # Get the open paren so _GetParameters() below works.
991  unused_open_paren = self._GetNextToken()
992 
993  # TODO(nnorwitz): store template_portion.
994  return_type = return_type_and_name
995  indices = name
996  if return_type:
997  indices = return_type[0]
998 
999  # Force ctor for templatized ctors.
1000  if name.name == self.in_class and not modifiers:
1001  modifiers |= FUNCTION_CTOR
1002  parameters = list(self._GetParameters())
1003  del parameters[-1] # Remove trailing ')'.
1004 
1005  # Handling operator() is especially weird.
1006  if name.name == 'operator' and not parameters:
1007  token = self._GetNextToken()
1008  assert token.name == '(', token
1009  parameters = list(self._GetParameters())
1010  del parameters[-1] # Remove trailing ')'.
1011 
1012  token = self._GetNextToken()
1013  while token.token_type == tokenize.NAME:
1014  modifier_token = token
1015  token = self._GetNextToken()
1016  if modifier_token.name == 'const':
1017  modifiers |= FUNCTION_CONST
1018  elif modifier_token.name == '__attribute__':
1019  # TODO(nnorwitz): handle more __attribute__ details.
1020  modifiers |= FUNCTION_ATTRIBUTE
1021  assert token.name == '(', token
1022  # Consume everything between the (parens).
1023  unused_tokens = list(self._GetMatchingChar('(', ')'))
1024  token = self._GetNextToken()
1025  elif modifier_token.name == 'throw':
1026  modifiers |= FUNCTION_THROW
1027  assert token.name == '(', token
1028  # Consume everything between the (parens).
1029  unused_tokens = list(self._GetMatchingChar('(', ')'))
1030  token = self._GetNextToken()
1031  elif modifier_token.name == 'override':
1032  modifiers |= FUNCTION_OVERRIDE
1033  elif modifier_token.name == modifier_token.name.upper():
1034  # HACK(nnorwitz): assume that all upper-case names
1035  # are some macro we aren't expanding.
1036  modifiers |= FUNCTION_UNKNOWN_ANNOTATION
1037  else:
1038  self.HandleError('unexpected token', modifier_token)
1039 
1040  assert token.token_type == tokenize.SYNTAX, token
1041  # Handle ctor initializers.
1042  if token.name == ':':
1043  # TODO(nnorwitz): anything else to handle for initializer list?
1044  while token.name != ';' and token.name != '{':
1045  token = self._GetNextToken()
1046 
1047  # Handle pointer to functions that are really data but look
1048  # like method declarations.
1049  if token.name == '(':
1050  if parameters[0].name == '*':
1051  # name contains the return type.
1052  name = parameters.pop()
1053  # parameters contains the name of the data.
1054  modifiers = [p.name for p in parameters]
1055  # Already at the ( to open the parameter list.
1056  function_parameters = list(self._GetMatchingChar('(', ')'))
1057  del function_parameters[-1] # Remove trailing ')'.
1058  # TODO(nnorwitz): store the function_parameters.
1059  token = self._GetNextToken()
1060  assert token.token_type == tokenize.SYNTAX, token
1061  assert token.name == ';', token
1062  return self._CreateVariable(indices, name.name, indices.name,
1063  modifiers, '', None)
1064  # At this point, we got something like:
1065  # return_type (type::*name_)(params);
1066  # This is a data member called name_ that is a function pointer.
1067  # With this code: void (sq_type::*field_)(string&);
1068  # We get: name=void return_type=[] parameters=sq_type ... field_
1069  # TODO(nnorwitz): is return_type always empty?
1070  # TODO(nnorwitz): this isn't even close to being correct.
1071  # Just put in something so we don't crash and can move on.
1072  real_name = parameters[-1]
1073  modifiers = [p.name for p in self._GetParameters()]
1074  del modifiers[-1] # Remove trailing ')'.
1075  return self._CreateVariable(indices, real_name.name, indices.name,
1076  modifiers, '', None)
1077 
1078  if token.name == '{':
1079  body = list(self.GetScope())
1080  del body[-1] # Remove trailing '}'.
1081  else:
1082  body = None
1083  if token.name == '=':
1084  token = self._GetNextToken()
1085 
1086  if token.name == 'default' or token.name == 'delete':
1087  # Ignore explicitly defaulted and deleted special members
1088  # in C++11.
1089  token = self._GetNextToken()
1090  else:
1091  # Handle pure-virtual declarations.
1092  assert token.token_type == tokenize.CONSTANT, token
1093  assert token.name == '0', token
1094  modifiers |= FUNCTION_PURE_VIRTUAL
1095  token = self._GetNextToken()
1096 
1097  if token.name == '[':
1098  # TODO(nnorwitz): store tokens and improve parsing.
1099  # template <typename T, size_t N> char (&ASH(T (&seq)[N]))[N];
1100  tokens = list(self._GetMatchingChar('[', ']'))
1101  token = self._GetNextToken()
1102 
1103  assert token.name == ';', (token, return_type_and_name, parameters)
1104 
1105  # Looks like we got a method, not a function.
1106  if len(return_type) > 2 and return_type[-1].name == '::':
1107  return_type, in_class = \
1108  self._GetReturnTypeAndClassName(return_type)
1109  return Method(indices.start, indices.end, name.name, in_class,
1110  return_type, parameters, modifiers, templated_types,
1111  body, self.namespace_stack)
1112  return Function(indices.start, indices.end, name.name, return_type,
1113  parameters, modifiers, templated_types, body,
1114  self.namespace_stack)
1115 
def _GetReturnTypeAndClassName(self, token_seq)
Definition: ast.py:1116
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def GetScope(self)
Definition: ast.py:902
def _GetNextToken(self)
Definition: ast.py:905
def _GetParameters(self)
Definition: ast.py:899
def cpp.ast.AstBuilder._GetNestedType (   self,
  ctor 
)
private

Definition at line 1193 of file ast.py.

1193  def _GetNestedType(self, ctor):
1194  name = None
1195  name_tokens, token = self.GetName()
1196  if name_tokens:
1197  name = ''.join([t.name for t in name_tokens])
1198 
1199  # Handle forward declarations.
1200  if token.token_type == tokenize.SYNTAX and token.name == ';':
1201  return ctor(token.start, token.end, name, None,
1202  self.namespace_stack)
1203 
1204  if token.token_type == tokenize.NAME and self._handling_typedef:
1205  self._AddBackToken(token)
1206  return ctor(token.start, token.end, name, None,
1207  self.namespace_stack)
1208 
1209  # Must be the type declaration.
1210  fields = list(self._GetMatchingChar('{', '}'))
1211  del fields[-1] # Remove trailing '}'.
1212  if token.token_type == tokenize.SYNTAX and token.name == '{':
1213  next = self._GetNextToken()
1214  new_type = ctor(token.start, token.end, name, fields,
1215  self.namespace_stack)
1216  # A name means this is an anonymous type and the name
1217  # is the variable declaration.
1218  if next.token_type != tokenize.NAME:
1219  return new_type
1220  name = new_type
1221  token = next
1222 
1223  # Must be variable declaration using the type prefixed with keyword.
1224  assert token.token_type == tokenize.NAME, token
1225  return self._CreateVariable(token, token.name, name, [], '', None)
1226 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNestedType(self, ctor)
Definition: ast.py:1193
Encoder::MutableCompressedList list
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def cpp.ast.AstBuilder._GetNestedType (   self,
  ctor 
)
private

Definition at line 1193 of file ast.py.

1193  def _GetNestedType(self, ctor):
1194  name = None
1195  name_tokens, token = self.GetName()
1196  if name_tokens:
1197  name = ''.join([t.name for t in name_tokens])
1198 
1199  # Handle forward declarations.
1200  if token.token_type == tokenize.SYNTAX and token.name == ';':
1201  return ctor(token.start, token.end, name, None,
1202  self.namespace_stack)
1203 
1204  if token.token_type == tokenize.NAME and self._handling_typedef:
1205  self._AddBackToken(token)
1206  return ctor(token.start, token.end, name, None,
1207  self.namespace_stack)
1208 
1209  # Must be the type declaration.
1210  fields = list(self._GetMatchingChar('{', '}'))
1211  del fields[-1] # Remove trailing '}'.
1212  if token.token_type == tokenize.SYNTAX and token.name == '{':
1213  next = self._GetNextToken()
1214  new_type = ctor(token.start, token.end, name, fields,
1215  self.namespace_stack)
1216  # A name means this is an anonymous type and the name
1217  # is the variable declaration.
1218  if next.token_type != tokenize.NAME:
1219  return new_type
1220  name = new_type
1221  token = next
1222 
1223  # Must be variable declaration using the type prefixed with keyword.
1224  assert token.token_type == tokenize.NAME, token
1225  return self._CreateVariable(token, token.name, name, [], '', None)
1226 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNestedType(self, ctor)
Definition: ast.py:1193
Encoder::MutableCompressedList list
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def cpp.ast.AstBuilder._GetNestedType (   self,
  ctor 
)
private

Definition at line 1193 of file ast.py.

Referenced by cpp.ast.AstBuilder._GetNestedType(), cpp.ast.AstBuilder.handle_enum(), and cpp.ast.AstBuilder.handle_union().

1193  def _GetNestedType(self, ctor):
1194  name = None
1195  name_tokens, token = self.GetName()
1196  if name_tokens:
1197  name = ''.join([t.name for t in name_tokens])
1198 
1199  # Handle forward declarations.
1200  if token.token_type == tokenize.SYNTAX and token.name == ';':
1201  return ctor(token.start, token.end, name, None,
1202  self.namespace_stack)
1203 
1204  if token.token_type == tokenize.NAME and self._handling_typedef:
1205  self._AddBackToken(token)
1206  return ctor(token.start, token.end, name, None,
1207  self.namespace_stack)
1208 
1209  # Must be the type declaration.
1210  fields = list(self._GetMatchingChar('{', '}'))
1211  del fields[-1] # Remove trailing '}'.
1212  if token.token_type == tokenize.SYNTAX and token.name == '{':
1213  next = self._GetNextToken()
1214  new_type = ctor(token.start, token.end, name, fields,
1215  self.namespace_stack)
1216  # A name means this is an anonymous type and the name
1217  # is the variable declaration.
1218  if next.token_type != tokenize.NAME:
1219  return new_type
1220  name = new_type
1221  token = next
1222 
1223  # Must be variable declaration using the type prefixed with keyword.
1224  assert token.token_type == tokenize.NAME, token
1225  return self._CreateVariable(token, token.name, name, [], '', None)
1226 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNestedType(self, ctor)
Definition: ast.py:1193
Encoder::MutableCompressedList list
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def cpp.ast.AstBuilder._GetNextToken (   self)
private

Definition at line 905 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), cpp.ast.next(), cpp.ast.AstBuilder.token_queue, and cpp.ast.AstBuilder.tokens.

905  def _GetNextToken(self):
906  if self.token_queue:
907  return self.token_queue.pop()
908  return next(self.tokens)
909 
def _GetNextToken(self)
Definition: ast.py:905
def next(obj)
Definition: ast.py:58
def cpp.ast.AstBuilder._GetNextToken (   self)
private

Definition at line 905 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), cpp.ast.next(), cpp.ast.AstBuilder.token_queue, and cpp.ast.AstBuilder.tokens.

905  def _GetNextToken(self):
906  if self.token_queue:
907  return self.token_queue.pop()
908  return next(self.tokens)
909 
def _GetNextToken(self)
Definition: ast.py:905
def next(obj)
Definition: ast.py:58
def cpp.ast.AstBuilder._GetParameters (   self)
private

Definition at line 899 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar().

Referenced by cpp.ast.AstBuilder._GetMethod(), and cpp.ast.AstBuilder._GetParameters().

899  def _GetParameters(self):
900  return self._GetMatchingChar('(', ')')
901 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetParameters(self)
Definition: ast.py:899
def cpp.ast.AstBuilder._GetParameters (   self)
private

Definition at line 899 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), and cpp.ast.AstBuilder._GetParameters().

899  def _GetParameters(self):
900  return self._GetMatchingChar('(', ')')
901 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetParameters(self)
Definition: ast.py:899
def cpp.ast.AstBuilder._GetParameters (   self)
private

Definition at line 899 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), and cpp.ast.AstBuilder._GetParameters().

899  def _GetParameters(self):
900  return self._GetMatchingChar('(', ')')
901 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetParameters(self)
Definition: ast.py:899
def cpp.ast.AstBuilder._GetReturnTypeAndClassName (   self,
  token_seq 
)
private

Definition at line 1116 of file ast.py.

References cpp.ast.AstBuilder.GetName().

Referenced by cpp.ast.AstBuilder._GetMethod(), and cpp.ast.AstBuilder._GetReturnTypeAndClassName().

1116  def _GetReturnTypeAndClassName(self, token_seq):
1117  # Splitting the return type from the class name in a method
1118  # can be tricky. For example, Return::Type::Is::Hard::To::Find().
1119  # Where is the return type and where is the class name?
1120  # The heuristic used is to pull the last name as the class name.
1121  # This includes all the templated type info.
1122  # TODO(nnorwitz): if there is only One name like in the
1123  # example above, punt and assume the last bit is the class name.
1124 
1125  # Ignore a :: prefix, if exists so we can find the first real name.
1126  i = 0
1127  if token_seq[0].name == '::':
1128  i = 1
1129  # Ignore a :: suffix, if exists.
1130  end = len(token_seq) - 1
1131  if token_seq[end-1].name == '::':
1132  end -= 1
1133 
1134  # Make a copy of the sequence so we can append a sentinel
1135  # value. This is required for GetName will has to have some
1136  # terminating condition beyond the last name.
1137  seq_copy = token_seq[i:end]
1138  seq_copy.append(tokenize.Token(tokenize.SYNTAX, '', 0, 0))
1139  names = []
1140  while i < end:
1141  # Iterate through the sequence parsing out each name.
1142  new_name, next = self.GetName(seq_copy[i:])
1143  assert new_name, 'Got empty new_name, next=%s' % next
1144  # We got a pointer or ref. Add it to the name.
1145  if next and next.token_type == tokenize.SYNTAX:
1146  new_name.append(next)
1147  names.append(new_name)
1148  i += len(new_name)
1149 
1150  # Now that we have the names, it's time to undo what we did.
1151 
1152  # Remove the sentinel value.
1153  names[-1].pop()
1154  # Flatten the token sequence for the return type.
1155  return_type = [e for seq in names[:-1] for e in seq]
1156  # The class name is the last name.
1157  class_name = names[-1]
1158  return return_type, class_name
1159 
def _GetReturnTypeAndClassName(self, token_seq)
Definition: ast.py:1116
def GetName(self, seq=None)
Definition: ast.py:928
def cpp.ast.AstBuilder._GetReturnTypeAndClassName (   self,
  token_seq 
)
private

Definition at line 1116 of file ast.py.

References cpp.ast.AstBuilder._GetReturnTypeAndClassName(), and cpp.ast.AstBuilder.GetName().

1116  def _GetReturnTypeAndClassName(self, token_seq):
1117  # Splitting the return type from the class name in a method
1118  # can be tricky. For example, Return::Type::Is::Hard::To::Find().
1119  # Where is the return type and where is the class name?
1120  # The heuristic used is to pull the last name as the class name.
1121  # This includes all the templated type info.
1122  # TODO(nnorwitz): if there is only One name like in the
1123  # example above, punt and assume the last bit is the class name.
1124 
1125  # Ignore a :: prefix, if exists so we can find the first real name.
1126  i = 0
1127  if token_seq[0].name == '::':
1128  i = 1
1129  # Ignore a :: suffix, if exists.
1130  end = len(token_seq) - 1
1131  if token_seq[end-1].name == '::':
1132  end -= 1
1133 
1134  # Make a copy of the sequence so we can append a sentinel
1135  # value. This is required for GetName will has to have some
1136  # terminating condition beyond the last name.
1137  seq_copy = token_seq[i:end]
1138  seq_copy.append(tokenize.Token(tokenize.SYNTAX, '', 0, 0))
1139  names = []
1140  while i < end:
1141  # Iterate through the sequence parsing out each name.
1142  new_name, next = self.GetName(seq_copy[i:])
1143  assert new_name, 'Got empty new_name, next=%s' % next
1144  # We got a pointer or ref. Add it to the name.
1145  if next and next.token_type == tokenize.SYNTAX:
1146  new_name.append(next)
1147  names.append(new_name)
1148  i += len(new_name)
1149 
1150  # Now that we have the names, it's time to undo what we did.
1151 
1152  # Remove the sentinel value.
1153  names[-1].pop()
1154  # Flatten the token sequence for the return type.
1155  return_type = [e for seq in names[:-1] for e in seq]
1156  # The class name is the last name.
1157  class_name = names[-1]
1158  return return_type, class_name
1159 
def _GetReturnTypeAndClassName(self, token_seq)
Definition: ast.py:1116
def GetName(self, seq=None)
Definition: ast.py:928
def cpp.ast.AstBuilder._GetReturnTypeAndClassName (   self,
  token_seq 
)
private

Definition at line 1116 of file ast.py.

References cpp.ast.AstBuilder._GetReturnTypeAndClassName(), and cpp.ast.AstBuilder.GetName().

1116  def _GetReturnTypeAndClassName(self, token_seq):
1117  # Splitting the return type from the class name in a method
1118  # can be tricky. For example, Return::Type::Is::Hard::To::Find().
1119  # Where is the return type and where is the class name?
1120  # The heuristic used is to pull the last name as the class name.
1121  # This includes all the templated type info.
1122  # TODO(nnorwitz): if there is only One name like in the
1123  # example above, punt and assume the last bit is the class name.
1124 
1125  # Ignore a :: prefix, if exists so we can find the first real name.
1126  i = 0
1127  if token_seq[0].name == '::':
1128  i = 1
1129  # Ignore a :: suffix, if exists.
1130  end = len(token_seq) - 1
1131  if token_seq[end-1].name == '::':
1132  end -= 1
1133 
1134  # Make a copy of the sequence so we can append a sentinel
1135  # value. This is required for GetName will has to have some
1136  # terminating condition beyond the last name.
1137  seq_copy = token_seq[i:end]
1138  seq_copy.append(tokenize.Token(tokenize.SYNTAX, '', 0, 0))
1139  names = []
1140  while i < end:
1141  # Iterate through the sequence parsing out each name.
1142  new_name, next = self.GetName(seq_copy[i:])
1143  assert new_name, 'Got empty new_name, next=%s' % next
1144  # We got a pointer or ref. Add it to the name.
1145  if next and next.token_type == tokenize.SYNTAX:
1146  new_name.append(next)
1147  names.append(new_name)
1148  i += len(new_name)
1149 
1150  # Now that we have the names, it's time to undo what we did.
1151 
1152  # Remove the sentinel value.
1153  names[-1].pop()
1154  # Flatten the token sequence for the return type.
1155  return_type = [e for seq in names[:-1] for e in seq]
1156  # The class name is the last name.
1157  class_name = names[-1]
1158  return return_type, class_name
1159 
def _GetReturnTypeAndClassName(self, token_seq)
Definition: ast.py:1116
def GetName(self, seq=None)
Definition: ast.py:928
def cpp.ast.AstBuilder._GetTemplatedTypes (   self)
private

Definition at line 1395 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder.GetName(), and bm.list.

1396  result = {}
1397  tokens = list(self._GetMatchingChar('<', '>'))
1398  len_tokens = len(tokens) - 1 # Ignore trailing '>'.
1399  i = 0
1400  while i < len_tokens:
1401  key = tokens[i].name
1402  i += 1
1403  if keywords.IsKeyword(key) or key == ',':
1404  continue
1405  type_name = default = None
1406  if i < len_tokens:
1407  i += 1
1408  if tokens[i-1].name == '=':
1409  assert i < len_tokens, '%s %s' % (i, tokens)
1410  default, unused_next_token = self.GetName(tokens[i:])
1411  i += len(default)
1412  else:
1413  if tokens[i-1].name != ',':
1414  # We got something like: Type variable.
1415  # Re-adjust the key (variable) and type_name (Type).
1416  key = tokens[i-1].name
1417  type_name = tokens[i-2]
1418 
1419  result[key] = (type_name, default)
1420  return result
1421 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetTemplatedTypes(self)
Definition: ast.py:1395
Encoder::MutableCompressedList list
def cpp.ast.AstBuilder._GetTemplatedTypes (   self)
private

Definition at line 1395 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder.GetName(), and bm.list.

1396  result = {}
1397  tokens = list(self._GetMatchingChar('<', '>'))
1398  len_tokens = len(tokens) - 1 # Ignore trailing '>'.
1399  i = 0
1400  while i < len_tokens:
1401  key = tokens[i].name
1402  i += 1
1403  if keywords.IsKeyword(key) or key == ',':
1404  continue
1405  type_name = default = None
1406  if i < len_tokens:
1407  i += 1
1408  if tokens[i-1].name == '=':
1409  assert i < len_tokens, '%s %s' % (i, tokens)
1410  default, unused_next_token = self.GetName(tokens[i:])
1411  i += len(default)
1412  else:
1413  if tokens[i-1].name != ',':
1414  # We got something like: Type variable.
1415  # Re-adjust the key (variable) and type_name (Type).
1416  key = tokens[i-1].name
1417  type_name = tokens[i-2]
1418 
1419  result[key] = (type_name, default)
1420  return result
1421 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetTemplatedTypes(self)
Definition: ast.py:1395
Encoder::MutableCompressedList list
def cpp.ast.AstBuilder._GetTemplatedTypes (   self)
private

Definition at line 1395 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder.GetName(), and bm.list.

Referenced by cpp.ast.AstBuilder._GetTemplatedTypes(), and cpp.ast.AstBuilder.handle_template().

1396  result = {}
1397  tokens = list(self._GetMatchingChar('<', '>'))
1398  len_tokens = len(tokens) - 1 # Ignore trailing '>'.
1399  i = 0
1400  while i < len_tokens:
1401  key = tokens[i].name
1402  i += 1
1403  if keywords.IsKeyword(key) or key == ',':
1404  continue
1405  type_name = default = None
1406  if i < len_tokens:
1407  i += 1
1408  if tokens[i-1].name == '=':
1409  assert i < len_tokens, '%s %s' % (i, tokens)
1410  default, unused_next_token = self.GetName(tokens[i:])
1411  i += len(default)
1412  else:
1413  if tokens[i-1].name != ',':
1414  # We got something like: Type variable.
1415  # Re-adjust the key (variable) and type_name (Type).
1416  key = tokens[i-1].name
1417  type_name = tokens[i-2]
1418 
1419  result[key] = (type_name, default)
1420  return result
1421 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetTemplatedTypes(self)
Definition: ast.py:1395
Encoder::MutableCompressedList list
def cpp.ast.AstBuilder._GetTokensUpTo (   self,
  expected_token_type,
  expected_token 
)
private

Definition at line 849 of file ast.py.

References cpp.ast.AstBuilder._GetVarTokensUpTo().

Referenced by cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._IgnoreUpTo(), cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.handle_friend(), cpp.ast.AstBuilder.handle_goto(), cpp.ast.AstBuilder.handle_typedef(), and cpp.ast.AstBuilder.handle_using().

849  def _GetTokensUpTo(self, expected_token_type, expected_token):
850  return self._GetVarTokensUpTo(expected_token_type, expected_token)[0]
851 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def cpp.ast.AstBuilder._GetTokensUpTo (   self,
  expected_token_type,
  expected_token 
)
private

Definition at line 849 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder._GetVarTokensUpTo().

849  def _GetTokensUpTo(self, expected_token_type, expected_token):
850  return self._GetVarTokensUpTo(expected_token_type, expected_token)[0]
851 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def cpp.ast.AstBuilder._GetTokensUpTo (   self,
  expected_token_type,
  expected_token 
)
private

Definition at line 849 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder._GetVarTokensUpTo().

849  def _GetTokensUpTo(self, expected_token_type, expected_token):
850  return self._GetVarTokensUpTo(expected_token_type, expected_token)[0]
851 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def cpp.ast.AstBuilder._GetVarTokensUpTo (   self,
  expected_token_type,
  expected_tokens 
)
private

Definition at line 852 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder._GetVarTokensUpTo().

852  def _GetVarTokensUpTo(self, expected_token_type, *expected_tokens):
853  last_token = self._GetNextToken()
854  tokens = []
855  while (last_token.token_type != expected_token_type or
856  last_token.name not in expected_tokens):
857  tokens.append(last_token)
858  last_token = self._GetNextToken()
859  return tokens, last_token
860 
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetVarTokensUpTo (   self,
  expected_token_type,
  expected_tokens 
)
private

Definition at line 852 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder._GetVarTokensUpTo().

852  def _GetVarTokensUpTo(self, expected_token_type, *expected_tokens):
853  last_token = self._GetNextToken()
854  tokens = []
855  while (last_token.token_type != expected_token_type or
856  last_token.name not in expected_tokens):
857  tokens.append(last_token)
858  last_token = self._GetNextToken()
859  return tokens, last_token
860 
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._GetVarTokensUpTo (   self,
  expected_token_type,
  expected_tokens 
)
private

Definition at line 852 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken().

Referenced by cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._GetVarTokensUpTo(), and cpp.ast.AstBuilder.handle_template().

852  def _GetVarTokensUpTo(self, expected_token_type, *expected_tokens):
853  last_token = self._GetNextToken()
854  tokens = []
855  while (last_token.token_type != expected_token_type or
856  last_token.name not in expected_tokens):
857  tokens.append(last_token)
858  last_token = self._GetNextToken()
859  return tokens, last_token
860 
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._IgnoreUpTo (   self,
  token_type,
  token 
)
private

Definition at line 862 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder._IgnoreUpTo().

862  def _IgnoreUpTo(self, token_type, token):
863  unused_tokens = self._GetTokensUpTo(token_type, token)
864 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def cpp.ast.AstBuilder._IgnoreUpTo (   self,
  token_type,
  token 
)
private

Definition at line 862 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder._IgnoreUpTo().

862  def _IgnoreUpTo(self, token_type, token):
863  unused_tokens = self._GetTokensUpTo(token_type, token)
864 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def cpp.ast.AstBuilder._IgnoreUpTo (   self,
  token_type,
  token 
)
private

Definition at line 862 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo().

Referenced by cpp.ast.AstBuilder._IgnoreUpTo(), and cpp.ast.AstBuilder.handle_continue().

862  def _IgnoreUpTo(self, token_type, token):
863  unused_tokens = self._GetTokensUpTo(token_type, token)
864 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def cpp.ast.AstBuilder._SkipIf0Blocks (   self)
private

Definition at line 865 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken().

Referenced by cpp.ast.AstBuilder._GenerateOne(), and cpp.ast.AstBuilder._SkipIf0Blocks().

865  def _SkipIf0Blocks(self):
866  count = 1
867  while 1:
868  token = self._GetNextToken()
869  if token.token_type != tokenize.PREPROCESSOR:
870  continue
871 
872  name = token.name[1:].lstrip()
873  if name.startswith('endif'):
874  count -= 1
875  if count == 0:
876  break
877  elif name.startswith('if'):
878  count += 1
879 
def _SkipIf0Blocks(self)
Definition: ast.py:865
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._SkipIf0Blocks (   self)
private

Definition at line 865 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder._SkipIf0Blocks().

865  def _SkipIf0Blocks(self):
866  count = 1
867  while 1:
868  token = self._GetNextToken()
869  if token.token_type != tokenize.PREPROCESSOR:
870  continue
871 
872  name = token.name[1:].lstrip()
873  if name.startswith('endif'):
874  count -= 1
875  if count == 0:
876  break
877  elif name.startswith('if'):
878  count += 1
879 
def _SkipIf0Blocks(self)
Definition: ast.py:865
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder._SkipIf0Blocks (   self)
private

Definition at line 865 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.AstBuilder._SkipIf0Blocks().

865  def _SkipIf0Blocks(self):
866  count = 1
867  while 1:
868  token = self._GetNextToken()
869  if token.token_type != tokenize.PREPROCESSOR:
870  continue
871 
872  name = token.name[1:].lstrip()
873  if name.startswith('endif'):
874  count -= 1
875  if count == 0:
876  break
877  elif name.startswith('if'):
878  count += 1
879 
def _SkipIf0Blocks(self)
Definition: ast.py:865
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.Generate (   self)

Definition at line 704 of file ast.py.

References cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.current_token, cpp.ast.AstBuilder.Generate(), and cpp.ast.AstBuilder.HandleError().

704  def Generate(self):
705  while 1:
706  token = self._GetNextToken()
707  if not token:
708  break
709 
710  # Get the next token.
711  self.current_token = token
712 
713  # Dispatch on the next token type.
714  if token.token_type == _INTERNAL_TOKEN:
715  if token.name == _NAMESPACE_POP:
716  self.namespace_stack.pop()
717  continue
718 
719  try:
720  result = self._GenerateOne(token)
721  if result is not None:
722  yield result
723  except:
724  self.HandleError('exception', token)
725  raise
726 
def Generate(self)
Definition: ast.py:704
def HandleError(self, msg, token)
Definition: ast.py:699
def _GenerateOne(self, token)
Definition: ast.py:738
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.Generate (   self)

Definition at line 704 of file ast.py.

References cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.current_token, cpp.ast.AstBuilder.Generate(), and cpp.ast.AstBuilder.HandleError().

704  def Generate(self):
705  while 1:
706  token = self._GetNextToken()
707  if not token:
708  break
709 
710  # Get the next token.
711  self.current_token = token
712 
713  # Dispatch on the next token type.
714  if token.token_type == _INTERNAL_TOKEN:
715  if token.name == _NAMESPACE_POP:
716  self.namespace_stack.pop()
717  continue
718 
719  try:
720  result = self._GenerateOne(token)
721  if result is not None:
722  yield result
723  except:
724  self.HandleError('exception', token)
725  raise
726 
def Generate(self)
Definition: ast.py:704
def HandleError(self, msg, token)
Definition: ast.py:699
def _GenerateOne(self, token)
Definition: ast.py:738
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.Generate (   self)

Definition at line 704 of file ast.py.

References cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GenerateOne(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.current_token, and cpp.ast.AstBuilder.HandleError().

Referenced by cpp.ast.AstBuilder.Generate().

704  def Generate(self):
705  while 1:
706  token = self._GetNextToken()
707  if not token:
708  break
709 
710  # Get the next token.
711  self.current_token = token
712 
713  # Dispatch on the next token type.
714  if token.token_type == _INTERNAL_TOKEN:
715  if token.name == _NAMESPACE_POP:
716  self.namespace_stack.pop()
717  continue
718 
719  try:
720  result = self._GenerateOne(token)
721  if result is not None:
722  yield result
723  except:
724  self.HandleError('exception', token)
725  raise
726 
def Generate(self)
Definition: ast.py:704
def HandleError(self, msg, token)
Definition: ast.py:699
def _GenerateOne(self, token)
Definition: ast.py:738
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.GetMethod (   self,
  modifiers,
  templated_types 
)

Definition at line 953 of file ast.py.

References cpp.ast.AstBuilder._GetMethod(), and cpp.ast.AstBuilder._GetTokensUpTo().

Referenced by cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.handle_explicit(), and cpp.ast.AstBuilder.handle_template().

953  def GetMethod(self, modifiers, templated_types):
954  return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(')
955  assert len(return_type_and_name) >= 1
956  return self._GetMethod(return_type_and_name, modifiers, templated_types,
957  False)
958 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.GetMethod (   self,
  modifiers,
  templated_types 
)

Definition at line 953 of file ast.py.

References cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder.GetMethod().

953  def GetMethod(self, modifiers, templated_types):
954  return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(')
955  assert len(return_type_and_name) >= 1
956  return self._GetMethod(return_type_and_name, modifiers, templated_types,
957  False)
958 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.GetMethod (   self,
  modifiers,
  templated_types 
)

Definition at line 953 of file ast.py.

References cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder.GetMethod().

953  def GetMethod(self, modifiers, templated_types):
954  return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(')
955  assert len(return_type_and_name) >= 1
956  return self._GetMethod(return_type_and_name, modifiers, templated_types,
957  False)
958 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.GetName (   self,
  seq = None 
)
Returns ([tokens], next_token_info).

Definition at line 928 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.GetName(), and cpp.ast.next().

928  def GetName(self, seq=None):
929  """Returns ([tokens], next_token_info)."""
930  GetNextToken = self._GetNextToken
931  if seq is not None:
932  it = iter(seq)
933  GetNextToken = lambda: next(it)
934  next_token = GetNextToken()
935  tokens = []
936  last_token_was_name = False
937  while (next_token.token_type == tokenize.NAME or
938  (next_token.token_type == tokenize.SYNTAX and
939  next_token.name in ('::', '<'))):
940  # Two NAMEs in a row means the identifier should terminate.
941  # It's probably some sort of variable declaration.
942  if last_token_was_name and next_token.token_type == tokenize.NAME:
943  break
944  last_token_was_name = next_token.token_type == tokenize.NAME
945  tokens.append(next_token)
946  # Handle templated names.
947  if next_token.name == '<':
948  tokens.extend(self._GetMatchingChar('<', '>', GetNextToken))
949  last_token_was_name = True
950  next_token = GetNextToken()
951  return tokens, next_token
952 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNextToken(self)
Definition: ast.py:905
def next(obj)
Definition: ast.py:58
def cpp.ast.AstBuilder.GetName (   self,
  seq = None 
)
Returns ([tokens], next_token_info).

Definition at line 928 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.GetName(), and cpp.ast.next().

928  def GetName(self, seq=None):
929  """Returns ([tokens], next_token_info)."""
930  GetNextToken = self._GetNextToken
931  if seq is not None:
932  it = iter(seq)
933  GetNextToken = lambda: next(it)
934  next_token = GetNextToken()
935  tokens = []
936  last_token_was_name = False
937  while (next_token.token_type == tokenize.NAME or
938  (next_token.token_type == tokenize.SYNTAX and
939  next_token.name in ('::', '<'))):
940  # Two NAMEs in a row means the identifier should terminate.
941  # It's probably some sort of variable declaration.
942  if last_token_was_name and next_token.token_type == tokenize.NAME:
943  break
944  last_token_was_name = next_token.token_type == tokenize.NAME
945  tokens.append(next_token)
946  # Handle templated names.
947  if next_token.name == '<':
948  tokens.extend(self._GetMatchingChar('<', '>', GetNextToken))
949  last_token_was_name = True
950  next_token = GetNextToken()
951  return tokens, next_token
952 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNextToken(self)
Definition: ast.py:905
def next(obj)
Definition: ast.py:58
def cpp.ast.AstBuilder.GetName (   self,
  seq = None 
)
Returns ([tokens], next_token_info).

Definition at line 928 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), cpp.ast.AstBuilder._GetNextToken(), and cpp.ast.next().

Referenced by cpp.ast.AstBuilder._GetBases(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetNestedType(), cpp.ast.AstBuilder._GetReturnTypeAndClassName(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.handle_namespace(), and cpp.ast.AstBuilder.handle_struct().

928  def GetName(self, seq=None):
929  """Returns ([tokens], next_token_info)."""
930  GetNextToken = self._GetNextToken
931  if seq is not None:
932  it = iter(seq)
933  GetNextToken = lambda: next(it)
934  next_token = GetNextToken()
935  tokens = []
936  last_token_was_name = False
937  while (next_token.token_type == tokenize.NAME or
938  (next_token.token_type == tokenize.SYNTAX and
939  next_token.name in ('::', '<'))):
940  # Two NAMEs in a row means the identifier should terminate.
941  # It's probably some sort of variable declaration.
942  if last_token_was_name and next_token.token_type == tokenize.NAME:
943  break
944  last_token_was_name = next_token.token_type == tokenize.NAME
945  tokens.append(next_token)
946  # Handle templated names.
947  if next_token.name == '<':
948  tokens.extend(self._GetMatchingChar('<', '>', GetNextToken))
949  last_token_was_name = True
950  next_token = GetNextToken()
951  return tokens, next_token
952 
def GetName(self, seq=None)
Definition: ast.py:928
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def _GetNextToken(self)
Definition: ast.py:905
def next(obj)
Definition: ast.py:58
def cpp.ast.AstBuilder.GetScope (   self)

Definition at line 902 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar().

Referenced by cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder.GetScope(), and cpp.ast.AstBuilder.handle_namespace().

902  def GetScope(self):
903  return self._GetMatchingChar('{', '}')
904 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def GetScope(self)
Definition: ast.py:902
def cpp.ast.AstBuilder.GetScope (   self)

Definition at line 902 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), and cpp.ast.AstBuilder.GetScope().

902  def GetScope(self):
903  return self._GetMatchingChar('{', '}')
904 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def GetScope(self)
Definition: ast.py:902
def cpp.ast.AstBuilder.GetScope (   self)

Definition at line 902 of file ast.py.

References cpp.ast.AstBuilder._GetMatchingChar(), and cpp.ast.AstBuilder.GetScope().

902  def GetScope(self):
903  return self._GetMatchingChar('{', '}')
904 
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
Definition: ast.py:880
def GetScope(self)
Definition: ast.py:902
def cpp.ast.AstBuilder.handle_asm (   self)

Definition at line 1451 of file ast.py.

References cpp.ast.AstBuilder.handle_asm().

1451  def handle_asm(self):
1452  pass # Not needed yet.
1453 
def handle_asm(self)
Definition: ast.py:1451
def cpp.ast.AstBuilder.handle_asm (   self)

Definition at line 1451 of file ast.py.

References cpp.ast.AstBuilder.handle_asm().

1451  def handle_asm(self):
1452  pass # Not needed yet.
1453 
def handle_asm(self)
Definition: ast.py:1451
def cpp.ast.AstBuilder.handle_asm (   self)

Definition at line 1451 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_asm().

1451  def handle_asm(self):
1452  pass # Not needed yet.
1453 
def handle_asm(self)
Definition: ast.py:1451
def cpp.ast.AstBuilder.handle_auto (   self)

Definition at line 1269 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_auto().

1269  def handle_auto(self):
1270  # TODO(nnorwitz): warn about using auto? Probably not since it
1271  # will be reclaimed and useful for C++0x.
1272  pass
1273 
def handle_auto(self)
Definition: ast.py:1269
def cpp.ast.AstBuilder.handle_auto (   self)

Definition at line 1269 of file ast.py.

References cpp.ast.AstBuilder.handle_auto().

1269  def handle_auto(self):
1270  # TODO(nnorwitz): warn about using auto? Probably not since it
1271  # will be reclaimed and useful for C++0x.
1272  pass
1273 
def handle_auto(self)
Definition: ast.py:1269
def cpp.ast.AstBuilder.handle_auto (   self)

Definition at line 1269 of file ast.py.

References cpp.ast.AstBuilder.handle_auto().

1269  def handle_auto(self):
1270  # TODO(nnorwitz): warn about using auto? Probably not since it
1271  # will be reclaimed and useful for C++0x.
1272  pass
1273 
def handle_auto(self)
Definition: ast.py:1269
def cpp.ast.AstBuilder.handle_bool (   self)

Definition at line 1160 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_bool().

1160  def handle_bool(self):
1161  pass
1162 
def handle_bool(self)
Definition: ast.py:1160
def cpp.ast.AstBuilder.handle_bool (   self)

Definition at line 1160 of file ast.py.

References cpp.ast.AstBuilder.handle_bool().

1160  def handle_bool(self):
1161  pass
1162 
def handle_bool(self)
Definition: ast.py:1160
def cpp.ast.AstBuilder.handle_bool (   self)

Definition at line 1160 of file ast.py.

References cpp.ast.AstBuilder.handle_bool().

1160  def handle_bool(self):
1161  pass
1162 
def handle_bool(self)
Definition: ast.py:1160
def cpp.ast.AstBuilder.handle_break (   self)

Definition at line 1656 of file ast.py.

1656  def handle_break(self):
1657  self._IgnoreUpTo(tokenize.SYNTAX, ';')
1658 
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def handle_break(self)
Definition: ast.py:1656
def cpp.ast.AstBuilder.handle_break (   self)

Definition at line 1656 of file ast.py.

1656  def handle_break(self):
1657  self._IgnoreUpTo(tokenize.SYNTAX, ';')
1658 
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def handle_break(self)
Definition: ast.py:1656
def cpp.ast.AstBuilder.handle_break (   self)

Definition at line 1656 of file ast.py.

1656  def handle_break(self):
1657  self._IgnoreUpTo(tokenize.SYNTAX, ';')
1658 
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def handle_break(self)
Definition: ast.py:1656
def cpp.ast.AstBuilder.handle_case (   self)

Definition at line 1610 of file ast.py.

1610  def handle_case(self):
1611  pass
1612 
def handle_case(self)
Definition: ast.py:1610
def cpp.ast.AstBuilder.handle_case (   self)

Definition at line 1610 of file ast.py.

1610  def handle_case(self):
1611  pass
1612 
def handle_case(self)
Definition: ast.py:1610
def cpp.ast.AstBuilder.handle_case (   self)

Definition at line 1610 of file ast.py.

1610  def handle_case(self):
1611  pass
1612 
def handle_case(self)
Definition: ast.py:1610
def cpp.ast.AstBuilder.handle_catch (   self)

Definition at line 1641 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_catch().

1641  def handle_catch(self):
1642  pass # Not needed yet.
1643 
def handle_catch(self)
Definition: ast.py:1641
def cpp.ast.AstBuilder.handle_catch (   self)

Definition at line 1641 of file ast.py.

References cpp.ast.AstBuilder.handle_catch().

1641  def handle_catch(self):
1642  pass # Not needed yet.
1643 
def handle_catch(self)
Definition: ast.py:1641
def cpp.ast.AstBuilder.handle_catch (   self)

Definition at line 1641 of file ast.py.

References cpp.ast.AstBuilder.handle_catch().

1641  def handle_catch(self):
1642  pass # Not needed yet.
1643 
def handle_catch(self)
Definition: ast.py:1641
def cpp.ast.AstBuilder.handle_char (   self)

Definition at line 1163 of file ast.py.

1163  def handle_char(self):
1164  pass
1165 
def handle_char(self)
Definition: ast.py:1163
def cpp.ast.AstBuilder.handle_char (   self)

Definition at line 1163 of file ast.py.

1163  def handle_char(self):
1164  pass
1165 
def handle_char(self)
Definition: ast.py:1163
def cpp.ast.AstBuilder.handle_char (   self)

Definition at line 1163 of file ast.py.

1163  def handle_char(self):
1164  pass
1165 
def handle_char(self)
Definition: ast.py:1163
def cpp.ast.AstBuilder.handle_class (   self)

Definition at line 1454 of file ast.py.

References cpp.ast.AstBuilder._GetClass(), and cpp.ast.AstBuilder.handle_class().

1454  def handle_class(self):
1455  return self._GetClass(Class, VISIBILITY_PRIVATE, None)
1456 
def handle_class(self)
Definition: ast.py:1454
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def cpp.ast.AstBuilder.handle_class (   self)

Definition at line 1454 of file ast.py.

References cpp.ast.AstBuilder._GetClass(), and cpp.ast.AstBuilder.handle_class().

1454  def handle_class(self):
1455  return self._GetClass(Class, VISIBILITY_PRIVATE, None)
1456 
def handle_class(self)
Definition: ast.py:1454
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def cpp.ast.AstBuilder.handle_class (   self)

Definition at line 1454 of file ast.py.

References cpp.ast.AstBuilder._GetClass().

Referenced by cpp.ast.AstBuilder.handle_class().

1454  def handle_class(self):
1455  return self._GetClass(Class, VISIBILITY_PRIVATE, None)
1456 
def handle_class(self)
Definition: ast.py:1454
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def cpp.ast.AstBuilder.handle_const (   self)

Definition at line 1277 of file ast.py.

1277  def handle_const(self):
1278  pass
1279 
def handle_const(self)
Definition: ast.py:1277
def cpp.ast.AstBuilder.handle_const (   self)

Definition at line 1277 of file ast.py.

1277  def handle_const(self):
1278  pass
1279 
def handle_const(self)
Definition: ast.py:1277
def cpp.ast.AstBuilder.handle_const (   self)

Definition at line 1277 of file ast.py.

1277  def handle_const(self):
1278  pass
1279 
def handle_const(self)
Definition: ast.py:1277
def cpp.ast.AstBuilder.handle_const_cast (   self)

Definition at line 1332 of file ast.py.

1333  pass
1334 
def handle_const_cast(self)
Definition: ast.py:1332
def cpp.ast.AstBuilder.handle_const_cast (   self)

Definition at line 1332 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_const_cast().

1333  pass
1334 
def handle_const_cast(self)
Definition: ast.py:1332
def cpp.ast.AstBuilder.handle_const_cast (   self)

Definition at line 1332 of file ast.py.

1333  pass
1334 
def handle_const_cast(self)
Definition: ast.py:1332
def cpp.ast.AstBuilder.handle_continue (   self)
def cpp.ast.AstBuilder.handle_continue (   self)

Definition at line 1659 of file ast.py.

References cpp.ast.AstBuilder._IgnoreUpTo().

Referenced by cpp.ast.AstBuilder.handle_continue().

1659  def handle_continue(self):
1660  self._IgnoreUpTo(tokenize.SYNTAX, ';')
1661 
1662 
def _IgnoreUpTo(self, token_type, token)
Definition: ast.py:862
def handle_continue(self)
Definition: ast.py:1659
def cpp.ast.AstBuilder.handle_continue (   self)
def cpp.ast.AstBuilder.handle_default (   self)

Definition at line 1616 of file ast.py.

1616  def handle_default(self):
1617  token = self._GetNextToken()
1618  assert token.token_type == tokenize.SYNTAX
1619  assert token.name == ':'
1620 
def _GetNextToken(self)
Definition: ast.py:905
def handle_default(self)
Definition: ast.py:1616
def cpp.ast.AstBuilder.handle_default (   self)

Definition at line 1616 of file ast.py.

1616  def handle_default(self):
1617  token = self._GetNextToken()
1618  assert token.token_type == tokenize.SYNTAX
1619  assert token.name == ':'
1620 
def _GetNextToken(self)
Definition: ast.py:905
def handle_default(self)
Definition: ast.py:1616
def cpp.ast.AstBuilder.handle_default (   self)

Definition at line 1616 of file ast.py.

1616  def handle_default(self):
1617  token = self._GetNextToken()
1618  assert token.token_type == tokenize.SYNTAX
1619  assert token.name == ':'
1620 
def _GetNextToken(self)
Definition: ast.py:905
def handle_default(self)
Definition: ast.py:1616
def cpp.ast.AstBuilder.handle_delete (   self)

Definition at line 1344 of file ast.py.

1344  def handle_delete(self):
1345  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1346  assert tokens
1347  return Delete(tokens[0].start, tokens[0].end, tokens)
1348 
def handle_delete(self)
Definition: ast.py:1344
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def cpp.ast.AstBuilder.handle_delete (   self)

Definition at line 1344 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_delete().

1344  def handle_delete(self):
1345  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1346  assert tokens
1347  return Delete(tokens[0].start, tokens[0].end, tokens)
1348 
def handle_delete(self)
Definition: ast.py:1344
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def cpp.ast.AstBuilder.handle_delete (   self)

Definition at line 1344 of file ast.py.

1344  def handle_delete(self):
1345  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1346  assert tokens
1347  return Delete(tokens[0].start, tokens[0].end, tokens)
1348 
def handle_delete(self)
Definition: ast.py:1344
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def cpp.ast.AstBuilder.handle_do (   self)

Definition at line 1650 of file ast.py.

1650  def handle_do(self):
1651  pass
1652 
def handle_do(self)
Definition: ast.py:1650
def cpp.ast.AstBuilder.handle_do (   self)

Definition at line 1650 of file ast.py.

1650  def handle_do(self):
1651  pass
1652 
def handle_do(self)
Definition: ast.py:1650
def cpp.ast.AstBuilder.handle_do (   self)

Definition at line 1650 of file ast.py.

1650  def handle_do(self):
1651  pass
1652 
def handle_do(self)
Definition: ast.py:1650
def cpp.ast.AstBuilder.handle_double (   self)

Definition at line 1175 of file ast.py.

1175  def handle_double(self):
1176  pass
1177 
def handle_double(self)
Definition: ast.py:1175
def cpp.ast.AstBuilder.handle_double (   self)

Definition at line 1175 of file ast.py.

1175  def handle_double(self):
1176  pass
1177 
def handle_double(self)
Definition: ast.py:1175
def cpp.ast.AstBuilder.handle_double (   self)

Definition at line 1175 of file ast.py.

1175  def handle_double(self):
1176  pass
1177 
def handle_double(self)
Definition: ast.py:1175
def cpp.ast.AstBuilder.handle_dynamic_cast (   self)

Definition at line 1335 of file ast.py.

1336  pass
1337 
def handle_dynamic_cast(self)
Definition: ast.py:1335
def cpp.ast.AstBuilder.handle_dynamic_cast (   self)

Definition at line 1335 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_dynamic_cast().

1336  pass
1337 
def handle_dynamic_cast(self)
Definition: ast.py:1335
def cpp.ast.AstBuilder.handle_dynamic_cast (   self)

Definition at line 1335 of file ast.py.

1336  pass
1337 
def handle_dynamic_cast(self)
Definition: ast.py:1335
def cpp.ast.AstBuilder.handle_else (   self)

Definition at line 1624 of file ast.py.

1624  def handle_else(self):
1625  pass
1626 
def handle_else(self)
Definition: ast.py:1624
def cpp.ast.AstBuilder.handle_else (   self)

Definition at line 1624 of file ast.py.

1624  def handle_else(self):
1625  pass
1626 
def handle_else(self)
Definition: ast.py:1624
def cpp.ast.AstBuilder.handle_else (   self)

Definition at line 1624 of file ast.py.

1624  def handle_else(self):
1625  pass
1626 
def handle_else(self)
Definition: ast.py:1624
def cpp.ast.AstBuilder.handle_enum (   self)

Definition at line 1266 of file ast.py.

References cpp.ast.AstBuilder._GetNestedType().

Referenced by cpp.ast.AstBuilder.handle_enum().

1266  def handle_enum(self):
1267  return self._GetNestedType(Enum)
1268 
def handle_enum(self)
Definition: ast.py:1266
def _GetNestedType(self, ctor)
Definition: ast.py:1193
def cpp.ast.AstBuilder.handle_enum (   self)

Definition at line 1266 of file ast.py.

References cpp.ast.AstBuilder._GetNestedType(), and cpp.ast.AstBuilder.handle_enum().

1266  def handle_enum(self):
1267  return self._GetNestedType(Enum)
1268 
def handle_enum(self)
Definition: ast.py:1266
def _GetNestedType(self, ctor)
Definition: ast.py:1193
def cpp.ast.AstBuilder.handle_enum (   self)

Definition at line 1266 of file ast.py.

References cpp.ast.AstBuilder._GetNestedType(), and cpp.ast.AstBuilder.handle_enum().

1266  def handle_enum(self):
1267  return self._GetNestedType(Enum)
1268 
def handle_enum(self)
Definition: ast.py:1266
def _GetNestedType(self, ctor)
Definition: ast.py:1193
def cpp.ast.AstBuilder.handle_explicit (   self)

Definition at line 1593 of file ast.py.

References cpp.ast.AstBuilder.GetMethod(), cpp.ast.Method.in_class, and cpp.ast.AstBuilder.in_class.

Referenced by cpp.ast.AstBuilder.handle_explicit().

1593  def handle_explicit(self):
1594  assert self.in_class
1595  # Nothing much to do.
1596  # TODO(nnorwitz): maybe verify the method name == class name.
1597  # This must be a ctor.
1598  return self.GetMethod(FUNCTION_CTOR, None)
1599 
def handle_explicit(self)
Definition: ast.py:1593
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def cpp.ast.AstBuilder.handle_explicit (   self)

Definition at line 1593 of file ast.py.

References cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.handle_explicit(), cpp.ast.Method.in_class, and cpp.ast.AstBuilder.in_class.

1593  def handle_explicit(self):
1594  assert self.in_class
1595  # Nothing much to do.
1596  # TODO(nnorwitz): maybe verify the method name == class name.
1597  # This must be a ctor.
1598  return self.GetMethod(FUNCTION_CTOR, None)
1599 
def handle_explicit(self)
Definition: ast.py:1593
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def cpp.ast.AstBuilder.handle_explicit (   self)

Definition at line 1593 of file ast.py.

References cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.handle_explicit(), cpp.ast.Method.in_class, and cpp.ast.AstBuilder.in_class.

1593  def handle_explicit(self):
1594  assert self.in_class
1595  # Nothing much to do.
1596  # TODO(nnorwitz): maybe verify the method name == class name.
1597  # This must be a ctor.
1598  return self.GetMethod(FUNCTION_CTOR, None)
1599 
def handle_explicit(self)
Definition: ast.py:1593
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def cpp.ast.AstBuilder.handle_extern (   self)

Definition at line 1283 of file ast.py.

1283  def handle_extern(self):
1284  pass
1285 
def handle_extern(self)
Definition: ast.py:1283
def cpp.ast.AstBuilder.handle_extern (   self)

Definition at line 1283 of file ast.py.

1283  def handle_extern(self):
1284  pass
1285 
def handle_extern(self)
Definition: ast.py:1283
def cpp.ast.AstBuilder.handle_extern (   self)

Definition at line 1283 of file ast.py.

1283  def handle_extern(self):
1284  pass
1285 
def handle_extern(self)
Definition: ast.py:1283
def cpp.ast.AstBuilder.handle_false (   self)

Definition at line 1448 of file ast.py.

References cpp.ast.AstBuilder.handle_false().

1448  def handle_false(self):
1449  pass # Nothing to do.
1450 
def handle_false(self)
Definition: ast.py:1448
def cpp.ast.AstBuilder.handle_false (   self)

Definition at line 1448 of file ast.py.

References cpp.ast.AstBuilder.handle_false().

1448  def handle_false(self):
1449  pass # Nothing to do.
1450 
def handle_false(self)
Definition: ast.py:1448
def cpp.ast.AstBuilder.handle_false (   self)

Definition at line 1448 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_false().

1448  def handle_false(self):
1449  pass # Nothing to do.
1450 
def handle_false(self)
Definition: ast.py:1448
def cpp.ast.AstBuilder.handle_float (   self)

Definition at line 1178 of file ast.py.

1178  def handle_float(self):
1179  pass
1180 
def handle_float(self)
Definition: ast.py:1178
def cpp.ast.AstBuilder.handle_float (   self)

Definition at line 1178 of file ast.py.

1178  def handle_float(self):
1179  pass
1180 
def handle_float(self)
Definition: ast.py:1178
def cpp.ast.AstBuilder.handle_float (   self)

Definition at line 1178 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_float().

1178  def handle_float(self):
1179  pass
1180 
def handle_float(self)
Definition: ast.py:1178
def cpp.ast.AstBuilder.handle_for (   self)

Definition at line 1653 of file ast.py.

1653  def handle_for(self):
1654  pass
1655 
def handle_for(self)
Definition: ast.py:1653
def cpp.ast.AstBuilder.handle_for (   self)

Definition at line 1653 of file ast.py.

1653  def handle_for(self):
1654  pass
1655 
def handle_for(self)
Definition: ast.py:1653
def cpp.ast.AstBuilder.handle_for (   self)

Definition at line 1653 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_for().

1653  def handle_for(self):
1654  pass
1655 
def handle_for(self)
Definition: ast.py:1653
def cpp.ast.AstBuilder.handle_friend (   self)

Definition at line 1323 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder.handle_friend(), cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

1323  def handle_friend(self):
1324  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1325  assert tokens
1326  t0 = tokens[0]
1327  return Friend(t0.start, t0.end, tokens, self.namespace_stack)
1328 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_friend(self)
Definition: ast.py:1323
def cpp.ast.AstBuilder.handle_friend (   self)

Definition at line 1323 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

Referenced by cpp.ast.AstBuilder.handle_friend(), and cpp.ast.AstBuilder.handle_template().

1323  def handle_friend(self):
1324  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1325  assert tokens
1326  t0 = tokens[0]
1327  return Friend(t0.start, t0.end, tokens, self.namespace_stack)
1328 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_friend(self)
Definition: ast.py:1323
def cpp.ast.AstBuilder.handle_friend (   self)

Definition at line 1323 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder.handle_friend(), cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

1323  def handle_friend(self):
1324  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1325  assert tokens
1326  t0 = tokens[0]
1327  return Friend(t0.start, t0.end, tokens, self.namespace_stack)
1328 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_friend(self)
Definition: ast.py:1323
def cpp.ast.AstBuilder.handle_goto (   self)

Definition at line 1633 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo().

Referenced by cpp.ast.AstBuilder.handle_goto().

1633  def handle_goto(self):
1634  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1635  assert len(tokens) == 1, str(tokens)
1636  return Goto(tokens[0].start, tokens[0].end, tokens[0].name)
1637 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_goto(self)
Definition: ast.py:1633
def cpp.ast.AstBuilder.handle_goto (   self)

Definition at line 1633 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder.handle_goto().

1633  def handle_goto(self):
1634  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1635  assert len(tokens) == 1, str(tokens)
1636  return Goto(tokens[0].start, tokens[0].end, tokens[0].name)
1637 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_goto(self)
Definition: ast.py:1633
def cpp.ast.AstBuilder.handle_goto (   self)

Definition at line 1633 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder.handle_goto().

1633  def handle_goto(self):
1634  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1635  assert len(tokens) == 1, str(tokens)
1636  return Goto(tokens[0].start, tokens[0].end, tokens[0].name)
1637 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_goto(self)
Definition: ast.py:1633
def cpp.ast.AstBuilder.handle_if (   self)

Definition at line 1621 of file ast.py.

References cpp.ast.AstBuilder.handle_if().

1621  def handle_if(self):
1622  pass
1623 
def handle_if(self)
Definition: ast.py:1621
def cpp.ast.AstBuilder.handle_if (   self)

Definition at line 1621 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_if().

1621  def handle_if(self):
1622  pass
1623 
def handle_if(self)
Definition: ast.py:1621
def cpp.ast.AstBuilder.handle_if (   self)

Definition at line 1621 of file ast.py.

References cpp.ast.AstBuilder.handle_if().

1621  def handle_if(self):
1622  pass
1623 
def handle_if(self)
Definition: ast.py:1621
def cpp.ast.AstBuilder.handle_inline (   self)

Definition at line 1280 of file ast.py.

1280  def handle_inline(self):
1281  pass
1282 
def handle_inline(self)
Definition: ast.py:1280
def cpp.ast.AstBuilder.handle_inline (   self)

Definition at line 1280 of file ast.py.

1280  def handle_inline(self):
1281  pass
1282 
def handle_inline(self)
Definition: ast.py:1280
def cpp.ast.AstBuilder.handle_inline (   self)

Definition at line 1280 of file ast.py.

1280  def handle_inline(self):
1281  pass
1282 
def handle_inline(self)
Definition: ast.py:1280
def cpp.ast.AstBuilder.handle_int (   self)

Definition at line 1166 of file ast.py.

1166  def handle_int(self):
1167  pass
1168 
def handle_int(self)
Definition: ast.py:1166
def cpp.ast.AstBuilder.handle_int (   self)

Definition at line 1166 of file ast.py.

1166  def handle_int(self):
1167  pass
1168 
def handle_int(self)
Definition: ast.py:1166
def cpp.ast.AstBuilder.handle_int (   self)

Definition at line 1166 of file ast.py.

1166  def handle_int(self):
1167  pass
1168 
def handle_int(self)
Definition: ast.py:1166
def cpp.ast.AstBuilder.handle_long (   self)

Definition at line 1169 of file ast.py.

1169  def handle_long(self):
1170  pass
1171 
def handle_long(self)
Definition: ast.py:1169
def cpp.ast.AstBuilder.handle_long (   self)

Definition at line 1169 of file ast.py.

1169  def handle_long(self):
1170  pass
1171 
def handle_long(self)
Definition: ast.py:1169
def cpp.ast.AstBuilder.handle_long (   self)

Definition at line 1169 of file ast.py.

1169  def handle_long(self):
1170  pass
1171 
def handle_long(self)
Definition: ast.py:1169
def cpp.ast.AstBuilder.handle_mutable (   self)

Definition at line 1308 of file ast.py.

1308  def handle_mutable(self):
1309  pass
1310 
def handle_mutable(self)
Definition: ast.py:1308
def cpp.ast.AstBuilder.handle_mutable (   self)

Definition at line 1308 of file ast.py.

1308  def handle_mutable(self):
1309  pass
1310 
def handle_mutable(self)
Definition: ast.py:1308
def cpp.ast.AstBuilder.handle_mutable (   self)

Definition at line 1308 of file ast.py.

1308  def handle_mutable(self):
1309  pass
1310 
def handle_mutable(self)
Definition: ast.py:1308
def cpp.ast.AstBuilder.handle_namespace (   self)

Definition at line 1561 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.GetScope(), and bm.list.

Referenced by cpp.ast.AstBuilder.handle_namespace().

1561  def handle_namespace(self):
1562  token = self._GetNextToken()
1563  # Support anonymous namespaces.
1564  name = None
1565  if token.token_type == tokenize.NAME:
1566  name = token.name
1567  token = self._GetNextToken()
1568  self.namespace_stack.append(name)
1569  assert token.token_type == tokenize.SYNTAX, token
1570  # Create an internal token that denotes when the namespace is complete.
1571  internal_token = tokenize.Token(_INTERNAL_TOKEN, _NAMESPACE_POP,
1572  None, None)
1573  internal_token.whence = token.whence
1574  if token.name == '=':
1575  # TODO(nnorwitz): handle aliasing namespaces.
1576  name, next_token = self.GetName()
1577  assert next_token.name == ';', next_token
1578  self._AddBackToken(internal_token)
1579  else:
1580  assert token.name == '{', token
1581  tokens = list(self.GetScope())
1582  # Replace the trailing } with the internal namespace pop token.
1583  tokens[-1] = internal_token
1584  # Handle namespace with nothing in it.
1585  self._AddBackTokens(tokens)
1586  return None
1587 
def handle_namespace(self)
Definition: ast.py:1561
def GetName(self, seq=None)
Definition: ast.py:928
Encoder::MutableCompressedList list
def GetScope(self)
Definition: ast.py:902
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder.handle_namespace (   self)

Definition at line 1561 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.handle_namespace(), and bm.list.

1561  def handle_namespace(self):
1562  token = self._GetNextToken()
1563  # Support anonymous namespaces.
1564  name = None
1565  if token.token_type == tokenize.NAME:
1566  name = token.name
1567  token = self._GetNextToken()
1568  self.namespace_stack.append(name)
1569  assert token.token_type == tokenize.SYNTAX, token
1570  # Create an internal token that denotes when the namespace is complete.
1571  internal_token = tokenize.Token(_INTERNAL_TOKEN, _NAMESPACE_POP,
1572  None, None)
1573  internal_token.whence = token.whence
1574  if token.name == '=':
1575  # TODO(nnorwitz): handle aliasing namespaces.
1576  name, next_token = self.GetName()
1577  assert next_token.name == ';', next_token
1578  self._AddBackToken(internal_token)
1579  else:
1580  assert token.name == '{', token
1581  tokens = list(self.GetScope())
1582  # Replace the trailing } with the internal namespace pop token.
1583  tokens[-1] = internal_token
1584  # Handle namespace with nothing in it.
1585  self._AddBackTokens(tokens)
1586  return None
1587 
def handle_namespace(self)
Definition: ast.py:1561
def GetName(self, seq=None)
Definition: ast.py:928
Encoder::MutableCompressedList list
def GetScope(self)
Definition: ast.py:902
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder.handle_namespace (   self)

Definition at line 1561 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.GetScope(), cpp.ast.AstBuilder.handle_namespace(), and bm.list.

1561  def handle_namespace(self):
1562  token = self._GetNextToken()
1563  # Support anonymous namespaces.
1564  name = None
1565  if token.token_type == tokenize.NAME:
1566  name = token.name
1567  token = self._GetNextToken()
1568  self.namespace_stack.append(name)
1569  assert token.token_type == tokenize.SYNTAX, token
1570  # Create an internal token that denotes when the namespace is complete.
1571  internal_token = tokenize.Token(_INTERNAL_TOKEN, _NAMESPACE_POP,
1572  None, None)
1573  internal_token.whence = token.whence
1574  if token.name == '=':
1575  # TODO(nnorwitz): handle aliasing namespaces.
1576  name, next_token = self.GetName()
1577  assert next_token.name == ';', next_token
1578  self._AddBackToken(internal_token)
1579  else:
1580  assert token.name == '{', token
1581  tokens = list(self.GetScope())
1582  # Replace the trailing } with the internal namespace pop token.
1583  tokens[-1] = internal_token
1584  # Handle namespace with nothing in it.
1585  self._AddBackTokens(tokens)
1586  return None
1587 
def handle_namespace(self)
Definition: ast.py:1561
def GetName(self, seq=None)
Definition: ast.py:928
Encoder::MutableCompressedList list
def GetScope(self)
Definition: ast.py:902
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder.handle_new (   self)

Definition at line 1341 of file ast.py.

1341  def handle_new(self):
1342  pass
1343 
def handle_new(self)
Definition: ast.py:1341
def cpp.ast.AstBuilder.handle_new (   self)

Definition at line 1341 of file ast.py.

1341  def handle_new(self):
1342  pass
1343 
def handle_new(self)
Definition: ast.py:1341
def cpp.ast.AstBuilder.handle_new (   self)

Definition at line 1341 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_new().

1341  def handle_new(self):
1342  pass
1343 
def handle_new(self)
Definition: ast.py:1341
def cpp.ast.AstBuilder.handle_operator (   self)

Definition at line 1603 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_operator().

1603  def handle_operator(self):
1604  # Pull off the next token(s?) and make that part of the method name.
1605  pass
1606 
def handle_operator(self)
Definition: ast.py:1603
def cpp.ast.AstBuilder.handle_operator (   self)

Definition at line 1603 of file ast.py.

References cpp.ast.AstBuilder.handle_operator().

1603  def handle_operator(self):
1604  # Pull off the next token(s?) and make that part of the method name.
1605  pass
1606 
def handle_operator(self)
Definition: ast.py:1603
def cpp.ast.AstBuilder.handle_operator (   self)

Definition at line 1603 of file ast.py.

References cpp.ast.AstBuilder.handle_operator().

1603  def handle_operator(self):
1604  # Pull off the next token(s?) and make that part of the method name.
1605  pass
1606 
def handle_operator(self)
Definition: ast.py:1603
def cpp.ast.AstBuilder.handle_private (   self)

Definition at line 1319 of file ast.py.

References cpp.ast.AstBuilder.handle_private(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, and cpp.ast.AstBuilder.visibility.

1319  def handle_private(self):
1320  assert self.in_class
1321  self.visibility = VISIBILITY_PRIVATE
1322 
def handle_private(self)
Definition: ast.py:1319
def cpp.ast.AstBuilder.handle_private (   self)

Definition at line 1319 of file ast.py.

References cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, and cpp.ast.AstBuilder.visibility.

Referenced by cpp.ast.AstBuilder.handle_private().

1319  def handle_private(self):
1320  assert self.in_class
1321  self.visibility = VISIBILITY_PRIVATE
1322 
def handle_private(self)
Definition: ast.py:1319
def cpp.ast.AstBuilder.handle_private (   self)

Definition at line 1319 of file ast.py.

References cpp.ast.AstBuilder.handle_private(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, and cpp.ast.AstBuilder.visibility.

1319  def handle_private(self):
1320  assert self.in_class
1321  self.visibility = VISIBILITY_PRIVATE
1322 
def handle_private(self)
Definition: ast.py:1319
def cpp.ast.AstBuilder.handle_protected (   self)

Definition at line 1315 of file ast.py.

References cpp.ast.AstBuilder.handle_protected(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, and cpp.ast.AstBuilder.visibility.

1315  def handle_protected(self):
1316  assert self.in_class
1317  self.visibility = VISIBILITY_PROTECTED
1318 
def handle_protected(self)
Definition: ast.py:1315
def cpp.ast.AstBuilder.handle_protected (   self)

Definition at line 1315 of file ast.py.

References cpp.ast.AstBuilder.handle_protected(), cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, and cpp.ast.AstBuilder.visibility.

1315  def handle_protected(self):
1316  assert self.in_class
1317  self.visibility = VISIBILITY_PROTECTED
1318 
def handle_protected(self)
Definition: ast.py:1315
def cpp.ast.AstBuilder.handle_protected (   self)

Definition at line 1315 of file ast.py.

References cpp.ast.Method.in_class, cpp.ast.AstBuilder.in_class, and cpp.ast.AstBuilder.visibility.

Referenced by cpp.ast.AstBuilder.handle_protected().

1315  def handle_protected(self):
1316  assert self.in_class
1317  self.visibility = VISIBILITY_PROTECTED
1318 
def handle_protected(self)
Definition: ast.py:1315
def cpp.ast.AstBuilder.handle_public (   self)

Definition at line 1311 of file ast.py.

1311  def handle_public(self):
1312  assert self.in_class
1313  self.visibility = VISIBILITY_PUBLIC
1314 
def handle_public(self)
Definition: ast.py:1311
def cpp.ast.AstBuilder.handle_public (   self)

Definition at line 1311 of file ast.py.

1311  def handle_public(self):
1312  assert self.in_class
1313  self.visibility = VISIBILITY_PUBLIC
1314 
def handle_public(self)
Definition: ast.py:1311
def cpp.ast.AstBuilder.handle_public (   self)

Definition at line 1311 of file ast.py.

1311  def handle_public(self):
1312  assert self.in_class
1313  self.visibility = VISIBILITY_PUBLIC
1314 
def handle_public(self)
Definition: ast.py:1311
def cpp.ast.AstBuilder.handle_register (   self)

Definition at line 1274 of file ast.py.

1274  def handle_register(self):
1275  pass
1276 
def handle_register(self)
Definition: ast.py:1274
def cpp.ast.AstBuilder.handle_register (   self)

Definition at line 1274 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_register().

1274  def handle_register(self):
1275  pass
1276 
def handle_register(self)
Definition: ast.py:1274
def cpp.ast.AstBuilder.handle_register (   self)

Definition at line 1274 of file ast.py.

1274  def handle_register(self):
1275  pass
1276 
def handle_register(self)
Definition: ast.py:1274
def cpp.ast.AstBuilder.handle_reinterpret_cast (   self)

Definition at line 1338 of file ast.py.

1339  pass
1340 
def handle_reinterpret_cast(self)
Definition: ast.py:1338
def cpp.ast.AstBuilder.handle_reinterpret_cast (   self)

Definition at line 1338 of file ast.py.

1339  pass
1340 
def handle_reinterpret_cast(self)
Definition: ast.py:1338
def cpp.ast.AstBuilder.handle_reinterpret_cast (   self)

Definition at line 1338 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_reinterpret_cast().

1339  pass
1340 
def handle_reinterpret_cast(self)
Definition: ast.py:1338
def cpp.ast.AstBuilder.handle_return (   self)

Definition at line 1627 of file ast.py.

1627  def handle_return(self):
1628  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1629  if not tokens:
1630  return Return(self.current_token.start, self.current_token.end, None)
1631  return Return(tokens[0].start, tokens[0].end, tokens)
1632 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_return(self)
Definition: ast.py:1627
def cpp.ast.AstBuilder.handle_return (   self)

Definition at line 1627 of file ast.py.

1627  def handle_return(self):
1628  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1629  if not tokens:
1630  return Return(self.current_token.start, self.current_token.end, None)
1631  return Return(tokens[0].start, tokens[0].end, tokens)
1632 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_return(self)
Definition: ast.py:1627
def cpp.ast.AstBuilder.handle_return (   self)

Definition at line 1627 of file ast.py.

1627  def handle_return(self):
1628  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1629  if not tokens:
1630  return Return(self.current_token.start, self.current_token.end, None)
1631  return Return(tokens[0].start, tokens[0].end, tokens)
1632 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_return(self)
Definition: ast.py:1627
def cpp.ast.AstBuilder.handle_short (   self)

Definition at line 1172 of file ast.py.

1172  def handle_short(self):
1173  pass
1174 
def handle_short(self)
Definition: ast.py:1172
def cpp.ast.AstBuilder.handle_short (   self)

Definition at line 1172 of file ast.py.

1172  def handle_short(self):
1173  pass
1174 
def handle_short(self)
Definition: ast.py:1172
def cpp.ast.AstBuilder.handle_short (   self)

Definition at line 1172 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_short().

1172  def handle_short(self):
1173  pass
1174 
def handle_short(self)
Definition: ast.py:1172
def cpp.ast.AstBuilder.handle_signed (   self)

Definition at line 1190 of file ast.py.

1190  def handle_signed(self):
1191  pass
1192 
def handle_signed(self)
Definition: ast.py:1190
def cpp.ast.AstBuilder.handle_signed (   self)

Definition at line 1190 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_signed().

1190  def handle_signed(self):
1191  pass
1192 
def handle_signed(self)
Definition: ast.py:1190
def cpp.ast.AstBuilder.handle_signed (   self)

Definition at line 1190 of file ast.py.

1190  def handle_signed(self):
1191  pass
1192 
def handle_signed(self)
Definition: ast.py:1190
def cpp.ast.AstBuilder.handle_sizeof (   self)

Definition at line 1607 of file ast.py.

1607  def handle_sizeof(self):
1608  pass
1609 
def handle_sizeof(self)
Definition: ast.py:1607
def cpp.ast.AstBuilder.handle_sizeof (   self)

Definition at line 1607 of file ast.py.

1607  def handle_sizeof(self):
1608  pass
1609 
def handle_sizeof(self)
Definition: ast.py:1607
def cpp.ast.AstBuilder.handle_sizeof (   self)

Definition at line 1607 of file ast.py.

1607  def handle_sizeof(self):
1608  pass
1609 
def handle_sizeof(self)
Definition: ast.py:1607
def cpp.ast.AstBuilder.handle_static (   self)

Definition at line 1286 of file ast.py.

1286  def handle_static(self):
1287  pass
1288 
def handle_static(self)
Definition: ast.py:1286
def cpp.ast.AstBuilder.handle_static (   self)

Definition at line 1286 of file ast.py.

1286  def handle_static(self):
1287  pass
1288 
def handle_static(self)
Definition: ast.py:1286
def cpp.ast.AstBuilder.handle_static (   self)

Definition at line 1286 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_static().

1286  def handle_static(self):
1287  pass
1288 
def handle_static(self)
Definition: ast.py:1286
def cpp.ast.AstBuilder.handle_static_cast (   self)

Definition at line 1329 of file ast.py.

References cpp.ast.AstBuilder.handle_static_cast().

1330  pass
1331 
def handle_static_cast(self)
Definition: ast.py:1329
def cpp.ast.AstBuilder.handle_static_cast (   self)

Definition at line 1329 of file ast.py.

References cpp.ast.AstBuilder.handle_static_cast().

1330  pass
1331 
def handle_static_cast(self)
Definition: ast.py:1329
def cpp.ast.AstBuilder.handle_static_cast (   self)

Definition at line 1329 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_static_cast().

1330  pass
1331 
def handle_static_cast(self)
Definition: ast.py:1329
def cpp.ast.AstBuilder.handle_struct (   self)

Definition at line 1227 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.handle_struct(), and join.

1227  def handle_struct(self):
1228  # Special case the handling typedef/aliasing of structs here.
1229  # It would be a pain to handle in the class code.
1230  name_tokens, var_token = self.GetName()
1231  if name_tokens:
1232  next_token = self._GetNextToken()
1233  is_syntax = (var_token.token_type == tokenize.SYNTAX and
1234  var_token.name[0] in '*&')
1235  is_variable = (var_token.token_type == tokenize.NAME and
1236  next_token.name == ';')
1237  variable = var_token
1238  if is_syntax and not is_variable:
1239  variable = next_token
1240  temp = self._GetNextToken()
1241  if temp.token_type == tokenize.SYNTAX and temp.name == '(':
1242  # Handle methods declared to return a struct.
1243  t0 = name_tokens[0]
1244  struct = tokenize.Token(tokenize.NAME, 'struct',
1245  t0.start-7, t0.start-2)
1246  type_and_name = [struct]
1247  type_and_name.extend(name_tokens)
1248  type_and_name.extend((var_token, next_token))
1249  return self._GetMethod(type_and_name, 0, None, False)
1250  assert temp.name == ';', (temp, name_tokens, var_token)
1251  if is_syntax or (is_variable and not self._handling_typedef):
1252  modifiers = ['struct']
1253  type_name = ''.join([t.name for t in name_tokens])
1254  position = name_tokens[0]
1255  return self._CreateVariable(position, variable.name, type_name,
1256  modifiers, var_token.name, None)
1257  name_tokens.extend((var_token, next_token))
1258  self._AddBackTokens(name_tokens)
1259  else:
1260  self._AddBackToken(var_token)
1261  return self._GetClass(Struct, VISIBILITY_PUBLIC, None)
1262 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def handle_struct(self)
Definition: ast.py:1227
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.handle_struct (   self)

Definition at line 1227 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.GetName(), cpp.ast.AstBuilder.handle_struct(), and join.

1227  def handle_struct(self):
1228  # Special case the handling typedef/aliasing of structs here.
1229  # It would be a pain to handle in the class code.
1230  name_tokens, var_token = self.GetName()
1231  if name_tokens:
1232  next_token = self._GetNextToken()
1233  is_syntax = (var_token.token_type == tokenize.SYNTAX and
1234  var_token.name[0] in '*&')
1235  is_variable = (var_token.token_type == tokenize.NAME and
1236  next_token.name == ';')
1237  variable = var_token
1238  if is_syntax and not is_variable:
1239  variable = next_token
1240  temp = self._GetNextToken()
1241  if temp.token_type == tokenize.SYNTAX and temp.name == '(':
1242  # Handle methods declared to return a struct.
1243  t0 = name_tokens[0]
1244  struct = tokenize.Token(tokenize.NAME, 'struct',
1245  t0.start-7, t0.start-2)
1246  type_and_name = [struct]
1247  type_and_name.extend(name_tokens)
1248  type_and_name.extend((var_token, next_token))
1249  return self._GetMethod(type_and_name, 0, None, False)
1250  assert temp.name == ';', (temp, name_tokens, var_token)
1251  if is_syntax or (is_variable and not self._handling_typedef):
1252  modifiers = ['struct']
1253  type_name = ''.join([t.name for t in name_tokens])
1254  position = name_tokens[0]
1255  return self._CreateVariable(position, variable.name, type_name,
1256  modifiers, var_token.name, None)
1257  name_tokens.extend((var_token, next_token))
1258  self._AddBackTokens(name_tokens)
1259  else:
1260  self._AddBackToken(var_token)
1261  return self._GetClass(Struct, VISIBILITY_PUBLIC, None)
1262 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def handle_struct(self)
Definition: ast.py:1227
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.handle_struct (   self)

Definition at line 1227 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._CreateVariable(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.GetName(), and join.

Referenced by cpp.ast.AstBuilder.handle_struct().

1227  def handle_struct(self):
1228  # Special case the handling typedef/aliasing of structs here.
1229  # It would be a pain to handle in the class code.
1230  name_tokens, var_token = self.GetName()
1231  if name_tokens:
1232  next_token = self._GetNextToken()
1233  is_syntax = (var_token.token_type == tokenize.SYNTAX and
1234  var_token.name[0] in '*&')
1235  is_variable = (var_token.token_type == tokenize.NAME and
1236  next_token.name == ';')
1237  variable = var_token
1238  if is_syntax and not is_variable:
1239  variable = next_token
1240  temp = self._GetNextToken()
1241  if temp.token_type == tokenize.SYNTAX and temp.name == '(':
1242  # Handle methods declared to return a struct.
1243  t0 = name_tokens[0]
1244  struct = tokenize.Token(tokenize.NAME, 'struct',
1245  t0.start-7, t0.start-2)
1246  type_and_name = [struct]
1247  type_and_name.extend(name_tokens)
1248  type_and_name.extend((var_token, next_token))
1249  return self._GetMethod(type_and_name, 0, None, False)
1250  assert temp.name == ';', (temp, name_tokens, var_token)
1251  if is_syntax or (is_variable and not self._handling_typedef):
1252  modifiers = ['struct']
1253  type_name = ''.join([t.name for t in name_tokens])
1254  position = name_tokens[0]
1255  return self._CreateVariable(position, variable.name, type_name,
1256  modifiers, var_token.name, None)
1257  name_tokens.extend((var_token, next_token))
1258  self._AddBackTokens(name_tokens)
1259  else:
1260  self._AddBackToken(var_token)
1261  return self._GetClass(Struct, VISIBILITY_PUBLIC, None)
1262 
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
Definition: ast.py:728
def GetName(self, seq=None)
Definition: ast.py:928
def handle_struct(self)
Definition: ast.py:1227
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetNextToken(self)
Definition: ast.py:905
#define join
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.handle_switch (   self)

Definition at line 1613 of file ast.py.

1613  def handle_switch(self):
1614  pass
1615 
def handle_switch(self)
Definition: ast.py:1613
def cpp.ast.AstBuilder.handle_switch (   self)

Definition at line 1613 of file ast.py.

1613  def handle_switch(self):
1614  pass
1615 
def handle_switch(self)
Definition: ast.py:1613
def cpp.ast.AstBuilder.handle_switch (   self)

Definition at line 1613 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_switch().

1613  def handle_switch(self):
1614  pass
1615 
def handle_switch(self)
Definition: ast.py:1613
def cpp.ast.AstBuilder.handle_template (   self)

Definition at line 1422 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder._GetVarTokensUpTo(), cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.handle_friend(), and cpp.ast.AstBuilder.handle_template().

1422  def handle_template(self):
1423  token = self._GetNextToken()
1424  assert token.token_type == tokenize.SYNTAX, token
1425  assert token.name == '<', token
1426  templated_types = self._GetTemplatedTypes()
1427  # TODO(nnorwitz): for now, just ignore the template params.
1428  token = self._GetNextToken()
1429  if token.token_type == tokenize.NAME:
1430  if token.name == 'class':
1431  return self._GetClass(Class, VISIBILITY_PRIVATE, templated_types)
1432  elif token.name == 'struct':
1433  return self._GetClass(Struct, VISIBILITY_PUBLIC, templated_types)
1434  elif token.name == 'friend':
1435  return self.handle_friend()
1436  self._AddBackToken(token)
1437  tokens, last = self._GetVarTokensUpTo(tokenize.SYNTAX, '(', ';')
1438  tokens.append(last)
1439  self._AddBackTokens(tokens)
1440  if last.name == '(':
1441  return self.GetMethod(FUNCTION_NONE, templated_types)
1442  # Must be a variable definition.
1443  return None
1444 
def _GetTemplatedTypes(self)
Definition: ast.py:1395
def handle_friend(self)
Definition: ast.py:1323
def handle_template(self)
Definition: ast.py:1422
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _GetNextToken(self)
Definition: ast.py:905
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder.handle_template (   self)

Definition at line 1422 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder._GetVarTokensUpTo(), cpp.ast.AstBuilder.GetMethod(), and cpp.ast.AstBuilder.handle_friend().

Referenced by cpp.ast.AstBuilder.handle_template().

1422  def handle_template(self):
1423  token = self._GetNextToken()
1424  assert token.token_type == tokenize.SYNTAX, token
1425  assert token.name == '<', token
1426  templated_types = self._GetTemplatedTypes()
1427  # TODO(nnorwitz): for now, just ignore the template params.
1428  token = self._GetNextToken()
1429  if token.token_type == tokenize.NAME:
1430  if token.name == 'class':
1431  return self._GetClass(Class, VISIBILITY_PRIVATE, templated_types)
1432  elif token.name == 'struct':
1433  return self._GetClass(Struct, VISIBILITY_PUBLIC, templated_types)
1434  elif token.name == 'friend':
1435  return self.handle_friend()
1436  self._AddBackToken(token)
1437  tokens, last = self._GetVarTokensUpTo(tokenize.SYNTAX, '(', ';')
1438  tokens.append(last)
1439  self._AddBackTokens(tokens)
1440  if last.name == '(':
1441  return self.GetMethod(FUNCTION_NONE, templated_types)
1442  # Must be a variable definition.
1443  return None
1444 
def _GetTemplatedTypes(self)
Definition: ast.py:1395
def handle_friend(self)
Definition: ast.py:1323
def handle_template(self)
Definition: ast.py:1422
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _GetNextToken(self)
Definition: ast.py:905
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder.handle_template (   self)

Definition at line 1422 of file ast.py.

References cpp.ast.AstBuilder._AddBackToken(), cpp.ast.AstBuilder._AddBackTokens(), cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTemplatedTypes(), cpp.ast.AstBuilder._GetVarTokensUpTo(), cpp.ast.AstBuilder.GetMethod(), cpp.ast.AstBuilder.handle_friend(), and cpp.ast.AstBuilder.handle_template().

1422  def handle_template(self):
1423  token = self._GetNextToken()
1424  assert token.token_type == tokenize.SYNTAX, token
1425  assert token.name == '<', token
1426  templated_types = self._GetTemplatedTypes()
1427  # TODO(nnorwitz): for now, just ignore the template params.
1428  token = self._GetNextToken()
1429  if token.token_type == tokenize.NAME:
1430  if token.name == 'class':
1431  return self._GetClass(Class, VISIBILITY_PRIVATE, templated_types)
1432  elif token.name == 'struct':
1433  return self._GetClass(Struct, VISIBILITY_PUBLIC, templated_types)
1434  elif token.name == 'friend':
1435  return self.handle_friend()
1436  self._AddBackToken(token)
1437  tokens, last = self._GetVarTokensUpTo(tokenize.SYNTAX, '(', ';')
1438  tokens.append(last)
1439  self._AddBackTokens(tokens)
1440  if last.name == '(':
1441  return self.GetMethod(FUNCTION_NONE, templated_types)
1442  # Must be a variable definition.
1443  return None
1444 
def _GetTemplatedTypes(self)
Definition: ast.py:1395
def handle_friend(self)
Definition: ast.py:1323
def handle_template(self)
Definition: ast.py:1422
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetClass(self, class_type, visibility, templated_types)
Definition: ast.py:1489
def _AddBackToken(self, token)
Definition: ast.py:910
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
Definition: ast.py:852
def _GetNextToken(self)
Definition: ast.py:905
def _AddBackTokens(self, tokens)
Definition: ast.py:918
def cpp.ast.AstBuilder.handle_this (   self)

Definition at line 1600 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_this().

1600  def handle_this(self):
1601  pass # Nothing to do.
1602 
def handle_this(self)
Definition: ast.py:1600
def cpp.ast.AstBuilder.handle_this (   self)

Definition at line 1600 of file ast.py.

References cpp.ast.AstBuilder.handle_this().

1600  def handle_this(self):
1601  pass # Nothing to do.
1602 
def handle_this(self)
Definition: ast.py:1600
def cpp.ast.AstBuilder.handle_this (   self)

Definition at line 1600 of file ast.py.

References cpp.ast.AstBuilder.handle_this().

1600  def handle_this(self):
1601  pass # Nothing to do.
1602 
def handle_this(self)
Definition: ast.py:1600
def cpp.ast.AstBuilder.handle_throw (   self)

Definition at line 1644 of file ast.py.

References cpp.ast.AstBuilder.handle_throw().

1644  def handle_throw(self):
1645  pass # Not needed yet.
1646 
def handle_throw(self)
Definition: ast.py:1644
def cpp.ast.AstBuilder.handle_throw (   self)

Definition at line 1644 of file ast.py.

References cpp.ast.AstBuilder.handle_throw().

1644  def handle_throw(self):
1645  pass # Not needed yet.
1646 
def handle_throw(self)
Definition: ast.py:1644
def cpp.ast.AstBuilder.handle_throw (   self)

Definition at line 1644 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_throw().

1644  def handle_throw(self):
1645  pass # Not needed yet.
1646 
def handle_throw(self)
Definition: ast.py:1644
def cpp.ast.AstBuilder.handle_true (   self)

Definition at line 1445 of file ast.py.

References cpp.ast.AstBuilder.handle_true().

1445  def handle_true(self):
1446  pass # Nothing to do.
1447 
def handle_true(self)
Definition: ast.py:1445
def cpp.ast.AstBuilder.handle_true (   self)

Definition at line 1445 of file ast.py.

References cpp.ast.AstBuilder.handle_true().

1445  def handle_true(self):
1446  pass # Nothing to do.
1447 
def handle_true(self)
Definition: ast.py:1445
def cpp.ast.AstBuilder.handle_true (   self)

Definition at line 1445 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_true().

1445  def handle_true(self):
1446  pass # Nothing to do.
1447 
def handle_true(self)
Definition: ast.py:1445
def cpp.ast.AstBuilder.handle_try (   self)

Definition at line 1638 of file ast.py.

References cpp.ast.AstBuilder.handle_try().

1638  def handle_try(self):
1639  pass # Not needed yet.
1640 
def handle_try(self)
Definition: ast.py:1638
def cpp.ast.AstBuilder.handle_try (   self)

Definition at line 1638 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_try().

1638  def handle_try(self):
1639  pass # Not needed yet.
1640 
def handle_try(self)
Definition: ast.py:1638
def cpp.ast.AstBuilder.handle_try (   self)

Definition at line 1638 of file ast.py.

References cpp.ast.AstBuilder.handle_try().

1638  def handle_try(self):
1639  pass # Not needed yet.
1640 
def handle_try(self)
Definition: ast.py:1638
def cpp.ast.AstBuilder.handle_typedef (   self)

Definition at line 1349 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.handle_typedef(), cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

1349  def handle_typedef(self):
1350  token = self._GetNextToken()
1351  if (token.token_type == tokenize.NAME and
1352  keywords.IsKeyword(token.name)):
1353  # Token must be struct/enum/union/class.
1354  method = getattr(self, 'handle_' + token.name)
1355  self._handling_typedef = True
1356  tokens = [method()]
1357  self._handling_typedef = False
1358  else:
1359  tokens = [token]
1360 
1361  # Get the remainder of the typedef up to the semi-colon.
1362  tokens.extend(self._GetTokensUpTo(tokenize.SYNTAX, ';'))
1363 
1364  # TODO(nnorwitz): clean all this up.
1365  assert tokens
1366  name = tokens.pop()
1367  indices = name
1368  if tokens:
1369  indices = tokens[0]
1370  if not indices:
1371  indices = token
1372  if name.name == ')':
1373  # HACK(nnorwitz): Handle pointers to functions "properly".
1374  if (len(tokens) >= 4 and
1375  tokens[1].name == '(' and tokens[2].name == '*'):
1376  tokens.append(name)
1377  name = tokens[3]
1378  elif name.name == ']':
1379  # HACK(nnorwitz): Handle arrays properly.
1380  if len(tokens) >= 2:
1381  tokens.append(name)
1382  name = tokens[1]
1383  new_type = tokens
1384  if tokens and isinstance(tokens[0], tokenize.Token):
1385  new_type = self.converter.ToType(tokens)[0]
1386  return Typedef(indices.start, indices.end, name.name,
1387  new_type, self.namespace_stack)
1388 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_typedef(self)
Definition: ast.py:1349
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.handle_typedef (   self)

Definition at line 1349 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.AstBuilder.handle_typedef(), cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

1349  def handle_typedef(self):
1350  token = self._GetNextToken()
1351  if (token.token_type == tokenize.NAME and
1352  keywords.IsKeyword(token.name)):
1353  # Token must be struct/enum/union/class.
1354  method = getattr(self, 'handle_' + token.name)
1355  self._handling_typedef = True
1356  tokens = [method()]
1357  self._handling_typedef = False
1358  else:
1359  tokens = [token]
1360 
1361  # Get the remainder of the typedef up to the semi-colon.
1362  tokens.extend(self._GetTokensUpTo(tokenize.SYNTAX, ';'))
1363 
1364  # TODO(nnorwitz): clean all this up.
1365  assert tokens
1366  name = tokens.pop()
1367  indices = name
1368  if tokens:
1369  indices = tokens[0]
1370  if not indices:
1371  indices = token
1372  if name.name == ')':
1373  # HACK(nnorwitz): Handle pointers to functions "properly".
1374  if (len(tokens) >= 4 and
1375  tokens[1].name == '(' and tokens[2].name == '*'):
1376  tokens.append(name)
1377  name = tokens[3]
1378  elif name.name == ']':
1379  # HACK(nnorwitz): Handle arrays properly.
1380  if len(tokens) >= 2:
1381  tokens.append(name)
1382  name = tokens[1]
1383  new_type = tokens
1384  if tokens and isinstance(tokens[0], tokenize.Token):
1385  new_type = self.converter.ToType(tokens)[0]
1386  return Typedef(indices.start, indices.end, name.name,
1387  new_type, self.namespace_stack)
1388 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_typedef(self)
Definition: ast.py:1349
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.handle_typedef (   self)

Definition at line 1349 of file ast.py.

References cpp.ast.AstBuilder._GetNextToken(), cpp.ast.AstBuilder._GetTokensUpTo(), cpp.ast.AstBuilder._handling_typedef, cpp.ast.TypeConverter.namespace_stack, and cpp.ast.AstBuilder.namespace_stack.

Referenced by cpp.ast.AstBuilder.handle_typedef().

1349  def handle_typedef(self):
1350  token = self._GetNextToken()
1351  if (token.token_type == tokenize.NAME and
1352  keywords.IsKeyword(token.name)):
1353  # Token must be struct/enum/union/class.
1354  method = getattr(self, 'handle_' + token.name)
1355  self._handling_typedef = True
1356  tokens = [method()]
1357  self._handling_typedef = False
1358  else:
1359  tokens = [token]
1360 
1361  # Get the remainder of the typedef up to the semi-colon.
1362  tokens.extend(self._GetTokensUpTo(tokenize.SYNTAX, ';'))
1363 
1364  # TODO(nnorwitz): clean all this up.
1365  assert tokens
1366  name = tokens.pop()
1367  indices = name
1368  if tokens:
1369  indices = tokens[0]
1370  if not indices:
1371  indices = token
1372  if name.name == ')':
1373  # HACK(nnorwitz): Handle pointers to functions "properly".
1374  if (len(tokens) >= 4 and
1375  tokens[1].name == '(' and tokens[2].name == '*'):
1376  tokens.append(name)
1377  name = tokens[3]
1378  elif name.name == ']':
1379  # HACK(nnorwitz): Handle arrays properly.
1380  if len(tokens) >= 2:
1381  tokens.append(name)
1382  name = tokens[1]
1383  new_type = tokens
1384  if tokens and isinstance(tokens[0], tokenize.Token):
1385  new_type = self.converter.ToType(tokens)[0]
1386  return Typedef(indices.start, indices.end, name.name,
1387  new_type, self.namespace_stack)
1388 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_typedef(self)
Definition: ast.py:1349
def _GetNextToken(self)
Definition: ast.py:905
def cpp.ast.AstBuilder.handle_typeid (   self)

Definition at line 1389 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_typeid().

1389  def handle_typeid(self):
1390  pass # Not needed yet.
1391 
def handle_typeid(self)
Definition: ast.py:1389
def cpp.ast.AstBuilder.handle_typeid (   self)

Definition at line 1389 of file ast.py.

References cpp.ast.AstBuilder.handle_typeid().

1389  def handle_typeid(self):
1390  pass # Not needed yet.
1391 
def handle_typeid(self)
Definition: ast.py:1389
def cpp.ast.AstBuilder.handle_typeid (   self)

Definition at line 1389 of file ast.py.

References cpp.ast.AstBuilder.handle_typeid().

1389  def handle_typeid(self):
1390  pass # Not needed yet.
1391 
def handle_typeid(self)
Definition: ast.py:1389
def cpp.ast.AstBuilder.handle_typename (   self)

Definition at line 1392 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_typename().

1392  def handle_typename(self):
1393  pass # Not needed yet.
1394 
def handle_typename(self)
Definition: ast.py:1392
def cpp.ast.AstBuilder.handle_typename (   self)

Definition at line 1392 of file ast.py.

References cpp.ast.AstBuilder.handle_typename().

1392  def handle_typename(self):
1393  pass # Not needed yet.
1394 
def handle_typename(self)
Definition: ast.py:1392
def cpp.ast.AstBuilder.handle_typename (   self)

Definition at line 1392 of file ast.py.

References cpp.ast.AstBuilder.handle_typename().

1392  def handle_typename(self):
1393  pass # Not needed yet.
1394 
def handle_typename(self)
Definition: ast.py:1392
def cpp.ast.AstBuilder.handle_union (   self)

Definition at line 1263 of file ast.py.

References cpp.ast.AstBuilder._GetNestedType(), and cpp.ast.AstBuilder.handle_union().

1263  def handle_union(self):
1264  return self._GetNestedType(Union)
1265 
def handle_union(self)
Definition: ast.py:1263
def _GetNestedType(self, ctor)
Definition: ast.py:1193
def cpp.ast.AstBuilder.handle_union (   self)

Definition at line 1263 of file ast.py.

References cpp.ast.AstBuilder._GetNestedType(), and cpp.ast.AstBuilder.handle_union().

1263  def handle_union(self):
1264  return self._GetNestedType(Union)
1265 
def handle_union(self)
Definition: ast.py:1263
def _GetNestedType(self, ctor)
Definition: ast.py:1193
def cpp.ast.AstBuilder.handle_union (   self)

Definition at line 1263 of file ast.py.

References cpp.ast.AstBuilder._GetNestedType().

Referenced by cpp.ast.AstBuilder.handle_union().

1263  def handle_union(self):
1264  return self._GetNestedType(Union)
1265 
def handle_union(self)
Definition: ast.py:1263
def _GetNestedType(self, ctor)
Definition: ast.py:1193
def cpp.ast.AstBuilder.handle_unsigned (   self)

Definition at line 1187 of file ast.py.

1187  def handle_unsigned(self):
1188  pass
1189 
def handle_unsigned(self)
Definition: ast.py:1187
def cpp.ast.AstBuilder.handle_unsigned (   self)

Definition at line 1187 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_unsigned().

1187  def handle_unsigned(self):
1188  pass
1189 
def handle_unsigned(self)
Definition: ast.py:1187
def cpp.ast.AstBuilder.handle_unsigned (   self)

Definition at line 1187 of file ast.py.

1187  def handle_unsigned(self):
1188  pass
1189 
def handle_unsigned(self)
Definition: ast.py:1187
def cpp.ast.AstBuilder.handle_using (   self)

Definition at line 1588 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder.handle_using().

1588  def handle_using(self):
1589  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1590  assert tokens
1591  return Using(tokens[0].start, tokens[0].end, tokens)
1592 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_using(self)
Definition: ast.py:1588
def cpp.ast.AstBuilder.handle_using (   self)

Definition at line 1588 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo().

Referenced by cpp.ast.AstBuilder.handle_using().

1588  def handle_using(self):
1589  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1590  assert tokens
1591  return Using(tokens[0].start, tokens[0].end, tokens)
1592 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_using(self)
Definition: ast.py:1588
def cpp.ast.AstBuilder.handle_using (   self)

Definition at line 1588 of file ast.py.

References cpp.ast.AstBuilder._GetTokensUpTo(), and cpp.ast.AstBuilder.handle_using().

1588  def handle_using(self):
1589  tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';')
1590  assert tokens
1591  return Using(tokens[0].start, tokens[0].end, tokens)
1592 
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def handle_using(self)
Definition: ast.py:1588
def cpp.ast.AstBuilder.handle_virtual (   self)

Definition at line 1289 of file ast.py.

1289  def handle_virtual(self):
1290  # What follows must be a method.
1291  token = token2 = self._GetNextToken()
1292  if token.name == 'inline':
1293  # HACK(nnorwitz): handle inline dtors by ignoring 'inline'.
1294  token2 = self._GetNextToken()
1295  if token2.token_type == tokenize.SYNTAX and token2.name == '~':
1296  return self.GetMethod(FUNCTION_VIRTUAL + FUNCTION_DTOR, None)
1297  assert token.token_type == tokenize.NAME or token.name == '::', token
1298  return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(') # )
1299  return_type_and_name.insert(0, token)
1300  if token2 is not token:
1301  return_type_and_name.insert(1, token2)
1302  return self._GetMethod(return_type_and_name, FUNCTION_VIRTUAL,
1303  None, False)
1304 
def handle_virtual(self)
Definition: ast.py:1289
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetNextToken(self)
Definition: ast.py:905
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.handle_virtual (   self)

Definition at line 1289 of file ast.py.

1289  def handle_virtual(self):
1290  # What follows must be a method.
1291  token = token2 = self._GetNextToken()
1292  if token.name == 'inline':
1293  # HACK(nnorwitz): handle inline dtors by ignoring 'inline'.
1294  token2 = self._GetNextToken()
1295  if token2.token_type == tokenize.SYNTAX and token2.name == '~':
1296  return self.GetMethod(FUNCTION_VIRTUAL + FUNCTION_DTOR, None)
1297  assert token.token_type == tokenize.NAME or token.name == '::', token
1298  return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(') # )
1299  return_type_and_name.insert(0, token)
1300  if token2 is not token:
1301  return_type_and_name.insert(1, token2)
1302  return self._GetMethod(return_type_and_name, FUNCTION_VIRTUAL,
1303  None, False)
1304 
def handle_virtual(self)
Definition: ast.py:1289
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetNextToken(self)
Definition: ast.py:905
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.handle_virtual (   self)

Definition at line 1289 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_virtual().

1289  def handle_virtual(self):
1290  # What follows must be a method.
1291  token = token2 = self._GetNextToken()
1292  if token.name == 'inline':
1293  # HACK(nnorwitz): handle inline dtors by ignoring 'inline'.
1294  token2 = self._GetNextToken()
1295  if token2.token_type == tokenize.SYNTAX and token2.name == '~':
1296  return self.GetMethod(FUNCTION_VIRTUAL + FUNCTION_DTOR, None)
1297  assert token.token_type == tokenize.NAME or token.name == '::', token
1298  return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(') # )
1299  return_type_and_name.insert(0, token)
1300  if token2 is not token:
1301  return_type_and_name.insert(1, token2)
1302  return self._GetMethod(return_type_and_name, FUNCTION_VIRTUAL,
1303  None, False)
1304 
def handle_virtual(self)
Definition: ast.py:1289
def _GetTokensUpTo(self, expected_token_type, expected_token)
Definition: ast.py:849
def GetMethod(self, modifiers, templated_types)
Definition: ast.py:953
def _GetNextToken(self)
Definition: ast.py:905
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
Definition: ast.py:960
def cpp.ast.AstBuilder.handle_void (   self)

Definition at line 1181 of file ast.py.

1181  def handle_void(self):
1182  pass
1183 
def handle_void(self)
Definition: ast.py:1181
def cpp.ast.AstBuilder.handle_void (   self)

Definition at line 1181 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_void().

1181  def handle_void(self):
1182  pass
1183 
def handle_void(self)
Definition: ast.py:1181
def cpp.ast.AstBuilder.handle_void (   self)

Definition at line 1181 of file ast.py.

1181  def handle_void(self):
1182  pass
1183 
def handle_void(self)
Definition: ast.py:1181
def cpp.ast.AstBuilder.handle_volatile (   self)

Definition at line 1305 of file ast.py.

References cpp.ast.AstBuilder.handle_volatile().

1305  def handle_volatile(self):
1306  pass
1307 
def handle_volatile(self)
Definition: ast.py:1305
def cpp.ast.AstBuilder.handle_volatile (   self)

Definition at line 1305 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_volatile().

1305  def handle_volatile(self):
1306  pass
1307 
def handle_volatile(self)
Definition: ast.py:1305
def cpp.ast.AstBuilder.handle_volatile (   self)

Definition at line 1305 of file ast.py.

References cpp.ast.AstBuilder.handle_volatile().

1305  def handle_volatile(self):
1306  pass
1307 
def handle_volatile(self)
Definition: ast.py:1305
def cpp.ast.AstBuilder.handle_wchar_t (   self)

Definition at line 1184 of file ast.py.

1184  def handle_wchar_t(self):
1185  pass
1186 
def handle_wchar_t(self)
Definition: ast.py:1184
def cpp.ast.AstBuilder.handle_wchar_t (   self)

Definition at line 1184 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_wchar_t().

1184  def handle_wchar_t(self):
1185  pass
1186 
def handle_wchar_t(self)
Definition: ast.py:1184
def cpp.ast.AstBuilder.handle_wchar_t (   self)

Definition at line 1184 of file ast.py.

1184  def handle_wchar_t(self):
1185  pass
1186 
def handle_wchar_t(self)
Definition: ast.py:1184
def cpp.ast.AstBuilder.handle_while (   self)

Definition at line 1647 of file ast.py.

References cpp.ast.AstBuilder.handle_while().

1647  def handle_while(self):
1648  pass
1649 
def handle_while(self)
Definition: ast.py:1647
def cpp.ast.AstBuilder.handle_while (   self)

Definition at line 1647 of file ast.py.

Referenced by cpp.ast.AstBuilder.handle_while().

1647  def handle_while(self):
1648  pass
1649 
def handle_while(self)
Definition: ast.py:1647
def cpp.ast.AstBuilder.handle_while (   self)

Definition at line 1647 of file ast.py.

References cpp.ast.AstBuilder.handle_while().

1647  def handle_while(self):
1648  pass
1649 
def handle_while(self)
Definition: ast.py:1647
def cpp.ast.AstBuilder.HandleError (   self,
  msg,
  token 
)

Definition at line 699 of file ast.py.

References cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.AstBuilder.HandleError(), bm.list, cpp.ast.reversed(), and cpp.ast.AstBuilder.token_queue.

699  def HandleError(self, msg, token):
700  printable_queue = list(reversed(self.token_queue[-20:]))
701  sys.stderr.write('Got %s in %s @ %s %s\n' %
702  (msg, self.filename, token, printable_queue))
703 
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def reversed(seq)
Definition: ast.py:52
def cpp.ast.AstBuilder.HandleError (   self,
  msg,
  token 
)

Definition at line 699 of file ast.py.

References cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, cpp.ast.AstBuilder.HandleError(), bm.list, cpp.ast.reversed(), and cpp.ast.AstBuilder.token_queue.

699  def HandleError(self, msg, token):
700  printable_queue = list(reversed(self.token_queue[-20:]))
701  sys.stderr.write('Got %s in %s @ %s %s\n' %
702  (msg, self.filename, token, printable_queue))
703 
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def reversed(seq)
Definition: ast.py:52
def cpp.ast.AstBuilder.HandleError (   self,
  msg,
  token 
)

Definition at line 699 of file ast.py.

References cpp.ast.Include.filename, cpp.ast.AstBuilder.filename, bm.list, cpp.ast.reversed(), and cpp.ast.AstBuilder.token_queue.

Referenced by cpp.ast.AstBuilder._GetClass(), cpp.ast.AstBuilder._GetMethod(), cpp.ast.AstBuilder.Generate(), and cpp.ast.AstBuilder.HandleError().

699  def HandleError(self, msg, token):
700  printable_queue = list(reversed(self.token_queue[-20:]))
701  sys.stderr.write('Got %s in %s @ %s %s\n' %
702  (msg, self.filename, token, printable_queue))
703 
Encoder::MutableCompressedList list
def HandleError(self, msg, token)
Definition: ast.py:699
def reversed(seq)
Definition: ast.py:52

Member Data Documentation

cpp.ast.AstBuilder.converter

Definition at line 697 of file ast.py.

Referenced by cpp.ast.AstBuilder.__init__().

cpp.ast.AstBuilder.current_token

Definition at line 693 of file ast.py.

Referenced by cpp.ast.AstBuilder.__init__(), and cpp.ast.AstBuilder.Generate().

cpp.ast.AstBuilder.filename
cpp.ast.AstBuilder.in_class_name_only

Definition at line 688 of file ast.py.

Referenced by cpp.ast.AstBuilder.__init__(), and cpp.ast.AstBuilder._GenerateOne().

cpp.ast.AstBuilder.in_function

Definition at line 692 of file ast.py.

Referenced by cpp.ast.AstBuilder.__init__().

cpp.ast.AstBuilder.tokens

Definition at line 679 of file ast.py.

Referenced by cpp.ast.AstBuilder.__init__(), and cpp.ast.AstBuilder._GetNextToken().


The documentation for this class was generated from the following file: