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

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

Issue 8045001: Update the IDL Generator to use Release instead of Version (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/generators/generator.py ('k') | ppapi/generators/idl_c_proto.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 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Nodes for PPAPI IDL AST.""" 7 """Nodes for PPAPI IDL AST."""
8 8
9 from idl_namespace import IDLNamespace, IDLVersionMap 9 from idl_namespace import IDLNamespace
10 from idl_node import IDLAttribute, IDLFile, IDLNode 10 from idl_node import IDLAttribute, IDLFile, IDLNode
11 from idl_option import GetOption 11 from idl_option import GetOption
12 from idl_visitor import IDLVisitor 12 from idl_visitor import IDLVisitor
13 from idl_release import IDLReleaseList, IDLReleaseMap
13 14
14 # 15 #
15 # IDL Predefined types 16 # IDL Predefined types
16 # 17 #
17 BuiltIn = set(['int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', 18 BuiltIn = set(['int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t',
18 'uint16_t', 'uint32_t', 'uint64_t', 'double_t', 'float_t', 19 'uint16_t', 'uint32_t', 'uint64_t', 'double_t', 'float_t',
19 'handle_t', 'interface_t', 'char', 'mem_t', 'str_t', 'void']) 20 'handle_t', 'interface_t', 'char', 'mem_t', 'str_t', 'void'])
20 21
21 22
22 # 23 #
23 # IDLNamespaceLabelResolver 24 # IDLNamespaceLabelResolver
24 # 25 #
25 # Once the AST is build, we need to resolve the namespace and version 26 # Once the AST is build, we need to resolve the namespace and version
26 # information. 27 # information.
27 # 28 #
28 class IDLNamespaceLabelResolver(IDLVisitor): 29 class IDLNamespaceLabelResolver(IDLVisitor):
29 NamespaceSet = set(['AST', 'Callspec', 'Interface', 'Member', 'Struct']) 30 NamespaceSet = set(['AST', 'Callspec', 'Interface', 'Member', 'Struct'])
30 # 31 #
31 # When we arrive at a node we must assign it a namespace and if the 32 # When we arrive at a node we must assign it a namespace and if the
32 # node is named, then place it in the appropriate namespace. 33 # node is named, then place it in the appropriate namespace.
33 # 34 #
34 def Arrive(self, node, parent_namespace): 35 def Arrive(self, node, parent_namespace):
35 # Set version min and max based on properties 36 # If we are entering a parent, clear the local Label\
36 vmin = node.GetProperty('version') 37 tab = ' ' * self.depth
37 vmax = node.GetProperty('deprecate') 38 #print '%s%s' % (tab, node)
brettw 2011/09/25 06:06:07 Did you mean to leave this in?
noelallen1 2011/09/26 17:01:06 Done.
38 node.SetVersionRange(vmin, vmax) 39 if node.IsA('File'): self.release_map = None
39 40
40 # If this object is not a namespace aware object, use the parent's one 41 # If this object is not a namespace aware object, use the parent's one
41 if node.cls not in self.NamespaceSet: 42 if node.cls not in self.NamespaceSet:
42 node.namespace = parent_namespace 43 node.namespace = parent_namespace
43 else: 44 else:
44 # otherwise create one. 45 # otherwise create one.
45 node.namespace = IDLNamespace(parent_namespace) 46 node.namespace = IDLNamespace(parent_namespace)
46 node.namespace.name = node.GetName() 47 node.namespace.name = node.GetName()
47 48
48 # If this node is named, place it in its parent's namespace 49 # If this node is named, place it in its parent's namespace
49 if parent_namespace and node.cls in IDLNode.NamedSet: 50 if parent_namespace and node.cls in IDLNode.NamedSet:
51 # Set version min and max based on properties
brettw 2011/09/25 06:06:07 Seems like this comment should be indented.
noelallen1 2011/09/26 17:01:06 Done.
52 if self.release_map:
53 vmin = node.GetProperty('version')
54 vmax = node.GetProperty('deprecate')
55 rmin = self.release_map.GetRelease(vmin)
56 rmax = self.release_map.GetRelease(vmax)
57 node.SetReleaseRange(rmin, rmax)
50 parent_namespace.AddNode(node) 58 parent_namespace.AddNode(node)
51 59
52 # Pass this namespace to each child in case they inherit it 60 # Pass this namespace to each child in case they inherit it
53 return node.namespace 61 return node.namespace
54 62
55 # 63 #
56 # As we return from a node, if the node is a LabelItem we pass back 64 # As we return from a node, if the node is a LabelItem we pass back
57 # the key=value pair representing the mapping of release to version. 65 # the key=value pair representing the mapping of release to version.
58 # If the node is a Label take the lists of mapping and generate a 66 # If the node is a Label take the lists of mapping and generate a
59 # version map which is assigned to the Labels parent as a property. 67 # version map which is assigned to the Labels parent as a property.
60 # 68 #
61 def Depart(self, node, data, childdata): 69 def Depart(self, node, data, childdata):
62 if node.IsA('LabelItem'): 70 if node.IsA('LabelItem'):
63 return (node.GetName(), node.GetProperty('VALUE')) 71 return (node.GetName(), node.GetProperty('VALUE'))
64 if node.IsA('Label') and node.GetName() == GetOption('label'): 72 if node.IsA('Label') and node.GetName() == GetOption('label'):
65 vmap = IDLVersionMap() 73 try:
66 for release, version in childdata: 74 self.release_map = IDLReleaseMap(childdata)
67 vmap.AddReleaseVersionMapping(release, float(version)) 75 node.parent.release_map = self.release_map
68 node.parent.SetProperty("LABEL", vmap) 76 except Exception as err:
77 node.Error('Unable to build release map: %s' % str(err))
69 return None 78 return None
70 79
71 80
72 class IDLFileTypeResolver(IDLVisitor): 81 class IDLFileTypeResolver(IDLVisitor):
73 def VisitFilter(self, node, data): 82 def VisitFilter(self, node, data):
74 return not node.IsA('Comment', 'Copyright') 83 return not node.IsA('Comment', 'Copyright')
75 84
76 def Arrive(self, node, filenode): 85 def Arrive(self, node, filenode):
77 # Track the file node to update errors 86 # Track the file node to update errors
78 if node.IsA('File'): 87 if node.IsA('File'):
79 node.SetProperty('FILE', node) 88 node.SetProperty('FILE', node)
80 89
81 # If this node has a TYPEREF, resolve it to a version list 90 # If this node has a TYPEREF, resolve it to a version list
82 typeref = node.property_node.GetPropertyLocal('TYPEREF') 91 typeref = node.property_node.GetPropertyLocal('TYPEREF')
83 if typeref: 92 if typeref:
84 node.typelist = node.parent.namespace.FindList(typeref) 93 node.typelist = node.parent.namespace.FindList(typeref)
85 if not node.typelist: 94 if not node.typelist:
86 node.Error('Could not resolve %s.' % typeref) 95 node.Error('Could not resolve %s.' % typeref)
87 else: 96 else:
88 node.typelist = None 97 node.typelist = None
89 return filenode 98 return filenode
90 99
91 100
92 class IDLReleaseResolver(IDLVisitor):
93 def VisitFilter(self, node, data):
94 return node.IsA('AST','File', 'Label')
95
96 def Depart(self, node, data, childdata):
97 if node.IsA('Label'):
98 return set([child.name for child in GetListOf('LabelItem')])
99 return childdata
100
101 class IDLVersionMapDefault(IDLVersionMap):
102 def GetRelease(self, version):
103 return 'M13'
104
105 def GetVersion(self, release):
106 return float(0.0)
107
108 # 101 #
109 # IDLAst 102 # IDLAst
110 # 103 #
111 # A specialized version of the IDLNode for containing the whole of the 104 # A specialized version of the IDLNode for containing the whole of the
112 # AST. The specialized BuildTree function pulls the per file namespaces 105 # AST. The specialized BuildTree function pulls the per file namespaces
113 # into the global AST namespace and checks for collisions. 106 # into the global AST namespace and checks for collisions.
114 # 107 #
115 class IDLAst(IDLNode): 108 class IDLAst(IDLNode):
116 def __init__(self, children): 109 def __init__(self, children):
117 objs = [] 110 objs = []
118 111
119 builtin = None 112 builtin = None
120 extranodes = [] 113 extranodes = []
121 for filenode in children: 114 for filenode in children:
122 if filenode.GetProperty('NAME') == 'pp_stdint.idl': 115 if filenode.GetProperty('NAME') == 'pp_stdint.idl':
123 builtin = filenode 116 builtin = filenode
124 break 117 break
125 118
126 IDLNode.__init__(self, 'AST', 'BuiltIn', 1, 0, extranodes + children) 119 IDLNode.__init__(self, 'AST', 'BuiltIn', 1, 0, extranodes + children)
127 self.SetProperty('LABEL', IDLVersionMapDefault())
128 self.Resolve() 120 self.Resolve()
129 121
130 def Resolve(self): 122 def Resolve(self):
131 self.namespace = IDLNamespace(None) 123 self.namespace = IDLNamespace(None)
132 self.namespace.name = 'AST' 124 self.namespace.name = 'AST'
133 IDLNamespaceLabelResolver().Visit(self, self.namespace) 125 IDLNamespaceLabelResolver().Visit(self, self.namespace)
134 IDLFileTypeResolver().Visit(self, None) 126 IDLFileTypeResolver().Visit(self, None)
135 127
136 # Build an ordered list of all releases 128 # Build an ordered list of all releases
137 self.releases = set() 129 self.releases = set()
138 for filenode in self.GetListOf('File'): 130 for filenode in self.GetListOf('File'):
139 vmap = filenode.GetProperty('LABEL') 131 self.releases |= set(filenode.release_map.GetReleases())
140 self.releases |= set(vmap.releases)
141 self.releases = sorted(self.releases) 132 self.releases = sorted(self.releases)
142 133
143 def SetTypeInfo(self, name, properties): 134 def SetTypeInfo(self, name, properties):
144 node = self.namespace[name] 135 node = self.namespace[name]
145 for prop in properties: 136 for prop in properties:
146 node.properties[prop] = properties[prop] 137 node.properties[prop] = properties[prop]
147 138
148 139
OLDNEW
« no previous file with comments | « ppapi/generators/generator.py ('k') | ppapi/generators/idl_c_proto.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698