Title: [125248] trunk/Source/WebCore
Revision
125248
Author
[email protected]
Date
2012-08-09 21:51:06 -0700 (Thu, 09 Aug 2012)

Log Message

Web Inspector: CodeGeneratorInspector.py: add complete support for TypeBuilder::Array
https://bugs.webkit.org/show_bug.cgi?id=93559

Patch by Peter Rybin <[email protected]> on 2012-08-09
Reviewed by Pavel Feldman.

Missing binding methods are added to templates. Core assert methods are declared in a helper class now.

* inspector/CodeGeneratorInspector.py:
(RawTypes.BaseType.generate_validate_method):
(RawTypes.BaseType.get_raw_validator_call_text):
(RawTypes.generate_validate_methods):
(RawTypes.Int.generate_validate_method):
(RawTypes.Int.get_raw_validator_call_text):
(RawTypes.Number.get_validate_method_params.ValidateMethodParams):
(RawTypes.Any.generate_validate_method):
(RawTypes.Any.get_raw_validator_call_text):
(RawTypes.Array.get_validate_method_params.ValidateMethodParams):
(RawTypes.Array.get_validate_method_params):
(PlainObjectBinding.get_validator_call_text):
(RuntimeCastHelper):
(Generator):
(Generator.go):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125247 => 125248)


--- trunk/Source/WebCore/ChangeLog	2012-08-10 04:45:23 UTC (rev 125247)
+++ trunk/Source/WebCore/ChangeLog	2012-08-10 04:51:06 UTC (rev 125248)
@@ -1,3 +1,28 @@
+2012-08-09  Peter Rybin  <[email protected]>
+
+        Web Inspector: CodeGeneratorInspector.py: add complete support for TypeBuilder::Array
+        https://bugs.webkit.org/show_bug.cgi?id=93559
+
+        Reviewed by Pavel Feldman.
+
+        Missing binding methods are added to templates. Core assert methods are declared in a helper class now.
+
+        * inspector/CodeGeneratorInspector.py:
+        (RawTypes.BaseType.generate_validate_method):
+        (RawTypes.BaseType.get_raw_validator_call_text):
+        (RawTypes.generate_validate_methods):
+        (RawTypes.Int.generate_validate_method):
+        (RawTypes.Int.get_raw_validator_call_text):
+        (RawTypes.Number.get_validate_method_params.ValidateMethodParams):
+        (RawTypes.Any.generate_validate_method):
+        (RawTypes.Any.get_raw_validator_call_text):
+        (RawTypes.Array.get_validate_method_params.ValidateMethodParams):
+        (RawTypes.Array.get_validate_method_params):
+        (PlainObjectBinding.get_validator_call_text):
+        (RuntimeCastHelper):
+        (Generator):
+        (Generator.go):
+
 2012-08-09  Sukolsak Sakshuwong  <[email protected]>
 
         Mouse-select then Cut, results in preceding character being lost

Modified: trunk/Source/WebCore/inspector/CodeGeneratorInspector.py (125247 => 125248)


--- trunk/Source/WebCore/inspector/CodeGeneratorInspector.py	2012-08-10 04:45:23 UTC (rev 125247)
+++ trunk/Source/WebCore/inspector/CodeGeneratorInspector.py	2012-08-10 04:51:06 UTC (rev 125248)
@@ -237,30 +237,12 @@
         @classmethod
         def request_raw_internal_runtime_cast(cls):
             if not cls.need_internal_runtime_cast_:
-                RawTypes.types_to_generate_validator_.append(cls)
                 cls.need_internal_runtime_cast_ = True
 
         @classmethod
-        def generate_validate_method(cls, writer):
-            params = cls.get_validate_method_params()
-            writer.newline("static void assert%s(InspectorValue* value)\n" % params.name)
-            writer.newline("{\n")
-            writer.newline("    ASSERT(value->type() == InspectorValue::Type%s);\n" % params.as_method_name)
-            writer.newline("}\n\n\n")
-
-        @classmethod
         def get_raw_validator_call_text(cls):
-            return "assert%s" % cls.get_validate_method_params().name
+            return "RuntimeCastHelper::assertType<InspectorValue::Type%s>" % cls.get_validate_method_params().template_type
 
