Web Inspector: [protocol] alter some type names generated from Inspector.json
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 11 Dec 2011 20:44:19 +0000 (20:44 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 11 Dec 2011 20:44:19 +0000 (20:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74247

Patch by Peter Rybin <peter.rybin@gmail.com> on 2011-12-11
Reviewed by Pavel Feldman.

Manually-filled map added that contains problem type names and its replacement.

* inspector/CodeGeneratorInspector.py:
(fix_type_name.Result):
(fix_type_name.Result.output_comment):
(fix_type_name):
(TypeBindings.create_for_named_type_declaration.write_doc):
(TypeBindings.create_for_named_type_declaration.EnumBinding.generate_type_builder):
(TypeBindings.create_for_named_type_declaration.PlainString.generate_type_builder):
(TypeBindings):
(TypeBindings.create_for_named_type_declaration.ClassBinding.generate_type_builder):
(Generator.process_types):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102541 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/CodeGeneratorInspector.py

index 6d89a6feaec1ab39fb9d38cc4be3ece63faaa53c..0d41471e2e0a2d717bb194a8e8eebbacd9c3e225 100644 (file)
@@ -1,3 +1,23 @@
+2011-12-11  Peter Rybin  <peter.rybin@gmail.com>
+
+        Web Inspector: [protocol] alter some type names generated from Inspector.json
+        https://bugs.webkit.org/show_bug.cgi?id=74247
+
+        Reviewed by Pavel Feldman.
+
+        Manually-filled map added that contains problem type names and its replacement.
+
+        * inspector/CodeGeneratorInspector.py:
+        (fix_type_name.Result):
+        (fix_type_name.Result.output_comment):
+        (fix_type_name):
+        (TypeBindings.create_for_named_type_declaration.write_doc):
+        (TypeBindings.create_for_named_type_declaration.EnumBinding.generate_type_builder):
+        (TypeBindings.create_for_named_type_declaration.PlainString.generate_type_builder):
+        (TypeBindings):
+        (TypeBindings.create_for_named_type_declaration.ClassBinding.generate_type_builder):
+        (Generator.process_types):
+
 2011-12-11  Andreas Kling  <kling@webkit.org>
 
         WK2/NetscapePlugin: Incorrect mouse event coordinates when frameScaleFactor != 1.
index 9bb6c4dff3266b84264448c7023b00e41d9b12cc..c195cb67011ffcc493bb3b29dc12a29e4219033a 100755 (executable)
@@ -48,6 +48,12 @@ DOMAIN_DEFINE_NAME_MAP = {
 }
 
 
+# Manually-filled map of type name replacements.
+TYPE_NAME_FIX_MAP = {
+    "RGBA": "Rgba",  # RGBA is reported to be conflicting with a define name in Windows CE.
+}
+
+
 cmdline_parser = optparse.OptionParser()
 cmdline_parser.add_option("--defines")
 cmdline_parser.add_option("--output_h_dir")
@@ -439,9 +445,40 @@ class ParamType(object):
 INSPECTOR_OBJECT_SETTER_NAMES = frozenset(["setValue", "setBoolean", "setNumber", "setString", "setValue", "setObject", "setArray"])
 
 
+def fix_type_name(json_name):
+    if json_name in TYPE_NAME_FIX_MAP:
+        fixed = TYPE_NAME_FIX_MAP[json_name]
+
+        class Result(object):
+            class_name = fixed
+
+            @staticmethod
+            def output_comment(output):
+                output.append("// Type originally was named '%s'.\n" % json_name)
+    else:
+
+        class Result(object):
+            class_name = json_name
+
+            @staticmethod
+            def output_comment(output):
+                pass
+
+    return Result
+
+
+
 class TypeBindings:
     @staticmethod
     def create_for_named_type_declaration(json_type, context_domain_name):
+        fixed_type_name = fix_type_name(json_type["id"])
+
+        def write_doc(output):
+            if "description" in json_type:
+                output.append("/* ")
+                output.append(json_type["description"])
+                output.append(" */\n")
+
         if json_type["type"] == "string":
             if "enum" in json_type:
 
@@ -449,9 +486,11 @@ class TypeBindings:
                     @staticmethod
                     def generate_type_builder(output, forward_listener):
                         enum = json_type["enum"]
-                        # TODO: doc
+                        write_doc(output)
+                        enum_name = fixed_type_name.class_name
+                        fixed_type_name.output_comment(output)
                         output.append("namespace ")
-                        output.append(json_type["id"])
+                        output.append(enum_name)
                         output.append(" {\n")
                         for enum_item in enum:
                             item_c_name = enum_item.replace('-', '_')
@@ -461,7 +500,7 @@ class TypeBindings:
                             output.append(enum_item)
                             output.append("\";\n")
                         output.append("} // namespace ")
-                        output.append(json_type["id"])
+                        output.append(enum_name)
                         output.append("\n\n")
 
                 return EnumBinding
@@ -470,12 +509,10 @@ class TypeBindings:
                 class PlainString:
                     @staticmethod
                     def generate_type_builder(output, forward_listener):
-                        if "description" in json_type:
-                            output.append("/* ")
-                            output.append(json_type["description"])
-                            output.append(" */\n")
+                        write_doc(output)
+                        fixed_type_name.output_comment(output)
                         output.append("typedef String ")
-                        output.append(json_type["id"])
+                        output.append(fixed_type_name.class_name)
                         output.append(";\n\n")
                 return PlainString
 
@@ -485,9 +522,10 @@ class TypeBindings:
                 class ClassBinding:
                     @staticmethod
                     def generate_type_builder(output, forward_listener):
-                        # TODO: doc
+                        write_doc(output)
+                        class_name = fixed_type_name.class_name
+                        fixed_type_name.output_comment(output)
                         output.append("class ")
-                        class_name = json_type["id"]
                         output.append(class_name)
                         output.append(" : public InspectorObject {\n")
                         output.append("public:\n")
@@ -1493,7 +1531,7 @@ class Generator:
 
             output.append("} // ")
             output.append(domain_data.name())
-            output.append("\n")
+            output.append("\n\n")
 
 Generator.go()