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

Unified Diff: third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py

Issue 2567473002: Made a generator for CSSPropertyDescriptor.cpp (Closed)
Patch Set: format Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py
diff --git a/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py b/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py
new file mode 100755
index 0000000000000000000000000000000000000000..4a44731ca7f06f6486c8eadf9efe3ba805efc883
--- /dev/null
+++ b/third_party/WebKit/Source/build/scripts/make_css_property_descriptor.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# Copyright 2016 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
+
+import in_generator
+import template_expander
+import make_style_builder
+from collections import namedtuple, defaultdict
sashab 2016/12/13 23:10:38 Check other .py files -- I thnik you might want a
aazzam 2016/12/13 23:27:53 done :)
+
+
+class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter):
+ def __init__(self, in_file_path):
+ super(CSSPropertyAPIWriter, self).__init__(in_file_path)
+ self._outputs = {
+ 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_h,
sashab 2016/12/13 23:10:38 Rename to generate_property_descriptor_cpp
aazzam 2016/12/13 23:27:53 done :)
+ }
+
+ # Temporary map of classname to list of propertyIDs.
sashab 2016/12/13 23:10:38 What class name? :) Maybe: # Temporary map of API
aazzam 2016/12/13 23:27:53 done :)
+ properties_for_class = defaultdict(list)
sashab 2016/12/13 23:10:38 Nice variable name
+ for property in self._properties.values():
+ if property['api_class'] is None:
+ continue
+ classname = self.get_classname(property)
+ properties_for_class[classname].append(property['property_id'])
+
+ # Stores a list of classes with elements (index, classname, [propertyIDs, ..]).
+ self._api_classes = []
+
+ ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids'))
+ for i, classname in enumerate(properties_for_class.keys()):
+ self._api_classes.append(ApiClass(index=i + 1, classname=classname, property_ids=properties_for_class[classname]))
+
+ # Gets the classname for a given property.
+ def get_classname(self, property):
sashab 2016/12/13 23:10:38 Nice!! This doesn't need to be a class method --
aazzam 2016/12/13 23:27:53 done :)
+ if property['api_class'] is True:
+ # This property had the generated_api_class flag set in CSSProperties.in.
+ return 'CSSPropertyAPI' + property['upper_camel_name']
+ # This property has a specified class name.
+ assert isinstance(property['api_class'], str)
sashab 2016/12/13 23:10:38 Assert is great! Maybe add an error message: asse
aazzam 2016/12/13 23:27:53 done
+ return property['api_class']
+
+ @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl')
+ def generate_property_descriptor_h(self):
+ return {
+ 'api_classes': self._api_classes,
+ }
+
+if __name__ == '__main__':
+ in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv)

Powered by Google App Engine
This is Rietveld 408576698