aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/codegen/GlobalGen.py
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-05-28 17:13:40 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-05-28 17:13:40 -0700
commitbf82bc54f349dd0944c37129af28dec6b43041fe (patch)
tree685e113347e8afd1965793aefc9743cd9f1f8494 /src/components/script/dom/bindings/codegen/GlobalGen.py
parent0ea1a94f8e8a07378d23552a620a45d610db31c7 (diff)
downloadservo-bf82bc54f349dd0944c37129af28dec6b43041fe.tar.gz
servo-bf82bc54f349dd0944c37129af28dec6b43041fe.zip
Separate the DOM and layout into separate crates.
Diffstat (limited to 'src/components/script/dom/bindings/codegen/GlobalGen.py')
-rw-r--r--src/components/script/dom/bindings/codegen/GlobalGen.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/codegen/GlobalGen.py b/src/components/script/dom/bindings/codegen/GlobalGen.py
new file mode 100644
index 00000000000..dbfc4f86e14
--- /dev/null
+++ b/src/components/script/dom/bindings/codegen/GlobalGen.py
@@ -0,0 +1,83 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# We do one global pass over all the WebIDL to generate our prototype enum
+# and generate information for subsequent phases.
+
+import sys
+sys.path.append("./parser/")
+sys.path.append("./ply/")
+import os
+import cStringIO
+import WebIDL
+import cPickle
+from Configuration import *
+from Codegen import GlobalGenRoots, replaceFileIfChanged
+# import Codegen in general, so we can set a variable on it
+import Codegen
+
+def generate_file(config, name, action):
+
+ root = getattr(GlobalGenRoots, name)(config)
+ if action is 'declare':
+ filename = name + '.h'
+ code = root.declare()
+ else:
+ assert action is 'define'
+ filename = name + '.cpp'
+ code = root.define()
+
+ if replaceFileIfChanged(filename, code):
+ print "Generating %s" % (filename)
+ else:
+ print "%s hasn't changed - not touching it" % (filename)
+
+def main():
+ # Parse arguments.
+ from optparse import OptionParser
+ usageString = "usage: %prog [options] webidldir [files]"
+ o = OptionParser(usage=usageString)
+ o.add_option("--cachedir", dest='cachedir', default=None,
+ help="Directory in which to cache lex/parse tables.")
+ o.add_option("--verbose-errors", action='store_true', default=False,
+ help="When an error happens, display the Python traceback.")
+ (options, args) = o.parse_args()
+
+ if len(args) < 2:
+ o.error(usageString)
+
+ configFile = args[0]
+ baseDir = args[1]
+ fileList = args[2:]
+
+ # Parse the WebIDL.
+ parser = WebIDL.Parser(options.cachedir)
+ for filename in fileList:
+ fullPath = os.path.normpath(os.path.join(baseDir, filename))
+ f = open(fullPath, 'rb')
+ lines = f.readlines()
+ f.close()
+ parser.parse(''.join(lines), fullPath)
+ parserResults = parser.finish()
+
+ # Write the parser results out to a pickle.
+ resultsFile = open('ParserResults.pkl', 'wb')
+ cPickle.dump(parserResults, resultsFile, -1)
+ resultsFile.close()
+
+ # Load the configuration.
+ config = Configuration(configFile, parserResults)
+
+ # Generate the prototype list.
+ generate_file(config, 'PrototypeList', 'declare')
+
+ # Generate the common code.
+ generate_file(config, 'RegisterBindings', 'declare')
+ generate_file(config, 'RegisterBindings', 'define')
+
+ generate_file(config, 'UnionTypes', 'declare')
+ generate_file(config, 'UnionConversions', 'declare')
+
+if __name__ == '__main__':
+ main()