| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2007 Neal Norwitz | 3 # Copyright 2007 Neal Norwitz |
| 4 # Portions Copyright 2007 Google Inc. | 4 # Portions Copyright 2007 Google Inc. |
| 5 # | 5 # |
| 6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
| 8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
| 9 # | 9 # |
| 10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 else: | 775 else: |
| 776 temp_tokens2, last_token = \ | 776 temp_tokens2, last_token = \ |
| 777 self._GetVarTokensUpTo(tokenize.SYNTAX, ';') | 777 self._GetVarTokensUpTo(tokenize.SYNTAX, ';') |
| 778 temp_tokens.extend(temp_tokens2) | 778 temp_tokens.extend(temp_tokens2) |
| 779 | 779 |
| 780 if last_token.name == ';': | 780 if last_token.name == ';': |
| 781 # Handle data, this isn't a method. | 781 # Handle data, this isn't a method. |
| 782 parts = self.converter.DeclarationToParts(temp_tokens, True) | 782 parts = self.converter.DeclarationToParts(temp_tokens, True) |
| 783 (name, type_name, templated_types, modifiers, default, | 783 (name, type_name, templated_types, modifiers, default, |
| 784 unused_other_tokens) = parts | 784 unused_other_tokens) = parts |
| 785 | 785 |
| 786 t0 = temp_tokens[0] | 786 t0 = temp_tokens[0] |
| 787 names = [t.name for t in temp_tokens] | 787 names = [t.name for t in temp_tokens] |
| 788 if templated_types: | 788 if templated_types: |
| 789 start, end = self.converter.GetTemplateIndices(names) | 789 start, end = self.converter.GetTemplateIndices(names) |
| 790 names = names[:start] + names[end:] | 790 names = names[:start] + names[end:] |
| 791 default = ''.join([t.name for t in default]) | 791 default = ''.join([t.name for t in default]) |
| 792 return self._CreateVariable(t0, name, type_name, modifiers, | 792 return self._CreateVariable(t0, name, type_name, modifiers, |
| 793 names, templated_types, default) | 793 names, templated_types, default) |
| 794 if last_token.name == '{': | 794 if last_token.name == '{': |
| 795 self._AddBackTokens(temp_tokens[1:]) | 795 self._AddBackTokens(temp_tokens[1:]) |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 | 1544 |
| 1545 def handle_namespace(self): | 1545 def handle_namespace(self): |
| 1546 token = self._GetNextToken() | 1546 token = self._GetNextToken() |
| 1547 # Support anonymous namespaces. | 1547 # Support anonymous namespaces. |
| 1548 name = None | 1548 name = None |
| 1549 if token.token_type == tokenize.NAME: | 1549 if token.token_type == tokenize.NAME: |
| 1550 name = token.name | 1550 name = token.name |
| 1551 token = self._GetNextToken() | 1551 token = self._GetNextToken() |
| 1552 self.namespace_stack.append(name) | 1552 self.namespace_stack.append(name) |
| 1553 assert token.token_type == tokenize.SYNTAX, token | 1553 assert token.token_type == tokenize.SYNTAX, token |
| 1554 # Create an internal token that denotes when the namespace is complete. |
| 1555 internal_token = tokenize.Token(_INTERNAL_TOKEN, _NAMESPACE_POP, |
| 1556 None, None) |
| 1557 internal_token.whence = token.whence |
| 1554 if token.name == '=': | 1558 if token.name == '=': |
| 1555 # TODO(nnorwitz): handle aliasing namespaces. | 1559 # TODO(nnorwitz): handle aliasing namespaces. |
| 1556 name, next_token = self.GetName() | 1560 name, next_token = self.GetName() |
| 1557 assert next_token.name == ';', next_token | 1561 assert next_token.name == ';', next_token |
| 1562 self._AddBackToken(internal_token) |
| 1558 else: | 1563 else: |
| 1559 assert token.name == '{', token | 1564 assert token.name == '{', token |
| 1560 tokens = list(self.GetScope()) | 1565 tokens = list(self.GetScope()) |
| 1561 del tokens[-1] # Remove trailing '}'. | 1566 # Replace the trailing } with the internal namespace pop token. |
| 1567 tokens[-1] = internal_token |
| 1562 # Handle namespace with nothing in it. | 1568 # Handle namespace with nothing in it. |
| 1563 self._AddBackTokens(tokens) | 1569 self._AddBackTokens(tokens) |
| 1564 token = tokenize.Token(_INTERNAL_TOKEN, _NAMESPACE_POP, None, None) | |
| 1565 self._AddBackToken(token) | |
| 1566 return None | 1570 return None |
| 1567 | 1571 |
| 1568 def handle_using(self): | 1572 def handle_using(self): |
| 1569 tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';') | 1573 tokens = self._GetTokensUpTo(tokenize.SYNTAX, ';') |
| 1570 assert tokens | 1574 assert tokens |
| 1571 return Using(tokens[0].start, tokens[0].end, tokens) | 1575 return Using(tokens[0].start, tokens[0].end, tokens) |
| 1572 | 1576 |
| 1573 def handle_explicit(self): | 1577 def handle_explicit(self): |
| 1574 assert self.in_class | 1578 assert self.in_class |
| 1575 # Nothing much to do. | 1579 # Nothing much to do. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 sys.stderr.write('Unable to find: %s\n' % filename) | 1669 sys.stderr.write('Unable to find: %s\n' % filename) |
| 1666 return | 1670 return |
| 1667 | 1671 |
| 1668 #print('Processing %s' % actual_filename) | 1672 #print('Processing %s' % actual_filename) |
| 1669 builder = BuilderFromSource(source, filename) | 1673 builder = BuilderFromSource(source, filename) |
| 1670 try: | 1674 try: |
| 1671 for node in builder.Generate(): | 1675 for node in builder.Generate(): |
| 1672 if should_print(node): | 1676 if should_print(node): |
| 1673 print(node.name) | 1677 print(node.name) |
| 1674 except KeyboardInterrupt: | 1678 except KeyboardInterrupt: |
| 1675 return | 1679 return |
| 1676 except: | 1680 except: |
| 1677 pass | 1681 pass |
| 1678 | 1682 |
| 1679 | 1683 |
| 1680 def PrintAllIndentifiers(filenames, should_print): | 1684 def PrintAllIndentifiers(filenames, should_print): |
| 1681 """Prints all identifiers for each C++ source file in filenames. | 1685 """Prints all identifiers for each C++ source file in filenames. |
| 1682 | 1686 |
| 1683 Args: | 1687 Args: |
| 1684 filenames: ['file1', 'file2', ...] | 1688 filenames: ['file1', 'file2', ...] |
| 1685 should_print: predicate with signature: bool Function(token) | 1689 should_print: predicate with signature: bool Function(token) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1704 # Already printed a warning, print the traceback and continue. | 1708 # Already printed a warning, print the traceback and continue. |
| 1705 traceback.print_exc() | 1709 traceback.print_exc() |
| 1706 else: | 1710 else: |
| 1707 if utils.DEBUG: | 1711 if utils.DEBUG: |
| 1708 for ast in entire_ast: | 1712 for ast in entire_ast: |
| 1709 print(ast) | 1713 print(ast) |
| 1710 | 1714 |
| 1711 | 1715 |
| 1712 if __name__ == '__main__': | 1716 if __name__ == '__main__': |
| 1713 main(sys.argv) | 1717 main(sys.argv) |
| OLD | NEW |