Index: third_party/inspector_protocol/CodeGenerator.py |
diff --git a/third_party/inspector_protocol/CodeGenerator.py b/third_party/inspector_protocol/CodeGenerator.py |
index 5589a453bed6c9ef99f626f4b3cfc3a01eb1bcec..082675d90648b99a013786d426323aa5f161ca6a 100644 |
--- a/third_party/inspector_protocol/CodeGenerator.py |
+++ b/third_party/inspector_protocol/CodeGenerator.py |
@@ -8,6 +8,7 @@ import optparse |
import collections |
import functools |
import re |
+import copy |
try: |
import json |
except ImportError: |
@@ -205,33 +206,33 @@ def calculate_imports_and_exports(config, protocol): |
protocol.imported_domains.append(domain) |
-def create_imported_type_definition(domain_name, type, imported_namespace): |
+def create_imported_type_definition(domain_name, type_id, imported_namespace): |
# pylint: disable=W0622 |
return { |
- "return_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, domain_name, type["id"]), |
- "pass_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, domain_name, type["id"]), |
+ "return_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, domain_name, type_id), |
+ "pass_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, domain_name, type_id), |
"to_raw_type": "%s.get()", |
"to_pass_type": "std::move(%s)", |
"to_rvalue": "std::move(%s)", |
- "type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, domain_name, type["id"]), |
- "raw_type": "%s::%s::API::%s" % (imported_namespace, domain_name, type["id"]), |
- "raw_pass_type": "%s::%s::API::%s*" % (imported_namespace, domain_name, type["id"]), |
- "raw_return_type": "%s::%s::API::%s*" % (imported_namespace, domain_name, type["id"]), |
+ "type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, domain_name, type_id), |
+ "raw_type": "%s::%s::API::%s" % (imported_namespace, domain_name, type_id), |
+ "raw_pass_type": "%s::%s::API::%s*" % (imported_namespace, domain_name, type_id), |
+ "raw_return_type": "%s::%s::API::%s*" % (imported_namespace, domain_name, type_id), |
} |
-def create_user_type_definition(domain_name, type): |
+def create_user_type_definition(domain_name, type_id): |
# pylint: disable=W0622 |
return { |
- "return_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["id"]), |
- "pass_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["id"]), |
+ "return_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type_id), |
+ "pass_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type_id), |
"to_raw_type": "%s.get()", |
"to_pass_type": "std::move(%s)", |
"to_rvalue": "std::move(%s)", |
- "type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["id"]), |
- "raw_type": "protocol::%s::%s" % (domain_name, type["id"]), |
- "raw_pass_type": "protocol::%s::%s*" % (domain_name, type["id"]), |
- "raw_return_type": "protocol::%s::%s*" % (domain_name, type["id"]), |
+ "type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type_id), |
+ "raw_type": "protocol::%s::%s" % (domain_name, type_id), |
+ "raw_pass_type": "protocol::%s::%s*" % (domain_name, type_id), |
+ "raw_return_type": "protocol::%s::%s*" % (domain_name, type_id), |
} |
@@ -336,14 +337,12 @@ def create_type_definitions(protocol, imported_namespace): |
protocol.type_definitions["any"] = create_any_type_definition() |
for domain in protocol.json_api["domains"]: |
protocol.type_definitions[domain["domain"] + ".string"] = create_string_type_definition() |
- if not ("types" in domain): |
- continue |
- for type in domain["types"]: |
+ for type in domain["types"] if "types" in domain else []: |
dgozman
2016/11/21 22:29:16
Advanced python right here!
|
type_name = domain["domain"] + "." + type["id"] |
if type["type"] == "object" and domain["domain"] in protocol.imported_domains: |
- protocol.type_definitions[type_name] = create_imported_type_definition(domain["domain"], type, imported_namespace) |
+ protocol.type_definitions[type_name] = create_imported_type_definition(domain["domain"], type["id"], imported_namespace) |
elif type["type"] == "object": |
- protocol.type_definitions[type_name] = create_user_type_definition(domain["domain"], type) |
+ protocol.type_definitions[type_name] = create_user_type_definition(domain["domain"], type["id"]) |
elif type["type"] == "array": |
items_type = type["items"]["type"] |
protocol.type_definitions[type_name] = wrap_array_definition(protocol.type_definitions[items_type]) |
@@ -351,7 +350,13 @@ def create_type_definitions(protocol, imported_namespace): |
protocol.type_definitions[type_name] = create_string_type_definition() |
else: |
protocol.type_definitions[type_name] = create_primitive_type_definition(type["type"]) |
- |
+ for event in domain["events"] if "events" in domain else []: |
+ type_id = to_title_case(event["name"]) + "Notification" |
+ type_name = domain["domain"] + "." + type_id |
+ if domain["domain"] in protocol.imported_domains: |
+ protocol.type_definitions[type_name] = create_imported_type_definition(domain["domain"], type_id, imported_namespace) |
+ else: |
+ protocol.type_definitions[type_name] = create_user_type_definition(domain["domain"], type_id) |
def type_definition(protocol, name): |
return protocol.type_definitions[name] |
@@ -501,6 +506,18 @@ def main(): |
for domain in protocol.json_api["domains"]: |
class_name = domain["domain"] |
+ if "events" in domain: |
+ for event in domain["events"]: |
+ event_type = dict() |
+ event_type["description"] = "Wrapper for notification params" |
+ event_type["type"] = "object" |
+ event_type["id"] = to_title_case(event["name"]) + "Notification" |
+ if "parameters" in event: |
+ event_type["properties"] = copy.deepcopy(event["parameters"]) |
+ if "types" not in domain: |
+ domain["types"] = list() |
+ domain["types"].append(event_type) |
+ |
template_context = { |
"config": config, |
"domain": domain, |