-    types_to_generate_validator_ = []
-
-    @classmethod
-    def generate_validate_methods(cls, writer):
-        for t in cls.types_to_generate_validator_:
-            if t.need_internal_runtime_cast_:
-                t.generate_validate_method(writer)
-
-
     class String(BaseType):
         @staticmethod
         def get_getter_name():
@@ -279,8 +261,7 @@
         @staticmethod
         def get_validate_method_params():
             class ValidateMethodParams:
-                name = "String"
-                as_method_name = "String"
+                template_type = "String"
             return ValidateMethodParams
 
         @staticmethod
@@ -317,18 +298,8 @@
             return "number"
 
         @classmethod
-        def generate_validate_method(cls, writer):
-            writer.newline("static void assertInt(InspectorValue* value)\n")
-            writer.newline("{\n")
-            writer.newline("    double v;\n")
-            writer.newline("    bool castRes = value->asNumber(&v);\n")
-            writer.newline("    ASSERT_UNUSED(castRes, castRes);\n")
-            writer.newline("    ASSERT(static_cast<double>(static_cast<int>(v)) == v);\n")
-            writer.newline("}\n\n\n")
-
-        @classmethod
         def get_raw_validator_call_text(cls):
-            return "assertInt"
+            return "RuntimeCastHelper::assertInt"
 
         @staticmethod
         def get_output_pass_model():
@@ -366,8 +337,7 @@
         @staticmethod
         def get_validate_method_params():
             class ValidateMethodParams:
-                name = "Double"
-                as_method_name = "Number"
+                template_type = "Number"
             return ValidateMethodParams
 
         @staticmethod
@@ -404,8 +374,7 @@
         @staticmethod
         def get_validate_method_params():
             class ValidateMethodParams:
-                name = "Boolean"
-                as_method_name = "Boolean"
+                template_type = "Boolean"
             return ValidateMethodParams
 
         @staticmethod
@@ -448,8 +417,7 @@
         @staticmethod
         def get_validate_method_params():
             class ValidateMethodParams:
-                name = "Object"
-                as_method_name = "Object"
+                template_type = "Object"
             return ValidateMethodParams
 
         @staticmethod
@@ -484,15 +452,8 @@
             raise Exception("Unsupported")
 
         @staticmethod
-        def generate_validate_method(writer):
-            writer.newline("static void assertAny(InspectorValue*)\n")
-            writer.newline("{\n")
-            writer.newline("    // No-op.\n")
-            writer.newline("}\n\n\n")
-
-        @staticmethod
         def get_raw_validator_call_text():
-            return "assertAny"
+            return "RuntimeCastHelper::assertAny"
 
         @staticmethod
         def get_output_pass_model():
@@ -533,7 +494,9 @@
 
         @staticmethod
         def get_validate_method_params():
-            raise Exception("TODO")
+            class ValidateMethodParams:
+                template_type = "Array"
+            return ValidateMethodParams
 
         @staticmethod
         def get_output_pass_model():
@@ -1452,7 +1415,7 @@
 
                     @staticmethod
                     def get_validator_call_text():
-                        return "assertObject"
+                        return "RuntimeCastHelper::assertType<InspectorValue::TypeObject>"
 
                     @classmethod
                     def get_array_item_c_type_text(cls):
@@ -2267,7 +2230,20 @@
 template<>
 inline int ExactlyInt::cast_to_int<unsigned int>(unsigned int i) { return i; }
 
+class RuntimeCastHelper {
+public:
+#if !ASSERT_DISABLED
+    template<InspectorValue::Type TYPE>
+    static void assertType(InspectorValue* value)
+    {
+        ASSERT(value->type() == TYPE);
+    }
+    static void assertAny(InspectorValue*);
+    static void assertInt(InspectorValue* value);
+#endif
+};
 
+
 // This class provides "Traits" type for the input type T. It is programmed using C++ template specialization
 // technique. By default it simply takes "ItemTraits" type from T, but it doesn't work with the base types.
 template<typename T>
@@ -2332,10 +2308,12 @@
         array->pushValue(value);
     }
 
+#if """ + VALIDATOR_IFDEF_NAME + """
     template<typename T>
     static void assertCorrectValue(InspectorValue* value) {
         T::assertCorrectValue(value);
     }
