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

Side by Side Diff: lib/html/scripts/systemhtml.py

Issue 11235060: Get rid of Dynamic. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 #!/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 system to generate 6 """This module provides shared functionality for the system to generate
7 Dart:html APIs from the IDL database.""" 7 Dart:html APIs from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 native_return_type = output_conversion.input_type 882 native_return_type = output_conversion.input_type
883 else: 883 else:
884 return_type = self._NarrowInputType(info.type_name) 884 return_type = self._NarrowInputType(info.type_name)
885 native_return_type = return_type 885 native_return_type = return_type
886 886
887 def InputType(type_name): 887 def InputType(type_name):
888 conversion = self._InputConversion(type_name, info.declared_name) 888 conversion = self._InputConversion(type_name, info.declared_name)
889 if conversion: 889 if conversion:
890 return conversion.input_type 890 return conversion.input_type
891 else: 891 else:
892 return self._NarrowInputType(type_name) if type_name else 'Dynamic' 892 return self._NarrowInputType(type_name) if type_name else 'dynamic'
893 893
894 body = self._members_emitter.Emit( 894 body = self._members_emitter.Emit(
895 '\n' 895 '\n'
896 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n' 896 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n'
897 '$!BODY' 897 '$!BODY'
898 ' }\n', 898 ' }\n',
899 MODIFIERS='static ' if info.IsStatic() else '', 899 MODIFIERS='static ' if info.IsStatic() else '',
900 TYPE=return_type, 900 TYPE=return_type,
901 HTML_NAME=html_name, 901 HTML_NAME=html_name,
902 PARAMS=info.ParametersDeclaration(InputType)) 902 PARAMS=info.ParametersDeclaration(InputType))
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 arguments.append(parameter_names[position]) 943 arguments.append(parameter_names[position])
944 param_type = self._NarrowInputType(arg.type.id) 944 param_type = self._NarrowInputType(arg.type.id)
945 # Verified by argument checking on entry to the dispatcher. 945 # Verified by argument checking on entry to the dispatcher.
946 verified_type = InputType(info.param_infos[position].type_id) 946 verified_type = InputType(info.param_infos[position].type_id)
947 947
948 # The native method does not need an argument type if we know the type. 948 # The native method does not need an argument type if we know the type.
949 # But we do need the native methods to have correct function types, so 949 # But we do need the native methods to have correct function types, so
950 # be conservative. 950 # be conservative.
951 if param_type == verified_type: 951 if param_type == verified_type:
952 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']: 952 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']:
953 param_type = 'Dynamic' 953 param_type = 'dynamic'
954 target_parameters.append( 954 target_parameters.append(
955 '%s%s' % (TypeOrNothing(param_type), param_name)) 955 '%s%s' % (TypeOrNothing(param_type), param_name))
956 956
957 argument_list = ', '.join(arguments) 957 argument_list = ', '.join(arguments)
958 # TODO(sra): If the native method has zero type checks, we can 'inline' is 958 # TODO(sra): If the native method has zero type checks, we can 'inline' is
959 # and call it directly with a JS-expression. 959 # and call it directly with a JS-expression.
960 call = '%s(%s)' % (target, argument_list) 960 call = '%s(%s)' % (target, argument_list)
961 961
962 if output_conversion: 962 if output_conversion:
963 call = '%s(%s)' % (output_conversion.function_name, call) 963 call = '%s(%s)' % (output_conversion.function_name, call)
(...skipping 10 matching lines...) Expand all
974 TARGET=target, 974 TARGET=target,
975 PARAMS=', '.join(target_parameters), 975 PARAMS=', '.join(target_parameters),
976 NATIVE=info.declared_name) 976 NATIVE=info.declared_name)
977 977
978 def GenerateChecksAndCall(operation, argument_count): 978 def GenerateChecksAndCall(operation, argument_count):
979 checks = ['!?%s' % name for name in parameter_names] 979 checks = ['!?%s' % name for name in parameter_names]
980 for i in range(0, argument_count): 980 for i in range(0, argument_count):
981 argument = operation.arguments[i] 981 argument = operation.arguments[i]
982 parameter_name = parameter_names[i] 982 parameter_name = parameter_names[i]
983 test_type = self._DartType(argument.type.id) 983 test_type = self._DartType(argument.type.id)
984 if test_type in ['Dynamic', 'Object']: 984 if test_type in ['dynamic', 'Object']:
985 checks[i] = '?%s' % parameter_name 985 checks[i] = '?%s' % parameter_name
986 elif test_type == parameter_types[i]: 986 elif test_type == parameter_types[i]:
987 checks[i] = 'true' 987 checks[i] = 'true'
988 else: 988 else:
989 checks[i] = '(%s is %s || %s == null)' % ( 989 checks[i] = '(%s is %s || %s == null)' % (
990 parameter_name, test_type, parameter_name) 990 parameter_name, test_type, parameter_name)
991 # There can be multiple presence checks. We need them all since a later 991 # There can be multiple presence checks. We need them all since a later
992 # optional argument could have been passed by name, leaving 'holes'. 992 # optional argument could have been passed by name, leaving 'holes'.
993 GenerateCall(operation, argument_count, checks) 993 GenerateCall(operation, argument_count, checks)
994 994
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 1116
1117 library_emitter = self._multiemitter.FileEmitter(library_file_path) 1117 library_emitter = self._multiemitter.FileEmitter(library_file_path)
1118 library_file_dir = os.path.dirname(library_file_path) 1118 library_file_dir = os.path.dirname(library_file_path)
1119 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) 1119 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
1120 imports_emitter = library_emitter.Emit( 1120 imports_emitter = library_emitter.Emit(
1121 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) 1121 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir))
1122 for path in sorted(self._path_to_emitter.keys()): 1122 for path in sorted(self._path_to_emitter.keys()):
1123 relpath = os.path.relpath(path, library_file_dir) 1123 relpath = os.path.relpath(path, library_file_dir)
1124 imports_emitter.Emit( 1124 imports_emitter.Emit(
1125 "#source('$PATH');\n", PATH=massage_path(relpath)) 1125 "#source('$PATH');\n", PATH=massage_path(relpath))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698