Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
scripts.idlnode.IDLNode Class Reference
Inheritance diagram for scripts.idlnode.IDLNode:
scripts.idlnode.IDLArgument scripts.idlnode.IDLCallbackFunction scripts.idlnode.IDLDictNode scripts.idlnode.IDLDictionary scripts.idlnode.IDLEnum scripts.idlnode.IDLExtAttrFunctionValue scripts.idlnode.IDLFile scripts.idlnode.IDLImplementsStatement scripts.idlnode.IDLInterface scripts.idlnode.IDLMember scripts.idlnode.IDLModule scripts.idlnode.IDLParentInterface scripts.idlnode.IDLType scripts.idlnode.IDLTypeDef

Public Member Functions

 __init__ (self, ast, id=None)
 
 __repr__ (self)
 
 __eq__ (self, other)
 
 __hash__ (self)
 
 reset_id (self, newId)
 
 all (self, type_filter=None)
 
 to_dict (self)
 
 to_hash (self)
 

Public Attributes

 id
 
 ext_attrs
 
 annotations
 
 members
 

Protected Member Functions

 _extra_repr (self)
 
 _all_subnodes (self)
 
 _to_hashable (self, obj)
 
 _find_all (self, ast, label, max_results=sys.maxsize)
 
 _find_first (self, ast, label)
 
 _has (self, ast, label)
 
 _convert_label_to_field (self, label)
 
 _convert_all (self, ast, label, idlnode_ctor)
 
 _convert_first (self, ast, label, idlnode_ctor)
 
 _convert_ext_attrs (self, ast)
 
 _convert_annotations (self, ast)
 
 _convert_constants (self, ast, js_name)
 

Detailed Description

Base class for all IDL elements.
IDLNode may contain various child nodes, and have properties. Examples
of IDLNode are interfaces, interface members, function arguments,
etc.

Definition at line 59 of file idlnode.py.

Constructor & Destructor Documentation

◆ __init__()

scripts.idlnode.IDLNode.__init__ (   self,
  ast,
  id = None 
)

Member Function Documentation

◆ __eq__()

scripts.idlnode.IDLNode.__eq__ (   self,
  other 
)
Override default equals operation.
IDLNodes are equal if all their properties are equal.

Definition at line 92 of file idlnode.py.

92 def __eq__(self, other):
93 """Override default equals operation.
94 IDLNodes are equal if all their properties are equal."""
95 if other is None or not isinstance(other, IDLNode):
96 return 1
97 return self.__dict__.__eq__(other.__dict__)
98

◆ __hash__()

scripts.idlnode.IDLNode.__hash__ (   self)
Define default hashing behavior.
In order to comply with a == b => hash(a) == hash(b), we recursively iterate
self.__dict__ and convert all objects to hashable objects.

Definition at line 99 of file idlnode.py.

99 def __hash__(self):
100 """Define default hashing behavior.
101 In order to comply with a == b => hash(a) == hash(b), we recursively iterate
102 self.__dict__ and convert all objects to hashable objects."""
103 return self.to_hash()
104

◆ __repr__()

scripts.idlnode.IDLNode.__repr__ (   self)
Generates string of the form <class id extra extra ... 0x12345678>.

Reimplemented in scripts.idlnode.IDLOperation, and scripts.idlnode.IDLArgument.

Definition at line 74 of file idlnode.py.

74 def __repr__(self):
75 """Generates string of the form <class id extra extra ... 0x12345678>."""
76 extras = self._extra_repr()
77 if isinstance(extras, list):
78 extras = ' '.join([str(e) for e in extras])
79 try:
80 if self.id:
81 return '<%s %s 0x%x>' % (type(self).__name__,
82 ('%s %s' % (self.id, extras)).strip(),
83 hash(self))
84 return '<%s %s 0x%x>' % (type(self).__name__, extras, hash(self))
85 except Exception as e:
86 return "can't convert to string: %s" % e
87
static uint32_t hash(const SkShaderBase::GradientInfo &v)

◆ _all_subnodes()

scripts.idlnode.IDLNode._all_subnodes (   self)
protected
Accessor used by all() to find subnodes.

Reimplemented in scripts.idlnode.IDLDictNode, and scripts.idlnode.IDLExtAttrs.

Definition at line 130 of file idlnode.py.

130 def _all_subnodes(self):
131 """Accessor used by all() to find subnodes."""
132 return self.__dict__.values()
133

◆ _convert_all()

