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

Side by Side Diff: lib/dom/scripts/systemnative.py

Issue 10741002: Replace 'NativeTraits' typedef with 'isNode', 'isActive', and 'isEventTarget' static boolean fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 | lib/dom/templates/dom/native/cpp_header.template » ('j') | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 ' static Dart_Handle toDart(NativeType* value);\n') 414 ' static Dart_Handle toDart(NativeType* value);\n')
415 else: 415 else:
416 to_dart_emitter.Emit( 416 to_dart_emitter.Emit(
417 ' static Dart_Handle toDart(NativeType* value)\n' 417 ' static Dart_Handle toDart(NativeType* value)\n'
418 ' {\n' 418 ' {\n'
419 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 419 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n'
420 ' }\n', 420 ' }\n',
421 INTERFACE=self._interface.id) 421 INTERFACE=self._interface.id)
422 422
423 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes()) 423 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes())
424 wrapper_type = _DOMWrapperType(self._database, self._interface) 424
425 is_node_checker = lambda interface: interface.id == 'Node'
Anton Muhin 2012/07/09 15:22:43 nit: _test instead of _checker?
podivilov 2012/07/10 10:51:13 Done.
426 is_active_checker = lambda interface: 'ActiveDOMObject' in interface.ext_att rs
427 is_event_target_checker = lambda interface: 'EventTarget' in interface.ext_a ttrs
428 def TypeCheckHelper(checker):
429 return 'true' if _FindInHierarchy(self._database, self._interface, checker ) else 'false'
430
425 self._cpp_header_emitter.Emit( 431 self._cpp_header_emitter.Emit(
426 self._system._templates.Load('cpp_header.template'), 432 self._system._templates.Load('cpp_header.template'),
427 INTERFACE=self._interface.id, 433 INTERFACE=self._interface.id,
428 WEBCORE_INCLUDES=webcore_includes, 434 WEBCORE_INCLUDES=webcore_includes,
429 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 435 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
430 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), 436 DECLARATIONS=self._cpp_declarations_emitter.Fragments(),
431 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type, 437 IS_NODE=TypeCheckHelper(is_node_checker),
438 IS_ACTIVE=TypeCheckHelper(is_active_checker),
439 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_checker),
432 TO_NATIVE=to_native_emitter.Fragments(), 440 TO_NATIVE=to_native_emitter.Fragments(),
433 TO_DART=to_dart_emitter.Fragments()) 441 TO_DART=to_dart_emitter.Fragments())
434 442
435 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum ents): 443 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum ents):
436 if 'CallWith' not in node.ext_attrs: 444 if 'CallWith' not in node.ext_attrs:
437 return False 445 return False
438 446
439 call_with = node.ext_attrs['CallWith'] 447 call_with = node.ext_attrs['CallWith']
440 if call_with == 'ScriptExecutionContext': 448 if call_with == 'ScriptExecutionContext':
441 parameter_definitions_emitter.Emit( 449 parameter_definitions_emitter.Emit(
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 arguments.insert(0, 'receiver') 943 arguments.insert(0, 'receiver')
936 self._cpp_impl_includes.add('"%s.h"' % attributes['ImplementedBy']) 944 self._cpp_impl_includes.add('"%s.h"' % attributes['ImplementedBy'])
937 945
938 return emitter.Format(invocation_template, 946 return emitter.Format(invocation_template,
939 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) 947 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
940 948
941 949
942 def _GenerateCPPIncludes(includes): 950 def _GenerateCPPIncludes(includes):
943 return ''.join(['#include %s\n' % include for include in sorted(includes)]) 951 return ''.join(['#include %s\n' % include for include in sorted(includes)])
944 952
945 def _DOMWrapperType(database, interface): 953 def _FindInHierarchy(database, interface, checker):
Anton Muhin 2012/07/09 15:22:43 ditto for test
podivilov 2012/07/10 10:51:13 Done.
946 if interface.id == 'MessagePort': 954 if checker(interface):
947 return 'MessagePort' 955 return interface
948
949 type = 'Object'
950 def is_node(interface):
951 return interface.id == 'Node'
952 if is_node(interface) or _FindParent(interface, database, is_node):
953 type = 'Node'
954 if 'ActiveDOMObject' in interface.ext_attrs:
955 type = 'Active%s' % type
956 return type
957
958 def _FindParent(interface, database, callback):
959 for parent in interface.parents: 956 for parent in interface.parents:
960 parent_name = parent.type.id 957 parent_name = parent.type.id
961 if not database.HasInterface(parent.type.id): 958 if not database.HasInterface(parent.type.id):
962 continue 959 continue
963 parent_interface = database.GetInterface(parent.type.id) 960 parent_interface = database.GetInterface(parent.type.id)
964 if callback(parent_interface): 961 parent_interface = _FindInHierarchy(database, parent_interface, checker)
965 return parent_interface
966 parent_interface = _FindParent(parent_interface, database, callback)
967 if parent_interface: 962 if parent_interface:
968 return parent_interface 963 return parent_interface
969 964
970 def _IsArgumentOptionalInWebCore(argument): 965 def _IsArgumentOptionalInWebCore(argument):
971 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 966 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
972 967
973 def _ToWebKitName(name): 968 def _ToWebKitName(name):
974 name = name[0].lower() + name[1:] 969 name = name[0].lower() + name[1:]
975 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 970 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
976 name) 971 name)
977 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 972 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
978 name) 973 name)
OLDNEW
« no previous file with comments | « no previous file | lib/dom/templates/dom/native/cpp_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698