Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: tools/binary_size/libsupersize/function_signature.py

Issue 2880003002: supersize: A few fixes for Android+clang builds (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Logic for parsing a C/C++ function signature.""" 5 """Logic for parsing a C/C++ function signature."""
6 6
7 7
8 def _FindParameterListParen(name): 8 def _FindParameterListParen(name):
9 """Finds index of the "(" that denotes the start of a paremeter list.""" 9 """Finds index of the "(" that denotes the start of a paremeter list."""
10 # This loops from left-to-right, but the only reason (I think) that this 10 # This loops from left-to-right, but the only reason (I think) that this
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 left_idx = _FindLastCharOutsideOfBrackets(name, '<', last_right_idx + 1) 95 left_idx = _FindLastCharOutsideOfBrackets(name, '<', last_right_idx + 1)
96 if left_idx == -1: 96 if left_idx == -1:
97 return name 97 return name
98 # Special case: std::operator<< < 98 # Special case: std::operator<< <
99 if left_idx > 0 and name[left_idx - 1] == ' ': 99 if left_idx > 0 and name[left_idx - 1] == ' ':
100 left_idx -= 1 100 left_idx -= 1
101 name = name[:left_idx] + name[last_right_idx + 1:] 101 name = name[:left_idx] + name[last_right_idx + 1:]
102 last_right_idx = left_idx 102 last_right_idx = left_idx
103 103
104 104
105 def _NormalizeTopLevelLambda(name, space_idx, left_paren_idx): 105 def _NormalizeTopLevelGccLambda(name, left_paren_idx):
106 # cc::{lambda(PaintOp*)#63}::_FUN() -> cc:{lambda#63}() 106 # cc::{lambda(PaintOp*)#63}::_FUN() -> cc::$lambda#63()
107 paren_idx = name.index('(', space_idx + 1) 107 left_brace_idx = name.index('{')
108 hash_idx = name.rindex('#', paren_idx) 108 hash_idx = name.index('#', left_brace_idx + 1)
109 return (name[:paren_idx] + name[hash_idx:left_paren_idx - 6] + 109 right_brace_idx = name.index('}', hash_idx + 1)
110 name[left_paren_idx:]) 110 number = name[hash_idx + 1:right_brace_idx]
111 return '{}$lambda#{}{}'.format(
112 name[:left_brace_idx], number, name[left_paren_idx:])
113
114
115 def _NormalizeTopLevelClangLambda(name, left_paren_idx):
116 # cc::$_21::__invoke() -> cc::$lambda#21()
117 dollar_idx = name.index('$')
118 colon_idx = name.index(':', dollar_idx + 1)
119 number = name[dollar_idx + 2:colon_idx]
120 return '{}$lambda#{}{}'.format(
121 name[:dollar_idx], number, name[left_paren_idx:])
111 122
112 123
113 def Parse(name): 124 def Parse(name):
114 """Strips return type and breaks function signature into parts. 125 """Strips return type and breaks function signature into parts.
115 126
116 See unit tests for example signatures. 127 See unit tests for example signatures.
117 128
118 Returns: 129 Returns:
119 A tuple of: 130 A tuple of:
120 * name without return type (symbol.full_name), 131 * name without return type (symbol.full_name),
121 * full_name without params (symbol.template_name), 132 * full_name without params (symbol.template_name),
122 * full_name without params and template args (symbol.name) 133 * full_name without params and template args (symbol.name)
123 """ 134 """
124 left_paren_idx = _FindParameterListParen(name) 135 left_paren_idx = _FindParameterListParen(name)
125 136
126 full_name = name 137 full_name = name
127 if left_paren_idx > 0: 138 if left_paren_idx > 0:
128 right_paren_idx = name.rindex(')') 139 right_paren_idx = name.rindex(')')
129 assert right_paren_idx > left_paren_idx 140 assert right_paren_idx > left_paren_idx
130 space_idx = _FindReturnValueSpace(name, left_paren_idx) 141 space_idx = _FindReturnValueSpace(name, left_paren_idx)
131 name_no_params = name[space_idx + 1:left_paren_idx] 142 name_no_params = name[space_idx + 1:left_paren_idx]
132 # Special case for top-level lamdas. 143 # Special case for top-level lamdas.
133 if name_no_params.endswith('}::_FUN'): 144 if name_no_params.endswith('}::_FUN'):
134 # Don't use name_no_params in here since prior _idx will be off if 145 # Don't use name_no_params in here since prior _idx will be off if
135 # there was a return value. 146 # there was a return value.
136 name = _NormalizeTopLevelLambda(name, space_idx, left_paren_idx) 147 name = _NormalizeTopLevelGccLambda(name, left_paren_idx)
148 return Parse(name)
149 elif name_no_params.endswith('::__invoke') and '$' in name_no_params:
150 assert '$_' in name_no_params, 'Surprising lambda: ' + name
151 name = _NormalizeTopLevelClangLambda(name, left_paren_idx)
137 return Parse(name) 152 return Parse(name)
138 153
139 full_name = name[space_idx + 1:] 154 full_name = name[space_idx + 1:]
140 name = name_no_params + name[right_paren_idx + 1:] 155 name = name_no_params + name[right_paren_idx + 1:]
141 156
142 template_name = name 157 template_name = name
143 name = _StripTemplateArgs(name) 158 name = _StripTemplateArgs(name)
144 return full_name, template_name, name 159 return full_name, template_name, name
145 160
146 161
147 # An odd place for this, but pylint doesn't want it as a static in models 162 # An odd place for this, but pylint doesn't want it as a static in models
148 # (circular dependency), nor as an method on BaseSymbol 163 # (circular dependency), nor as an method on BaseSymbol
149 # (attribute-defined-outside-init). 164 # (attribute-defined-outside-init).
150 def InternSameNames(symbol): 165 def InternSameNames(symbol):
151 """Allow using "is" to compare names (and should help with RAM).""" 166 """Allow using "is" to compare names (and should help with RAM)."""
152 if symbol.template_name == symbol.full_name: 167 if symbol.template_name == symbol.full_name:
153 symbol.template_name = symbol.full_name 168 symbol.template_name = symbol.full_name
154 if symbol.name == symbol.template_name: 169 if symbol.name == symbol.template_name:
155 symbol.name = symbol.template_name 170 symbol.name = symbol.template_name
OLDNEW
« no previous file with comments | « tools/binary_size/libsupersize/archive.py ('k') | tools/binary_size/libsupersize/function_signature_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698