| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, 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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 lib_template -- template file in this directory for generated lib file. | 417 lib_template -- template file in this directory for generated lib file. |
| 418 """ | 418 """ |
| 419 | 419 |
| 420 self._emitters = multiemitter.MultiEmitter() | 420 self._emitters = multiemitter.MultiEmitter() |
| 421 self._database = database | 421 self._database = database |
| 422 self._output_dir = output_dir | 422 self._output_dir = output_dir |
| 423 | 423 |
| 424 self._ComputeInheritanceClosure() | 424 self._ComputeInheritanceClosure() |
| 425 | 425 |
| 426 interface_system = WrappingInterfacesSystem( | 426 interface_system = WrappingInterfacesSystem( |
| 427 TemplateLoader('../templates', ['dom/interface', 'dom', '']), |
| 427 self._database, self._emitters, self._output_dir) | 428 self._database, self._emitters, self._output_dir) |
| 428 | 429 |
| 429 wrapping_system = WrappingImplementationSystem( | 430 wrapping_system = WrappingImplementationSystem( |
| 431 TemplateLoader('../templates', ['dom/wrapping', 'dom', '']), |
| 430 self._database, self._emitters, self._output_dir) | 432 self._database, self._emitters, self._output_dir) |
| 431 | 433 |
| 432 # Makes wrapper implementations available for listing in interface lib. | 434 # Makes wrapper implementations available for listing in interface lib. |
| 433 interface_system._implementation_system = wrapping_system | 435 interface_system._implementation_system = wrapping_system |
| 434 | 436 |
| 435 frog_system = FrogSystem( | 437 frog_system = FrogSystem( |
| 438 TemplateLoader('../templates', ['dom/frog', 'dom', '']), |
| 436 self._database, self._emitters, self._output_dir) | 439 self._database, self._emitters, self._output_dir) |
| 437 | 440 |
| 438 self._systems = [interface_system, | 441 self._systems = [interface_system, |
| 439 wrapping_system, | 442 wrapping_system, |
| 440 frog_system] | 443 frog_system] |
| 441 | 444 |
| 442 # Render all interfaces into Dart and save them in files. | 445 # Render all interfaces into Dart and save them in files. |
| 443 for interface in database.GetInterfaces(): | 446 for interface in database.GetInterfaces(): |
| 444 | 447 |
| 445 super_interface = None | 448 super_interface = None |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 info.declared_name = operations[0].id | 681 info.declared_name = operations[0].id |
| 679 info.name = operations[0].ext_attrs.get('DartName', info.declared_name) | 682 info.name = operations[0].ext_attrs.get('DartName', info.declared_name) |
| 680 info.js_name = info.declared_name | 683 info.js_name = info.declared_name |
| 681 info.type_name = operations[0].type.id # TODO: widen. | 684 info.type_name = operations[0].type.id # TODO: widen. |
| 682 info.arg_interface_declaration = FormatArgs(args, True) | 685 info.arg_interface_declaration = FormatArgs(args, True) |
| 683 info.arg_implementation_declaration = FormatArgs(args, False) | 686 info.arg_implementation_declaration = FormatArgs(args, False) |
| 684 info.arg_infos = args | 687 info.arg_infos = args |
| 685 return info | 688 return info |
| 686 | 689 |
| 687 | 690 |
| 688 def GenerateOldLibFile(self, lib_template, lib_file_path, file_paths): | |
| 689 """Generates a lib file from a template and a list of files.""" | |
| 690 # Generate the .lib file. | |
| 691 if lib_file_path: | |
| 692 # Load template. | |
| 693 template = ''.join(open(lib_template).readlines()) | |
| 694 lib_file_contents = self._emitters.FileEmitter(lib_file_path) | |
| 695 | |
| 696 # Emit the list of path names. | |
| 697 list_emitter = lib_file_contents.Emit(template) | |
| 698 lib_file_dir = os.path.dirname(lib_file_path) | |
| 699 for path in sorted(file_paths): | |
| 700 relpath = os.path.relpath(path, lib_file_dir) | |
| 701 list_emitter.Emit("\n '$PATH',", PATH=relpath) | |
| 702 | |
| 703 def GenerateLibFile(self, lib_template, lib_file_path, file_paths): | |
| 704 """Generates a lib file from a template and a list of files.""" | |
| 705 # Load template. | |
| 706 template = ''.join(open(lib_template).readlines()) | |
| 707 # Generate the .lib file. | |
| 708 lib_file_contents = self._emitters.FileEmitter(lib_file_path) | |
| 709 | |
| 710 # Emit the list of #source directives. | |
| 711 list_emitter = lib_file_contents.Emit(template) | |
| 712 lib_file_dir = os.path.dirname(lib_file_path) | |
| 713 for path in sorted(file_paths): | |
| 714 relpath = os.path.relpath(path, lib_file_dir) | |
| 715 list_emitter.Emit("#source('$PATH');\n", PATH=relpath) | |
| 716 | |
| 717 | |
| 718 def Flush(self): | 691 def Flush(self): |
| 719 """Write out all pending files.""" | 692 """Write out all pending files.""" |
| 720 _logger.info('Flush...') | 693 _logger.info('Flush...') |
| 721 self._emitters.Flush() | 694 self._emitters.Flush() |
| 722 | 695 |
| 723 | 696 |
| 724 def FilePathForDartInterface(self, interface_name): | 697 def FilePathForDartInterface(self, interface_name): |
| 725 """Returns the file path of the Dart interface definition.""" | 698 """Returns the file path of the Dart interface definition.""" |
| 726 return os.path.join(self._output_dir, 'src', 'interface', | 699 return os.path.join(self._output_dir, 'src', 'interface', |
| 727 '%s.dart' % interface_name) | 700 '%s.dart' % interface_name) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 """Format lines of text with indent.""" | 854 """Format lines of text with indent.""" |
| 882 def FormatLine(line): | 855 def FormatLine(line): |
| 883 if line.strip(): | 856 if line.strip(): |
| 884 return '%s%s\n' % (indent, line) | 857 return '%s%s\n' % (indent, line) |
| 885 else: | 858 else: |
| 886 return '\n' | 859 return '\n' |
| 887 return ''.join(FormatLine(line) for line in text.split('\n')) | 860 return ''.join(FormatLine(line) for line in text.split('\n')) |
| 888 | 861 |
| 889 # ------------------------------------------------------------------------------ | 862 # ------------------------------------------------------------------------------ |
| 890 | 863 |
| 864 class TemplateLoader(object): |
| 865 """Loads template files from a path.""" |
| 866 |
| 867 def __init__(self, root, subpaths): |
| 868 """Initializes loader. |
| 869 |
| 870 Args: |
| 871 root - a string, the directory under which the templates are stored. |
| 872 subpaths - a list of strings, subpaths of root in search order. |
| 873 """ |
| 874 self._root = root |
| 875 self._subpaths = subpaths |
| 876 self._cache = {} |
| 877 |
| 878 def TryLoad(self, name): |
| 879 """Returns content of template file as a string, or None of not found.""" |
| 880 if name in self._cache: |
| 881 return self._cache[name] |
| 882 |
| 883 for subpath in self._subpaths: |
| 884 template_file = os.path.join(self._root, subpath, name) |
| 885 if os.path.exists(template_file): |
| 886 template = ''.join(open(template_file).readlines()) |
| 887 self._cache[name] = template |
| 888 return template |
| 889 |
| 890 return None |
| 891 |
| 892 def Load(self, name): |
| 893 """Returns contents of template file as a string, or raises an exception.""" |
| 894 template = self.TryLoad(name) |
| 895 if template is not None: # Can be empty string |
| 896 return template |
| 897 raise Exception("Could not find template '%s' on %s / %s" % ( |
| 898 name, self._root, self._subpaths)) |
| 899 |
| 900 |
| 901 # ------------------------------------------------------------------------------ |
| 902 |
| 891 class System(object): | 903 class System(object): |
| 892 """Generates all the files for one implementation.""" | 904 """Generates all the files for one implementation.""" |
| 893 | 905 |
| 894 def __init__(self, database, emitters, output_dir): | 906 def __init__(self, templates, database, emitters, output_dir): |
| 907 self._templates = templates |
| 895 self._database = database | 908 self._database = database |
| 896 self._emitters = emitters | 909 self._emitters = emitters |
| 897 self._output_dir = output_dir | 910 self._output_dir = output_dir |
| 898 self._dart_callback_file_paths = [] | 911 self._dart_callback_file_paths = [] |
| 899 | 912 |
| 900 def InterfaceGenerator(self, | 913 def InterfaceGenerator(self, |
| 901 interface, | 914 interface, |
| 902 common_prefix, | 915 common_prefix, |
| 903 super_interface_name, | 916 super_interface_name, |
| 904 source_filter): | 917 source_filter): |
| 905 """Returns an interface generator for |interface|.""" | 918 """Returns an interface generator for |interface|.""" |
| 906 return None | 919 return None |
| 907 | 920 |
| 908 def ProcessCallback(self, interface, info): | 921 def ProcessCallback(self, interface, info): |
| 909 pass | 922 pass |
| 910 | 923 |
| 911 def GenerateLibraries(self, lib_dir): | 924 def GenerateLibraries(self, lib_dir): |
| 912 pass | 925 pass |
| 913 | 926 |
| 914 def Finish(self): | 927 def Finish(self): |
| 915 pass | 928 pass |
| 916 | 929 |
| 917 | 930 |
| 918 def _ProcessCallback(self, interface, info, file_path): | 931 def _ProcessCallback(self, interface, info, file_path): |
| 919 """Generates a typedef for the callback interface.""" | 932 """Generates a typedef for the callback interface.""" |
| 920 self._dart_callback_file_paths.append(file_path) | 933 self._dart_callback_file_paths.append(file_path) |
| 921 code = self._emitters.FileEmitter(file_path) | 934 code = self._emitters.FileEmitter(file_path) |
| 922 | 935 |
| 923 template_file = 'template_callback.darttemplate' | 936 code.Emit(self._templates.Load('callback.darttemplate')) |
| 924 code.Emit(''.join(open(template_file).readlines())) | |
| 925 code.Emit('typedef $TYPE $NAME($ARGS);\n', | 937 code.Emit('typedef $TYPE $NAME($ARGS);\n', |
| 926 NAME=interface.id, | 938 NAME=interface.id, |
| 927 TYPE=info.type_name, | 939 TYPE=info.type_name, |
| 928 ARGS=info.arg_implementation_declaration) | 940 ARGS=info.arg_implementation_declaration) |
| 929 | 941 |
| 930 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths): | 942 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths): |
| 931 """Generates a lib file from a template and a list of files.""" | 943 """Generates a lib file from a template and a list of files.""" |
| 932 # Load template. | 944 # Load template. |
| 933 template = ''.join(open(lib_template).readlines()) | 945 template = self._templates.Load(lib_template) |
| 934 # Generate the .lib file. | 946 # Generate the .lib file. |
| 935 lib_file_contents = self._emitters.FileEmitter(lib_file_path) | 947 lib_file_contents = self._emitters.FileEmitter(lib_file_path) |
| 936 | 948 |
| 937 # Emit the list of #source directives. | 949 # Emit the list of #source directives. |
| 938 list_emitter = lib_file_contents.Emit(template) | 950 list_emitter = lib_file_contents.Emit(template) |
| 939 lib_file_dir = os.path.dirname(lib_file_path) | 951 lib_file_dir = os.path.dirname(lib_file_path) |
| 940 for path in sorted(file_paths): | 952 for path in sorted(file_paths): |
| 941 relpath = os.path.relpath(path, lib_file_dir) | 953 relpath = os.path.relpath(path, lib_file_dir) |
| 942 list_emitter.Emit("#source('$PATH');\n", PATH=relpath) | 954 list_emitter.Emit("#source('$PATH');\n", PATH=relpath) |
| 943 | 955 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 962 | 974 |
| 963 result = set() | 975 result = set() |
| 964 WalkParentChain(interface) | 976 WalkParentChain(interface) |
| 965 return result; | 977 return result; |
| 966 | 978 |
| 967 | 979 |
| 968 # ------------------------------------------------------------------------------ | 980 # ------------------------------------------------------------------------------ |
| 969 | 981 |
| 970 class WrappingInterfacesSystem(System): | 982 class WrappingInterfacesSystem(System): |
| 971 | 983 |
| 972 def __init__(self, database, emitters, output_dir): | 984 def __init__(self, templates, database, emitters, output_dir): |
| 973 super(WrappingInterfacesSystem, self).__init__( | 985 super(WrappingInterfacesSystem, self).__init__( |
| 974 database, emitters, output_dir) | 986 templates, database, emitters, output_dir) |
| 975 self._dart_interface_file_paths = [] | 987 self._dart_interface_file_paths = [] |
| 976 | 988 |
| 977 | 989 |
| 978 def InterfaceGenerator(self, | 990 def InterfaceGenerator(self, |
| 979 interface, | 991 interface, |
| 980 common_prefix, | 992 common_prefix, |
| 981 super_interface_name, | 993 super_interface_name, |
| 982 source_filter): | 994 source_filter): |
| 983 """.""" | 995 """.""" |
| 984 interface_name = interface.id | 996 interface_name = interface.id |
| 985 dart_interface_file_path = self._FilePathForDartInterface(interface_name) | 997 dart_interface_file_path = self._FilePathForDartInterface(interface_name) |
| 986 | 998 |
| 987 self._dart_interface_file_paths.append(dart_interface_file_path) | 999 self._dart_interface_file_paths.append(dart_interface_file_path) |
| 988 | 1000 |
| 989 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) | 1001 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| 990 | 1002 |
| 991 template_file = 'template_interface_%s.darttemplate' % interface_name | 1003 template_file = 'interface_%s.darttemplate' % interface_name |
| 992 if not os.path.exists(template_file): | 1004 template = self._templates.TryLoad(template_file) |
| 993 template_file = 'template_interface.darttemplate' | 1005 if not template: |
| 994 template = ''.join(open(template_file).readlines()) | 1006 template = self._templates.Load('interface.darttemplate') |
| 995 | 1007 |
| 996 return DartInterfaceGenerator( | 1008 return DartInterfaceGenerator( |
| 997 interface, dart_interface_code, | 1009 interface, dart_interface_code, |
| 998 template, | 1010 template, |
| 999 common_prefix, super_interface_name, | 1011 common_prefix, super_interface_name, |
| 1000 source_filter) | 1012 source_filter) |
| 1001 | 1013 |
| 1002 def ProcessCallback(self, interface, info): | 1014 def ProcessCallback(self, interface, info): |
| 1003 """Generates a typedef for the callback interface.""" | 1015 """Generates a typedef for the callback interface.""" |
| 1004 interface_name = interface.id | 1016 interface_name = interface.id |
| 1005 file_path = self._FilePathForDartInterface(interface_name) | 1017 file_path = self._FilePathForDartInterface(interface_name) |
| 1006 self._ProcessCallback(interface, info, file_path) | 1018 self._ProcessCallback(interface, info, file_path) |
| 1007 | 1019 |
| 1008 def GenerateLibraries(self, lib_dir): | 1020 def GenerateLibraries(self, lib_dir): |
| 1009 # Library generated for implementation. | 1021 # Library generated for implementation. |
| 1010 self._GenerateLibFile( | 1022 self._GenerateLibFile( |
| 1011 'template_wrapping_dom.darttemplate', | 1023 'wrapping_dom.darttemplate', |
| 1012 os.path.join(lib_dir, 'wrapping_dom.dart'), | 1024 os.path.join(lib_dir, 'wrapping_dom.dart'), |
| 1013 (self._dart_interface_file_paths + | 1025 (self._dart_interface_file_paths + |
| 1014 self._dart_callback_file_paths + | 1026 self._dart_callback_file_paths + |
| 1015 # FIXME: Move the implementation to a separate | 1027 # FIXME: Move the implementation to a separate |
| 1016 # library. | 1028 # library. |
| 1017 self._implementation_system._dart_wrapping_file_paths | 1029 self._implementation_system._dart_wrapping_file_paths |
| 1018 )) | 1030 )) |
| 1019 | 1031 |
| 1020 | 1032 |
| 1021 def _FilePathForDartInterface(self, interface_name): | 1033 def _FilePathForDartInterface(self, interface_name): |
| 1022 """Returns the file path of the Dart interface definition.""" | 1034 """Returns the file path of the Dart interface definition.""" |
| 1023 return os.path.join(self._output_dir, 'src', 'interface', | 1035 return os.path.join(self._output_dir, 'src', 'interface', |
| 1024 '%s.dart' % interface_name) | 1036 '%s.dart' % interface_name) |
| 1025 | 1037 |
| 1026 | 1038 |
| 1027 # ------------------------------------------------------------------------------ | 1039 # ------------------------------------------------------------------------------ |
| 1028 | 1040 |
| 1029 class WrappingImplementationSystem(System): | 1041 class WrappingImplementationSystem(System): |
| 1030 | 1042 |
| 1031 def __init__(self, database, emitters, output_dir): | 1043 def __init__(self, templates, database, emitters, output_dir): |
| 1032 """Prepared for generating wrapping implementation. | 1044 """Prepared for generating wrapping implementation. |
| 1033 | 1045 |
| 1034 - Creates emitter for JS code. | 1046 - Creates emitter for JS code. |
| 1035 - Creates emitter for Dart code. | 1047 - Creates emitter for Dart code. |
| 1036 """ | 1048 """ |
| 1037 super(WrappingImplementationSystem, self).__init__( | 1049 super(WrappingImplementationSystem, self).__init__( |
| 1038 database, emitters, output_dir) | 1050 templates, database, emitters, output_dir) |
| 1039 self._dart_wrapping_file_paths = [] | 1051 self._dart_wrapping_file_paths = [] |
| 1040 | 1052 |
| 1041 js_file_name = os.path.join(output_dir, 'wrapping_dom.js') | 1053 js_file_name = os.path.join(output_dir, 'wrapping_dom.js') |
| 1042 code = self._emitters.FileEmitter(js_file_name) | 1054 code = self._emitters.FileEmitter(js_file_name) |
| 1043 template = ''.join(open('template_wrapping_dom.js').readlines()) | 1055 template = self._templates.Load('wrapping_dom.js') |
| 1044 (self._wrapping_js_natives, | 1056 (self._wrapping_js_natives, |
| 1045 self._wrapping_map) = code.Emit(template) | 1057 self._wrapping_map) = code.Emit(template) |
| 1046 | 1058 |
| 1047 _logger.info('Started Generating %s' % js_file_name) | 1059 _logger.info('Started Generating %s' % js_file_name) |
| 1048 | 1060 |
| 1049 # Set of (interface, name, kind), kind is 'attribute' or 'operation'. | 1061 # Set of (interface, name, kind), kind is 'attribute' or 'operation'. |
| 1050 self._wrapping_externs = set() | 1062 self._wrapping_externs = set() |
| 1051 | 1063 |
| 1052 | 1064 |
| 1053 def InterfaceGenerator(self, | 1065 def InterfaceGenerator(self, |
| 1054 interface, | 1066 interface, |
| 1055 common_prefix, | 1067 common_prefix, |
| 1056 super_interface_name, | 1068 super_interface_name, |
| 1057 source_filter): | 1069 source_filter): |
| 1058 """.""" | 1070 """.""" |
| 1059 interface_name = interface.id | 1071 interface_name = interface.id |
| 1060 dart_wrapping_file_path = self._FilePathForDartWrappingImpl(interface_name) | 1072 dart_wrapping_file_path = self._FilePathForDartWrappingImpl(interface_name) |
| 1061 | 1073 |
| 1062 self._dart_wrapping_file_paths.append(dart_wrapping_file_path) | 1074 self._dart_wrapping_file_paths.append(dart_wrapping_file_path) |
| 1063 | 1075 |
| 1064 dart_code = self._emitters.FileEmitter(dart_wrapping_file_path) | 1076 dart_code = self._emitters.FileEmitter(dart_wrapping_file_path) |
| 1065 dart_code.Emit( | 1077 dart_code.Emit(self._templates.Load('wrapping_impl.darttemplate')) |
| 1066 ''.join(open('template_wrapping_impl.darttemplate').readlines())) | |
| 1067 return WrappingInterfaceGenerator(interface, super_interface_name, | 1078 return WrappingInterfaceGenerator(interface, super_interface_name, |
| 1068 dart_code, self._wrapping_js_natives, | 1079 dart_code, self._wrapping_js_natives, |
| 1069 self._wrapping_map, | 1080 self._wrapping_map, |
| 1070 self._wrapping_externs, | 1081 self._wrapping_externs, |
| 1071 self._BaseDefines(interface)) | 1082 self._BaseDefines(interface)) |
| 1072 | 1083 |
| 1073 def ProcessCallback(self, interface, info): | 1084 def ProcessCallback(self, interface, info): |
| 1074 pass | 1085 pass |
| 1075 | 1086 |
| 1076 def GenerateLibraries(self, lib_dir): | 1087 def GenerateLibraries(self, lib_dir): |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1088 def _GenerateJavaScriptExternsWrapping(self, database, output_dir): | 1099 def _GenerateJavaScriptExternsWrapping(self, database, output_dir): |
| 1089 """Generates a JavaScript externs file. | 1100 """Generates a JavaScript externs file. |
| 1090 | 1101 |
| 1091 Generates an externs file that is consistent with generated JavaScript code | 1102 Generates an externs file that is consistent with generated JavaScript code |
| 1092 and Dart APIs for the wrapping implementation. | 1103 and Dart APIs for the wrapping implementation. |
| 1093 """ | 1104 """ |
| 1094 externs_file_name = os.path.join(output_dir, 'wrapping_dom_externs.js') | 1105 externs_file_name = os.path.join(output_dir, 'wrapping_dom_externs.js') |
| 1095 code = self._emitters.FileEmitter(externs_file_name) | 1106 code = self._emitters.FileEmitter(externs_file_name) |
| 1096 _logger.info('Started generating %s' % externs_file_name) | 1107 _logger.info('Started generating %s' % externs_file_name) |
| 1097 | 1108 |
| 1098 template = ''.join(open('template_wrapping_dom_externs.js').readlines()) | 1109 template = self._templates.Load('wrapping_dom_externs.js') |
| 1099 namespace = 'dom_externs' | 1110 namespace = 'dom_externs' |
| 1100 members = code.Emit(template, NAMESPACE=namespace) | 1111 members = code.Emit(template, NAMESPACE=namespace) |
| 1101 | 1112 |
| 1102 # TODO: Filter out externs that are known to the JavaScript back-end. Some | 1113 # TODO: Filter out externs that are known to the JavaScript back-end. Some |
| 1103 # of the known externs have useful declarations like @nosideeffects that | 1114 # of the known externs have useful declarations like @nosideeffects that |
| 1104 # might improve back-end analysis. | 1115 # might improve back-end analysis. |
| 1105 | 1116 |
| 1106 names = dict() # maps name to (interface, kind) | 1117 names = dict() # maps name to (interface, kind) |
| 1107 for (interface, name, kind) in self._wrapping_externs: | 1118 for (interface, name, kind) in self._wrapping_externs: |
| 1108 if name not in _javascript_keywords: | 1119 if name not in _javascript_keywords: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1122 for (interface, kind) in sorted(names[name]): | 1133 for (interface, kind) in sorted(names[name]): |
| 1123 members.Emit('$SEP $KIND $INTERFACE.$NAME', | 1134 members.Emit('$SEP $KIND $INTERFACE.$NAME', |
| 1124 NAME=name, INTERFACE=interface, KIND=kind, SEP=separator) | 1135 NAME=name, INTERFACE=interface, KIND=kind, SEP=separator) |
| 1125 separator = ',' | 1136 separator = ',' |
| 1126 members.Emit('\n') | 1137 members.Emit('\n') |
| 1127 | 1138 |
| 1128 # ------------------------------------------------------------------------------ | 1139 # ------------------------------------------------------------------------------ |
| 1129 | 1140 |
| 1130 class FrogSystem(System): | 1141 class FrogSystem(System): |
| 1131 | 1142 |
| 1132 def __init__(self, database, emitters, output_dir): | 1143 def __init__(self, templates, database, emitters, output_dir): |
| 1133 super(FrogSystem, self).__init__(database, emitters, output_dir) | 1144 super(FrogSystem, self).__init__( |
| 1145 templates, database, emitters, output_dir) |
| 1134 self._dart_frog_file_paths = [] | 1146 self._dart_frog_file_paths = [] |
| 1135 | 1147 |
| 1136 def InterfaceGenerator(self, | 1148 def InterfaceGenerator(self, |
| 1137 interface, | 1149 interface, |
| 1138 common_prefix, | 1150 common_prefix, |
| 1139 super_interface_name, | 1151 super_interface_name, |
| 1140 source_filter): | 1152 source_filter): |
| 1141 """.""" | 1153 """.""" |
| 1142 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) | 1154 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) |
| 1143 | 1155 |
| 1144 self._dart_frog_file_paths.append(dart_frog_file_path) | 1156 self._dart_frog_file_paths.append(dart_frog_file_path) |
| 1145 | 1157 |
| 1146 dart_code = self._emitters.FileEmitter(dart_frog_file_path) | 1158 dart_code = self._emitters.FileEmitter(dart_frog_file_path) |
| 1147 dart_code.Emit( | 1159 dart_code.Emit(self._templates.Load('frog_impl.darttemplate')) |
| 1148 ''.join(open('template_frog_impl.darttemplate').readlines())) | |
| 1149 return FrogInterfaceGenerator(interface, super_interface_name, | 1160 return FrogInterfaceGenerator(interface, super_interface_name, |
| 1150 dart_code) | 1161 dart_code) |
| 1151 | 1162 |
| 1152 def ProcessCallback(self, interface, info): | 1163 def ProcessCallback(self, interface, info): |
| 1153 """Generates a typedef for the callback interface.""" | 1164 """Generates a typedef for the callback interface.""" |
| 1154 file_path = self._FilePathForFrogImpl(interface.id) | 1165 file_path = self._FilePathForFrogImpl(interface.id) |
| 1155 self._ProcessCallback(interface, info, file_path) | 1166 self._ProcessCallback(interface, info, file_path) |
| 1156 | 1167 |
| 1157 def GenerateLibraries(self, lib_dir): | 1168 def GenerateLibraries(self, lib_dir): |
| 1158 self._GenerateLibFile( | 1169 self._GenerateLibFile( |
| 1159 'template_frog_dom.darttemplate', | 1170 'frog_dom.darttemplate', |
| 1160 os.path.join(lib_dir, 'dom_frog.dart'), | 1171 os.path.join(lib_dir, 'dom_frog.dart'), |
| 1161 self._dart_frog_file_paths + | 1172 self._dart_frog_file_paths + |
| 1162 self._dart_callback_file_paths) | 1173 self._dart_callback_file_paths) |
| 1163 | 1174 |
| 1164 def Finish(self): | 1175 def Finish(self): |
| 1165 pass | 1176 pass |
| 1166 | 1177 |
| 1167 def _FilePathForFrogImpl(self, interface_name): | 1178 def _FilePathForFrogImpl(self, interface_name): |
| 1168 """Returns the file path of the Frog implementation.""" | 1179 """Returns the file path of the Frog implementation.""" |
| 1169 return os.path.join(self._output_dir, 'src', 'frog', | 1180 return os.path.join(self._output_dir, 'src', 'frog', |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 '$!FALSE' | 1827 '$!FALSE' |
| 1817 '$(INDENT)}\n', | 1828 '$(INDENT)}\n', |
| 1818 COND=test, INDENT=indent) | 1829 COND=test, INDENT=indent) |
| 1819 fallthrough1 = self.GenerateDispatch( | 1830 fallthrough1 = self.GenerateDispatch( |
| 1820 true_code, info, indent + ' ', position + 1, positive) | 1831 true_code, info, indent + ' ', position + 1, positive) |
| 1821 fallthrough2 = self.GenerateDispatch( | 1832 fallthrough2 = self.GenerateDispatch( |
| 1822 false_code, info, indent + ' ', position, negative) | 1833 false_code, info, indent + ' ', position, negative) |
| 1823 return fallthrough1 or fallthrough2 | 1834 return fallthrough1 or fallthrough2 |
| 1824 | 1835 |
| 1825 if negative: | 1836 if negative: |
| 1826 raise 'Internal error, must be all positive' | 1837 raise Exception('Internal error, must be all positive') |
| 1827 | 1838 |
| 1828 # All overloads require the same test. Do we bother? | 1839 # All overloads require the same test. Do we bother? |
| 1829 | 1840 |
| 1830 # If the test is the same as the method's formal parameter then checked mode | 1841 # If the test is the same as the method's formal parameter then checked mode |
| 1831 # will have done the test already. (It could be null too but we ignore that | 1842 # will have done the test already. (It could be null too but we ignore that |
| 1832 # case since all the overload behave the same and we don't know which types | 1843 # case since all the overload behave the same and we don't know which types |
| 1833 # in the IDL are not nullable.) | 1844 # in the IDL are not nullable.) |
| 1834 if type == param_type: | 1845 if type == param_type: |
| 1835 return self.GenerateDispatch( | 1846 return self.GenerateDispatch( |
| 1836 emitter, info, indent, position + 1, positive) | 1847 emitter, info, indent, position + 1, positive) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2062 Arguments: | 2073 Arguments: |
| 2063 info: An OperationInfo object. | 2074 info: An OperationInfo object. |
| 2064 """ | 2075 """ |
| 2065 # TODO(vsm): Handle overloads. | 2076 # TODO(vsm): Handle overloads. |
| 2066 self._members_emitter.Emit( | 2077 self._members_emitter.Emit( |
| 2067 '\n' | 2078 '\n' |
| 2068 ' $TYPE $NAME($ARGS) native;\n', | 2079 ' $TYPE $NAME($ARGS) native;\n', |
| 2069 TYPE=info.type_name, | 2080 TYPE=info.type_name, |
| 2070 NAME=info.name, | 2081 NAME=info.name, |
| 2071 ARGS=info.arg_implementation_declaration) | 2082 ARGS=info.arg_implementation_declaration) |
| OLD | NEW |