Web Inspector: CodeGeneratorInspector.py: use generated types in method parameters
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 14:54:35 +0000 (14:54 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 14:54:35 +0000 (14:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74661

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

Type binding object is added to raw_type object.

* inspector/CodeGeneratorInspector.py:
(TypeBindings.create_for_named_type_declaration.EnumBinding.generate_type_builder):
(TypeBindings.create_for_named_type_declaration.EnumBinding.get_in_c_type_text):
(TypeBindings.create_for_named_type_declaration.EnumBinding):
(TypeBindings.create_for_named_type_declaration.EnumBinding.reduce_to_raw_type):
(TypeBindings.create_for_named_type_declaration.PlainString.generate_type_builder):
(TypeBindings.create_for_named_type_declaration.PlainString.reduce_to_raw_type):
(TypeBindings.create_for_named_type_declaration.PlainString):
(TypeBindings.create_for_named_type_declaration.PlainString.get_in_c_type_text):
(TypeBindings):
(TypeBindings.create_for_named_type_declaration.ClassBinding):
(get_in_c_type_text):
(reduce_to_raw_type):
(PlainObjectBinding.generate_type_builder):
(PlainObjectBinding.get_in_c_type_text):
(PlainObjectBinding):
(PlainObjectBinding.reduce_to_raw_type):
(RawTypesBinding.generate_type_builder):
(RawTypesBinding.get_in_c_type_text):
(RawTypesBinding):
(RawTypesBinding.reduce_to_raw_type):
(resolve_param_type.RawTypeBinding.reduce_to_raw_type):
(resolve_param_type.RawTypeBinding):
(resolve_param_type.RawTypeBinding.get_in_c_type_text):
(resolve_param_type):
(Generator.process_event):

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

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

index fccaae236a32684583af7144b1eff19f75330384..4b1f96ac6f01ce4b1ca2e3f3e8a2db97f692af7d 100644 (file)
@@ -1,3 +1,39 @@
+2011-12-18  Peter Rybin  <peter.rybin@gmail.com>
+
+        Web Inspector: CodeGeneratorInspector.py: use generated types in method parameters
+        https://bugs.webkit.org/show_bug.cgi?id=74661
+
+        Reviewed by Pavel Feldman.
+
+        Type binding object is added to raw_type object.
+
+        * inspector/CodeGeneratorInspector.py:
+        (TypeBindings.create_for_named_type_declaration.EnumBinding.generate_type_builder):
+        (TypeBindings.create_for_named_type_declaration.EnumBinding.get_in_c_type_text):
+        (TypeBindings.create_for_named_type_declaration.EnumBinding):
+        (TypeBindings.create_for_named_type_declaration.EnumBinding.reduce_to_raw_type):
+        (TypeBindings.create_for_named_type_declaration.PlainString.generate_type_builder):
+        (TypeBindings.create_for_named_type_declaration.PlainString.reduce_to_raw_type):
+        (TypeBindings.create_for_named_type_declaration.PlainString):
+        (TypeBindings.create_for_named_type_declaration.PlainString.get_in_c_type_text):
+        (TypeBindings):
+        (TypeBindings.create_for_named_type_declaration.ClassBinding):
+        (get_in_c_type_text):
+        (reduce_to_raw_type):
+        (PlainObjectBinding.generate_type_builder):
+        (PlainObjectBinding.get_in_c_type_text):
+        (PlainObjectBinding):
+        (PlainObjectBinding.reduce_to_raw_type):
+        (RawTypesBinding.generate_type_builder):
+        (RawTypesBinding.get_in_c_type_text):
+        (RawTypesBinding):
+        (RawTypesBinding.reduce_to_raw_type):
+        (resolve_param_type.RawTypeBinding.reduce_to_raw_type):
+        (resolve_param_type.RawTypeBinding):
+        (resolve_param_type.RawTypeBinding.get_in_c_type_text):
+        (resolve_param_type):
+        (Generator.process_event):
+
 2011-12-18  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r103169.
index 4a436059773c984cf0b90766683bc2b940c86935..dcdb32d55649fa905113d9992412490de5af8a92 100755 (executable)
@@ -505,6 +505,14 @@ class TypeBindings:
                         output.append(enum_name)
                         output.append("\n\n")
 
+                    @classmethod
+                    def get_in_c_type_text(cls, optional):
+                        return cls.reduce_to_raw_type().get_c_param_type(ParamType.EVENT, optional).get_text()
+
+                    @staticmethod
+                    def reduce_to_raw_type():
+                        return RawTypes.String
+
                 return EnumBinding
             else:
 
@@ -516,12 +524,23 @@ class TypeBindings:
                         output.append("typedef String ")
                         output.append(fixed_type_name.class_name)
                         output.append(";\n\n")
+
+                    @staticmethod
+                    def reduce_to_raw_type():
+                        return RawTypes.String
+
+                    @classmethod
+                    def get_in_c_type_text(cls, optional):
+                        return cls.reduce_to_raw_type().get_c_param_type(ParamType.EVENT, optional).get_text()
+
                 return PlainString
 
         elif json_type["type"] == "object":
             if "properties" in json_type:
 
                 class ClassBinding:
+                    class_name_ = json_type["id"]
+
                     @staticmethod
                     def generate_type_builder(output, forward_listener):
                         write_doc(output)
@@ -644,6 +663,16 @@ class TypeBindings:
                                 output.append("    using InspectorObject::%s;\n\n" % setter_name)
 
                         output.append("};\n\n")
+
+                    @classmethod
+                    def get_in_c_type_text(cls, optional):
+                        return "PassRefPtr<TypeBuilder::" + context_domain_name + "::" + cls.class_name_ + ">"
+
+                    @staticmethod
+                    def reduce_to_raw_type():
+                        return RawTypes.Object
+
+                        output.append("};\n\n")
                 return ClassBinding
             else:
 
@@ -652,6 +681,15 @@ class TypeBindings:
                     def generate_type_builder(output, forward_listener):
                         # No-op
                         pass
+
+                    @classmethod
+                    def get_in_c_type_text(cls, optional):
+                        return cls.reduce_to_raw_type().get_c_param_type(ParamType.EVENT, optional).get_text()
+
+                    @staticmethod
+                    def reduce_to_raw_type():
+                        return RawTypes.Object
+
                 return PlainObjectBinding
         else:
             raw_type = RawTypes.get(json_type["type"])
@@ -661,6 +699,15 @@ class TypeBindings:
                 def generate_type_builder(output, forward_listener):
                     # No-op
                     pass
+
+                @classmethod
+                def get_in_c_type_text(cls, optional):
+                    return cls.reduce_to_raw_type().get_c_param_type(ParamType.EVENT, optional).get_text()
+
+                @staticmethod
+                def reduce_to_raw_type():
+                    return raw_type
+
             return RawTypesBinding
 
 
@@ -727,6 +774,28 @@ class TypeMap:
         return self.map_[domain_name][type_name]
 
 
+def resolve_param_type(json_parameter, scope_domain_name):
+    if "$ref" in json_parameter:
+        json_ref = json_parameter["$ref"]
+        type_data = get_ref_data(json_ref, scope_domain_name)
+        return type_data.get_binding()
+    elif "type" in json_parameter:
+        json_type = json_parameter["type"]
+        raw_type = RawTypes.get(json_type)
+
+        class RawTypeBinding:
+            @staticmethod
+            def reduce_to_raw_type():
+                return raw_type
+
+            @staticmethod
+            def get_in_c_type_text(optional):
+                return raw_type.get_c_param_type(ParamType.EVENT, optional).get_text()
+
+        return RawTypeBinding
+    else:
+        raise Exception("Unknown type")
+
 def resolve_param_raw_type(json_parameter, scope_domain_name):
     if "$ref" in json_parameter:
         json_ref = json_parameter["$ref"]
@@ -1306,6 +1375,13 @@ $domainInitializers
 
 type_map = TypeMap(json_api)
 
+
+def get_annotated_type_text(raw_type, annotated_type):
+    if annotated_type != raw_type:
+        return "/*%s*/ %s" % (annotated_type, raw_type)
+    else:
+        return raw_type
+
 class Generator:
     frontend_class_field_lines = []
     frontend_domain_class_lines = []
@@ -1436,7 +1512,11 @@ class Generator:
 
                 optional = optional_mask and json_optional
 
-                parameter_list.append("%s %s" % (c_type.get_text(), parameter_name))
+                param_type_binding = resolve_param_type(json_parameter, domain_name)
+
+                annotated_type = get_annotated_type_text(c_type.get_text(), param_type_binding.get_in_c_type_text(json_optional))
+
+                parameter_list.append("%s %s" % (annotated_type, parameter_name))
 
                 setter_argument = c_type.get_setter_format() % parameter_name