Web Inspector: clear fixme in generator script
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Nov 2011 05:47:57 +0000 (05:47 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Nov 2011 05:47:57 +0000 (05:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71372

Remove unnecessary field name map and update license year number.

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

* inspector/CodeGeneratorInspector.py:

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

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

index af610d033adc5f5f5039a7ba1e23d3b696e079dc..2c369c4207879c51789d70f79e7916471e061b5e 100644 (file)
@@ -1,3 +1,14 @@
+2011-11-17  Peter Rybin  <peter.rybin@gmail.com>
+
+        Web Inspector: clear fixme in generator script
+        https://bugs.webkit.org/show_bug.cgi?id=71372
+
+        Remove unnecessary field name map and update license year number.
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/CodeGeneratorInspector.py:
+
 2011-11-17  Raphael Kubo da Costa  <kubo@profusion.mobi>
 
         [EFL] Clean up the use of DATA_DIR in the buildsystem
index 4ff2b25a5fa7151a362c1c0b23da3a983357a923..8cbaad7251a011c8bf568a88b67d069e3ceba9aa 100644 (file)
@@ -37,6 +37,16 @@ try:
 except ImportError:
     import simplejson as json
 
+
+DOMAIN_DEFINE_NAME_MAP = {
+    "Database": "ENABLE_SQL_DATABASE",
+    "Debugger": "ENABLE_JAVASCRIPT_DEBUGGER",
+    "DOMDebugger": "ENABLE_JAVASCRIPT_DEBUGGER",
+    "Profiler": "ENABLE_JAVASCRIPT_DEBUGGER",
+    "Worker": "ENABLE_WORKERS",
+}
+
+
 cmdline_parser = optparse.OptionParser()
 cmdline_parser.add_option("--defines")
 cmdline_parser.add_option("--output_h_dir")
@@ -91,6 +101,27 @@ def parse_defines(str):
 defines_map = parse_defines(arg_options.defines)
 
 
+class Capitalizer:
+    @staticmethod
+    def upper_camel_case_to_lower(str):
+        pos = 0
+        while pos < len(str) and str[pos].isupper():
+            pos += 1
+        if pos == 0:
+            return str
+        if pos == 1:
+            return str[0].lower() + str[1:]
+        if pos < len(str):
+            pos -= 1
+        possible_abbreviation = str[0:pos]
+        if possible_abbreviation not in Capitalizer.ABBREVIATION:
+            raise Exception("Unknown abbreviation %s" % possible_abbreviation)
+        str = possible_abbreviation.lower() + str[pos:]
+        return str
+
+    ABBREVIATION = frozenset(["XHR", "DOM", "CSS"])
+
+
 class DomainNameFixes:
     @classmethod
     def get_fixed_data(cls, domain_name):
@@ -99,10 +130,7 @@ class DomainNameFixes:
         else:
             agent_name_res = "Inspector%sAgent" % domain_name
 
-        if domain_name in cls.agent_field_name_map:
-            field_name_res = cls.agent_field_name_map[domain_name]
-        else:
-            field_name_res = domain_name.lower() + "Agent"
+        field_name_res = Capitalizer.upper_camel_case_to_lower(domain_name) + "Agent"
 
         class Res(object):
             agent_type_name = agent_name_res
@@ -112,11 +140,11 @@ class DomainNameFixes:
 
             @staticmethod
             def is_disabled(defines):
-                if not domain_name in cls.domain_define_name_map:
+                if not domain_name in DOMAIN_DEFINE_NAME_MAP:
                     # Has not corresponding preprocessor symbol.
                     return False
 
-                define_name = cls.domain_define_name_map[domain_name]
+                define_name = DOMAIN_DEFINE_NAME_MAP[domain_name]
 
                 if not define_name in defines:
                     # Disabled when not mentioned
@@ -131,31 +159,6 @@ class DomainNameFixes:
     hidden_domains = set(["Inspector"])
     agent_type_map = {"Network": "InspectorResourceAgent"}
 
-    # TODO: get rid of this, generate names instead.
-    agent_field_name_map = {
-        "Page": "pageAgent",
-        "Runtime": "runtimeAgent",
-        "Console": "consoleAgent",
-        "Network":  "resourceAgent",
-        "Database":  "databaseAgent",
-        "DOMStorage":  "domStorageAgent",
-        "ApplicationCache":  "applicationCacheAgent",
-        "DOM":  "domAgent",
-        "CSS":  "cssAgent",
-        "Debugger": "debuggerAgent",
-        "DOMDebugger": "domDebuggerAgent",
-        "Profiler": "profilerAgent",
-        "Worker": "workerAgent",
-    }
-
-    domain_define_name_map = {
-        "Database": "ENABLE_SQL_DATABASE",
-        "Debugger": "ENABLE_JAVASCRIPT_DEBUGGER",
-        "DOMDebugger": "ENABLE_JAVASCRIPT_DEBUGGER",
-        "Profiler": "ENABLE_JAVASCRIPT_DEBUGGER",
-        "Worker": "ENABLE_WORKERS",
-    }
-
 
 class CParamType(object):
     def __init__(self, type, setter_format="%s"):
@@ -447,11 +450,11 @@ ${frontendDomainMethodDeclarations}        void setInspectorFrontendChannel(Insp
 $methodOutCode
     ErrorString error;
 $methodInCode
-if (!protocolErrors->length())
-    $agentField->$methodName(&error$agentCallParams);
+    if (!protocolErrors->length())
+        $agentField->$methodName(&error$agentCallParams);
 
     RefPtr<InspectorObject> result = InspectorObject::create();
-${responseCook}sendResponse(callId, result, String::format("Some arguments of method '%s' can't be processed", "$domainName.$methodName"), protocolErrors, error);
+${responseCook}    sendResponse(callId, result, String::format("Some arguments of method '%s' can't be processed", "$domainName.$methodName"), protocolErrors, error);
 }
 """)
 
@@ -464,7 +467,7 @@ $code    if (m_inspectorFrontendChannel)
 }
 """)
 
-    frontend_h = string.Template("""// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+    frontend_h = string.Template("""// Copyright (c) 2011 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.
 #ifndef InspectorFrontend_h
@@ -495,7 +498,7 @@ ${fieldDeclarations}};
 #endif // !defined(InspectorFrontend_h)
 """)
 
-    backend_h = string.Template("""// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+    backend_h = string.Template("""// Copyright (c) 2011 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.
 #ifndef InspectorBackendDispatcher_h
@@ -567,7 +570,7 @@ $fieldDeclarations
 
 """)
 
-    backend_cpp = string.Template("""// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+    backend_cpp = string.Template("""// Copyright (c) 2011 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.
 
@@ -898,7 +901,7 @@ bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
 #endif // ENABLE(INSPECTOR)
 """)
 
-    frontend_cpp = string.Template("""// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+    frontend_cpp = string.Template("""// Copyright (c) 2011 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.
 
@@ -930,7 +933,7 @@ $methods
 #endif // ENABLE(INSPECTOR)
 """)
 
-    backend_js = string.Template("""// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+    backend_js = string.Template("""// Copyright (c) 2011 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.
 
@@ -1319,7 +1322,7 @@ class Generator:
     def process_command(json_command, domain_name, agent_field_name):
         json_command_name = json_command["name"]
         Generator.method_name_enum_list.append("        k%s_%sCmd," % (domain_name, json_command["name"]))
-        Generator.method_handler_list.append("        &InspectorBackendDispatcher::%s_%s," % (domain_name, json_command_name))
+        Generator.method_handler_list.append("            &InspectorBackendDispatcher::%s_%s," % (domain_name, json_command_name))
         Generator.backend_method_declaration_list.append("    void %s_%s(long callId, InspectorObject* requestMessageObject);" % (domain_name, json_command_name))
 
         method_in_code = ""