+#endif  // !ASSERT_DISABLED
 };
 
 template<>
@@ -2345,6 +2323,13 @@
         {
             array->pushString(value);
         }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertType<InspectorValue::TypeString>(value);
+        }
+#endif  // !ASSERT_DISABLED
     };
 };
 
@@ -2355,16 +2340,64 @@
         {
             array->pushInt(value);
         }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertInt(value);
+        }
+#endif  // !ASSERT_DISABLED
     };
 };
 
 template<>
+struct ArrayItemHelper<double> {
+    struct Traits {
+        static void pushRaw(InspectorArray* array, double value)
+        {
+            array->pushNumber(value);
+        }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertType<InspectorValue::TypeNumber>(value);
+        }
+#endif  // !ASSERT_DISABLED
+    };
+};
+
+template<>
+struct ArrayItemHelper<bool> {
+    struct Traits {
+        static void pushRaw(InspectorArray* array, bool value)
+        {
+            array->pushBoolean(value);
+        }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertType<InspectorValue::TypeBoolean>(value);
+        }
+#endif  // !ASSERT_DISABLED
+    };
+};
+
+template<>
 struct ArrayItemHelper<InspectorValue> {
     struct Traits {
         static void pushRefPtr(InspectorArray* array, PassRefPtr<InspectorValue> value)
         {
             array->pushValue(value);
         }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertAny(value);
+        }
+#endif  // !ASSERT_DISABLED
     };
 };
 
@@ -2375,9 +2408,33 @@
         {
             array->pushValue(value);
         }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertType<InspectorValue::TypeObject>(value);
+        }
+#endif  // !ASSERT_DISABLED
     };
 };
 
+template<>
+struct ArrayItemHelper<InspectorArray> {
+    struct Traits {
+        static void pushRefPtr(InspectorArray* array, PassRefPtr<InspectorArray> value)
+        {
+            array->pushArray(value);
+        }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename T>
+        static void assertCorrectValue(InspectorValue* value) {
+            RuntimeCastHelper::assertType<InspectorValue::TypeArray>(value);
+        }
+#endif  // !ASSERT_DISABLED
+    };
+};
+
 template<typename T>
 struct ArrayItemHelper<TypeBuilder::Array<T> > {
     struct Traits {
@@ -2385,6 +2442,13 @@
         {
             array->pushValue(value);
         }
+
+#if """ + VALIDATOR_IFDEF_NAME + """
+        template<typename S>
+        static void assertCorrectValue(InspectorValue* value) {
+            S::assertCorrectValue(value);
+        }
+#endif  // !ASSERT_DISABLED
     };
 };
 
@@ -2429,6 +2493,20 @@
 
 #if """ + VALIDATOR_IFDEF_NAME + """
 
+void TypeBuilder::RuntimeCastHelper::assertAny(InspectorValue*)
+{
+    // No-op.
+}
+
+
+void TypeBuilder::RuntimeCastHelper::assertInt(InspectorValue* value)
+{
+    double v;
+    bool castRes = value->asNumber(&v);
+    ASSERT_UNUSED(castRes, castRes);
+    ASSERT(static_cast<double>(static_cast<int>(v)) == v);
+}
+
 $validatorCode
 
 #endif // """ + VALIDATOR_IFDEF_NAME + """
@@ -2545,14 +2623,11 @@
     type_builder_fragments = []
     type_builder_forwards = []
     validator_impl_list = []
-    validator_impl_raw_types_list = []
     type_builder_impl_list = []
 
 
     @staticmethod
     def go():
-        Generator.validator_impl_list.append(Generator.validator_impl_raw_types_list)
-
         Generator.process_types(type_map)
 
         first_cycle_guardable_list_list = [
@@ -2625,8 +2700,6 @@
                     domain_guard.generate_close(l)
             Generator.backend_js_domain_initializer_list.append("\n")
 
-        RawTypes.generate_validate_methods(Writer(Generator.validator_impl_raw_types_list, ""))
-
     @staticmethod
     def process_event(json_event, domain_name, frontend_method_declaration_lines):
         event_name = json_event["name"]
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to