OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Nodes for PPAPI IDL AST.""" | 5 """Nodes for PPAPI IDL AST.""" |
6 | 6 |
7 from idl_namespace import IDLNamespace | 7 from idl_namespace import IDLNamespace |
8 from idl_node import IDLNode | 8 from idl_node import IDLNode |
9 from idl_option import GetOption | 9 from idl_option import GetOption |
10 from idl_visitor import IDLVisitor | 10 from idl_visitor import IDLVisitor |
11 from idl_release import IDLReleaseMap | 11 from idl_release import IDLReleaseMap |
12 | 12 |
13 # | 13 # |
14 # IDL Predefined types | |
15 # | |
16 BuiltIn = set(['int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', | |
17 'uint16_t', 'uint32_t', 'uint64_t', 'double_t', 'float_t', | |
18 'handle_t', 'interface_t', 'char', 'mem_t', 'mem_ptr_t', | |
19 'str_t', 'void']) | |
20 | |
21 | |
22 # | |
23 # IDLLabelResolver | 14 # IDLLabelResolver |
24 # | 15 # |
25 # A specialized visitor which traverses the AST, building a mapping of | 16 # A specialized visitor which traverses the AST, building a mapping of |
26 # Release names to Versions numbers and calculating a min version. | 17 # Release names to Versions numbers and calculating a min version. |
27 # The mapping is applied to the File nodes within the AST. | 18 # The mapping is applied to the File nodes within the AST. |
28 # | 19 # |
29 class IDLLabelResolver(IDLVisitor): | 20 class IDLLabelResolver(IDLVisitor): |
30 def Depart(self, node, ignore, childdata): | 21 def Depart(self, node, ignore, childdata): |
31 # Build list of Release=Version | 22 # Build list of Release=Version |
32 if node.IsA('LabelItem'): | 23 if node.IsA('LabelItem'): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 if not node.IsA('AST', 'File', 'Label', 'LabelItem'): | 62 if not node.IsA('AST', 'File', 'Label', 'LabelItem'): |
72 my_min, _ = node.GetMinMax() | 63 my_min, _ = node.GetMinMax() |
73 if not my_min: | 64 if not my_min: |
74 node.SetMin(self.rmin) | 65 node.SetMin(self.rmin) |
75 | 66 |
76 # If this object is not a namespace aware object, use the parent's one | 67 # If this object is not a namespace aware object, use the parent's one |
77 if node.cls not in self.NamespaceSet: | 68 if node.cls not in self.NamespaceSet: |
78 node.namespace = parent_namespace | 69 node.namespace = parent_namespace |
79 else: | 70 else: |
80 # otherwise create one. | 71 # otherwise create one. |
81 node.namespace = IDLNamespace(parent_namespace, node.GetName()) | 72 node.namespace = IDLNamespace(parent_namespace) |
82 | 73 |
83 # If this node is named, place it in its parent's namespace | 74 # If this node is named, place it in its parent's namespace |
84 if parent_namespace and node.cls in IDLNode.NamedSet: | 75 if parent_namespace and node.cls in IDLNode.NamedSet: |
85 # Set version min and max based on properties | 76 # Set version min and max based on properties |
86 if self.release_map: | 77 if self.release_map: |
87 vmin = node.GetProperty('version') | 78 vmin = node.GetProperty('version') |
88 vmax = node.GetProperty('deprecate') | 79 vmax = node.GetProperty('deprecate') |
89 # If no min is available, the use the parent File's min | 80 # If no min is available, the use the parent File's min |
90 if vmin == None: | 81 if vmin == None: |
91 rmin = self.rmin | 82 rmin = self.rmin |
(...skipping 25 matching lines...) Expand all Loading... |
117 node.SetProperty('FILE', node) | 108 node.SetProperty('FILE', node) |
118 filenode = node | 109 filenode = node |
119 | 110 |
120 if not node.IsA('AST'): | 111 if not node.IsA('AST'): |
121 file_min, _ = filenode.release_map.GetReleaseRange() | 112 file_min, _ = filenode.release_map.GetReleaseRange() |
122 if not file_min: | 113 if not file_min: |
123 print 'Resetting min on %s to %s' % (node, file_min) | 114 print 'Resetting min on %s to %s' % (node, file_min) |
124 node.SetMinRange(file_min) | 115 node.SetMinRange(file_min) |
125 | 116 |
126 # If this node has a TYPEREF, resolve it to a version list | 117 # If this node has a TYPEREF, resolve it to a version list |
127 typeref = node.property_node.GetPropertyLocal('TYPEREF') | 118 typeref = node.GetPropertyLocal('TYPEREF') |
128 if typeref: | 119 if typeref: |
129 node.typelist = node.parent.namespace.FindList(typeref) | 120 node.typelist = node.parent.namespace.FindList(typeref) |
130 if not node.typelist: | 121 if not node.typelist: |
131 node.Error('Could not resolve %s.' % typeref) | 122 node.Error('Could not resolve %s.' % typeref) |
132 else: | 123 else: |
133 node.typelist = None | 124 node.typelist = None |
134 return filenode | 125 return filenode |
135 | 126 |
136 # | 127 # |
137 # IDLReleaseResolver | 128 # IDLReleaseResolver |
(...skipping 19 matching lines...) Expand all Loading... |
157 class IDLAst(IDLNode): | 148 class IDLAst(IDLNode): |
158 def __init__(self, children): | 149 def __init__(self, children): |
159 IDLNode.__init__(self, 'AST', 'BuiltIn', 1, 0, children) | 150 IDLNode.__init__(self, 'AST', 'BuiltIn', 1, 0, children) |
160 self.Resolve() | 151 self.Resolve() |
161 | 152 |
162 def Resolve(self): | 153 def Resolve(self): |
163 # Set the appropriate Release=Version mapping for each File | 154 # Set the appropriate Release=Version mapping for each File |
164 IDLLabelResolver().Visit(self, None) | 155 IDLLabelResolver().Visit(self, None) |
165 | 156 |
166 # Generate the Namesapce Tree | 157 # Generate the Namesapce Tree |
167 self.namespace = IDLNamespace(None, 'AST') | 158 self.namespace = IDLNamespace(None) |
168 IDLNamespaceVersionResolver().Visit(self, self.namespace) | 159 IDLNamespaceVersionResolver().Visit(self, self.namespace) |
169 | 160 |
170 # Using the namespace, resolve type references | 161 # Using the namespace, resolve type references |
171 IDLFileTypeResolver().Visit(self, None) | 162 IDLFileTypeResolver().Visit(self, None) |
172 | 163 |
173 # Build an ordered list of all releases | 164 # Build an ordered list of all releases |
174 releases = set() | 165 releases = set() |
175 for filenode in self.GetListOf('File'): | 166 for filenode in self.GetListOf('File'): |
176 releases |= set(filenode.release_map.GetReleases()) | 167 releases |= set(filenode.release_map.GetReleases()) |
177 | 168 |
178 # Generate a per node list of releases and release mapping | 169 # Generate a per node list of releases and release mapping |
179 IDLReleaseResolver().Visit(self, sorted(releases)) | 170 IDLReleaseResolver().Visit(self, sorted(releases)) |
180 | 171 |
181 for filenode in self.GetListOf('File'): | 172 for filenode in self.GetListOf('File'): |
182 errors = filenode.GetProperty('ERRORS') | 173 errors = filenode.GetProperty('ERRORS') |
183 if errors: | 174 if errors: |
184 self.errors += errors | 175 self.errors += errors |
185 | 176 |
186 | 177 |
OLD | NEW |