[GTK] Make script dialogs modal to the current web view only
[WebKit-https.git] / Source / JavaScriptCore / Scripts / builtins / builtins_generate_combined_header.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2014-2016 Apple Inc. All rights reserved.
4 # Copyright (c) 2014 University of Washington. All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 # THE POSSIBILITY OF SUCH DAMAGE.
26
27
28 import logging
29 import re
30 import string
31 from string import Template
32
33 from builtins_generator import BuiltinsGenerator
34 from builtins_templates import BuiltinsGeneratorTemplates as Templates
35
36 log = logging.getLogger('global')
37
38
39 class BuiltinsCombinedHeaderGenerator(BuiltinsGenerator):
40     def __init__(self, model):
41         BuiltinsGenerator.__init__(self, model)
42
43     def output_filename(self):
44         return "%sBuiltins.h" % self.model().framework.setting('namespace')
45
46     def generate_output(self):
47         args = {
48             'namespace': self.model().framework.setting('namespace'),
49             'macroPrefix': self.model().framework.setting('macro_prefix'),
50         }
51
52         sections = []
53         sections.append(self.generate_license())
54         sections.append(Template(Templates.DoNotEditWarning).substitute(args))
55         sections.append(Template(Templates.HeaderIncludeGuard).substitute(args))
56         sections.append(self.generate_forward_declarations())
57         sections.append(Template(Templates.NamespaceTop).substitute(args))
58         for object in self.model().objects:
59             sections.append(self.generate_section_for_object(object))
60         sections.append(self.generate_section_for_code_table_macro())
61         sections.append(self.generate_section_for_code_name_macro())
62         sections.append(self.generate_section_for_global_private_code_name_macro())
63         sections.append(Template(Templates.CombinedHeaderStaticMacros).substitute(args))
64         sections.append(Template(Templates.NamespaceBottom).substitute(args))
65
66         return "\n\n".join(sections)
67
68     def generate_forward_declarations(self):
69         return """namespace JSC {
70 class FunctionExecutable;
71 class VM;
72
73 enum class ConstructAbility : unsigned;
74 }"""
75
76     def generate_section_for_object(self, object):
77         lines = []
78         lines.append('/* %s */' % object.object_name)
79         lines.extend(self.generate_externs_for_object(object))
80         lines.append("")
81         lines.extend(self.generate_macros_for_object(object))
82         return '\n'.join(lines)
83
84     def generate_externs_for_object(self, object):
85         lines = []
86
87         for function in object.functions:
88             function_args = {
89                 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code',
90             }
91
92             lines.append("""extern const char* s_%(codeName)s;
93 extern const int s_%(codeName)sLength;
94 extern const JSC::ConstructAbility s_%(codeName)sConstructAbility;""" % function_args)
95
96         return lines
97
98     def generate_macros_for_object(self, object):
99         args = {
100             'macroPrefix': self.model().framework.setting('macro_prefix'),
101             'objectMacro': object.object_name.replace('.', '').upper(),
102         }
103
104         lines = []
105         lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_DATA(macro) \\" % args)
106         for function in object.functions:
107             function_args = {
108                 'funcName': function.function_name,
109                 'mangledName': BuiltinsGenerator.mangledNameForFunction(function),
110                 'paramCount': len(function.parameters),
111             }
112
113             lines.append("    macro(%(funcName)s, %(mangledName)s, %(paramCount)d) \\" % function_args)
114         return lines
115
116     def generate_section_for_code_table_macro(self):
117         args = {
118             'macroPrefix': self.model().framework.setting('macro_prefix'),
119         }
120
121         lines = []
122         lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_CODE(macro) \\" % args)
123         for function in self.model().all_functions():
124             function_args = {
125                 'funcName': function.function_name,
126                 'overriddenName': function.overridden_name,
127                 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code',
128             }
129
130             lines.append("    macro(%(codeName)s, %(funcName)s, %(overriddenName)s, s_%(codeName)sLength) \\" % function_args)
131         return '\n'.join(lines)
132
133     def generate_section_for_code_name_macro(self):
134         args = {
135             'macroPrefix': self.model().framework.setting('macro_prefix'),
136         }
137
138         internal_function_names = [function.function_name for function in self.model().all_internal_functions()]
139         if len(internal_function_names) != len(set(internal_function_names)):
140             log.error("There are several internal functions with the same name. Private identifiers may clash.")
141
142         lines = []
143         lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_FUNCTION_NAME(macro) \\" % args)
144         unique_names = list(set([function.function_name for function in self.model().all_functions()]))
145         unique_names.sort()
146         for function_name in unique_names:
147             function_args = {
148                 'funcName': function_name,
149             }
150
151             lines.append("    macro(%(funcName)s) \\" % function_args)
152         return '\n'.join(lines)
153
154     def generate_section_for_global_private_code_name_macro(self):
155         args = {
156             'macroPrefix': self.model().framework.setting('macro_prefix'),
157         }
158
159         lines = []
160         lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(macro) \\" % args)
161         functions = filter(lambda function: function.is_global_private, self.model().all_functions())
162         functions.sort(key=lambda x: x.function_name)
163         for function in functions:
164             function_args = {
165                 'funcName': function.function_name,
166                 'codeName': BuiltinsGenerator.mangledNameForFunction(function),
167             }
168
169             lines.append("    macro(%(funcName)s, %(codeName)s) \\" % function_args)
170
171         return '\n'.join(lines)