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

Side by Side Diff: Source/bindings/dart/scripts/dart_interface.py

Issue 469373002: Bindings generation emits (more) correct null checking (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Adding in fixes to binding generation Created 6 years, 4 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
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 'idl_type_object': argument.idl_type, 830 'idl_type_object': argument.idl_type,
831 'preprocessed_type': argument.idl_type.preprocessed_type, 831 'preprocessed_type': argument.idl_type.preprocessed_type,
832 } 832 }
833 833
834 834
835 # [Constructor] 835 # [Constructor]
836 def generate_constructor(interface, constructor): 836 def generate_constructor(interface, constructor):
837 return { 837 return {
838 'argument_list': constructor_argument_list(interface, constructor), 838 'argument_list': constructor_argument_list(interface, constructor),
839 # TODO(terry): Use dart_methods.generate_argument instead constructor_ar gument. 839 # TODO(terry): Use dart_methods.generate_argument instead constructor_ar gument.
840 'arguments': [constructor_argument(argument, index) 840 'arguments': [constructor_argument(interface, argument, index)
841 for index, argument in enumerate(constructor.arguments)], 841 for index, argument in enumerate(constructor.arguments)],
842 'has_exception_state': 842 'has_exception_state':
843 # [RaisesException=Constructor] 843 # [RaisesException=Constructor]
844 interface.extended_attributes.get('RaisesException') == 'Constructor ' or 844 interface.extended_attributes.get('RaisesException') == 'Constructor ' or
845 any(argument for argument in constructor.arguments 845 any(argument for argument in constructor.arguments
846 if argument.idl_type.name == 'SerializedScriptValue' or 846 if argument.idl_type.name == 'SerializedScriptValue' or
847 argument.idl_type.is_integer_type), 847 argument.idl_type.is_integer_type),
848 'is_constructor': True, 848 'is_constructor': True,
849 'auto_scope': 'true', 849 'auto_scope': 'true',
850 'is_auto_scope': True, 850 'is_auto_scope': True,
(...skipping 27 matching lines...) Expand all
878 878
879 # [RaisesException=Constructor] 879 # [RaisesException=Constructor]
880 if interface.extended_attributes.get('RaisesException') == 'Constructor': 880 if interface.extended_attributes.get('RaisesException') == 'Constructor':
881 arguments.append('es') 881 arguments.append('es')
882 882
883 return arguments 883 return arguments
884 884
885 885
886 # TODO(terry): Eliminate this function use dart_methods.generate_argument instea d 886 # TODO(terry): Eliminate this function use dart_methods.generate_argument instea d
887 # for all constructor arguments. 887 # for all constructor arguments.
888 def constructor_argument(argument, index): 888 def constructor_argument(interface, argument, index):
889 idl_type = argument.idl_type 889 idl_type = argument.idl_type
890 default_value = str(argument.default_value) if argument.default_value else N one 890 default_value = str(argument.default_value) if argument.default_value else N one
891 891
892 argument_content = { 892 argument_content = {
893 'cpp_type': idl_type.cpp_type_args(), 893 'cpp_type': idl_type.cpp_type_args(),
894 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u sed_as_argument=True), 894 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u sed_as_argument=True),
895 # FIXME: check that the default value's type is compatible with the argu ment's 895 # FIXME: check that the default value's type is compatible with the argu ment's
896 'default_value': default_value, 896 'default_value': default_value,
897 # FIXME: remove once [Default] removed and just use argument.default_val ue 897 # FIXME: remove once [Default] removed and just use argument.default_val ue
898 'has_default': 'Default' in argument.extended_attributes or default_valu e, 898 'has_default': 'Default' in argument.extended_attributes or default_valu e,
899 'idl_type_object': idl_type, 899 'idl_type_object': idl_type,
900 'preprocessed_type': idl_type.preprocessed_type, 900 'preprocessed_type': idl_type.preprocessed_type,
901 # Dictionary is special-cased, but arrays and sequences shouldn't be 901 # Dictionary is special-cased, but arrays and sequences shouldn't be
902 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 902 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type,
903 'index': index, 903 'index': index,
904 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type, 904 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type,
905 'is_optional': argument.is_optional, 905 'is_optional': argument.is_optional,
906 'is_strict_type_checking': False, # Required for overload resolution 906 'is_strict_type_checking': False, # Required for overload resolution
907 'name': argument.name, 907 'name': argument.name,
908 'dart_value_to_local_cpp_value': dart_methods.dart_value_to_local_cpp_va lue(argument, index), 908 'dart_value_to_local_cpp_value': dart_methods.dart_value_to_local_cpp_va lue(interface, argument, index),
909 } 909 }
910 return argument_content 910 return argument_content
911 911
912 912
913 def generate_constructor_overloads(constructors): 913 def generate_constructor_overloads(constructors):
914 if len(constructors) <= 1: 914 if len(constructors) <= 1:
915 return 915 return
916 for overload_index, constructor in enumerate(constructors): 916 for overload_index, constructor in enumerate(constructors):
917 constructor.update({ 917 constructor.update({
918 'overload_index': overload_index + 1, 918 'overload_index': overload_index + 1,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 'is_null_expression': is_null_expression(idl_type), 999 'is_null_expression': is_null_expression(idl_type),
1000 'is_raises_exception': is_raises_exception, 1000 'is_raises_exception': is_raises_exception,
1001 'name': DartUtilities.cpp_name(getter), 1001 'name': DartUtilities.cpp_name(getter),
1002 'union_arguments': union_arguments, 1002 'union_arguments': union_arguments,
1003 'dart_set_return_value': idl_type.dart_set_return_value('result', 1003 'dart_set_return_value': idl_type.dart_set_return_value('result',
1004 extended_attribu tes=extended_attributes, 1004 extended_attribu tes=extended_attributes,
1005 script_wrappable ='receiver', 1005 script_wrappable ='receiver',
1006 release=idl_type .release)} 1006 release=idl_type .release)}
1007 1007
1008 1008
1009 def property_setter(setter): 1009 def property_setter(interface, setter):
1010 idl_type = setter.arguments[1].idl_type 1010 idl_type = setter.arguments[1].idl_type
1011 extended_attributes = setter.extended_attributes 1011 extended_attributes = setter.extended_attributes
1012 interface_extended_attributes = interface.extended_attributes
1012 is_raises_exception = 'RaisesException' in extended_attributes 1013 is_raises_exception = 'RaisesException' in extended_attributes
1013 return { 1014 return {
1014 'has_strict_type_checking': 1015 'has_strict_type_checking':
1015 'StrictTypeChecking' in extended_attributes and 1016 'StrictTypeChecking' in extended_attributes and
1016 idl_type.is_wrapper_type, 1017 idl_type.is_wrapper_type,
1017 'idl_type': idl_type.base_type, 1018 'idl_type': idl_type.base_type,
1018 'is_custom': 'Custom' in extended_attributes, 1019 'is_custom': 'Custom' in extended_attributes,
1019 'has_exception_state': is_raises_exception or 1020 'has_exception_state': is_raises_exception or
1020 idl_type.is_integer_type, 1021 idl_type.is_integer_type,
1021 'is_raises_exception': is_raises_exception, 1022 'is_raises_exception': is_raises_exception,
1022 'name': DartUtilities.cpp_name(setter), 1023 'name': DartUtilities.cpp_name(setter),
1023 'dart_value_to_local_cpp_value': idl_type.dart_value_to_local_cpp_value( 1024 'dart_value_to_local_cpp_value': idl_type.dart_value_to_local_cpp_value(
1024 extended_attributes, 'propertyValue', False), 1025 interface_extended_attributes, extended_attributes, 'propertyValue', False),
1025 } 1026 }
1026 1027
1027 1028
1028 def property_deleter(deleter): 1029 def property_deleter(deleter):
1029 idl_type = deleter.idl_type 1030 idl_type = deleter.idl_type
1030 if str(idl_type) != 'boolean': 1031 if str(idl_type) != 'boolean':
1031 raise Exception( 1032 raise Exception(
1032 'Only deleters with boolean type are allowed, but type is "%s"' % 1033 'Only deleters with boolean type are allowed, but type is "%s"' %
1033 idl_type) 1034 idl_type)
1034 extended_attributes = deleter.extended_attributes 1035 extended_attributes = deleter.extended_attributes
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1, ARG_TYPE ARG2) 1069 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1, ARG_TYPE ARG2)
1069 setter = next( 1070 setter = next(
1070 method 1071 method
1071 for method in interface.operations 1072 for method in interface.operations
1072 if ('setter' in method.specials and 1073 if ('setter' in method.specials and
1073 len(method.arguments) == 2 and 1074 len(method.arguments) == 2 and
1074 str(method.arguments[0].idl_type) == 'unsigned long')) 1075 str(method.arguments[0].idl_type) == 'unsigned long'))
1075 except StopIteration: 1076 except StopIteration:
1076 return None 1077 return None
1077 1078
1078 return property_setter(setter) 1079 return property_setter(interface, setter)
1079 1080
1080 1081
1081 def indexed_property_deleter(interface): 1082 def indexed_property_deleter(interface):
1082 try: 1083 try:
1083 # Find indexed property deleter, if present; has form: 1084 # Find indexed property deleter, if present; has form:
1084 # deleter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG) 1085 # deleter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG)
1085 deleter = next( 1086 deleter = next(
1086 method 1087 method
1087 for method in interface.operations 1088 for method in interface.operations
1088 if ('deleter' in method.specials and 1089 if ('deleter' in method.specials and
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1, ARG_TYPE ARG2 ) 1123 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1, ARG_TYPE ARG2 )
1123 setter = next( 1124 setter = next(
1124 method 1125 method
1125 for method in interface.operations 1126 for method in interface.operations
1126 if ('setter' in method.specials and 1127 if ('setter' in method.specials and
1127 len(method.arguments) == 2 and 1128 len(method.arguments) == 2 and
1128 str(method.arguments[0].idl_type) == 'DOMString')) 1129 str(method.arguments[0].idl_type) == 'DOMString'))
1129 except StopIteration: 1130 except StopIteration:
1130 return None 1131 return None
1131 1132
1132 return property_setter(setter) 1133 return property_setter(interface, setter)
1133 1134
1134 1135
1135 def named_property_deleter(interface): 1136 def named_property_deleter(interface):
1136 try: 1137 try:
1137 # Find named property deleter, if present; has form: 1138 # Find named property deleter, if present; has form:
1138 # deleter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG) 1139 # deleter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG)
1139 deleter = next( 1140 deleter = next(
1140 method 1141 method
1141 for method in interface.operations 1142 for method in interface.operations
1142 if ('deleter' in method.specials and 1143 if ('deleter' in method.specials and
1143 len(method.arguments) == 1 and 1144 len(method.arguments) == 1 and
1144 str(method.arguments[0].idl_type) == 'DOMString')) 1145 str(method.arguments[0].idl_type) == 'DOMString'))
1145 except StopIteration: 1146 except StopIteration:
1146 return None 1147 return None
1147 1148
1148 return property_deleter(deleter) 1149 return property_deleter(deleter)
OLDNEW
« no previous file with comments | « Source/bindings/dart/scripts/dart_attributes.py ('k') | Source/bindings/dart/scripts/dart_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698