Changeset 102005 in webkit
- Timestamp:
- Dec 5, 2011 9:07:30 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r102004 r102005 1 2011-12-05 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r102004. 4 http://trac.webkit.org/changeset/102004 5 https://bugs.webkit.org/show_bug.cgi?id=73835 6 7 Breaks qt minimal release compilation (Requested by vsevik on 8 #webkit). 9 10 * inspector/CodeGeneratorInspector.py: 11 (Capitalizer.upper_camel_case_to_lower): 12 (RawTypes.get): 13 (RawTypes.String.get_c_param_type): 14 (RawTypes.Object.get_c_param_type): 15 (RawTypes.Object): 16 (ParamType): 17 (TypeData.__init__): 18 (TypeData.get_raw_type): 19 (TypeMap.__init__): 20 (InspectorFrontend_h): 21 (InspectorArray): 22 (InspectorObject): 23 (String): 24 (InspectorBackendDispatcher_h): 25 (Generator.process_command): 26 * inspector/InspectorValues.h: 27 1 28 2011-12-05 Peter Rybin <peter.rybin@gmail.com> 2 29 -
trunk/Source/WebCore/inspector/CodeGeneratorInspector.py
r102004 r102005 105 105 class Capitalizer: 106 106 @staticmethod 107 def lower_camel_case_to_upper(str):108 if len(str) > 0 and str[0].islower():109 str = str[0].upper() + str[1:]110 return str111 112 @staticmethod113 107 def upper_camel_case_to_lower(str): 114 108 pos = 0 … … 127 121 return str 128 122 129 @staticmethod130 def camel_case_to_capitalized_with_underscores(str):131 if len(str) == 0:132 return str133 output = Capitalizer.split_camel_case_(str)134 pos = 0135 while pos < len(output):136 output[pos] = output[pos].upper()137 pos += 1138 return "_".join(output)139 140 @staticmethod141 def split_camel_case_(str):142 output = []143 pos_being = 0144 pos = 1145 has_oneletter = False146 while pos < len(str):147 if str[pos].isupper():148 output.append(str[pos_being:pos].upper())149 if pos - pos_being == 1:150 has_oneletter = True151 pos_being = pos152 pos += 1153 output.append(str[pos_being:])154 if has_oneletter:155 array_pos = 0156 while array_pos < len(output) - 1:157 if len(output[array_pos]) == 1:158 array_pos_end = array_pos + 1159 while array_pos_end < len(output) and len(output[array_pos_end]) == 1:160 array_pos_end += 1161 if array_pos_end - array_pos > 1:162 possible_abbreviation = "".join(output[array_pos:array_pos_end])163 if possible_abbreviation.upper() in Capitalizer.ABBREVIATION:164 output[array_pos:array_pos_end] = [possible_abbreviation]165 else:166 array_pos = array_pos_end - 1167 array_pos += 1168 return output169 170 123 ABBREVIATION = frozenset(["XHR", "DOM", "CSS"]) 171 124 … … 234 187 elif json_type == "number": 235 188 return RawTypes.Number 236 elif json_type == "any":237 return RawTypes.Any238 189 else: 239 190 raise Exception("Unknown type: %s" % json_type) … … 251 202 @classmethod 252 203 def get_c_param_type(cls, param_type, optional): 253 if param_type == ParamType.EVENT or param_type == ParamType.TYPE_BUILDER_OUTPUT:204 if param_type == ParamType.EVENT: 254 205 return cls._ref_c_type 255 206 else: … … 346 297 @classmethod 347 298 def get_c_param_type(cls, param_type, optional): 348 if param_type == ParamType.EVENT or param_type == ParamType.TYPE_BUILDER_OUTPUT:299 if param_type == ParamType.EVENT: 349 300 return cls._ref_c_type 350 301 else: … … 371 322 _plain_c_type = CParamType("RefPtr<InspectorObject>") 372 323 _ref_c_type = CParamType("PassRefPtr<InspectorObject>") 373 374 class Any(BaseType):375 @classmethod376 def get_c_param_type(cls, param_type, optional):377 if param_type == ParamType.EVENT or param_type == ParamType.TYPE_BUILDER_OUTPUT:378 return cls._ref_c_type379 else:380 return cls._plain_c_type381 382 @staticmethod383 def get_getter_name():384 return "Value"385 386 get_setter_name = get_getter_name387 388 @staticmethod389 def get_c_initializer():390 return "InspectorValue::create()"391 392 @staticmethod393 def get_js_bind_type():394 raise Exception("Unsupported")395 396 @staticmethod397 def is_event_param_check_optional():398 return True399 400 _plain_c_type = CParamType("RefPtr<InspectorValue>")401 _ref_c_type = CParamType("PassRefPtr<InspectorValue>")402 324 403 325 class Array(BaseType): … … 437 359 OUTPUT = "output" 438 360 EVENT = "event" 439 TYPE_BUILDER_OUTPUT = "typeBuilderOutput"440 441 # Collection of InspectorObject class methods that are likely to be overloaded in generated class.442 # We must explicitly import all overloaded methods or they won't be available to user.443 INSPECTOR_OBJECT_SETTER_NAMES = frozenset(["setValue", "setBoolean", "setNumber", "setString", "setValue", "setObject", "setArray"])444 445 446 class TypeBindings:447 @staticmethod448 def create_for_named_type_declaration(json_type, context_domain_name):449 if json_type["type"] == "string":450 if "enum" in json_type:451 452 class EnumBinding:453 @staticmethod454 def generate_type_builder(output, forward_listener):455 enum = json_type["enum"]456 # TODO: doc457 output.append("namespace ")458 output.append(json_type["id"])459 output.append(" {\n")460 for enum_item in enum:461 item_c_name = enum_item.replace('-', '_')462 output.append("const char* const ")463 output.append(Capitalizer.upper_camel_case_to_lower(item_c_name))464 output.append(" = \"")465 output.append(enum_item)466 output.append("\";\n")467 output.append("} // namespace ")468 output.append(json_type["id"])469 output.append("\n\n")470 471 return EnumBinding472 else:473 474 class PlainString:475 @staticmethod476 def generate_type_builder(output, forward_listener):477 if "description" in json_type:478 output.append("/* ")479 output.append(json_type["description"])480 output.append(" */\n")481 output.append("typedef String ")482 output.append(json_type["id"])483 output.append(";\n\n")484 return PlainString485 486 elif json_type["type"] == "object":487 if "properties" in json_type:488 489 class ClassBinding:490 @staticmethod491 def generate_type_builder(output, forward_listener):492 # TODO: doc493 output.append("class ")494 class_name = json_type["id"]495 output.append(class_name)496 output.append(" : public InspectorObject {\n")497 output.append("public:\n")498 499 properties = json_type["properties"]500 main_properties = []501 optional_properties = []502 for p in properties:503 if "optional" in p and p["optional"]:504 optional_properties.append(p)505 else:506 main_properties.append(p)507 508 output.append(509 """ enum {510 NO_FIELDS_SET = 0,511 """)512 513 state_enum_items = []514 if len(main_properties) > 0:515 pos = 0516 for p in main_properties:517 item_name = Capitalizer.camel_case_to_capitalized_with_underscores(p["name"]) + "_SET"518 state_enum_items.append(item_name)519 output.append(" %s = 1 << %s,\n" % (item_name, pos))520 pos += 1521 all_fields_set_value = "(" + (" | ".join(state_enum_items)) + ")"522 else:523 all_fields_set_value = "0"524 525 output.append(526 """ ALL_FIELDS_SET = %s527 };528 529 template<int STATE>530 class Builder {531 private:532 RefPtr<InspectorObject> m_result;533 534 template<int STEP> Builder<STATE | STEP>& castState()535 {536 return *reinterpret_cast<Builder<STATE | STEP>*>(this);537 }538 539 Builder(PassRefPtr<%s> ptr)540 {541 COMPILE_ASSERT(STATE == NO_FIELDS_SET, builder_created_in_non_init_state);542 m_result = ptr;543 }544 friend class %s;545 public:546 """ % (all_fields_set_value, class_name, class_name))547 548 pos = 0549 for prop in main_properties:550 prop_name = prop["name"]551 param_raw_type = resolve_param_raw_type(prop, context_domain_name)552 output.append("""553 Builder<STATE | %s>& set%s(%s value)554 {555 COMPILE_ASSERT(!(STATE & %s), property_%s_already_set);556 m_result->set%s("%s", value);557 return castState<%s>();558 }559 """560 % (state_enum_items[pos],561 Capitalizer.lower_camel_case_to_upper(prop_name),562 param_raw_type.get_c_param_type(ParamType.TYPE_BUILDER_OUTPUT, False).get_text(),563 state_enum_items[pos], prop_name,564 param_raw_type.get_setter_name(), prop_name, state_enum_items[pos]))565 566 pos += 1567 568 output.append("""569 operator RefPtr<%s>& ()570 {571 COMPILE_ASSERT(STATE == ALL_FIELDS_SET, result_is_not_ready);572 return *reinterpret_cast<RefPtr<%s>*>(&m_result);573 }574 575 operator PassRefPtr<%s> ()576 {577 return RefPtr<%s>(*this);578 }579 };580 581 """582 % (class_name, class_name, class_name, class_name))583 584 output.append(" /*\n")585 output.append(" * Synthetic constructor:\n")586 output.append(" * RefPtr<%s> result = %s::create()" % (class_name, class_name))587 for prop in main_properties:588 output.append("\n * .set%s(...)" % Capitalizer.lower_camel_case_to_upper(prop["name"]))589 output.append(";\n */\n")590 591 output.append(592 """ static Builder<NO_FIELDS_SET> create()593 {594 return Builder<NO_FIELDS_SET>(adoptRef(new %s()));595 }596 """ % class_name)597 598 for prop in optional_properties:599 param_raw_type = resolve_param_raw_type(prop, context_domain_name)600 setter_name = "set%s" % Capitalizer.lower_camel_case_to_upper(prop["name"])601 output.append("\n void %s" % setter_name)602 output.append("(%s value)\n" % param_raw_type.get_c_param_type(ParamType.TYPE_BUILDER_OUTPUT, False).get_text())603 output.append(" {\n")604 output.append(" this->set%s(\"%s\", value);\n" % (param_raw_type.get_setter_name(), prop["name"]))605 output.append(" }\n")606 607 if setter_name in INSPECTOR_OBJECT_SETTER_NAMES:608 output.append(" using InspectorObject::%s;\n\n" % setter_name)609 610 output.append("};\n\n")611 return ClassBinding612 else:613 614 class PlainObjectBinding:615 @staticmethod616 def generate_type_builder(output, forward_listener):617 # No-op618 pass619 return PlainObjectBinding620 else:621 raw_type = RawTypes.get(json_type["type"])622 623 class RawTypesBinding:624 @staticmethod625 def generate_type_builder(output, forward_listener):626 # No-op627 pass628 return RawTypesBinding629 361 630 362 631 363 class TypeData(object): 632 def __init__(self, json_type, json_domain , domain_data):364 def __init__(self, json_type, json_domain): 633 365 self.json_type_ = json_type 634 366 self.json_domain_ = json_domain 635 self.domain_data_ = domain_data 636 637 if "type" not in json_type: 367 368 if "type" in json_type: 369 json_type_name = json_type["type"] 370 raw_type = RawTypes.get(json_type_name) 371 else: 638 372 raise Exception("Unknown type") 639 640 json_type_name = json_type["type"]641 raw_type = RawTypes.get(json_type_name)642 373 self.raw_type_ = raw_type 643 self.binding_ = TypeBindings.create_for_named_type_declaration(json_type, json_domain["domain"])644 374 645 375 def get_raw_type(self): 646 376 return self.raw_type_ 647 648 def get_binding(self):649 return self.binding_650 651 652 class DomainData:653 def __init__(self, json_domain):654 self.json_domain = json_domain655 self.types_ = []656 657 def add_type(self, type_data):658 self.types_.append(type_data)659 660 def name(self):661 return self.json_domain["domain"]662 663 def types(self):664 return self.types_665 377 666 378 … … 668 380 def __init__(self, api): 669 381 self.map_ = {} 670 self.domains_ = []671 382 for json_domain in api["domains"]: 672 383 domain_name = json_domain["domain"] … … 674 385 domain_map = {} 675 386 self.map_[domain_name] = domain_map 676 677 domain_data = DomainData(json_domain)678 self.domains_.append(domain_data)679 387 680 388 if "types" in json_domain: 681 389 for json_type in json_domain["types"]: 682 390 type_name = json_type["id"] 683 type_data = TypeData(json_type, json_domain , domain_data)391 type_data = TypeData(json_type, json_domain) 684 392 domain_map[type_name] = type_data 685 domain_data.add_type(type_data)686 687 def domains(self):688 return self.domains_689 393 690 394 def get(self, domain_name, type_name): … … 722 426 723 427 class Templates: 724 def get_this_script_path_(absolute_path):725 absolute_path = os.path.abspath(absolute_path)726 components = []727 728 def fill_recursive(path_part, depth):729 if depth <= 0 or path_part == '/':730 return731 fill_recursive(os.path.dirname(path_part), depth - 1)732 components.append(os.path.basename(path_part))733 734 # Typical path is /Source/WebCore/inspector/CodeGeneratorInspector.py735 # Let's take 4 components from the real path then.736 fill_recursive(absolute_path, 4)737 738 return "/".join(components)739 740 file_header_ = ("// File is generated by %s\n\n" % get_this_script_path_(sys.argv[0]) +741 """// Copyright (c) 2011 The Chromium Authors. All rights reserved.742 // Use of this source code is governed by a BSD-style license that can be743 // found in the LICENSE file.744 """)745 746 747 748 428 frontend_domain_class = string.Template( 749 429 """ class $domainClassName { … … 787 467 """) 788 468 789 frontend_h = string.Template(file_header_ + 790 """#ifndef InspectorFrontend_h 469 frontend_h = string.Template("""// Copyright (c) 2011 The Chromium Authors. All rights reserved. 470 // Use of this source code is governed by a BSD-style license that can be 471 // found in the LICENSE file. 472 #ifndef InspectorFrontend_h 791 473 #define InspectorFrontend_h 792 474 793 #include "InspectorValues.h"794 475 #include <PlatformString.h> 795 476 #include <wtf/PassRefPtr.h> … … 797 478 namespace WebCore { 798 479 480 class InspectorArray; 799 481 class InspectorFrontendChannel; 482 class InspectorObject; 800 483 801 484 typedef String ErrorString; 802 803 namespace TypeBuilder {804 ${typeBuilders}805 } // namespace TypeBuilder806 485 807 486 class InspectorFrontend { … … 819 498 """) 820 499 821 backend_h = string.Template(file_header_ + 822 """#ifndef InspectorBackendDispatcher_h 500 backend_h = string.Template("""// Copyright (c) 2011 The Chromium Authors. All rights reserved. 501 // Use of this source code is governed by a BSD-style license that can be 502 // found in the LICENSE file. 503 #ifndef InspectorBackendDispatcher_h 823 504 #define InspectorBackendDispatcher_h 824 505 … … 890 571 """) 891 572 892 backend_cpp = string.Template(file_header_ + 893 """ 573 backend_cpp = string.Template("""// Copyright (c) 2011 The Chromium Authors. All rights reserved. 574 // Use of this source code is governed by a BSD-style license that can be 575 // found in the LICENSE file. 576 894 577 895 578 #include "config.h" … … 1219 902 """) 1220 903 1221 frontend_cpp = string.Template(file_header_ + 1222 """ 904 frontend_cpp = string.Template("""// Copyright (c) 2011 The Chromium Authors. All rights reserved. 905 // Use of this source code is governed by a BSD-style license that can be 906 // found in the LICENSE file. 907 1223 908 1224 909 #include "config.h" … … 1247 932 """) 1248 933 1249 backend_js = string.Template(file_header_ + 1250 """ 934 backend_js = string.Template("""// Copyright (c) 2011 The Chromium Authors. All rights reserved. 935 // Use of this source code is governed by a BSD-style license that can be 936 // found in the LICENSE file. 1251 937 1252 938 $delegates … … 1284 970 backend_include_list = [] 1285 971 frontend_constructor_init_list = [] 1286 type_builder_fragments = []1287 972 1288 973 @staticmethod 1289 974 def go(): 1290 Generator.process_types(type_map)1291 1292 975 for json_domain in json_api["domains"]: 1293 976 domain_name = json_domain["domain"] … … 1473 1156 Generator.backend_js_initializer_list.append("InspectorBackend.registerCommand(\"%s.%s\", [%s], %s);\n" % (domain_name, json_command_name, js_parameters_text, js_reply_list)) 1474 1157 1475 @staticmethod1476 def process_types(type_map):1477 output = Generator.type_builder_fragments1478 1479 class ForwardListener:1480 pass1481 1482 for domain_data in type_map.domains():1483 output.append("namespace ")1484 output.append(domain_data.name())1485 output.append(" {\n")1486 for type_data in domain_data.types():1487 type_data.get_binding().generate_type_builder(output, ForwardListener)1488 1489 output.append("} // ")1490 output.append(domain_data.name())1491 output.append("\n")1492 1493 1158 Generator.go() 1494 1159 … … 1504 1169 frontend_h_file.write(Templates.frontend_h.substitute(None, 1505 1170 fieldDeclarations=join(Generator.frontend_class_field_lines, ""), 1506 domainClassList=join(Generator.frontend_domain_class_lines, ""), 1507 typeBuilders=join(Generator.type_builder_fragments, ""))) 1171 domainClassList=join(Generator.frontend_domain_class_lines, ""))) 1508 1172 1509 1173 backend_h_file.write(Templates.backend_h.substitute(None, -
trunk/Source/WebCore/inspector/InspectorValues.h
r102004 r102005 206 206 const_iterator end() const { return m_data.end(); } 207 207 208 pr otected:208 private: 209 209 InspectorObject(); 210 211 private:212 210 Dictionary m_data; 213 211 Vector<String> m_order;
Note: See TracChangeset
for help on using the changeset viewer.