Unreviewed, rolling out r221327.
[WebKit-https.git] / Source / JavaScriptCore / Scripts / builtins / builtins_generate_combined_implementation.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2014, 2015 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_model import Framework, Frameworks
35 from builtins_templates import BuiltinsGeneratorTemplates as Templates
36
37 log = logging.getLogger('global')
38
39
40 class BuiltinsCombinedImplementationGenerator(BuiltinsGenerator):
41     def __init__(self, model):
42         BuiltinsGenerator.__init__(self, model)
43
44     def output_filename(self):
45         return "%sBuiltins.cpp" % self.model().framework.setting('namespace')
46
47     def generate_output(self):
48         args = {
49             'namespace': self.model().framework.setting('namespace'),
50             'macroPrefix': self.model().framework.setting('macro_prefix'),
51         }
52
53         sections = []
54         sections.append(self.generate_license())
55         sections.append(Template(Templates.DoNotEditWarning).substitute(args))
56         sections.append(self.generate_primary_header_includes())
57         sections.append(self.generate_secondary_header_includes())
58         sections.append(Template(Templates.NamespaceTop).substitute(args))
59         for function in self.model().all_functions():
60             sections.append(self.generate_embedded_code_string_section_for_function(function))
61         if self.model().framework is Frameworks.JavaScriptCore:
62             sections.append(Template(Templates.CombinedJSCImplementationStaticMacros).substitute(args))
63         elif self.model().framework is Frameworks.WebCore:
64             sections.append(Template(Templates.CombinedWebCoreImplementationStaticMacros).substitute(args))
65         sections.append(Template(Templates.NamespaceBottom).substitute(args))
66
67         return "\n\n".join(sections)
68
69     def generate_secondary_header_includes(self):
70         header_includes = [
71             (["JavaScriptCore"],
72                 ("JavaScriptCore", "builtins/BuiltinExecutables.h"),
73             ),
74             (["JavaScriptCore", "WebCore"],
75                 ("JavaScriptCore", "heap/HeapInlines.h"),
76             ),
77             (["JavaScriptCore", "WebCore"],
78                 ("JavaScriptCore", "runtime/UnlinkedFunctionExecutable.h"),
79             ),
80             (["JavaScriptCore", "WebCore"],
81                 ("JavaScriptCore", "runtime/JSCellInlines.h"),
82             ),
83             (["WebCore"],
84                 ("JavaScriptCore", "runtime/StructureInlines.h"),
85             ),
86             (["WebCore"],
87                 ("JavaScriptCore", "runtime/JSCJSValueInlines.h"),
88             ),
89             (["JavaScriptCore", "WebCore"],
90                 ("JavaScriptCore", "runtime/VM.h"),
91             ),
92             (["JavaScriptCore", "WebCore"],
93                 ("JavaScriptCore", "runtime/Intrinsic.h"),
94             ),
95         ]
96
97         return '\n'.join(self.generate_includes_from_entries(header_includes))