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

Unified Diff: Source/build/scripts/make_element_type_helpers.py

Issue 175693007: Generate isHTML*Element() / toHTML*Element() helper functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make toHTMLObjectElement() work for FormAssociatedElement input Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/build/scripts/scripts.gypi » ('j') | Source/core/html/HTMLObjectElement.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/make_element_type_helpers.py
diff --git a/Source/build/scripts/make_element_type_helpers.py b/Source/build/scripts/make_element_type_helpers.py
new file mode 100755
index 0000000000000000000000000000000000000000..ff5c4491e381031f3c534f356f47f6343e6ff2f5
--- /dev/null
+++ b/Source/build/scripts/make_element_type_helpers.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import sys
+from collections import defaultdict
+
+import hasher
+import in_generator
+import name_utilities
+import template_expander
+
+from in_file import InFile
+
+
+class MakeElementTypeHelpersWriter(in_generator.Writer):
+ defaults = {
+ 'interfaceName': None,
+ 'noConstructor': None,
+ 'JSInterfaceName': None,
+ 'constructorNeedsCreatedByParser': None,
+ 'constructorNeedsFormElement': None,
+ 'contextConditional': None,
+ 'interfaceName': None,
+ 'noConstructor': None,
+ 'runtimeEnabled': None,
+ }
+ default_parameters = {
+ 'attrsNullNamespace': None,
+ 'namespace': '',
+ 'namespacePrefix': '',
+ 'namespaceURI': '',
+ 'fallbackInterfaceName': '',
+ 'fallbackJSInterfaceName': '',
+ }
+ filters = {
+ 'hash': hasher.hash,
+ }
+
+ def __init__(self, in_file_path):
+ super(MakeElementTypeHelpersWriter, self).__init__(in_file_path)
+
+ self.namespace = self.in_file.parameters['namespace'].strip('"')
+
+ assert self.namespace, 'A namespace is required.'
+
+ self._outputs = {
+ (self.namespace + "ElementTypeHelpers.h"): self.generate_helper_header,
+ }
+
+ self._template_context = {
+ 'namespace': self.namespace,
+ 'tags': self.in_file.name_dictionaries,
+ }
+
+ tags = self._template_context['tags']
+ interface_counts = defaultdict(int)
+ for tag in tags:
+ tag['interface'] = self._interface(tag)
+ interface_counts[tag['interface']] += 1
+
+ for tag in tags:
+ tag['multipleTagNames'] = interface_counts[tag['interface']] > 1
+
+ @template_expander.use_jinja("ElementTypeHelpers.h.tmpl", filters=filters)
+ def generate_helper_header(self):
+ return self._template_context
+
+ def _interface(self, tag):
+ if tag['interfaceName']:
+ return tag['interfaceName']
+ name = name_utilities.upper_first(tag['name'])
+ # FIXME: We shouldn't hard-code HTML here.
+ if name == 'HTML':
+ name = 'Html'
+ dash = name.find('-')
+ while dash != -1:
+ name = name[:dash] + name[dash + 1].upper() + name[dash + 2:]
+ dash = name.find('-')
+ return '%s%sElement' % (self.namespace, name)
+
+if __name__ == "__main__":
+ in_generator.Maker(MakeElementTypeHelpersWriter).main(sys.argv)
« no previous file with comments | « no previous file | Source/build/scripts/scripts.gypi » ('j') | Source/core/html/HTMLObjectElement.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698