idl-parser 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {idl_parser-0.3.2/idl_parser.egg-info → idl_parser-0.4.0}/PKG-INFO +1 -1
- {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/api/index.rst +2 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/bitset.py +4 -8
- idl_parser-0.4.0/idl_parser/definitions.py +416 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/exception.py +9 -9
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/interface.py +228 -5
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/module.py +100 -332
- idl_parser-0.4.0/idl_parser/native.py +42 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/node.py +20 -10
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/parser.py +6 -3
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/struct.py +52 -1
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/type.py +14 -3
- {idl_parser-0.3.2 → idl_parser-0.4.0/idl_parser.egg-info}/PKG-INFO +1 -1
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/SOURCES.txt +7 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/scm_file_list.json +7 -0
- idl_parser-0.4.0/idl_parser.egg-info/scm_version.json +8 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/README.md +3 -3
- idl_parser-0.4.0/tests/interface/interface_body_test.py +188 -0
- idl_parser-0.4.0/tests/interface/local_abstract_test.py +109 -0
- idl_parser-0.4.0/tests/primitive_const/native_test.py +134 -0
- idl_parser-0.4.0/tests/scope/pathname_test.py +39 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/unknown_word_test.py +52 -63
- idl_parser-0.4.0/tests/struct_enum_union/exception_test.py +178 -0
- idl_parser-0.3.2/idl_parser.egg-info/scm_version.json +0 -8
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.github/workflows/release.yml +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.github/workflows/test.yml +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.gitignore +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.readthedocs.yaml +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.vscode/extensions.json +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.vscode/launch.json +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/.vscode/settings.json +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/LICENSE +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/README.md +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/README.rst +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/conf.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/index.rst +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/requirements.txt +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/_path.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/annotation_example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/argument_direction_example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/enum_example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/scoped_name_example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/struct_example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/union_example.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/bitmask.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/const.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/enum.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/pragma.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/token_buffer.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/typedef.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/union.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/dependency_links.txt +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/top_level.txt +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/pyproject.toml +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/setup.cfg +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/annotation_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/bit_bound_scope_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/string_argument_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/bitmask_bitset/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/bitmask_bitset/bitmask_bitset_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/examples/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/examples/examples_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/element_type_forward_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/interface_forward_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/struct_union_forward_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/basic_module_test.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/circular/circular_a.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/circular/circular_b.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/circular/diamond.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/forward_declaration.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/generalization.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/generalization_extended.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/included_idl.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/including_idl.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/invalid_idl.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue12_subpath/relative_include.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue12_subpath/sensor_msgs/msg/Imu.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue12_subpath/std/msg/Header.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue18_idl42_int_types.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue28_pragma_keylist.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue9_const_pragma.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue9_tabs_bounded_string.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue9_whitespace_variants.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/multi_module_test.idl +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/circular_include_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/include_dirs_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/subpath_include_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/argument_direction_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/basic_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/inheritance_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/raises_context_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/basic_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/bracket_spacing_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/error_line_number_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/exception_message_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/opensplice_idl_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/string_literal_comment_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/token_split_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/constructor_python_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_enum_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_inherits_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_member_only_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_member_type_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/key_annotation_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/keylist_validation_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/pragma_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/basic_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/const_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/int_types_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/basename_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/basic_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/leading_scope_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/multi_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/same_name_resolution_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/unsupported_block_scope_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/basic_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/element_type_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/nested_bounded_sequence_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/syntax_error_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/__init__.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/basic_module_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/syntax_error_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/union_char_label_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/union_default_label_test.py +0 -0
- {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/support.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: idl_parser
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Very simple OMG IDL (Interface Definition Language) parser. This parses IDL files and outputs intermediate class objects.
|
|
5
5
|
Author-email: ysuga <ysuga@ysuga.net>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -245,13 +245,11 @@ class IDLBitset(node.IDLNode):
|
|
|
245
245
|
return candidates
|
|
246
246
|
|
|
247
247
|
def _find_base(self, name, ln, fn):
|
|
248
|
+
from .module import definition_scopes
|
|
248
249
|
bitsets = {}
|
|
249
|
-
|
|
250
|
+
for m in definition_scopes(self.root_node, self):
|
|
250
251
|
for b in m.bitsets:
|
|
251
252
|
bitsets[b.full_path.lstrip(':')] = b
|
|
252
|
-
for sub in m.modules:
|
|
253
|
-
collect(sub)
|
|
254
|
-
collect(self.root_node)
|
|
255
253
|
for c in self._scopes(name):
|
|
256
254
|
if c in bitsets:
|
|
257
255
|
return bitsets[c]
|
|
@@ -259,13 +257,11 @@ class IDLBitset(node.IDLNode):
|
|
|
259
257
|
ln, fn, 'Can not find "%s" bitset which is the base of "%s"' % (name, self.name))
|
|
260
258
|
|
|
261
259
|
def _find_const(self, name):
|
|
260
|
+
from .module import definition_scopes
|
|
262
261
|
consts = {}
|
|
263
|
-
|
|
262
|
+
for m in definition_scopes(self.root_node, self):
|
|
264
263
|
for c in m.consts:
|
|
265
264
|
consts[(m.full_path.lstrip(':') + sep + c.name).lstrip(':')] = c
|
|
266
|
-
for sub in m.modules:
|
|
267
|
-
collect(sub)
|
|
268
|
-
collect(self.root_node)
|
|
269
265
|
for c in self._scopes(name):
|
|
270
266
|
if c in consts:
|
|
271
267
|
return consts[c]
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"""Type and constant definitions shared by modules and interfaces.
|
|
2
|
+
|
|
3
|
+
A ``module`` and an ``interface`` can both hold ``struct``, ``union``,
|
|
4
|
+
``enum``, ``typedef``, ``const``, ``exception``, ``native``, ``bitmask`` and
|
|
5
|
+
``bitset`` definitions (issue #101). :class:`IDLDefinitionScope` keeps them
|
|
6
|
+
and parses them for both.
|
|
7
|
+
"""
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from . import node
|
|
11
|
+
from . import struct, typedef, enum, const, union, bitmask, bitset, native
|
|
12
|
+
from .exception import InvalidIDLSyntaxError
|
|
13
|
+
|
|
14
|
+
# Keywords that start a definition handled by IDLDefinitionScope.parse_definition().
|
|
15
|
+
definition_keywords = ('typedef', 'struct', 'exception', 'enum', 'bitmask',
|
|
16
|
+
'bitset', 'union', 'native', 'const')
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class IDLDefinitionScope(object):
|
|
20
|
+
"""Mixin for a scope that holds type and constant definitions.
|
|
21
|
+
|
|
22
|
+
Used by :class:`~idl_parser.module.IDLModule` and
|
|
23
|
+
:class:`~idl_parser.interface.IDLInterface`.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def _init_definitions(self):
|
|
27
|
+
self._typedefs = []
|
|
28
|
+
self._structs = []
|
|
29
|
+
self._forward_structs = []
|
|
30
|
+
self._exceptions = []
|
|
31
|
+
self._enums = []
|
|
32
|
+
self._bitmasks = []
|
|
33
|
+
self._bitsets = []
|
|
34
|
+
self._unions = []
|
|
35
|
+
self._forward_unions = []
|
|
36
|
+
self._consts = []
|
|
37
|
+
self._natives = []
|
|
38
|
+
|
|
39
|
+
def parse_definition(self, token, token_buf, filepath=None, annotations=()):
|
|
40
|
+
"""Parse a definition whose keyword ``token`` is already consumed.
|
|
41
|
+
|
|
42
|
+
:param token: The keyword (one of :data:`definition_keywords`).
|
|
43
|
+
:param token_buf: :class:`~idl_parser.token_buffer.TokenBuffer` to read from.
|
|
44
|
+
:param filepath: File name recorded in the parsed nodes.
|
|
45
|
+
:param annotations: Annotations written before the keyword.
|
|
46
|
+
:return: False if ``token`` does not start a definition (nothing is read).
|
|
47
|
+
:raises ~idl_parser.exception.InvalidIDLSyntaxError: The definition is
|
|
48
|
+
not valid IDL.
|
|
49
|
+
"""
|
|
50
|
+
pending_annotations = list(annotations)
|
|
51
|
+
if token == 'typedef':
|
|
52
|
+
blocks = []
|
|
53
|
+
while True:
|
|
54
|
+
ln, fn, t = token_buf.pop()
|
|
55
|
+
if t == None:
|
|
56
|
+
raise InvalidIDLSyntaxError()
|
|
57
|
+
elif t == ';':
|
|
58
|
+
break
|
|
59
|
+
else:
|
|
60
|
+
blocks.append(t)
|
|
61
|
+
t = typedef.IDLTypedef(self)
|
|
62
|
+
anns, blocks = node.parse_annotations(blocks)
|
|
63
|
+
t._add_annotations(pending_annotations + anns)
|
|
64
|
+
t.parse_blocks(blocks, filepath=filepath)
|
|
65
|
+
t_ = self.typedef_by_name(t.name)
|
|
66
|
+
if t_:
|
|
67
|
+
if self._verbose: sys.stdout.write('# Error. Same Typedef Defined (%s)\n' % t.name)
|
|
68
|
+
else:
|
|
69
|
+
self._typedefs.append(t)
|
|
70
|
+
|
|
71
|
+
elif token == 'struct':
|
|
72
|
+
ln, fn, name_ = token_buf.pop()
|
|
73
|
+
s_ = self.struct_by_name(name_)
|
|
74
|
+
s = struct.IDLStruct(name_, self)
|
|
75
|
+
s._add_annotations(pending_annotations)
|
|
76
|
+
s.parse_tokens(token_buf, filepath=filepath)
|
|
77
|
+
if s.is_forward:
|
|
78
|
+
# Forward declaration ("struct A;"): remember the name only.
|
|
79
|
+
# The definition, if any, is added to structs when it appears.
|
|
80
|
+
if name_ not in self._forward_structs:
|
|
81
|
+
self._forward_structs.append(name_)
|
|
82
|
+
elif s_:
|
|
83
|
+
if self._verbose: sys.stdout.write('# Error. Same Struct Defined (%s)\n' % name_)
|
|
84
|
+
# raise InvalidIDLSyntaxError
|
|
85
|
+
else:
|
|
86
|
+
self._structs.append(s)
|
|
87
|
+
|
|
88
|
+
elif token == 'exception':
|
|
89
|
+
ln, fn, name_ = token_buf.pop()
|
|
90
|
+
s = struct.IDLException(name_, self)
|
|
91
|
+
s._add_annotations(pending_annotations)
|
|
92
|
+
s.parse_tokens(token_buf, filepath=filepath)
|
|
93
|
+
if self.exception_by_name(name_):
|
|
94
|
+
if self._verbose: sys.stdout.write('# Error. Same Exception Defined (%s)\n' % name_)
|
|
95
|
+
else:
|
|
96
|
+
self._exceptions.append(s)
|
|
97
|
+
|
|
98
|
+
elif token == 'enum':
|
|
99
|
+
ln, fn, name_ = token_buf.pop()
|
|
100
|
+
s = enum.IDLEnum(name_, self)
|
|
101
|
+
s._add_annotations(pending_annotations)
|
|
102
|
+
s.parse_tokens(token_buf, filepath)
|
|
103
|
+
s_ = self.enum_by_name(name_)
|
|
104
|
+
if s_:
|
|
105
|
+
if self._verbose: sys.stdout.write('# Error. Same Enum Defined (%s)\n' % name_)
|
|
106
|
+
# raise InvalidIDLSyntaxError
|
|
107
|
+
else:
|
|
108
|
+
self._enums.append(s)
|
|
109
|
+
|
|
110
|
+
elif token == 'bitmask':
|
|
111
|
+
ln, fn, name_ = token_buf.pop()
|
|
112
|
+
s = bitmask.IDLBitmask(name_, self, pending_annotations)
|
|
113
|
+
s.parse_tokens(token_buf, filepath)
|
|
114
|
+
if self.bitmask_by_name(name_):
|
|
115
|
+
if self._verbose: sys.stdout.write('# Error. Same Bitmask Defined (%s)\n' % name_)
|
|
116
|
+
else:
|
|
117
|
+
self._bitmasks.append(s)
|
|
118
|
+
|
|
119
|
+
elif token == 'bitset':
|
|
120
|
+
ln, fn, name_ = token_buf.pop()
|
|
121
|
+
s = bitset.IDLBitset(name_, self)
|
|
122
|
+
s._add_annotations(pending_annotations)
|
|
123
|
+
s.parse_tokens(token_buf, filepath)
|
|
124
|
+
if self.bitset_by_name(name_):
|
|
125
|
+
if self._verbose: sys.stdout.write('# Error. Same Bitset Defined (%s)\n' % name_)
|
|
126
|
+
else:
|
|
127
|
+
self._bitsets.append(s)
|
|
128
|
+
|
|
129
|
+
elif token == 'union':
|
|
130
|
+
ln, fn, name_ = token_buf.pop()
|
|
131
|
+
s = union.IDLUnion(name_, self)
|
|
132
|
+
s._add_annotations(pending_annotations)
|
|
133
|
+
s.parse_tokens(token_buf, filepath)
|
|
134
|
+
if s.is_forward:
|
|
135
|
+
# Forward declaration ("union A;"): remember the name only.
|
|
136
|
+
if name_ not in self._forward_unions:
|
|
137
|
+
self._forward_unions.append(name_)
|
|
138
|
+
elif self.union_by_name(name_):
|
|
139
|
+
if self._verbose: sys.stdout.write('# Error. Same Union Defined (%s)\n' % name_)
|
|
140
|
+
# raise InvalidIDLSyntaxError
|
|
141
|
+
else:
|
|
142
|
+
self._unions.append(s)
|
|
143
|
+
|
|
144
|
+
elif token == 'native':
|
|
145
|
+
# "native N;": a type with a name only (issue #93).
|
|
146
|
+
ln, fn, name_ = token_buf.pop()
|
|
147
|
+
if name_ is None or name_ in (';', '{', '}'):
|
|
148
|
+
raise InvalidIDLSyntaxError(ln, fn, 'No name after "native"')
|
|
149
|
+
ln2, fn2, t = token_buf.pop()
|
|
150
|
+
if t != ';':
|
|
151
|
+
raise InvalidIDLSyntaxError(ln, fn, 'No ";" after "native %s"' % name_)
|
|
152
|
+
n = native.IDLNative(name_, self, filepath=filepath)
|
|
153
|
+
n._add_annotations(pending_annotations)
|
|
154
|
+
if self.native_by_name(name_):
|
|
155
|
+
if self._verbose: sys.stdout.write('# Error. Same Native Defined (%s)\n' % name_)
|
|
156
|
+
else:
|
|
157
|
+
self._natives.append(n)
|
|
158
|
+
|
|
159
|
+
elif token == 'const':
|
|
160
|
+
values = []
|
|
161
|
+
while True:
|
|
162
|
+
ln, fn, t = token_buf.pop()
|
|
163
|
+
if t is None:
|
|
164
|
+
if self._verbose: sys.stdout.write('# Error. No ";" after const.\n')
|
|
165
|
+
raise InvalidIDLSyntaxError(message='No ";" after const definition')
|
|
166
|
+
if t == ';':
|
|
167
|
+
break
|
|
168
|
+
values.append(t)
|
|
169
|
+
|
|
170
|
+
# Split at '=': "<type> <name> = <value>" (issue #52).
|
|
171
|
+
# The value is every token after '=', so that an
|
|
172
|
+
# expression such as "1 + 2" is kept whole.
|
|
173
|
+
if '=' not in values:
|
|
174
|
+
raise InvalidIDLSyntaxError(ln, fn, 'No "=" in const definition "%s"' % ' '.join(values))
|
|
175
|
+
eq = values.index('=')
|
|
176
|
+
if eq < 2:
|
|
177
|
+
raise InvalidIDLSyntaxError(ln, fn, 'No type or name in const definition "%s"' % ' '.join(values))
|
|
178
|
+
if eq == len(values) - 1:
|
|
179
|
+
raise InvalidIDLSyntaxError(ln, fn, 'No value in const definition "%s"' % ' '.join(values))
|
|
180
|
+
value_ = ' '.join(values[eq+1:])
|
|
181
|
+
name_ = values[eq-1]
|
|
182
|
+
typename = ' '.join(values[:eq-1])
|
|
183
|
+
s = const.IDLConst(name_, typename, value_, self, filepath=filepath)
|
|
184
|
+
s._add_annotations(pending_annotations)
|
|
185
|
+
s_ = self.const_by_name(name_)
|
|
186
|
+
if s_:
|
|
187
|
+
if self._verbose: sys.stdout.write('# Error. Same Const Defined (%s)\n' % name_)
|
|
188
|
+
else:
|
|
189
|
+
self._consts.append(s)
|
|
190
|
+
|
|
191
|
+
else:
|
|
192
|
+
return False
|
|
193
|
+
return True
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def has_definitions(self):
|
|
197
|
+
"""True if any type or constant is defined in this scope."""
|
|
198
|
+
return any((self._typedefs, self._structs, self._exceptions, self._enums,
|
|
199
|
+
self._bitmasks, self._bitsets, self._unions, self._consts,
|
|
200
|
+
self._natives))
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def structs(self):
|
|
204
|
+
"""Structs defined directly in this scope (list of :class:`~idl_parser.struct.IDLStruct`)."""
|
|
205
|
+
return self._structs
|
|
206
|
+
|
|
207
|
+
def struct_by_name(self, name):
|
|
208
|
+
"""The struct named ``name`` (not scoped) in this scope, or None."""
|
|
209
|
+
for s in self.structs:
|
|
210
|
+
if s.name == name:
|
|
211
|
+
return s
|
|
212
|
+
return None
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def forward_structs(self):
|
|
216
|
+
"""Names of structs forward-declared ("struct A;") in this scope,
|
|
217
|
+
in declaration order, whether or not they are defined later."""
|
|
218
|
+
return list(self._forward_structs)
|
|
219
|
+
|
|
220
|
+
@property
|
|
221
|
+
def undefined_forward_structs(self):
|
|
222
|
+
"""Forward-declared struct names that have no definition in this scope."""
|
|
223
|
+
return [n for n in self._forward_structs if self.struct_by_name(n) is None]
|
|
224
|
+
|
|
225
|
+
def for_each_struct(self, func, filter=None):
|
|
226
|
+
"""Call ``func`` with each struct and return the results as a list.
|
|
227
|
+
|
|
228
|
+
:param filter: If given, only the structs for which ``filter(struct)`` is
|
|
229
|
+
true are passed to ``func``.
|
|
230
|
+
"""
|
|
231
|
+
retval = []
|
|
232
|
+
for m in self.structs:
|
|
233
|
+
if filter:
|
|
234
|
+
if filter(m):
|
|
235
|
+
retval.append(func(m))
|
|
236
|
+
pass
|
|
237
|
+
else:
|
|
238
|
+
retval.append(func(m))
|
|
239
|
+
return retval
|
|
240
|
+
|
|
241
|
+
@property
|
|
242
|
+
def exceptions(self):
|
|
243
|
+
"""Exceptions defined directly in this scope (list of :class:`~idl_parser.struct.IDLException`)."""
|
|
244
|
+
return self._exceptions
|
|
245
|
+
|
|
246
|
+
def exception_by_name(self, name):
|
|
247
|
+
"""The exception named ``name`` (not scoped) in this scope, or None."""
|
|
248
|
+
for x in self.exceptions:
|
|
249
|
+
if x.name == name:
|
|
250
|
+
return x
|
|
251
|
+
return None
|
|
252
|
+
|
|
253
|
+
def for_each_exception(self, func):
|
|
254
|
+
"""Call ``func`` with each exception and return the results as a list."""
|
|
255
|
+
return [func(x) for x in self.exceptions]
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def enums(self):
|
|
259
|
+
"""Enums defined directly in this scope (list of :class:`~idl_parser.enum.IDLEnum`)."""
|
|
260
|
+
return self._enums
|
|
261
|
+
|
|
262
|
+
def enum_by_name(self, name):
|
|
263
|
+
"""The enum named ``name`` (not scoped) in this scope, or None."""
|
|
264
|
+
for e in self.enums:
|
|
265
|
+
if e.name == name:
|
|
266
|
+
return e
|
|
267
|
+
return None
|
|
268
|
+
|
|
269
|
+
def for_each_enum(self, func):
|
|
270
|
+
"""Call ``func`` with each enum and return the results as a list."""
|
|
271
|
+
retval = []
|
|
272
|
+
for m in self.enums:
|
|
273
|
+
retval.append(func(m))
|
|
274
|
+
return retval
|
|
275
|
+
|
|
276
|
+
@property
|
|
277
|
+
def bitmasks(self):
|
|
278
|
+
"""Bitmasks defined directly in this scope (list of :class:`~idl_parser.bitmask.IDLBitmask`)."""
|
|
279
|
+
return self._bitmasks
|
|
280
|
+
|
|
281
|
+
def bitmask_by_name(self, name):
|
|
282
|
+
"""The bitmask named ``name`` (not scoped) in this scope, or None."""
|
|
283
|
+
for b in self.bitmasks:
|
|
284
|
+
if b.name == name:
|
|
285
|
+
return b
|
|
286
|
+
return None
|
|
287
|
+
|
|
288
|
+
def for_each_bitmask(self, func):
|
|
289
|
+
"""Call ``func`` with each bitmask and return the results as a list."""
|
|
290
|
+
return [func(b) for b in self.bitmasks]
|
|
291
|
+
|
|
292
|
+
@property
|
|
293
|
+
def bitsets(self):
|
|
294
|
+
"""Bitsets defined directly in this scope (list of :class:`~idl_parser.bitset.IDLBitset`)."""
|
|
295
|
+
return self._bitsets
|
|
296
|
+
|
|
297
|
+
def bitset_by_name(self, name):
|
|
298
|
+
"""The bitset named ``name`` (not scoped) in this scope, or None."""
|
|
299
|
+
for b in self.bitsets:
|
|
300
|
+
if b.name == name:
|
|
301
|
+
return b
|
|
302
|
+
return None
|
|
303
|
+
|
|
304
|
+
def for_each_bitset(self, func):
|
|
305
|
+
"""Call ``func`` with each bitset and return the results as a list."""
|
|
306
|
+
return [func(b) for b in self.bitsets]
|
|
307
|
+
|
|
308
|
+
@property
|
|
309
|
+
def unions(self):
|
|
310
|
+
"""Unions defined directly in this scope (list of :class:`~idl_parser.union.IDLUnion`)."""
|
|
311
|
+
return self._unions
|
|
312
|
+
|
|
313
|
+
def union_by_name(self, name):
|
|
314
|
+
"""The union named ``name`` (not scoped) in this scope, or None."""
|
|
315
|
+
for u in self.unions:
|
|
316
|
+
if u.name == name:
|
|
317
|
+
return u
|
|
318
|
+
return None
|
|
319
|
+
|
|
320
|
+
@property
|
|
321
|
+
def forward_unions(self):
|
|
322
|
+
"""Names of unions forward-declared ("union A;") in this scope,
|
|
323
|
+
in declaration order, whether or not they are defined later."""
|
|
324
|
+
return list(self._forward_unions)
|
|
325
|
+
|
|
326
|
+
@property
|
|
327
|
+
def undefined_forward_unions(self):
|
|
328
|
+
"""Forward-declared union names that have no definition in this scope."""
|
|
329
|
+
return [n for n in self._forward_unions if self.union_by_name(n) is None]
|
|
330
|
+
|
|
331
|
+
def for_each_union(self, func):
|
|
332
|
+
"""Call ``func`` with each union and return the results as a list."""
|
|
333
|
+
retval = []
|
|
334
|
+
for m in self.unions:
|
|
335
|
+
retval.append(func(m))
|
|
336
|
+
return retval
|
|
337
|
+
|
|
338
|
+
@property
|
|
339
|
+
def consts(self):
|
|
340
|
+
"""Constants defined directly in this scope (list of :class:`~idl_parser.const.IDLConst`)."""
|
|
341
|
+
return self._consts
|
|
342
|
+
|
|
343
|
+
def const_by_name(self, name):
|
|
344
|
+
"""The constant named ``name`` (not scoped) in this scope, or None."""
|
|
345
|
+
for c in self.consts:
|
|
346
|
+
if c.name == name:
|
|
347
|
+
return c
|
|
348
|
+
return None
|
|
349
|
+
|
|
350
|
+
def for_each_const(self, func):
|
|
351
|
+
"""Call ``func`` with each constant and return the results as a list."""
|
|
352
|
+
retval = []
|
|
353
|
+
for m in self.consts:
|
|
354
|
+
retval.append(func(m))
|
|
355
|
+
return retval
|
|
356
|
+
|
|
357
|
+
@property
|
|
358
|
+
def natives(self):
|
|
359
|
+
"""Native types declared directly in this scope (list of :class:`~idl_parser.native.IDLNative`)."""
|
|
360
|
+
return self._natives
|
|
361
|
+
|
|
362
|
+
def native_by_name(self, name):
|
|
363
|
+
"""The native type named ``name`` (not scoped) in this scope, or None."""
|
|
364
|
+
for n in self.natives:
|
|
365
|
+
if n.name == name:
|
|
366
|
+
return n
|
|
367
|
+
return None
|
|
368
|
+
|
|
369
|
+
def for_each_native(self, func):
|
|
370
|
+
"""Call ``func`` with each native type and return the results as a list."""
|
|
371
|
+
return [func(n) for n in self.natives]
|
|
372
|
+
|
|
373
|
+
@property
|
|
374
|
+
def typedefs(self):
|
|
375
|
+
"""Typedefs defined directly in this scope (list of :class:`~idl_parser.typedef.IDLTypedef`)."""
|
|
376
|
+
return self._typedefs
|
|
377
|
+
|
|
378
|
+
def typedef_by_name(self, name):
|
|
379
|
+
"""The typedef named ``name`` (not scoped) in this scope, or None."""
|
|
380
|
+
for t in self.typedefs:
|
|
381
|
+
if t.name == name:
|
|
382
|
+
return t
|
|
383
|
+
return None
|
|
384
|
+
|
|
385
|
+
def for_each_typedef(self, func):
|
|
386
|
+
"""Call ``func`` with each typedef.
|
|
387
|
+
|
|
388
|
+
Unlike the other ``for_each_*`` methods, it returns None.
|
|
389
|
+
"""
|
|
390
|
+
retval = []
|
|
391
|
+
for m in self.typedefs:
|
|
392
|
+
retval.append(func(m))
|
|
393
|
+
|
|
394
|
+
def _definitions_simple_dic(self, quiet=False):
|
|
395
|
+
"""``to_simple_dic()`` of the definitions in this scope, grouped by kind."""
|
|
396
|
+
return ([s.to_simple_dic(quiet) for s in self.structs] +
|
|
397
|
+
[x.to_simple_dic(quiet) for x in self.exceptions] +
|
|
398
|
+
[e.to_simple_dic(quiet) for e in self.enums] +
|
|
399
|
+
[b.to_simple_dic(quiet) for b in self.bitmasks] +
|
|
400
|
+
[b.to_simple_dic(quiet) for b in self.bitsets] +
|
|
401
|
+
[u.to_simple_dic(quiet) for u in self.unions] +
|
|
402
|
+
[t.to_simple_dic(quiet) for t in self.typedefs] +
|
|
403
|
+
[n.to_simple_dic(quiet) for n in self.natives] +
|
|
404
|
+
[c.to_simple_dic(quiet) for c in self.consts])
|
|
405
|
+
|
|
406
|
+
def _definitions_dic(self):
|
|
407
|
+
"""``to_dic()`` of the definitions in this scope, keyed by kind."""
|
|
408
|
+
return { 'typedefs' : [t.to_dic() for t in self.typedefs],
|
|
409
|
+
'natives' : [n.to_dic() for n in self.natives],
|
|
410
|
+
'structs' : [s.to_dic() for s in self.structs],
|
|
411
|
+
'exceptions' : [x.to_dic() for x in self.exceptions],
|
|
412
|
+
'enums' : [e.to_dic() for e in self.enums],
|
|
413
|
+
'bitmasks' : [b.to_dic() for b in self.bitmasks],
|
|
414
|
+
'bitsets' : [b.to_dic() for b in self.bitsets],
|
|
415
|
+
'unions' : [u.to_dic() for u in self.unions],
|
|
416
|
+
'consts' : [c.to_dic() for c in self.consts] }
|
|
@@ -54,7 +54,8 @@ class InvalidDataTypeException(IDLParserException):
|
|
|
54
54
|
pass
|
|
55
55
|
|
|
56
56
|
class IDLCanNotFindException(IDLParserException):
|
|
57
|
-
"""An ``#include`` file
|
|
57
|
+
"""An ``#include`` file, a base interface / bitset or an exception in
|
|
58
|
+
``raises (...)`` can not be found."""
|
|
58
59
|
pass
|
|
59
60
|
|
|
60
61
|
|
|
@@ -63,18 +64,17 @@ class IDLParserWarning(UserWarning):
|
|
|
63
64
|
pass
|
|
64
65
|
|
|
65
66
|
class UnknownIDLSyntaxWarning(IDLParserWarning):
|
|
66
|
-
"""
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
"""No longer issued: an unknown word in a module or the global scope (a
|
|
68
|
+
misspelled keyword such as ``strcut``) is an :class:`InvalidIDLSyntaxError`
|
|
69
|
+
since 0.4.0 (issue #94).
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
warnings.simplefilter('error', UnknownIDLSyntaxWarning)
|
|
71
|
+
It was issued from 0.3.2 (issue #76), and is kept so that code referring
|
|
72
|
+
to it (``warnings.simplefilter('error', UnknownIDLSyntaxWarning)``) still
|
|
73
|
+
works.
|
|
74
74
|
"""
|
|
75
75
|
pass
|
|
76
76
|
|
|
77
77
|
class UnsupportedIDLSyntaxWarning(IDLParserWarning):
|
|
78
78
|
"""A valid IDL definition that idl_parser does not support yet
|
|
79
|
-
(``
|
|
79
|
+
(``valuetype``, ``component``, ...) was skipped (issue #76)."""
|
|
80
80
|
pass
|