scripts.idlnode.IDLNode._convert_all (   self,
  ast,
  label,
  idlnode_ctor 
)
protected
Converts AST elements into IDLNode elements.
Uses _find_all to find elements with a given label and converts
them into IDLNodes with a given constructor.
Returns:
A list of the converted nodes.
Args:
ast -- the ast element to start a search at.
label -- the element label to look for.
idlnode_ctor -- a constructor function of one of the IDLNode
sub-classes.

Definition at line 306 of file idlnode.py.

306 def _convert_all(self, ast, label, idlnode_ctor):
307 """Converts AST elements into IDLNode elements.
308 Uses _find_all to find elements with a given label and converts
309 them into IDLNodes with a given constructor.
310 Returns:
311 A list of the converted nodes.
312 Args:
313 ast -- the ast element to start a search at.
314 label -- the element label to look for.
315 idlnode_ctor -- a constructor function of one of the IDLNode
316 sub-classes.
317 """
318 res = []
319 found = self._find_all(ast, label)
320 if not found:
321 return res
322 if not isinstance(found, list):
323 raise RuntimeError("Expected list but %s found" % type(found))
324 for childAst in found:
325 converted = idlnode_ctor(childAst)
326 res.append(converted)
327 return res
328

◆ _convert_annotations()

scripts.idlnode.IDLNode._convert_annotations (   self,
  ast 
)
protected
Helper method for uniform conversion of annotations.

Definition at line 340 of file idlnode.py.

340 def _convert_annotations(self, ast):
341 """Helper method for uniform conversion of annotations."""
342 self.annotations = IDLAnnotations(ast)
343

◆ _convert_constants()

scripts.idlnode.IDLNode._convert_constants (   self,
  ast,
  js_name 
)
protected
Helper method for uniform conversion of dictionary members.

Definition at line 344 of file idlnode.py.

344 def _convert_constants(self, ast, js_name):
345 """Helper method for uniform conversion of dictionary members."""
346 self.members = IDLDictionaryMembers(ast, js_name)
347
348

◆ _convert_ext_attrs()

scripts.idlnode.IDLNode._convert_ext_attrs (   self,
  ast 
)
protected
Helper method for uniform conversion of extended attributes.

Definition at line 336 of file idlnode.py.

336 def _convert_ext_attrs(self, ast):
337 """Helper method for uniform conversion of extended attributes."""
338 self.ext_attrs = IDLExtAttrs(ast)
339

◆ _convert_first()

scripts.idlnode.IDLNode._convert_first (   self,
  ast,
  label,
  idlnode_ctor 
)
protected
Like _convert_all, but only converts the first found results.

Definition at line 329 of file idlnode.py.

329 def _convert_first(self, ast, label, idlnode_ctor):
330 """Like _convert_all, but only converts the first found results."""
331 childAst = self._find_first(ast, label)
332 if not childAst:
333 return None
334 return idlnode_ctor(childAst)
335

◆ _convert_label_to_field()

scripts.idlnode.IDLNode._convert_label_to_field (   self,
  label 
)
protected

Definition at line 270 of file idlnode.py.

270 def _convert_label_to_field(self, label):
271 label_field = {
272 # Keys old AST names, Values Blink IdlInterface names.
273 'ParentInterface': 'parent',
274 'Id': 'name',
275 'Interface': 'interfaces',
276 'Callback_Function': 'callback_functions',
277 'Callback': 'is_callback',
278 'Partial': 'is_partial',
279 'Operation': 'operations',
280 'Attribute': 'attributes',
281 'Const': 'constants',
282 'Type': 'idl_type',
283 'ExtAttrs': 'extended_attributes',
284 'Special': 'specials',
285 'ReturnType': 'idl_type',
286 'Argument': 'arguments',
287 'InterfaceType': 'name',
288 'ConstExpr': 'value',
289 'Static': 'is_static',
290 'ReadOnly': 'is_read_only',
291 'Optional': 'is_optional',
292 'Nullable': 'is_nullable',
293 'Enum': 'enumerations',
294 'Annotation':
295 '', # TODO(terry): Ignore annotation used for database cache.
296 'TypeDef': '', # typedef in an IDL are already resolved.
297 'Dictionary': 'dictionaries',
298 'Member': 'members',
299 'Default': 'default_value', # Dictionary member default value
300 }
301 result = label_field.get(label)
302 if result != '' and not (result):
303 print('FATAL ERROR: AST mapping name not found %s.' % label)
304 return result if result else ''
305
void print(void *str)
Definition bridge.cpp:126

