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

Side by Side Diff: ppapi/generators/idl_version.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/idl_release.py ('k') | ppapi/generators/test_cgen/interface.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
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
5 # found in the LICENSE file.
6
7 """
8 IDLVersion for PPAPI
9
10 This file defines the behavior of the AST namespace which allows for resolving
11 a symbol as one or more AST nodes given a version or range of versions.
12 """
13
14 import sys
15
16 from idl_log import ErrOut, InfoOut, WarnOut
17 from idl_option import GetOption, Option, ParseOptions
18
19 Option('version_debug', 'Debug version data')
20 Option('wgap', 'Ignore version gap warning')
21
22
23 #
24 # Module level functions and data used for testing.
25 #
26 error = None
27 warning = None
28 def ReportVersionError(msg):
29 global error
30 error = msg
31
32 def ReportVersionWarning(msg):
33 global warning
34 warning = msg
35
36 def ReportClear():
37 global error, warning
38 error = None
39 warning = None
40
41 #
42 # IDLVersion
43 #
44 # IDLVersion is an object which stores the association of a given symbol
45 # name, with an AST node for a range of versions for that object.
46 #
47 # A vmin value of None indicates that the object begins at the earliest
48 # available version number. The value of vmin is always inclusive.
49
50 # A vmax value of None indicates that the object is never deprecated, so
51 # it exists until it is overloaded or until the latest available version.
52 # The value of vmax is always exclusive, representing the first version
53 # on which the object is no longer valid.
54 class IDLVersion(object):
55 def __init__(self, vmin, vmax):
56 self.vmin = vmin
57 self.vmax = vmax
58
59 def __str__(self):
60 if not self.vmin:
61 vmin = '0'
62 else:
63 vmin = str(self.vmin)
64 if not self.vmax:
65 vmax = '+oo'
66 else:
67 vmax = str(self.vmax)
68 return '[%s,%s)' % (vmin, vmax)
69
70 def SetVersionRange(self, vmin, vmax):
71 if vmin is not None: vmin = float(vmin)
72 if vmax is not None: vmax = float(vmax)
73 self.vmin = vmin
74 self.vmax = vmax
75
76 # True, if version falls within the interval [self.vmin, self.vmax)
77 def IsVersion(self, version):
78 assert type(version) == float
79
80 if self.vmax and self.vmax <= version:
81 return False
82 if self.vmin and self.vmin > version:
83 return False
84 if GetOption('version_debug'):
85 InfoOut.Log('%f is in %s' % (version, self))
86 return True
87
88 # True, if interval [vmin, vmax) overlaps interval [self.vmin, self.vmax)
89 def InRange(self, vmin, vmax):
90 assert type(vmin) == float
91 assert type(vmax) == float
92 assert vmin != vmax
93
94 if self.vmax and self.vmax <= vmin:
95 return False
96 if self.vmin and self.vmin >= vmax:
97 return False
98
99 if GetOption('version_debug'):
100 InfoOut.Log('%f to %f is in %s' % (vmin, vmax, self))
101 return True
102
103 def Error(self, msg):
104 ReportVersionError(msg)
105
106 def Warning(self, msg):
107 ReportVersionWarning(msg)
108
109
110 #
111 # Test Code
112 #
113 def Main(args):
114 global errors
115
116 FooXX = IDLVersion(None, None)
117 Foo1X = IDLVersion(1.0, None)
118 Foo23 = IDLVersion(2.0, 3.0)
119
120 assert FooXX.IsVersion(0.0)
121 assert FooXX.IsVersion(1.0)
122 assert FooXX.InRange(0.0, 0.1)
123 assert FooXX.InRange(1.0,2.0)
124
125 assert not Foo1X.IsVersion(0.0)
126 assert Foo1X.IsVersion(1.0)
127 assert Foo1X.IsVersion(2.0)
128
129 assert not Foo1X.InRange(0.0, 1.0)
130 assert not Foo1X.InRange(0.5, 1.0)
131 assert Foo1X.InRange(1.0, 2.0)
132 assert Foo1X.InRange(2.0, 3.0)
133
134 assert not Foo23.InRange(0.0, 1.0)
135 assert not Foo23.InRange(0.5, 1.0)
136 assert not Foo23.InRange(1.0, 2.0)
137 assert Foo23.InRange(2.0, 3.0)
138 assert Foo23.InRange(1.0, 2.1)
139 assert Foo23.InRange(2.9, 4.0)
140 assert not Foo23.InRange(3.0, 4.0)
141
142 print "Passed"
143 return 0
144
145 if __name__ == '__main__':
146 sys.exit(Main(sys.argv[1:]))
147
OLDNEW
« no previous file with comments | « ppapi/generators/idl_release.py ('k') | ppapi/generators/test_cgen/interface.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698