18 """Generate an Abstract Syntax Tree (AST) for C++.""" 20 __author__ =
'nnorwitz@google.com (Neal Norwitz)' 40 import builtins
as builtins
45 from cpp
import keywords
46 from cpp
import tokenize
50 if not hasattr(builtins,
'reversed'):
53 for i
in range(len(seq)-1, -1, -1):
56 if not hasattr(builtins,
'next'):
62 VISIBILITY_PUBLIC, VISIBILITY_PROTECTED, VISIBILITY_PRIVATE = list(range(3))
66 FUNCTION_VIRTUAL = 0x02
67 FUNCTION_PURE_VIRTUAL = 0x04
70 FUNCTION_ATTRIBUTE = 0x20
71 FUNCTION_UNKNOWN_ANNOTATION = 0x40
75 These are currently unused. Should really handle these properly at some point. 77 TYPE_MODIFIER_INLINE = 0x010000 78 TYPE_MODIFIER_EXTERN = 0x020000 79 TYPE_MODIFIER_STATIC = 0x040000 80 TYPE_MODIFIER_CONST = 0x080000 81 TYPE_MODIFIER_REGISTER = 0x100000 82 TYPE_MODIFIER_VOLATILE = 0x200000 83 TYPE_MODIFIER_MUTABLE = 0x400000 86 'inline': TYPE_MODIFIER_INLINE, 87 'extern': TYPE_MODIFIER_EXTERN, 88 'static': TYPE_MODIFIER_STATIC, 89 'const': TYPE_MODIFIER_CONST, 90 'register': TYPE_MODIFIER_REGISTER, 91 'volatile': TYPE_MODIFIER_VOLATILE, 92 'mutable': TYPE_MODIFIER_MUTABLE, 96 _INTERNAL_TOKEN =
'internal' 97 _NAMESPACE_POP =
'ns-pop' 103 __contains__ =
lambda self:
False 104 keys = values = items = iterkeys = itervalues = iteritems =
lambda self: ()
116 """Returns bool if this node is a declaration.""" 120 """Returns bool if this node is a definition.""" 124 """Returns bool if this node exportable from a header file.""" 128 """Does this AST node require the definition of the node passed in?""" 136 return '%s(%s)' % (name, suffix)
137 return '%s(%d, %d, %s)' % (name, self.
start, self.
end, suffix)
145 Node.__init__(self, start, end)
156 Node.__init__(self, start, end)
169 Node.__init__(self, start, end)
178 Node.__init__(self, start, end)
199 Expr.__init__(self, start, end, expr)
205 Node.__init__(self, start, end)
213 def __init__(self, start, end, name, parameter_type, default):
214 Node.__init__(self, start, end)
221 return self.type.name == node.name
224 name = str(self.
type)
225 suffix =
'%s %s' % (name, self.
name)
227 suffix +=
' = ' +
''.join([d.name
for d
in self.
default])
233 Node.__init__(self, start, end)
240 prefix =
'::'.join(self.
namespace) +
'::' 241 return prefix + self.
name 245 names = [n
or '<anonymous>' for n
in self.
namespace]
246 suffix +=
' in ' +
'::'.join(names)
252 def __init__(self, start, end, name, var_type, initial_value, namespace):
253 _GenericDeclaration.__init__(self, start, end, name, namespace)
259 return self.type.name == node.name
262 """Return a string that tries to reconstitute the variable decl.""" 263 suffix =
'%s %s' % (self.
type, self.
name)
273 def __init__(self, start, end, name, alias, namespace):
274 _GenericDeclaration.__init__(self, start, end, name, namespace)
286 for token
in self.
alias:
287 if token
is not None and name == token.name:
292 suffix =
'%s, %s' % (self.
name, self.
alias)
297 def __init__(self, start, end, name, fields, namespace):
298 _GenericDeclaration.__init__(self, start, end, name, namespace)
308 suffix =
'%s, {%s}' % (self.
name, self.
fields)
316 class Enum(_NestedType):
321 def __init__(self, start, end, name, bases, templated_types, body, namespace):
322 _GenericDeclaration.__init__(self, start, end, name, namespace)
328 return self.
bases is None and self.
body is None 339 for token_list
in self.
bases:
341 for token
in token_list:
342 if token.name == node.name:
351 suffix =
'%s, %s, %s' % (name, self.
bases, self.
body)
359 class Function(_GenericDeclaration):
360 def __init__(self, start, end, name, return_type, parameters,
361 modifiers, templated_types, body, namespace):
362 _GenericDeclaration.__init__(self, start, end, name, namespace)
371 return self.
body is None 374 return self.
body is not None 377 if self.
return_type and 'static' in self.return_type.modifiers:
385 if p.name == node.name:
392 suffix = (
'%s %s(%s), 0x%02x, %s' %
399 def __init__(self, start, end, name, in_class, return_type, parameters,
400 modifiers, templated_types, body, namespace):
401 Function.__init__(self, start, end, name, return_type, parameters,
402 modifiers, templated_types, body, namespace)
409 """Type used for any variable (eg class, primitive, struct, etc).""" 411 def __init__(self, start, end, name, templated_types, modifiers,
412 reference, pointer, array):
415 name: str name of main type 416 templated_types: [Class (Type?)] template type info between <> 417 modifiers: [str] type modifiers (keywords) eg, const, mutable, etc. 418 reference, pointer, array: bools 420 _GenericDeclaration.__init__(self, start, end, name, [])
422 if not name
and modifiers:
433 name = str(self.
name)
436 suffix = prefix + name
468 if token.name ==
'<':
470 elif token.name ==
'>':
474 return tokens[start:end-1], end
477 """Convert [Token,...] to [Class(...), ] useful for base classes. 478 For example, code like class Foo : public Bar<x, y> { ... }; 479 the "Bar<x, y>" portion gets converted to an AST. 486 reference = pointer = array =
False 488 def AddType(templated_types):
492 for t
in name_tokens:
493 if keywords.IsKeyword(t.name):
494 modifiers.append(t.name)
497 name =
''.join(names)
498 result.append(
Type(name_tokens[0].start, name_tokens[-1].end,
499 name, templated_types, modifiers,
500 reference, pointer, array))
507 if token.name ==
'<':
509 AddType(self.
ToType(new_tokens))
513 reference = pointer = array =
False 514 elif token.name ==
',':
516 reference = pointer = array =
False 517 elif token.name ==
'*':
519 elif token.name ==
'&':
521 elif token.name ==
'[':
523 elif token.name ==
']':
526 name_tokens.append(token)
537 if needs_name_removed:
539 for i, t
in enumerate(parts):
541 default = parts[i+1:]
542 name = parts[i-1].name
543 if name ==
']' and parts[i-2].name ==
'[':
544 name = parts[i-3].name
549 if parts[-1].token_type == tokenize.NAME:
550 name = parts.pop().name
564 if keywords.IsKeyword(p.name):
565 modifiers.append(p.name)
568 templated_types = self.
ToType(templated_tokens)
572 if next_index < end
and parts[next_index].name ==
'::':
574 elif p.name
in (
'[',
']',
'='):
576 other_tokens.append(p)
577 elif p.name
not in (
'*',
'&',
'>'):
579 if (type_name
and type_name[-1].token_type == tokenize.NAME
and 580 p.token_type == tokenize.NAME):
584 other_tokens.append(p)
586 type_name =
''.join([t.name
for t
in type_name])
587 return name, type_name, templated_types, modifiers, default, other_tokens
594 name = type_name =
'' 596 pointer = reference = array =
False 603 end = type_modifiers[-1].end
605 (name, type_name, templated_types, modifiers,
606 unused_default, unused_other_tokens) = parts
607 parameter_type =
Type(first_token.start, first_token.end,
608 type_name, templated_types, modifiers,
609 reference, pointer, array)
610 p =
Parameter(first_token.start, end, name,
611 parameter_type, default)
622 if template_count > 0:
623 type_modifiers.append(s)
628 name = type_name =
'' 630 pointer = reference = array =
False 647 type_modifiers.append(s)
652 if not return_type_seq:
654 start = return_type_seq[0].start
655 end = return_type_seq[-1].end
656 _, name, templated_types, modifiers, default, other_tokens = \
658 names = [n.name
for n
in other_tokens]
659 reference =
'&' in names
660 pointer =
'*' in names
662 return Type(start, end, name, templated_types, modifiers,
663 reference, pointer, array)
667 start = names.index(
'<')
670 if names[end] ==
'>':
676 def __init__(self, token_stream, filename, in_class='', visibility=None,
700 sys.stderr.write(
'Got %s in %s @ %s %s\n' %
701 (msg, self.
filename, token, printable_queue))
713 if token.token_type == _INTERNAL_TOKEN:
714 if token.name == _NAMESPACE_POP:
715 self.namespace_stack.pop()
720 if result
is not None:
727 ref_pointer_name_seq, templated_types, value=
None):
728 reference =
'&' in ref_pointer_name_seq
729 pointer =
'*' in ref_pointer_name_seq
730 array =
'[' in ref_pointer_name_seq
731 var_type =
Type(pos_token.start, pos_token.end, type_name,
732 templated_types, type_modifiers,
733 reference, pointer, array)
738 if token.token_type == tokenize.NAME:
739 if (keywords.IsKeyword(token.name)
and 740 not keywords.IsBuiltinType(token.name)):
741 method = getattr(self,
'handle_' + token.name)
749 if next.token_type == tokenize.SYNTAX
and next.name ==
'(':
750 return self.
_GetMethod([token], FUNCTION_CTOR,
None,
True)
754 syntax = tokenize.SYNTAX
755 temp_tokens, last_token = \
757 temp_tokens.insert(0, token)
758 if last_token.name ==
'(':
761 expr = bool([e
for e
in temp_tokens
if e.name ==
'='])
764 temp_tokens.append(last_token)
765 temp_tokens.extend(new_temp)
768 if last_token.name ==
'[':
772 temp_tokens.append(last_token)
773 if temp_tokens[-2].name ==
'operator':
776 temp_tokens2, last_token = \
778 temp_tokens.extend(temp_tokens2)
780 if last_token.name ==
';':
782 parts = self.converter.DeclarationToParts(temp_tokens,
True)
783 (name, type_name, templated_types, modifiers, default,
784 unused_other_tokens) = parts
787 names = [t.name
for t
in temp_tokens]
789 start, end = self.converter.GetTemplateIndices(names)
790 names = names[:start] + names[end:]
791 default =
''.join([t.name
for t
in default])
793 names, templated_types, default)
794 if last_token.name ==
'{':
797 method_name = temp_tokens[0].name
798 method = getattr(self,
'handle_' + method_name,
None)
804 return self.
_GetMethod(temp_tokens, 0,
None,
False)
805 elif token.token_type == tokenize.SYNTAX:
806 if token.name ==
'~' and self.
in_class:
811 if (token.token_type == tokenize.NAME
and 813 return self.
_GetMethod([token], FUNCTION_DTOR,
None,
True)
815 elif token.token_type == tokenize.PREPROCESSOR:
818 name = token.name[1:].lstrip()
819 if name.startswith(
'include'):
821 name = name[7:].strip()
824 if name.startswith(
'\\'):
825 name = name[1:].strip()
826 assert name[0]
in '<"', token
827 assert name[-1]
in '>"', token
828 system = name[0] ==
'<' 829 filename = name[1:-1]
830 return Include(token.start, token.end, filename, system)
831 if name.startswith(
'define'):
833 name = name[6:].strip()
836 for i, c
in enumerate(name):
838 value = name[i:].lstrip()
841 return Define(token.start, token.end, name, value)
842 if name.startswith(
'if')
and name[2:3].isspace():
843 condition = name[3:].strip()
844 if condition.startswith(
'0')
or condition.startswith(
'(0)'):
854 while (last_token.token_type != expected_token_type
or 855 last_token.name
not in expected_tokens):
856 tokens.append(last_token)
858 return tokens, last_token
868 if token.token_type != tokenize.PREPROCESSOR:
871 name = token.name[1:].lstrip()
872 if name.startswith(
'endif'):
876 elif name.startswith(
'if'):
880 if GetNextToken
is None:
885 token = GetNextToken()
887 if token.token_type == tokenize.SYNTAX:
888 if token.name == open_paren:
890 elif token.name == close_paren:
895 token = GetNextToken()
906 return self.token_queue.pop()
910 if token.whence == tokenize.WHENCE_STREAM:
911 token.whence = tokenize.WHENCE_QUEUE
912 self.token_queue.insert(0, token)
914 assert token.whence == tokenize.WHENCE_QUEUE, token
915 self.token_queue.append(token)
919 if tokens[-1].whence == tokenize.WHENCE_STREAM:
921 token.whence = tokenize.WHENCE_QUEUE
924 assert tokens[-1].whence == tokenize.WHENCE_QUEUE, tokens
925 self.token_queue.extend(
reversed(tokens))
928 """Returns ([tokens], next_token_info).""" 932 GetNextToken =
lambda:
next(it)
933 next_token = GetNextToken()
935 last_token_was_name =
False 936 while (next_token.token_type == tokenize.NAME
or 937 (next_token.token_type == tokenize.SYNTAX
and 938 next_token.name
in (
'::',
'<'))):
941 if last_token_was_name
and next_token.token_type == tokenize.NAME:
943 last_token_was_name = next_token.token_type == tokenize.NAME
944 tokens.append(next_token)
946 if next_token.name ==
'<':
948 last_token_was_name =
True 949 next_token = GetNextToken()
950 return tokens, next_token
954 assert len(return_type_and_name) >= 1
955 return self.
_GetMethod(return_type_and_name, modifiers, templated_types,
958 def _GetMethod(self, return_type_and_name, modifiers, templated_types,
960 template_portion =
None 963 assert token.token_type == tokenize.SYNTAX, token
964 if token.name ==
'<':
966 template_portion = [token]
969 assert token.token_type == tokenize.SYNTAX, token
970 assert token.name ==
'(', token
972 name = return_type_and_name.pop()
976 while return_type_and_name[index].name !=
'<':
978 template_portion = return_type_and_name[index:] + [name]
979 del return_type_and_name[index:]
980 name = return_type_and_name.pop()
981 elif name.name ==
']':
982 rt = return_type_and_name
983 assert rt[-1].name ==
'[', return_type_and_name
984 assert rt[-2].name ==
'operator', return_type_and_name
985 name_seq = return_type_and_name[-2:]
986 del return_type_and_name[-2:]
988 name_seq[0].start, name.end)
993 return_type = return_type_and_name
996 indices = return_type[0]
999 if name.name == self.
in_class and not modifiers:
1000 modifiers |= FUNCTION_CTOR
1005 if name.name ==
'operator' and not parameters:
1007 assert token.name ==
'(', token
1012 while token.token_type == tokenize.NAME:
1013 modifier_token = token
1015 if modifier_token.name ==
'const':
1016 modifiers |= FUNCTION_CONST
1017 elif modifier_token.name ==
'__attribute__':
1019 modifiers |= FUNCTION_ATTRIBUTE
1020 assert token.name ==
'(', token
1024 elif modifier_token.name ==
'throw':
1025 modifiers |= FUNCTION_THROW
1026 assert token.name ==
'(', token
1030 elif modifier_token.name == modifier_token.name.upper():
1033 modifiers |= FUNCTION_UNKNOWN_ANNOTATION
1035 self.
HandleError(
'unexpected token', modifier_token)
1037 assert token.token_type == tokenize.SYNTAX, token
1039 if token.name ==
':':
1041 while token.name !=
';' and token.name !=
'{':
1046 if token.name ==
'(':
1047 if parameters[0].name ==
'*':
1049 name = parameters.pop()
1051 modifiers = [p.name
for p
in parameters]
1054 del function_parameters[-1]
1057 assert token.token_type == tokenize.SYNTAX, token
1058 assert token.name ==
';', token
1060 modifiers,
'',
None)
1069 real_name = parameters[-1]
1073 modifiers,
'',
None)
1075 if token.name ==
'{':
1080 if token.name ==
'=':
1082 assert token.token_type == tokenize.CONSTANT, token
1083 assert token.name ==
'0', token
1084 modifiers |= FUNCTION_PURE_VIRTUAL
1087 if token.name ==
'[':
1093 assert token.name ==
';', (token, return_type_and_name, parameters)
1096 if len(return_type) > 2
and return_type[-1].name ==
'::':
1097 return_type, in_class = \
1099 return Method(indices.start, indices.end, name.name, in_class,
1100 return_type, parameters, modifiers, templated_types,
1102 return Function(indices.start, indices.end, name.name, return_type,
1103 parameters, modifiers, templated_types, body,
1117 if token_seq[0].name ==
'::':
1120 end = len(token_seq) - 1
1121 if token_seq[end-1].name ==
'::':
1127 seq_copy = token_seq[i:end]
1132 new_name, next = self.
GetName(seq_copy[i:])
1133 assert new_name,
'Got empty new_name, next=%s' % next
1135 if next
and next.token_type == tokenize.SYNTAX:
1136 new_name.append(next)
1137 names.append(new_name)
1145 return_type = [e
for seq
in names[:-1]
for e
in seq]
1147 class_name = names[-1]
1148 return return_type, class_name
1185 name_tokens, token = self.GetName()
1187 name =
''.join([t.name
for t
in name_tokens])
1190 if token.token_type == tokenize.SYNTAX
and token.name ==
';':
1191 return ctor(token.start, token.end, name,
None,
1192 self.namespace_stack)
1194 if token.token_type == tokenize.NAME
and self._handling_typedef:
1195 self._AddBackToken(token)
1196 return ctor(token.start, token.end, name,
None,
1197 self.namespace_stack)
1200 fields = list(self._GetMatchingChar(
'{',
'}'))
1202 if token.token_type == tokenize.SYNTAX
and token.name ==
'{':
1203 next = self._GetNextToken()
1204 new_type = ctor(token.start, token.end, name, fields,
1205 self.namespace_stack)
1208 if next.token_type != tokenize.NAME:
1214 assert token.token_type == tokenize.NAME, token
1215 return self._CreateVariable(token, token.name, name, [],
'',
None)
1220 name_tokens, var_token = self.
GetName()
1223 is_syntax = (var_token.token_type == tokenize.SYNTAX
and 1224 var_token.name[0]
in '*&')
1225 is_variable = (var_token.token_type == tokenize.NAME
and 1226 next_token.name ==
';')
1227 variable = var_token
1228 if is_syntax
and not is_variable:
1229 variable = next_token
1231 if temp.token_type == tokenize.SYNTAX
and temp.name ==
'(':
1235 t0.start-7, t0.start-2)
1236 type_and_name = [struct]
1237 type_and_name.extend(name_tokens)
1238 type_and_name.extend((var_token, next_token))
1239 return self.
_GetMethod(type_and_name, 0,
None,
False)
1240 assert temp.name ==
';', (temp, name_tokens, var_token)
1242 modifiers = [
'struct']
1243 type_name =
''.join([t.name
for t
in name_tokens])
1244 position = name_tokens[0]
1246 modifiers, var_token.name,
None)
1247 name_tokens.extend((var_token, next_token))
1251 return self.
_GetClass(Struct, VISIBILITY_PUBLIC,
None)
1281 token = token2 = self._GetNextToken()
1282 if token.name ==
'inline':
1284 token2 = self._GetNextToken()
1285 if token2.token_type == tokenize.SYNTAX
and token2.name ==
'~':
1286 return self.GetMethod(FUNCTION_VIRTUAL + FUNCTION_DTOR,
None)
1287 assert token.token_type == tokenize.NAME
or token.name ==
'::', token
1288 return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX,
'(')
1289 return_type_and_name.insert(0, token)
1290 if token2
is not token:
1291 return_type_and_name.insert(1, token2)
1292 return self._GetMethod(return_type_and_name, FUNCTION_VIRTUAL,
1302 assert self.in_class
1303 self.visibility = VISIBILITY_PUBLIC
1335 tokens = self._GetTokensUpTo(tokenize.SYNTAX,
';')
1337 return Delete(tokens[0].start, tokens[0].end, tokens)
1341 if (token.token_type == tokenize.NAME
and 1342 keywords.IsKeyword(token.name)):
1344 method = getattr(self,
'handle_' + token.name)
1362 if name.name ==
')':
1364 if (len(tokens) >= 4
and 1365 tokens[1].name ==
'(' and tokens[2].name ==
'*'):
1368 elif name.name ==
']':
1370 if len(tokens) >= 2:
1375 new_type = self.converter.ToType(tokens)[0]
1376 return Typedef(indices.start, indices.end, name.name,
1388 len_tokens = len(tokens) - 1
1390 while i < len_tokens:
1391 key = tokens[i].name
1393 if keywords.IsKeyword(key)
or key ==
',':
1395 type_name = default =
None 1398 if tokens[i-1].name ==
'=':
1399 assert i < len_tokens,
'%s %s' % (i, tokens)
1400 default, unused_next_token = self.
GetName(tokens[i:])
1403 if tokens[i-1].name !=
',':
1406 key = tokens[i-1].name
1407 type_name = tokens[i-2]
1409 result[key] = (type_name, default)
1414 assert token.token_type == tokenize.SYNTAX, token
1415 assert token.name ==
'<', token
1419 if token.token_type == tokenize.NAME:
1420 if token.name ==
'class':
1421 return self.
_GetClass(Class, VISIBILITY_PRIVATE, templated_types)
1422 elif token.name ==
'struct':
1423 return self.
_GetClass(Struct, VISIBILITY_PUBLIC, templated_types)
1424 elif token.name ==
'friend':
1430 if last.name ==
'(':
1431 return self.
GetMethod(FUNCTION_NONE, templated_types)
1445 return self.
_GetClass(Class, VISIBILITY_PRIVATE,
None)
1452 assert token.token_type == tokenize.NAME, token
1454 if token.name
not in (
'public',
'protected',
'private'):
1462 if token.name !=
'virtual':
1467 base, next_token = self.
GetName()
1468 bases_ast = self.converter.ToType(base)
1469 assert len(bases_ast) == 1, bases_ast
1470 bases.append(bases_ast[0])
1471 assert next_token.token_type == tokenize.SYNTAX, next_token
1472 if next_token.name ==
'{':
1476 assert next_token.name ==
',', next_token
1479 def _GetClass(self, class_type, visibility, templated_types):
1482 if class_token.token_type != tokenize.NAME:
1483 assert class_token.token_type == tokenize.SYNTAX, class_token
1489 if next_token.token_type == tokenize.NAME:
1493 name_tokens, token = self.
GetName()
1494 class_name =
''.join([t.name
for t
in name_tokens])
1496 if token.token_type == tokenize.SYNTAX:
1497 if token.name ==
';':
1499 return class_type(class_token.start, class_token.end,
1500 class_name,
None, templated_types,
None,
1502 if token.name
in '*&':
1506 if next_token.name ==
';':
1508 modifiers = [
'class']
1511 modifiers, token.name,
None)
1514 tokens = (class_token, token, name_token, next_token)
1516 return self.
GetMethod(FUNCTION_NONE,
None)
1517 if token.name ==
':':
1521 if token.token_type == tokenize.SYNTAX
and token.name ==
'{':
1522 assert token.token_type == tokenize.SYNTAX, token
1523 assert token.name ==
'{', token
1527 body = list(ast.Generate())
1531 if token.token_type != tokenize.NAME:
1532 assert token.token_type == tokenize.SYNTAX, token
1533 assert token.name ==
';', token
1535 new_class = class_type(class_token.start, class_token.end,
1536 class_name, bases,
None,
1541 token.name, new_class,
1542 modifiers, token.name,
None)
1548 return class_type(class_token.start, class_token.end, class_name,
1555 if token.token_type == tokenize.NAME:
1558 self.namespace_stack.append(name)
1559 assert token.token_type == tokenize.SYNTAX, token
1563 internal_token.whence = token.whence
1564 if token.name ==
'=':
1566 name, next_token = self.
GetName()
1567 assert next_token.name ==
';', next_token
1570 assert token.name ==
'{', token
1573 tokens[-1] = internal_token
1581 return Using(tokens[0].start, tokens[0].end, tokens)
1588 return self.
GetMethod(FUNCTION_CTOR,
None)
1607 token = self._GetNextToken()
1608 assert token.token_type == tokenize.SYNTAX
1609 assert token.name ==
':' 1618 tokens = self._GetTokensUpTo(tokenize.SYNTAX,
';')
1620 return Return(self.current_token.start, self.current_token.end,
None)
1621 return Return(tokens[0].start, tokens[0].end, tokens)
1625 assert len(tokens) == 1, str(tokens)
1626 return Goto(tokens[0].start, tokens[0].end, tokens[0].name)
1647 self._IgnoreUpTo(tokenize.SYNTAX,
';')
1654 """Utility method that returns an AstBuilder from source code. 1657 source: 'C++ source code' 1663 return AstBuilder(tokenize.GetTokens(source), filename)
1667 """Prints all identifiers for a C++ source file. 1671 should_print: predicate with signature: bool Function(token) 1673 source = utils.ReadFile(filename,
False)
1675 sys.stderr.write(
'Unable to find: %s\n' % filename)
1681 for node
in builder.Generate():
1682 if should_print(node):
1684 except KeyboardInterrupt:
1691 """Prints all identifiers for each C++ source file in filenames. 1694 filenames: ['file1', 'file2', ...] 1695 should_print: predicate with signature: bool Function(token) 1697 for path
in filenames:
1702 for filename
in argv[1:]:
1703 source = utils.ReadFile(filename)
1707 print((
'Processing %s' % filename))
1710 entire_ast = [_f
for _f
in builder.Generate()
if _f]
1711 except KeyboardInterrupt:
1715 traceback.print_exc()
1718 for ast
in entire_ast:
1722 if __name__ ==
'__main__':
def _GetReturnTypeAndClassName(self, token_seq)
def _GetTemplateEnd(self, tokens, start)
def CreateReturnType(self, return_type_seq)
def BuilderFromSource(source, filename)
def handle_namespace(self)
def _CreateVariable(self, pos_token, name, type_name, type_modifiers, ref_pointer_name_seq, templated_types, value=None)
def __init__(self, start, end, name, in_class, return_type, parameters, modifiers, templated_types, body, namespace)
def handle_unsigned(self)
def handle_operator(self)
def __init__(self, start, end, name, var_type, initial_value, namespace)
def PrintIndentifiers(filename, should_print)
def handle_explicit(self)
def GetName(self, seq=None)
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args)
def PrintAllIndentifiers(filenames, should_print)
def __init__(self, namespace_stack)
def _StringHelper(self, name, suffix)
def GetTemplateIndices(self, names)
def handle_static_cast(self)
def __init__(self, start, end)
def handle_dynamic_cast(self)
def handle_protected(self)
def __init__(self, start, end, expr)
def handle_const_cast(self)
def _GetMatchingChar(self, open_paren, close_paren, GetNextToken=None)
def _GetTemplatedTypes(self)
def __init__(self, start, end, expr, namespace)
def _GetTokensUpTo(self, expected_token_type, expected_token)
def __init__(self, start, end, name, templated_types, modifiers, reference, pointer, array)
def ToParameters(self, tokens)
def _GetNestedType(self, ctor)
def __init__(self, start, end, name, namespace)
def _IgnoreUpTo(self, token_type, token)
def __init__(self, start, end, label)
def handle_register(self)
def __init__(self, start, end, name, parameter_type, default)
def __init__(self, token_stream, filename, in_class='', visibility=None, namespace_stack=[])
def handle_typename(self)
def handle_template(self)
def handle_volatile(self)
def HandleError(self, msg, token)
def GetMethod(self, modifiers, templated_types)
def __init__(self, start, end, names)
def _GetClass(self, class_type, visibility, templated_types)
def _GenerateOne(self, token)
def _TypeStringHelper(self, suffix)
def __init__(self, start, end, name, return_type, parameters, modifiers, templated_types, body, namespace)
def __init__(self, start, end, name, bases, templated_types, body, namespace)
def __init__(self, start, end, name, definition)
def _AddBackToken(self, token)
def _GetVarTokensUpTo(self, expected_token_type, expected_tokens)
def handle_reinterpret_cast(self)
def __init__(self, start, end, name, fields, namespace)
def __init__(self, start, end, name, alias, namespace)
def _AddBackTokens(self, tokens)
def handle_continue(self)
def __init__(self, start, end, filename, system)
def _GetMethod(self, return_type_and_name, modifiers, templated_types, get_paren)
def DeclarationToParts(self, parts, needs_name_removed)