◆ _extra_repr()

scripts.idlnode.IDLNode._extra_repr (   self)
protected
Returns string of extra info for __repr__().

Reimplemented in scripts.idlnode.IDLOperation, and scripts.idlnode.IDLAttribute.

Definition at line 88 of file idlnode.py.

88 def _extra_repr(self):
89 """Returns string of extra info for __repr__()."""
90 return ''
91

◆ _find_all()

scripts.idlnode.IDLNode._find_all (   self,
  ast,
  label,
  max_results = sys.maxsize 
)
protected
Searches the AST for tuples with a given label. The PegParser
output is composed of lists and tuples, where the tuple 1st argument
is a label. If ast root is a list, will search recursively inside each
member in the list.

Args:
ast -- the AST to search.
label -- the label to look for.
res -- results are put into this list.
max_results -- maximum number of results.

Definition at line 191 of file idlnode.py.

191 def _find_all(self, ast, label, max_results=sys.maxsize):
192 """Searches the AST for tuples with a given label. The PegParser
193 output is composed of lists and tuples, where the tuple 1st argument
194 is a label. If ast root is a list, will search recursively inside each
195 member in the list.
196
197 Args:
198 ast -- the AST to search.
199 label -- the label to look for.
200 res -- results are put into this list.
201 max_results -- maximum number of results.
202 """
203 res = []
204 if max_results <= 0:
205 return res
206
207 if isinstance(ast, list):
208 for childAst in ast:
209 if childAst and \
210 not(isinstance(childAst, dict)) and \
211 not(isinstance(childAst, str)) and \
212 not(isinstance(childAst, tuple)) and \
213 childAst.__module__ == "idl_definitions":
214 field_name = self._convert_label_to_field(label)
215 if hasattr(childAst, field_name):
216 field_value = getattr(childAst, field_name)
217 # It's an IdlType we need the string name of the type.
218 if field_name == 'idl_type':
219 field_value = getattr(field_value, 'base_type')
220 res.append(field_value)
221 else:
222 sub_res = self._find_all(childAst, label,
223 max_results - len(res))
224 res.extend(sub_res)
225 elif isinstance(ast, tuple):
226 (nodeLabel, value) = ast
227 if nodeLabel == label:
228 res.append(value)
229 # TODO(terry): Seems bogus to check for so many things probably better to just
230 # pass in blink_compile and drive it off from that...
231 elif (ast and not (isinstance(ast, dict)) and
232 not (isinstance(ast, str)) and
233 (ast.__module__ == "idl_definitions" or
234 ast.__module__ == "idl_types")):
235 field_name = self._convert_label_to_field(label)
236 if hasattr(ast, field_name):
237 field_value = getattr(ast, field_name)
238 if field_value:
239 if label == 'Interface' or label == 'Enum' or label == "Dictionary":
240 for key in field_value:
241 value = field_value[key]
242 res.append(value)
243 elif isinstance(field_value, list):
244 for item in field_value:
245 res.append(item)
246 elif label == 'ParentInterface' or label == 'InterfaceType':
247 # Fetch the AST for the parent interface.
248 parent_idlnode = new_asts[field_value]
249 res.append(parent_idlnode.interfaces[field_value])
250 else:
251 res.append(field_value)
252
253 return res
254

◆ _find_first()

scripts.idlnode.IDLNode._find_first (   self,
  ast,
  label 
)
protected
Convenience method for _find_all(..., max_results=1).
Returns a single element instead of a list, or None if nothing
is found.

Definition at line 255 of file idlnode.py.

255 def _find_first(self, ast, label):
256 """Convenience method for _find_all(..., max_results=1).
257 Returns a single element instead of a list, or None if nothing
258 is found."""
259 res = self._find_all(ast, label, max_results=1)
260 if len(res):
261 return res[0]
262 return None
263

◆ _has()

scripts.idlnode.IDLNode._has (   self,
  ast,
  label 
)
protected
Returns true if an element with the given label is
in the AST by searching for it.

Definition at line 264 of file idlnode.py.

264 def _has(self, ast, label):
265 """Returns true if an element with the given label is
266 in the AST by searching for it."""
267 return len(self._find_all(ast, label, max_results=1)) == 1
268

◆ _to_hashable()

scripts.idlnode.IDLNode._to_hashable (   self,
  obj 
)
protected

