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

Side by Side Diff: ppapi/generators/idl_ast.py

Issue 98803004: Pepper: Clean up IDLNode internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix potential KeyError Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/generators/idl_node.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 IDLAttribute, IDLFile, 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 IDLReleaseList, IDLReleaseMap 11 from idl_release import IDLReleaseMap
12 12
13 # 13 #
14 # IDL Predefined types 14 # IDL Predefined types
15 # 15 #
16 BuiltIn = set(['int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', 16 BuiltIn = set(['int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t',
17 'uint16_t', 'uint32_t', 'uint64_t', 'double_t', 'float_t', 17 'uint16_t', 'uint32_t', 'uint64_t', 'double_t', 'float_t',
18 'handle_t', 'interface_t', 'char', 'mem_t', 'mem_ptr_t', 18 'handle_t', 'interface_t', 'char', 'mem_t', 'mem_ptr_t',
19 'str_t', 'void']) 19 'str_t', 'void'])
20 20
21 21
(...skipping 13 matching lines...) Expand all
35 # On completion of the Label, apply to the parent File if the 35 # On completion of the Label, apply to the parent File if the
36 # name of the label matches the generation label. 36 # name of the label matches the generation label.
37 if node.IsA('Label') and node.GetName() == GetOption('label'): 37 if node.IsA('Label') and node.GetName() == GetOption('label'):
38 try: 38 try:
39 node.parent.release_map = IDLReleaseMap(childdata) 39 node.parent.release_map = IDLReleaseMap(childdata)
40 except Exception as err: 40 except Exception as err:
41 node.Error('Unable to build release map: %s' % str(err)) 41 node.Error('Unable to build release map: %s' % str(err))
42 42
43 # For File objects, set the minimum version 43 # For File objects, set the minimum version
44 if node.IsA('File'): 44 if node.IsA('File'):
45 file_min, file_max = node.release_map.GetReleaseRange() 45 file_min, _ = node.release_map.GetReleaseRange()
46 node.SetMin(file_min) 46 node.SetMin(file_min)
47 47
48 return None 48 return None
49 49
50 50
51 # 51 #
52 # IDLNamespaceVersionResolver 52 # IDLNamespaceVersionResolver
53 # 53 #
54 # A specialized visitor which traverses the AST, building a namespace tree 54 # A specialized visitor which traverses the AST, building a namespace tree
55 # as it goes. The namespace tree is mapping from a name to a version list. 55 # as it goes. The namespace tree is mapping from a name to a version list.
56 # Labels must already be resolved to use. 56 # Labels must already be resolved to use.
57 # 57 #
58 class IDLNamespaceVersionResolver(IDLVisitor): 58 class IDLNamespaceVersionResolver(IDLVisitor):
59 NamespaceSet = set(['AST', 'Callspec', 'Interface', 'Member', 'Struct']) 59 NamespaceSet = set(['AST', 'Callspec', 'Interface', 'Member', 'Struct'])
60 # 60 #
61 # When we arrive at a node we must assign it a namespace and if the 61 # When we arrive at a node we must assign it a namespace and if the
62 # node is named, then place it in the appropriate namespace. 62 # node is named, then place it in the appropriate namespace.
63 # 63 #
64 def Arrive(self, node, parent_namespace): 64 def Arrive(self, node, parent_namespace):
65 # If we are a File, grab the Min version and replease mapping 65 # If we are a File, grab the Min version and replease mapping
66 if node.IsA('File'): 66 if node.IsA('File'):
67 self.rmin = node.GetMinMax()[0] 67 self.rmin = node.GetMinMax()[0]
68 self.release_map = node.release_map 68 self.release_map = node.release_map
69 69
70 # Set the min version on any non Label within the File 70 # Set the min version on any non Label within the File
71 if not node.IsA('AST', 'File', 'Label', 'LabelItem'): 71 if not node.IsA('AST', 'File', 'Label', 'LabelItem'):
72 my_min, my_max = node.GetMinMax() 72 my_min, _ = node.GetMinMax()
73 if not my_min: 73 if not my_min:
74 node.SetMin(self.rmin) 74 node.SetMin(self.rmin)
75 75
76 # If this object is not a namespace aware object, use the parent's one 76 # If this object is not a namespace aware object, use the parent's one
77 if node.cls not in self.NamespaceSet: 77 if node.cls not in self.NamespaceSet:
78 node.namespace = parent_namespace 78 node.namespace = parent_namespace
79 else: 79 else:
80 # otherwise create one. 80 # otherwise create one.
81 node.namespace = IDLNamespace(parent_namespace, node.GetName()) 81 node.namespace = IDLNamespace(parent_namespace, node.GetName())
82 82
(...skipping 28 matching lines...) Expand all
111 def VisitFilter(self, node, data): 111 def VisitFilter(self, node, data):
112 return not node.IsA('Comment', 'Copyright') 112 return not node.IsA('Comment', 'Copyright')
113 113
114 def Arrive(self, node, filenode): 114 def Arrive(self, node, filenode):
115 # Track the file node to update errors 115 # Track the file node to update errors
116 if node.IsA('File'): 116 if node.IsA('File'):
117 node.SetProperty('FILE', node) 117 node.SetProperty('FILE', node)
118 filenode = node 118 filenode = node
119 119
120 if not node.IsA('AST'): 120 if not node.IsA('AST'):
121 file_min, file_max = filenode.release_map.GetReleaseRange() 121 file_min, _ = filenode.release_map.GetReleaseRange()
122 if not file_min: 122 if not file_min:
123 print 'Resetting min on %s to %s' % (node, file_min) 123 print 'Resetting min on %s to %s' % (node, file_min)
124 node.SetMinRange(file_min) 124 node.SetMinRange(file_min)
125 125
126 # If this node has a TYPEREF, resolve it to a version list 126 # If this node has a TYPEREF, resolve it to a version list
127 typeref = node.property_node.GetPropertyLocal('TYPEREF') 127 typeref = node.property_node.GetPropertyLocal('TYPEREF')
128 if typeref: 128 if typeref:
129 node.typelist = node.parent.namespace.FindList(typeref) 129 node.typelist = node.parent.namespace.FindList(typeref)
130 if not node.typelist: 130 if not node.typelist:
131 node.Error('Could not resolve %s.' % typeref) 131 node.Error('Could not resolve %s.' % typeref)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 # Build an ordered list of all releases 173 # Build an ordered list of all releases
174 releases = set() 174 releases = set()
175 for filenode in self.GetListOf('File'): 175 for filenode in self.GetListOf('File'):
176 releases |= set(filenode.release_map.GetReleases()) 176 releases |= set(filenode.release_map.GetReleases())
177 177
178 # Generate a per node list of releases and release mapping 178 # Generate a per node list of releases and release mapping
179 IDLReleaseResolver().Visit(self, sorted(releases)) 179 IDLReleaseResolver().Visit(self, sorted(releases))
180 180
181 for filenode in self.GetListOf('File'): 181 for filenode in self.GetListOf('File'):
182 self.errors += int(filenode.GetProperty('ERRORS', 0)) 182 errors = filenode.GetProperty('ERRORS')
183 if errors:
184 self.errors += errors
183 185
184 186
OLDNEW
« no previous file with comments | « no previous file | ppapi/generators/idl_node.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698