Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / tools / telemetry / catapult_base / refactor / annotated_symbol / __init__.py
blob32858b523d5275aecb0abd21efe11e568c9a87be
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # pylint: disable=wildcard-import
6 from catapult_base.refactor.annotated_symbol.class_definition import *
7 from catapult_base.refactor.annotated_symbol.function_definition import *
8 from catapult_base.refactor.annotated_symbol.import_statement import *
9 from catapult_base.refactor.annotated_symbol.reference import *
10 from catapult_base.refactor import snippet
13 __all__ = [
14 'Annotate',
16 'Class',
17 'Function',
18 'Import',
19 'Reference',
23 # Specific symbol types with extra methods for manipulating them.
24 # Python's full grammar is here:
25 # https://docs.python.org/2/reference/grammar.html
27 # Annotated Symbols have an Annotate classmethod that takes a symbol type and
28 # list of children, and returns an instance of that annotated Symbol.
30 ANNOTATED_SYMBOLS = (
31 AsName,
32 Class,
33 DottedName,
34 ImportFrom,
35 ImportName,
36 Function,
40 # Unfortunately, some logical groupings are not represented by a node in the
41 # parse tree. To work around this, some annotated Symbols have an Annotate
42 # classmethod that takes and returns a list of Snippets instead.
44 ANNOTATED_GROUPINGS = (
45 Reference,
49 def Annotate(f):
50 """Return the syntax tree of the given file."""
51 return _AnnotateNode(snippet.Snippetize(f))
54 def _AnnotateNode(node):
55 if not isinstance(node, snippet.Symbol):
56 return node
58 children = map(_AnnotateNode, node.children)
60 for symbol_type in ANNOTATED_GROUPINGS:
61 annotated_grouping = symbol_type.Annotate(children)
62 if annotated_grouping:
63 children = annotated_grouping
64 break
66 for symbol_type in ANNOTATED_SYMBOLS:
67 annotated_symbol = symbol_type.Annotate(node.type, children)
68 if annotated_symbol:
69 return annotated_symbol
71 return snippet.Symbol(node.type, children)