Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: Source/core/inspector/CodeGeneratorInspector.py

Issue 558593003: DevTools: Code clean up in CodeGeneratorInspector.py (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 Google Inc. All rights reserved. 2 # Copyright (c) 2011 Google Inc. All rights reserved.
3 # Copyright (c) 2012 Intel Corporation. All rights reserved. 3 # Copyright (c) 2012 Intel Corporation. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 array_pos = array_pos_end - 1 153 array_pos = array_pos_end - 1
154 array_pos += 1 154 array_pos += 1
155 return output 155 return output
156 156
157 ABBREVIATION = frozenset(["XHR", "DOM", "CSS"]) 157 ABBREVIATION = frozenset(["XHR", "DOM", "CSS"])
158 158
159 VALIDATOR_IFDEF_NAME = "ENABLE(ASSERT)" 159 VALIDATOR_IFDEF_NAME = "ENABLE(ASSERT)"
160 160
161 161
162 class DomainNameFixes: 162 class DomainNameFixes:
163 @classmethod 163 @staticmethod
164 def get_fixed_data(cls, domain_name): 164 def get_fixed_data(domain_name):
165 field_name_res = Capitalizer.upper_camel_case_to_lower(domain_name) + "A gent" 165 return Capitalizer.upper_camel_case_to_lower(domain_name) + "Agent"
166
167 class Res(object):
168 agent_field_name = field_name_res
169
170 return Res
171
172 166
173 class RawTypes(object): 167 class RawTypes(object):
174 @staticmethod 168 @staticmethod
175 def get(json_type): 169 def get(json_type):
176 if json_type == "boolean": 170 if json_type == "boolean":
177 return RawTypes.Bool 171 return RawTypes.Bool
178 elif json_type == "string": 172 elif json_type == "string":
179 return RawTypes.String 173 return RawTypes.String
180 elif json_type == "array": 174 elif json_type == "array":
181 return RawTypes.Array 175 return RawTypes.Array
(...skipping 22 matching lines...) Expand all
204 class ByReference: 198 class ByReference:
205 @staticmethod 199 @staticmethod
206 def get_argument_prefix(): 200 def get_argument_prefix():
207 return "" 201 return ""
208 202
209 @staticmethod 203 @staticmethod
210 def get_parameter_type_suffix(): 204 def get_parameter_type_suffix():
211 return "&" 205 return "&"
212 206
213 class BaseType(object): 207 class BaseType(object):
214 need_internal_runtime_cast_ = False
215
216 @classmethod
217 def request_raw_internal_runtime_cast(cls):
218 if not cls.need_internal_runtime_cast_:
219 cls.need_internal_runtime_cast_ = True
220
221 @classmethod 208 @classmethod
222 def get_raw_validator_call_text(cls): 209 def get_raw_validator_call_text(cls):
223 return "RuntimeCastHelper::assertType<JSONValue::Type%s>" % cls.get_ validate_method_params().template_type 210 return "RuntimeCastHelper::assertType<JSONValue::Type%s>" % cls.get_ getter_name()
224 211
225 @staticmethod 212 @staticmethod
226 def get_validate_method_params(): 213 def get_getter_name():
227 raise Exception("Abstract method") 214 raise Exception("Unsupported")
228 215
229 class String(BaseType): 216 class String(BaseType):
230 @staticmethod 217 @staticmethod
231 def get_getter_name(): 218 def get_getter_name():
232 return "String" 219 return "String"
233 220
234 get_setter_name = get_getter_name 221 get_setter_name = get_getter_name
235 222
236 @staticmethod 223 @staticmethod
237 def get_constructor_pattern(): 224 def get_constructor_pattern():
238 return "InspectorString::create(%s)" 225 return "InspectorString::create(%s)"
239 226
240 @staticmethod 227 @staticmethod
241 def get_c_initializer():
242 return "\"\""
243
244 @staticmethod
245 def get_validate_method_params():
246 class ValidateMethodParams:
247 template_type = "String"
248 return ValidateMethodParams
249
250 @staticmethod
251 def get_output_pass_model(): 228 def get_output_pass_model():
252 return RawTypes.OutputPassModel.ByPointer 229 return RawTypes.OutputPassModel.ByPointer
253 230
254 @staticmethod 231 @staticmethod
255 def is_heavy_value(): 232 def is_heavy_value():
256 return True 233 return True
257 234
258 @staticmethod 235 @staticmethod
259 def get_array_item_raw_c_type_text(): 236 def get_array_item_raw_c_type_text():
260 return "String" 237 return "String"
261 238
262 @staticmethod 239 @staticmethod
263 def get_raw_type_model(): 240 def get_raw_type_model():
264 return TypeModel.String 241 return TypeModel.String
265 242
266 class Int(BaseType): 243 class Int(BaseType):
267 @staticmethod 244 @staticmethod
268 def get_getter_name(): 245 def get_getter_name():
269 return "Int" 246 return "Int"
270 247
271 @staticmethod 248 @staticmethod
272 def get_setter_name(): 249 def get_setter_name():
273 return "Number" 250 return "Number"
274 251
275 @staticmethod 252 @staticmethod
276 def get_constructor_pattern(): 253 def get_constructor_pattern():
277 return "InspectorBasicValue::create(%s)" 254 return "InspectorBasicValue::create(%s)"
278 255
279 @staticmethod
280 def get_c_initializer():
281 return "0"
282
283 @classmethod 256 @classmethod
284 def get_raw_validator_call_text(cls): 257 def get_raw_validator_call_text(cls):
285 return "RuntimeCastHelper::assertInt" 258 return "RuntimeCastHelper::assertInt"
286 259
287 @staticmethod 260 @staticmethod
288 def get_output_pass_model(): 261 def get_output_pass_model():
289 return RawTypes.OutputPassModel.ByPointer 262 return RawTypes.OutputPassModel.ByPointer
290 263
291 @staticmethod 264 @staticmethod
292 def is_heavy_value(): 265 def is_heavy_value():
(...skipping 14 matching lines...) Expand all
307 280
308 @staticmethod 281 @staticmethod
309 def get_setter_name(): 282 def get_setter_name():
310 return "Number" 283 return "Number"
311 284
312 @staticmethod 285 @staticmethod
313 def get_constructor_pattern(): 286 def get_constructor_pattern():
314 return "InspectorBasicValue::create(%s)" 287 return "InspectorBasicValue::create(%s)"
315 288
316 @staticmethod 289 @staticmethod
317 def get_c_initializer(): 290 def get_raw_validator_call_text():
318 return "0" 291 return "RuntimeCastHelper::assertType<JSONValue::TypeNumber>"
319
320 @staticmethod
321 def get_validate_method_params():
322 class ValidateMethodParams:
323 template_type = "Number"
324 return ValidateMethodParams
325 292
326 @staticmethod 293 @staticmethod
327 def get_output_pass_model(): 294 def get_output_pass_model():
328 return RawTypes.OutputPassModel.ByPointer 295 return RawTypes.OutputPassModel.ByPointer
329 296
330 @staticmethod 297 @staticmethod
331 def is_heavy_value(): 298 def is_heavy_value():
332 return False 299 return False
333 300
334 @staticmethod 301 @staticmethod
335 def get_array_item_raw_c_type_text(): 302 def get_array_item_raw_c_type_text():
336 return "double" 303 return "double"
337 304
338 @staticmethod 305 @staticmethod
339 def get_raw_type_model(): 306 def get_raw_type_model():
340 return TypeModel.Number 307 return TypeModel.Number
341 308
342 class Bool(BaseType): 309 class Bool(BaseType):
343 @staticmethod 310 @staticmethod
344 def get_getter_name(): 311 def get_getter_name():
345 return "Boolean" 312 return "Boolean"
346 313
347 get_setter_name = get_getter_name 314 get_setter_name = get_getter_name
348 315
349 @staticmethod 316 @staticmethod
350 def get_constructor_pattern(): 317 def get_constructor_pattern():
351 return "InspectorBasicValue::create(%s)" 318 return "InspectorBasicValue::create(%s)"
352 319
353 @staticmethod 320 @staticmethod
354 def get_c_initializer():
355 return "false"
356
357 @staticmethod
358 def get_validate_method_params():
359 class ValidateMethodParams:
360 template_type = "Boolean"
361 return ValidateMethodParams
362
363 @staticmethod
364 def get_output_pass_model(): 321 def get_output_pass_model():
365 return RawTypes.OutputPassModel.ByPointer 322 return RawTypes.OutputPassModel.ByPointer
366 323
367 @staticmethod 324 @staticmethod
368 def is_heavy_value(): 325 def is_heavy_value():
369 return False 326 return False
370 327
371 @staticmethod 328 @staticmethod
372 def get_array_item_raw_c_type_text(): 329 def get_array_item_raw_c_type_text():
373 return "bool" 330 return "bool"
374 331
375 @staticmethod 332 @staticmethod
376 def get_raw_type_model(): 333 def get_raw_type_model():
377 return TypeModel.Bool 334 return TypeModel.Bool
378 335
379 class Object(BaseType): 336 class Object(BaseType):
380 @staticmethod 337 @staticmethod
381 def get_getter_name(): 338 def get_getter_name():
382 return "Object" 339 return "Object"
383 340
384 @staticmethod 341 @staticmethod
385 def get_setter_name(): 342 def get_setter_name():
386 return "Value" 343 return "Value"
387 344
388 @staticmethod 345 @staticmethod
389 def get_constructor_pattern(): 346 def get_constructor_pattern():
390 return "%s" 347 return "%s"
391 348
392 @staticmethod 349 @staticmethod
393 def get_c_initializer():
394 return "JSONObject::create()"
395
396 @staticmethod
397 def get_output_argument_prefix(): 350 def get_output_argument_prefix():
398 return "" 351 return ""
399 352
400 @staticmethod 353 @staticmethod
401 def get_validate_method_params():
402 class ValidateMethodParams:
403 template_type = "Object"
404 return ValidateMethodParams
405
406 @staticmethod
407 def get_output_pass_model(): 354 def get_output_pass_model():
408 return RawTypes.OutputPassModel.ByReference 355 return RawTypes.OutputPassModel.ByReference
409 356
410 @staticmethod 357 @staticmethod
411 def is_heavy_value(): 358 def is_heavy_value():
412 return True 359 return True
413 360
414 @staticmethod 361 @staticmethod
415 def get_array_item_raw_c_type_text(): 362 def get_array_item_raw_c_type_text():
416 return "JSONObject" 363 return "JSONObject"
417 364
418 @staticmethod 365 @staticmethod
419 def get_raw_type_model(): 366 def get_raw_type_model():
420 return TypeModel.Object 367 return TypeModel.Object
421 368
422 class Any(BaseType): 369 class Any(BaseType):
423 @staticmethod 370 @staticmethod
424 def get_getter_name(): 371 def get_getter_name():
425 return "Value" 372 return "Value"
426 373
427 get_setter_name = get_getter_name 374 get_setter_name = get_getter_name
428 375
429 @staticmethod 376 @staticmethod
430 def get_c_initializer():
431 raise Exception("Unsupported")
432
433 @staticmethod
434 def get_constructor_pattern(): 377 def get_constructor_pattern():
435 raise Exception("Unsupported") 378 raise Exception("Unsupported")
436 379
437 @staticmethod 380 @staticmethod
438 def get_raw_validator_call_text(): 381 def get_raw_validator_call_text():
439 return "RuntimeCastHelper::assertAny" 382 return "RuntimeCastHelper::assertAny"
440 383
441 @staticmethod 384 @staticmethod
442 def get_output_pass_model(): 385 def get_output_pass_model():
443 return RawTypes.OutputPassModel.ByReference 386 return RawTypes.OutputPassModel.ByReference
(...skipping 17 matching lines...) Expand all
461 404
462 @staticmethod 405 @staticmethod
463 def get_setter_name(): 406 def get_setter_name():
464 return "Value" 407 return "Value"
465 408
466 @staticmethod 409 @staticmethod
467 def get_constructor_pattern(): 410 def get_constructor_pattern():
468 return "%s" 411 return "%s"
469 412
470 @staticmethod 413 @staticmethod
471 def get_c_initializer():
472 return "JSONArray::create()"
473
474 @staticmethod
475 def get_output_argument_prefix(): 414 def get_output_argument_prefix():
476 return "" 415 return ""
477 416
478 @staticmethod 417 @staticmethod
479 def get_validate_method_params():
480 class ValidateMethodParams:
481 template_type = "Array"
482 return ValidateMethodParams
483
484 @staticmethod
485 def get_output_pass_model(): 418 def get_output_pass_model():
486 return RawTypes.OutputPassModel.ByReference 419 return RawTypes.OutputPassModel.ByReference
487 420
488 @staticmethod 421 @staticmethod
489 def is_heavy_value(): 422 def is_heavy_value():
490 return True 423 return True
491 424
492 @staticmethod 425 @staticmethod
493 def get_array_item_raw_c_type_text(): 426 def get_array_item_raw_c_type_text():
494 return "JSONArray" 427 return "JSONArray"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 parts = str.split('\n') 680 parts = str.split('\n')
748 self.append(parts[0]) 681 self.append(parts[0])
749 for p in parts[1:]: 682 for p in parts[1:]:
750 self.output.append('\n') 683 self.output.append('\n')
751 if p: 684 if p:
752 self.newline(p) 685 self.newline(p)
753 686
754 def get_indent(self): 687 def get_indent(self):
755 return self.indent 688 return self.indent
756 689
757 def get_indented(self, additional_indent):
758 return Writer(self.output, self.indent + additional_indent)
759
760 def insert_writer(self, additional_indent): 690 def insert_writer(self, additional_indent):
761 new_output = [] 691 new_output = []
762 self.output.append(new_output) 692 self.output.append(new_output)
763 return Writer(new_output, self.indent + additional_indent) 693 return Writer(new_output, self.indent + additional_indent)
764 694
765 695
766 class EnumConstants: 696 class EnumConstants:
767 map_ = {} 697 map_ = {}
768 constants_ = [] 698 constants_ = []
769 699
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 if request: 782 if request:
853 cls.need_user_runtime_cast_ = True 783 cls.need_user_runtime_cast_ = True
854 request.acknowledge() 784 request.acknowledge()
855 785
856 @classmethod 786 @classmethod
857 def request_internal_runtime_cast(cls): 787 def request_internal_runtime_cast(cls):
858 cls.need_internal_runtime_cast_ = True 788 cls.need_internal_runtime_cast_ = True
859 789
860 @classmethod 790 @classmethod
861 def get_code_generator(enum_binding_cls): 791 def get_code_generator(enum_binding_cls):
862 #FIXME: generate ad-hoc enums too once we figure out how to better implement them in C++.
863 comment_out = helper.is_ad_hoc
864 792
865 class CodeGenerator: 793 class CodeGenerator:
866 @staticmethod 794 @staticmethod
867 def generate_type_builder(writer, generate_context): 795 def generate_type_builder(writer, generate_context):
868 enum = json_typable["enum"] 796 enum = json_typable["enum"]
869 helper.write_doc(writer) 797 helper.write_doc(writer)
870 enum_name = fixed_type_name.class_name 798 enum_name = fixed_type_name.class_name
871 fixed_type_name.output_comment(writer) 799 fixed_type_name.output_comment(writer)
872 writer.newline("struct ") 800 writer.newline("struct ")
873 writer.append(enum_name) 801 writer.append(enum_name)
(...skipping 15 matching lines...) Expand all
889 if enum_binding_cls.need_user_runtime_cast_: 817 if enum_binding_cls.need_user_runtime_cast_:
890 raise Exception("Not yet implemented") 818 raise Exception("Not yet implemented")
891 819
892 if enum_binding_cls.need_internal_runtime_cast_: 820 if enum_binding_cls.need_internal_runtime_cast_:
893 writer.append("#if %s\n" % VALIDATOR_IFDEF_N AME) 821 writer.append("#if %s\n" % VALIDATOR_IFDEF_N AME)
894 writer.newline(" static void assertCorrec tValue(JSONValue* value);\n") 822 writer.newline(" static void assertCorrec tValue(JSONValue* value);\n")
895 writer.append("#endif // %s\n" % VALIDATOR_ IFDEF_NAME) 823 writer.append("#endif // %s\n" % VALIDATOR_ IFDEF_NAME)
896 824
897 validator_writer = generate_context.validato r_writer 825 validator_writer = generate_context.validato r_writer
898 826
899 domain_fixes = DomainNameFixes.get_fixed_dat a(context_domain_name)
900
901 validator_writer.newline("void %s%s::assertC orrectValue(JSONValue* value)\n" % (helper.full_name_prefix_for_impl, enum_name) ) 827 validator_writer.newline("void %s%s::assertC orrectValue(JSONValue* value)\n" % (helper.full_name_prefix_for_impl, enum_name) )
902 validator_writer.newline("{\n") 828 validator_writer.newline("{\n")
903 validator_writer.newline(" WTF::String s; \n") 829 validator_writer.newline(" WTF::String s; \n")
904 validator_writer.newline(" bool cast_res = value->asString(&s);\n") 830 validator_writer.newline(" bool cast_res = value->asString(&s);\n")
905 validator_writer.newline(" ASSERT(cast_re s);\n") 831 validator_writer.newline(" ASSERT(cast_re s);\n")
906 if len(enum) > 0: 832 if len(enum) > 0:
907 condition_list = [] 833 condition_list = []
908 for enum_item in enum: 834 for enum_item in enum:
909 enum_pos = EnumConstants.add_constan t(enum_item) 835 enum_pos = EnumConstants.add_constan t(enum_item)
910 condition_list.append("s == \"%s\"" % enum_item) 836 condition_list.append("s == \"%s\"" % enum_item)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 @classmethod 922 @classmethod
997 def resolve_inner(cls, resolve_context): 923 def resolve_inner(cls, resolve_context):
998 pass 924 pass
999 925
1000 @staticmethod 926 @staticmethod
1001 def request_user_runtime_cast(request): 927 def request_user_runtime_cast(request):
1002 raise Exception("Unsupported") 928 raise Exception("Unsupported")
1003 929
1004 @staticmethod 930 @staticmethod
1005 def request_internal_runtime_cast(): 931 def request_internal_runtime_cast():
1006 RawTypes.String.request_raw_internal_runtime_cast() 932 pass
1007 933
1008 @staticmethod 934 @staticmethod
1009 def get_code_generator(): 935 def get_code_generator():
1010 class CodeGenerator: 936 class CodeGenerator:
1011 @staticmethod 937 @staticmethod
1012 def generate_type_builder(writer, generate_conte xt): 938 def generate_type_builder(writer, generate_conte xt):
1013 helper.write_doc(writer) 939 helper.write_doc(writer)
1014 fixed_type_name.output_comment(writer) 940 fixed_type_name.output_comment(writer)
1015 writer.newline("typedef String ") 941 writer.newline("typedef String ")
1016 writer.append(fixed_type_name.class_name) 942 writer.append(fixed_type_name.class_name)
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 writer.append_multiline("\n * .set%s (...)" % Capitalizer.lower_camel_case_to_upper(prop_data.p["name"])) 1115 writer.append_multiline("\n * .set%s (...)" % Capitalizer.lower_camel_case_to_upper(prop_data.p["name"]))
1190 writer.append_multiline(";\n */\n") 1116 writer.append_multiline(";\n */\n")
1191 1117
1192 writer.newline_multiline(CodeGeneratorInspectorS trings.class_binding_builder_part_4) 1118 writer.newline_multiline(CodeGeneratorInspectorS trings.class_binding_builder_part_4)
1193 1119
1194 writer.newline(" typedef TypeBuilder::StructI temTraits ItemTraits;\n") 1120 writer.newline(" typedef TypeBuilder::StructI temTraits ItemTraits;\n")
1195 1121
1196 for prop_data in resolve_data.main_properties: 1122 for prop_data in resolve_data.main_properties:
1197 prop_name = prop_data.p["name"] 1123 prop_name = prop_data.p["name"]
1198 param_type_binding = prop_data.param_type_bi nding 1124 param_type_binding = prop_data.param_type_bi nding
1199 raw_type = param_type_binding.reduce_to_raw_ type()
1200 if isinstance(param_type_binding.get_type_mo del(), TypeModel.ValueType): 1125 if isinstance(param_type_binding.get_type_mo del(), TypeModel.ValueType):
1201 writer.append_multiline("\n void %s" % prop_name) 1126 writer.append_multiline("\n void %s" % prop_name)
1202 writer.append("(%s value)\n" % param_typ e_binding.get_type_model().get_command_return_pass_model().get_output_parameter_ type()) 1127 writer.append("(%s value)\n" % param_typ e_binding.get_type_model().get_command_return_pass_model().get_output_parameter_ type())
1203 writer.newline(" {\n") 1128 writer.newline(" {\n")
1204 writer.newline(" JSONObjectBase:: get%s(\"%s\", value);\n" 1129 writer.newline(" JSONObjectBase:: get%s(\"%s\", value);\n"
1205 % (param_type_binding.reduce_to_raw_ type().get_setter_name(), prop_data.p["name"])) 1130 % (param_type_binding.reduce_to_raw_ type().get_setter_name(), prop_data.p["name"]))
1206 writer.newline(" }\n") 1131 writer.newline(" }\n")
1207 1132
1208 for prop_data in resolve_data.optional_propertie s: 1133 for prop_data in resolve_data.optional_propertie s:
1209 prop_name = prop_data.p["name"] 1134 prop_name = prop_data.p["name"]
(...skipping 27 matching lines...) Expand all
1237 1162
1238 if class_binding_cls.need_internal_runtime_cast_ : 1163 if class_binding_cls.need_internal_runtime_cast_ :
1239 writer.append("#if %s\n" % VALIDATOR_IFDEF_N AME) 1164 writer.append("#if %s\n" % VALIDATOR_IFDEF_N AME)
1240 writer.newline(" static void assertCorrec tValue(JSONValue* value);\n") 1165 writer.newline(" static void assertCorrec tValue(JSONValue* value);\n")
1241 writer.append("#endif // %s\n" % VALIDATOR_ IFDEF_NAME) 1166 writer.append("#endif // %s\n" % VALIDATOR_ IFDEF_NAME)
1242 1167
1243 closed_field_set = (context_domain_name + ". " + class_name) not in TYPES_WITH_OPEN_FIELD_LIST_SET 1168 closed_field_set = (context_domain_name + ". " + class_name) not in TYPES_WITH_OPEN_FIELD_LIST_SET
1244 1169
1245 validator_writer = generate_context.validato r_writer 1170 validator_writer = generate_context.validato r_writer
1246 1171
1247 domain_fixes = DomainNameFixes.get_fixed_dat a(context_domain_name)
1248
1249 validator_writer.newline("void %s%s::assertC orrectValue(JSONValue* value)\n" % (helper.full_name_prefix_for_impl, class_name )) 1172 validator_writer.newline("void %s%s::assertC orrectValue(JSONValue* value)\n" % (helper.full_name_prefix_for_impl, class_name ))
1250 validator_writer.newline("{\n") 1173 validator_writer.newline("{\n")
1251 validator_writer.newline(" RefPtr<JSONObj ect> object;\n") 1174 validator_writer.newline(" RefPtr<JSONObj ect> object;\n")
1252 validator_writer.newline(" bool castRes = value->asObject(&object);\n") 1175 validator_writer.newline(" bool castRes = value->asObject(&object);\n")
1253 validator_writer.newline(" ASSERT_UNUSED( castRes, castRes);\n") 1176 validator_writer.newline(" ASSERT_UNUSED( castRes, castRes);\n")
1254 for prop_data in resolve_data.main_propertie s: 1177 for prop_data in resolve_data.main_propertie s:
1255 validator_writer.newline(" {\n") 1178 validator_writer.newline(" {\n")
1256 it_name = "%sPos" % prop_data.p["name"] 1179 it_name = "%sPos" % prop_data.p["name"]
1257 validator_writer.newline(" JSONOb ject::iterator %s;\n" % it_name) 1180 validator_writer.newline(" JSONOb ject::iterator %s;\n" % it_name)
1258 validator_writer.newline(" %s = o bject->find(\"%s\");\n" % (it_name, prop_data.p["name"])) 1181 validator_writer.newline(" %s = o bject->find(\"%s\");\n" % (it_name, prop_data.p["name"]))
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 @classmethod 1285 @classmethod
1363 def resolve_inner(cls, resolve_context): 1286 def resolve_inner(cls, resolve_context):
1364 pass 1287 pass
1365 1288
1366 @staticmethod 1289 @staticmethod
1367 def request_user_runtime_cast(request): 1290 def request_user_runtime_cast(request):
1368 pass 1291 pass
1369 1292
1370 @staticmethod 1293 @staticmethod
1371 def request_internal_runtime_cast(): 1294 def request_internal_runtime_cast():
1372 RawTypes.Object.request_raw_internal_runtime_cast() 1295 pass
1373 1296
1374 @staticmethod 1297 @staticmethod
1375 def get_code_generator(): 1298 def get_code_generator():
1376 pass 1299 pass
1377 1300
1378 @staticmethod 1301 @staticmethod
1379 def get_validator_call_text(): 1302 def get_validator_call_text():
1380 return "RuntimeCastHelper::assertType<JSONValue::TypeObj ect>" 1303 return "RuntimeCastHelper::assertType<JSONValue::TypeObj ect>"
1381 1304
1382 @classmethod 1305 @classmethod
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 def __init__(self, raw_type): 1432 def __init__(self, raw_type):
1510 self.raw_type_ = raw_type 1433 self.raw_type_ = raw_type
1511 1434
1512 def resolve_inner(self, resolve_context): 1435 def resolve_inner(self, resolve_context):
1513 pass 1436 pass
1514 1437
1515 def request_user_runtime_cast(self, request): 1438 def request_user_runtime_cast(self, request):
1516 raise Exception("Unsupported") 1439 raise Exception("Unsupported")
1517 1440
1518 def request_internal_runtime_cast(self): 1441 def request_internal_runtime_cast(self):
1519 self.raw_type_.request_raw_internal_runtime_cast() 1442 pass
1520 1443
1521 def get_code_generator(self): 1444 def get_code_generator(self):
1522 return None 1445 return None
1523 1446
1524 def get_validator_call_text(self): 1447 def get_validator_call_text(self):
1525 return self.raw_type_.get_raw_validator_call_text() 1448 return self.raw_type_.get_raw_validator_call_text()
1526 1449
1527 def get_array_item_c_type_text(self): 1450 def get_array_item_c_type_text(self):
1528 return self.raw_type_.get_array_item_raw_c_type_text() 1451 return self.raw_type_.get_array_item_raw_c_type_text()
1529 1452
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 type_builder_fragments = [] 1719 type_builder_fragments = []
1797 type_builder_forwards = [] 1720 type_builder_forwards = []
1798 validator_impl_list = [] 1721 validator_impl_list = []
1799 type_builder_impl_list = [] 1722 type_builder_impl_list = []
1800 1723
1801 1724
1802 @staticmethod 1725 @staticmethod
1803 def go(): 1726 def go():
1804 Generator.process_types(type_map) 1727 Generator.process_types(type_map)
1805 1728
1806 first_cycle_guardable_list_list = [
1807 Generator.backend_method_declaration_list,
1808 Generator.backend_method_implementation_list,
1809 Generator.backend_method_name_declaration_list,
1810 Generator.backend_method_name_declaration_index_list,
1811 Generator.backend_agent_interface_list,
1812 Generator.frontend_class_field_lines,
1813 Generator.frontend_constructor_init_list,
1814 Generator.frontend_domain_class_lines,
1815 Generator.frontend_method_list,
1816 Generator.method_handler_list,
1817 Generator.method_name_enum_list,
1818 Generator.backend_constructor_init_list,
1819 Generator.backend_virtual_setters_list,
1820 Generator.backend_setters_list,
1821 Generator.backend_field_list]
1822
1823 for json_domain in json_api["domains"]: 1729 for json_domain in json_api["domains"]:
1824 domain_name = json_domain["domain"] 1730 domain_name = json_domain["domain"]
1825 domain_name_lower = domain_name.lower() 1731 domain_name_lower = domain_name.lower()
1826 1732
1827 domain_fixes = DomainNameFixes.get_fixed_data(domain_name) 1733 agent_field_name = DomainNameFixes.get_fixed_data(domain_name)
1828
1829 agent_field_name = domain_fixes.agent_field_name
1830 1734
1831 frontend_method_declaration_lines = [] 1735 frontend_method_declaration_lines = []
1832 1736
1833 if "events" in json_domain: 1737 if "events" in json_domain:
1834 for json_event in json_domain["events"]: 1738 for json_event in json_domain["events"]:
1835 Generator.process_event(json_event, domain_name, frontend_me thod_declaration_lines) 1739 Generator.process_event(json_event, domain_name, frontend_me thod_declaration_lines)
1836 1740
1837 Generator.frontend_class_field_lines.append(" %s m_%s;\n" % (doma in_name, domain_name_lower)) 1741 Generator.frontend_class_field_lines.append(" %s m_%s;\n" % (doma in_name, domain_name_lower))
1838 if Generator.frontend_constructor_init_list: 1742 if Generator.frontend_constructor_init_list:
1839 Generator.frontend_constructor_init_list.append(" , ") 1743 Generator.frontend_constructor_init_list.append(" , ")
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 backend_agent_interface_list = [] if "redirect" in json_command else Gen erator.backend_agent_interface_list 1811 backend_agent_interface_list = [] if "redirect" in json_command else Gen erator.backend_agent_interface_list
1908 1812
1909 ad_hoc_type_output = [] 1813 ad_hoc_type_output = []
1910 backend_agent_interface_list.append(ad_hoc_type_output) 1814 backend_agent_interface_list.append(ad_hoc_type_output)
1911 ad_hoc_type_writer = Writer(ad_hoc_type_output, " ") 1815 ad_hoc_type_writer = Writer(ad_hoc_type_output, " ")
1912 1816
1913 backend_agent_interface_list.append(" virtual void %s(ErrorString *" % json_command_name) 1817 backend_agent_interface_list.append(" virtual void %s(ErrorString *" % json_command_name)
1914 1818
1915 method_in_code = "" 1819 method_in_code = ""
1916 method_out_code = "" 1820 method_out_code = ""
1917 result_object_declaration = ""
1918 agent_call_param_list = ["&error"] 1821 agent_call_param_list = ["&error"]
1919 agent_call_params_declaration_list = [" ErrorString error;"] 1822 agent_call_params_declaration_list = [" ErrorString error;"]
1920 send_response_call_params_list = ["error"] 1823 send_response_call_params_list = ["error"]
1921 request_message_param = "" 1824 request_message_param = ""
1922 normal_response_cook_text = "" 1825 normal_response_cook_text = ""
1923 error_type_binding = None 1826 error_type_binding = None
1924 if "error" in json_command: 1827 if "error" in json_command:
1925 json_error = json_command["error"] 1828 json_error = json_command["error"]
1926 error_type_binding = Generator.resolve_type_and_generate_ad_hoc(json _error, json_command_name + "Error", json_command_name, domain_name, ad_hoc_type _writer, agent_interface_name + "::") 1829 error_type_binding = Generator.resolve_type_and_generate_ad_hoc(json _error, json_command_name + "Error", json_command_name, domain_name, ad_hoc_type _writer, agent_interface_name + "::")
1927 error_type_model = error_type_binding.get_type_model().get_optional( ) 1830 error_type_model = error_type_binding.get_type_model().get_optional( )
(...skipping 12 matching lines...) Expand all
1940 1843
1941 for json_parameter in json_params: 1844 for json_parameter in json_params:
1942 json_param_name = json_parameter["name"] 1845 json_param_name = json_parameter["name"]
1943 param_raw_type = resolve_param_raw_type(json_parameter, domain_n ame) 1846 param_raw_type = resolve_param_raw_type(json_parameter, domain_n ame)
1944 1847
1945 getter_name = param_raw_type.get_getter_name() 1848 getter_name = param_raw_type.get_getter_name()
1946 1849
1947 optional = json_parameter.get("optional") 1850 optional = json_parameter.get("optional")
1948 1851
1949 non_optional_type_model = param_raw_type.get_raw_type_model() 1852 non_optional_type_model = param_raw_type.get_raw_type_model()
1950 if optional:
1951 type_model = non_optional_type_model.get_optional()
1952 else:
1953 type_model = non_optional_type_model
1954 1853
1955 if optional: 1854 if optional:
1956 code = (" bool %s_valueFound = false;\n" 1855 code = (" bool %s_valueFound = false;\n"
1957 " %s in_%s = get%s(paramsContainerPtr, \"%s\", &% s_valueFound, protocolErrors);\n" % 1856 " %s in_%s = get%s(paramsContainerPtr, \"%s\", &% s_valueFound, protocolErrors);\n" %
1958 (json_param_name, non_optional_type_model.get_command _return_pass_model().get_return_var_type(), json_param_name, getter_name, json_p aram_name, json_param_name)) 1857 (json_param_name, non_optional_type_model.get_command _return_pass_model().get_return_var_type(), json_param_name, getter_name, json_p aram_name, json_param_name))
1959 param = "%s_valueFound ? &in_%s : 0" % (json_param_name, jso n_param_name) 1858 param = "%s_valueFound ? &in_%s : 0" % (json_param_name, jso n_param_name)
1960 # FIXME: pass optional refptr-values as PassRefPtr 1859 # FIXME: pass optional refptr-values as PassRefPtr
1961 formal_param_type_pattern = "const %s*" 1860 formal_param_type_pattern = "const %s*"
1962 else: 1861 else:
1963 code = (" %s in_%s = get%s(paramsContainerPtr, \"%s\", 0, protocolErrors);\n" % 1862 code = (" %s in_%s = get%s(paramsContainerPtr, \"%s\", 0, protocolErrors);\n" %
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 for json_return in json_command["returns"]: 1923 for json_return in json_command["returns"]:
2025 1924
2026 json_return_name = json_return["name"] 1925 json_return_name = json_return["name"]
2027 1926
2028 optional = bool(json_return.get("optional")) 1927 optional = bool(json_return.get("optional"))
2029 1928
2030 return_type_binding = Generator.resolve_param_type_and_gener ate_ad_hoc(json_return, json_command_name, domain_name, ad_hoc_type_writer, agen t_interface_name + "::") 1929 return_type_binding = Generator.resolve_param_type_and_gener ate_ad_hoc(json_return, json_command_name, domain_name, ad_hoc_type_writer, agen t_interface_name + "::")
2031 1930
2032 raw_type = return_type_binding.reduce_to_raw_type() 1931 raw_type = return_type_binding.reduce_to_raw_type()
2033 setter_type = raw_type.get_setter_name() 1932 setter_type = raw_type.get_setter_name()
2034 initializer = raw_type.get_c_initializer()
2035 1933
2036 type_model = return_type_binding.get_type_model() 1934 type_model = return_type_binding.get_type_model()
2037 if optional: 1935 if optional:
2038 type_model = type_model.get_optional() 1936 type_model = type_model.get_optional()
2039 1937
2040 code = " %s out_%s;\n" % (type_model.get_command_return_p ass_model().get_return_var_type(), json_return_name) 1938 code = " %s out_%s;\n" % (type_model.get_command_return_p ass_model().get_return_var_type(), json_return_name)
2041 param = "%sout_%s" % (type_model.get_command_return_pass_mod el().get_output_argument_prefix(), json_return_name) 1939 param = "%sout_%s" % (type_model.get_command_return_pass_mod el().get_output_argument_prefix(), json_return_name)
2042 var_name = "out_%s" % json_return_name 1940 var_name = "out_%s" % json_return_name
2043 setter_argument = type_model.get_command_return_pass_model() .get_output_to_raw_expression() % var_name 1941 setter_argument = type_model.get_command_return_pass_model() .get_output_to_raw_expression() % var_name
2044 if return_type_binding.get_setter_value_expression_pattern() : 1942 if return_type_binding.get_setter_value_expression_pattern() :
(...skipping 18 matching lines...) Expand all
2063 agent_call_param_list.append(param) 1961 agent_call_param_list.append(param)
2064 1962
2065 normal_response_cook_text += "".join(response_cook_list) 1963 normal_response_cook_text += "".join(response_cook_list)
2066 1964
2067 if len(normal_response_cook_text) != 0: 1965 if len(normal_response_cook_text) != 0:
2068 normal_response_cook_text = " if (!error.length()) {\n" + normal_response_cook_text + " }" 1966 normal_response_cook_text = " if (!error.length()) {\n" + normal_response_cook_text + " }"
2069 1967
2070 # Redirect to another agent's implementation. 1968 # Redirect to another agent's implementation.
2071 agent_field = "m_" + agent_field_name 1969 agent_field = "m_" + agent_field_name
2072 if "redirect" in json_command: 1970 if "redirect" in json_command:
2073 domain_fixes = DomainNameFixes.get_fixed_data(json_command.get("redi rect")) 1971 agent_field = "m_" + DomainNameFixes.get_fixed_data(json_command.get ("redirect"))
2074 agent_field = "m_" + domain_fixes.agent_field_name
2075 1972
2076 Generator.backend_method_implementation_list.append(Templates.backend_me thod.substitute(None, 1973 Generator.backend_method_implementation_list.append(Templates.backend_me thod.substitute(None,
2077 domainName=domain_name, methodName=json_command_name, 1974 domainName=domain_name, methodName=json_command_name,
2078 agentField=agent_field, 1975 agentField=agent_field,
2079 methodCode="".join([method_in_code, method_out_code]), 1976 methodCode="".join([method_in_code, method_out_code]),
2080 agentCallParamsDeclaration="\n".join(agent_call_params_declaration_l ist), 1977 agentCallParamsDeclaration="\n".join(agent_call_params_declaration_l ist),
2081 agentCallParams=", ".join(agent_call_param_list), 1978 agentCallParams=", ".join(agent_call_param_list),
2082 requestMessageObject=request_message_param, 1979 requestMessageObject=request_message_param,
2083 responseCook=normal_response_cook_text, 1980 responseCook=normal_response_cook_text,
2084 sendResponseCallParams=", ".join(send_response_call_params_list), 1981 sendResponseCallParams=", ".join(send_response_call_params_list),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 def process_types(type_map): 2101 def process_types(type_map):
2205 output = Generator.type_builder_fragments 2102 output = Generator.type_builder_fragments
2206 2103
2207 class GenerateContext: 2104 class GenerateContext:
2208 validator_writer = Writer(Generator.validator_impl_list, "") 2105 validator_writer = Writer(Generator.validator_impl_list, "")
2209 cpp_writer = Writer(Generator.type_builder_impl_list, "") 2106 cpp_writer = Writer(Generator.type_builder_impl_list, "")
2210 2107
2211 def generate_all_domains_code(out, type_data_callback): 2108 def generate_all_domains_code(out, type_data_callback):
2212 writer = Writer(out, "") 2109 writer = Writer(out, "")
2213 for domain_data in type_map.domains(): 2110 for domain_data in type_map.domains():
2214 domain_fixes = DomainNameFixes.get_fixed_data(domain_data.name() )
2215
2216 namespace_declared = [] 2111 namespace_declared = []
2217 2112
2218 def namespace_lazy_generator(): 2113 def namespace_lazy_generator():
2219 if not namespace_declared: 2114 if not namespace_declared:
2220 writer.newline("namespace ") 2115 writer.newline("namespace ")
2221 writer.append(domain_data.name()) 2116 writer.append(domain_data.name())
2222 writer.append(" {\n") 2117 writer.append(" {\n")
2223 # What is a better way to change value from outer scope? 2118 # What is a better way to change value from outer scope?
2224 namespace_declared.append(True) 2119 namespace_declared.append(True)
2225 return writer 2120 return writer
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 validatorIfdefName=VALIDATOR_IFDEF_NAME)) 2250 validatorIfdefName=VALIDATOR_IFDEF_NAME))
2356 2251
2357 backend_h_file.close() 2252 backend_h_file.close()
2358 backend_cpp_file.close() 2253 backend_cpp_file.close()
2359 2254
2360 frontend_h_file.close() 2255 frontend_h_file.close()
2361 frontend_cpp_file.close() 2256 frontend_cpp_file.close()
2362 2257
2363 typebuilder_h_file.close() 2258 typebuilder_h_file.close()
2364 typebuilder_cpp_file.close() 2259 typebuilder_cpp_file.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698