Definition at line 165 of file idlnode.py.

165 def _to_hashable(self, obj):
166 # By default, lists and dicts are not hashable, and user-defined objects
167 # are unordered. In order to make a consistent hash for a given object,
168 # this converts unhashable types and sorts properties.
169 if isinstance(obj, list):
170 # Convert lists to tuples.
171 new_obj = []
172 for item in obj:
173 new_obj.append(self._to_hashable(item))
174 return tuple(new_obj)
175 elif isinstance(obj, dict):
176 # Convert dicts to frozensets of tuples.
177 new_obj = set()
178 # Sort to ensure fixed order.
179 for (k2, v2) in sorted(obj.items(), key=MultitypeSortKey):
180 new_obj.add((self._to_hashable(k2), self._to_hashable(v2)))
181 return frozenset(new_obj)
182 elif hasattr(obj, '__dict__'):
183 items = []
184 # Sort properties to ensure fixed order.
185 for (k, v) in sorted(obj.__dict__.items(), key=MultitypeSortKey):
186 items.append((k, self._to_hashable(v)))
187 return tuple(items)
188 else:
189 return obj
190

◆ all()

scripts.idlnode.IDLNode.all (   self,
  type_filter = None 
)
Returns a list containing this node and all it child nodes
(recursive).

Args:
type_filter -- can be used to limit the results to a specific
node type (e.g. IDLOperation).

Definition at line 110 of file idlnode.py.

110 def all(self, type_filter=None):
111 """Returns a list containing this node and all it child nodes
112 (recursive).
113
114 Args:
115 type_filter -- can be used to limit the results to a specific
116 node type (e.g. IDLOperation).
117 """
118 res = []
119 if type_filter is None or isinstance(self, type_filter):
120 res.append(self)
121 for v in self._all_subnodes():
122 if isinstance(v, IDLNode):
123 res.extend(v.all(type_filter))
124 elif isinstance(v, list):
125 for item in v:
126 if isinstance(item, IDLNode):
127 res.extend(item.all(type_filter))
128 return res
129

◆ reset_id()

scripts.idlnode.IDLNode.reset_id (   self,
  newId 
)
Reset the id of the Node.  This is typically done during a normalization
phase (e.g., "DOMWindow" -> "Window").

Reimplemented in scripts.idlnode.IDLInterface.

Definition at line 105 of file idlnode.py.

105 def reset_id(self, newId):
106 """Reset the id of the Node. This is typically done during a normalization
107 phase (e.g., "DOMWindow" -> "Window")."""
108 self.id = newId
109

◆ to_dict()

scripts.idlnode.IDLNode.to_dict (   self)
Converts the IDLNode and its children into a dictionary.
This method is useful mostly for debugging and pretty printing.

Reimplemented in scripts.idlnode.IDLDictNode.

Definition at line 134 of file idlnode.py.

134 def to_dict(self):
135 """Converts the IDLNode and its children into a dictionary.
136 This method is useful mostly for debugging and pretty printing.
137 """
138 res = {}
139 for (k, v) in self.__dict__.items():
140 if v == None or v == False or v == [] or v == {}:
141 # Skip empty/false members.
142 continue
143 elif isinstance(v, IDLDictNode) and not len(v):
144 # Skip empty dict sub-nodes.
145 continue
146 elif isinstance(v, list):
147 # Convert lists:
148 new_v = []
149 for sub_node in v:
150 if isinstance(sub_node, IDLNode):
151 # Convert sub-node:
152 new_v.append(sub_node.to_dict())
153 else:
154 new_v.append(sub_node)
155 v = new_v
156 elif isinstance(v, IDLNode):
157 # Convert sub-node:
158 v = v.to_dict()
159 res[k] = v
160 return res
161

◆ to_hash()

scripts.idlnode.IDLNode.to_hash (   self)

Definition at line 162 of file idlnode.py.

162 def to_hash(self):
163 return hash(self._to_hashable(self))
164

Member Data Documentation

◆ annotations

scripts.idlnode.IDLNode.annotations

Definition at line 342 of file idlnode.py.

◆ ext_attrs

scripts.idlnode.IDLNode.ext_attrs

Definition at line 338 of file idlnode.py.

◆ id

scripts.idlnode.IDLNode.id

Definition at line 69 of file idlnode.py.

◆ members

scripts.idlnode.IDLNode.members

Definition at line 346 of file idlnode.py.


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