From cd875b317ba9ef63f946d2a07b7e67c1e05f93ac Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Tue, 25 Feb 2020 22:21:50 +0300 Subject: Import QtWebKit commit 887b98440a46eb30f8a1998e930ddd9218934e1e Change-Id: I87077d70c358887aa76233566c2e864d1eeb8f73 Reviewed-by: Konstantin Tokarev --- Source/JavaScriptCore/CMakeLists.txt | 5 +- Source/JavaScriptCore/Scripts/builtins/__init__.py | 3 - Source/JavaScriptCore/Scripts/builtins/builtins.py | 11 - .../builtins/builtins_generate_combined_header.py | 152 ----------- .../builtins_generate_combined_implementation.py | 91 ------- .../builtins/builtins_generate_separate_header.py | 199 --------------- .../builtins_generate_separate_implementation.py | 106 -------- .../Scripts/builtins/builtins_generator.py | 169 ------------- .../Scripts/builtins/builtins_model.py | 274 -------------------- .../Scripts/builtins/builtins_templates.py | 216 ---------------- .../JavaScriptCore/Scripts/generate-js-builtins.py | 16 +- Source/JavaScriptCore/Scripts/jsmin.py | 22 +- .../JavaScriptCore/Scripts/make-js-file-arrays.py | 57 +++-- .../JavaScriptCore/Scripts/wkbuiltins/__init__.py | 3 + .../builtins_generate_combined_header.py | 152 +++++++++++ .../builtins_generate_combined_implementation.py | 91 +++++++ .../builtins_generate_separate_header.py | 199 +++++++++++++++ .../builtins_generate_separate_implementation.py | 106 ++++++++ .../Scripts/wkbuiltins/builtins_generator.py | 169 +++++++++++++ .../Scripts/wkbuiltins/builtins_model.py | 277 +++++++++++++++++++++ .../Scripts/wkbuiltins/builtins_templates.py | 216 ++++++++++++++++ .../Scripts/wkbuiltins/wkbuiltins.py | 11 + .../disassembler/udis86/ud_opcode.py | 4 +- Source/JavaScriptCore/generate-bytecode-files | 8 +- .../inspector/scripts/codegen/__init__.py | 42 ++-- .../inspector/scripts/codegen/cpp_generator.py | 8 +- ...rate_cpp_alternate_backend_dispatcher_header.py | 13 +- .../generate_cpp_backend_dispatcher_header.py | 22 +- ...nerate_cpp_backend_dispatcher_implementation.py | 18 +- .../generate_cpp_frontend_dispatcher_header.py | 18 +- ...erate_cpp_frontend_dispatcher_implementation.py | 18 +- .../codegen/generate_cpp_protocol_types_header.py | 44 ++-- .../generate_cpp_protocol_types_implementation.py | 27 +- .../codegen/generate_js_backend_commands.py | 17 +- .../generate_objc_backend_dispatcher_header.py | 21 +- ...erate_objc_backend_dispatcher_implementation.py | 25 +- .../codegen/generate_objc_configuration_header.py | 11 +- .../generate_objc_configuration_implementation.py | 11 +- .../codegen/generate_objc_conversion_helpers.py | 14 +- ...rate_objc_frontend_dispatcher_implementation.py | 22 +- .../scripts/codegen/generate_objc_header.py | 34 +-- .../codegen/generate_objc_internal_header.py | 15 +- .../generate_objc_protocol_types_implementation.py | 22 +- .../inspector/scripts/codegen/generator.py | 16 +- .../inspector/scripts/codegen/models.py | 2 +- .../inspector/scripts/codegen/objc_generator.py | 10 +- .../generate-inspector-protocol-bindings.py | 4 +- Source/WebCore/CMakeLists.txt | 2 +- Source/WebCore/DerivedSources.make | 2 +- .../platform/network/create-http-header-name-table | 2 +- .../Scripts/copy-user-interface-resources.pl | 2 + Source/cmake/WebKitCommon.cmake | 4 +- Tools/jhbuild/jhbuildutils.py | 2 +- 53 files changed, 1572 insertions(+), 1433 deletions(-) delete mode 100644 Source/JavaScriptCore/Scripts/builtins/__init__.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_header.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_implementation.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_header.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_implementation.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins_generator.py delete mode 100755 Source/JavaScriptCore/Scripts/builtins/builtins_model.py delete mode 100644 Source/JavaScriptCore/Scripts/builtins/builtins_templates.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/__init__.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_header.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_implementation.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_header.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_implementation.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generator.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_model.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/builtins_templates.py create mode 100644 Source/JavaScriptCore/Scripts/wkbuiltins/wkbuiltins.py diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt index 937b3ed00..afd76ca1a 100644 --- a/Source/JavaScriptCore/CMakeLists.txt +++ b/Source/JavaScriptCore/CMakeLists.txt @@ -883,7 +883,8 @@ set(JavaScriptCore_SCRIPTS_SOURCES_DIR "${JAVASCRIPTCORE_DIR}/Scripts") set(JavaScriptCore_SCRIPTS_SOURCES_PATHS ${JavaScriptCore_SCRIPTS_SOURCES_DIR}/*.pl ${JavaScriptCore_SCRIPTS_SOURCES_DIR}/*.py - ${JavaScriptCore_SCRIPTS_SOURCES_DIR}/builtins/builtins*.py + ${JavaScriptCore_SCRIPTS_SOURCES_DIR}/wkbuiltins/builtins*.py + ${JavaScriptCore_SCRIPTS_SOURCES_DIR}/wkbuiltins/wkbuiltins.py ) # Force JavaScriptCore to run scripts from the same staging path as WebCore. @@ -1174,7 +1175,7 @@ add_custom_command( # JSCBuiltins set(BUILTINS_GENERATOR_SCRIPTS - ${JavaScriptCore_SCRIPTS_DIR}/builtins.py + ${JavaScriptCore_SCRIPTS_DIR}/wkbuiltins.py ${JavaScriptCore_SCRIPTS_DIR}/builtins_generator.py ${JavaScriptCore_SCRIPTS_DIR}/builtins_model.py ${JavaScriptCore_SCRIPTS_DIR}/builtins_templates.py diff --git a/Source/JavaScriptCore/Scripts/builtins/__init__.py b/Source/JavaScriptCore/Scripts/builtins/__init__.py deleted file mode 100644 index fdfcba981..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# Required for Python to search this directory for module files - -from builtins import * diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins.py b/Source/JavaScriptCore/Scripts/builtins/builtins.py deleted file mode 100644 index 9349eeef6..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins.py +++ /dev/null @@ -1,11 +0,0 @@ -# This file is used to simulate the builtins/ directory when generate-js-builtins.py -# is run from JavaScriptCore framework's private headers directory, which is flattened. - -from builtins_model import * -from builtins_templates import * - -from builtins_generator import * -from builtins_generate_combined_header import * -from builtins_generate_combined_implementation import * -from builtins_generate_separate_header import * -from builtins_generate_separate_implementation import * diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_header.py b/Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_header.py deleted file mode 100644 index 891bd3cb4..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_header.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. -# Copyright (c) 2014 University of Washington. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - - -import logging -import re -import string -from string import Template - -from builtins_generator import BuiltinsGenerator -from builtins_templates import BuiltinsGeneratorTemplates as Templates - -log = logging.getLogger('global') - - -class BuiltinsCombinedHeaderGenerator(BuiltinsGenerator): - def __init__(self, model): - BuiltinsGenerator.__init__(self, model) - - def output_filename(self): - return "%sBuiltins.h" % self.model().framework.setting('namespace') - - def generate_output(self): - args = { - 'namespace': self.model().framework.setting('namespace'), - 'headerGuard': self.output_filename().replace('.', '_'), - 'macroPrefix': self.model().framework.setting('macro_prefix'), - } - - sections = [] - sections.append(self.generate_license()) - sections.append(Template(Templates.DoNotEditWarning).substitute(args)) - sections.append(Template(Templates.HeaderIncludeGuardTop).substitute(args)) - sections.append(self.generate_forward_declarations()) - sections.append(Template(Templates.NamespaceTop).substitute(args)) - for object in self.model().objects: - sections.append(self.generate_section_for_object(object)) - sections.append(self.generate_section_for_code_table_macro()) - sections.append(self.generate_section_for_code_name_macro()) - sections.append(Template(Templates.CombinedHeaderStaticMacros).substitute(args)) - sections.append(Template(Templates.NamespaceBottom).substitute(args)) - sections.append(Template(Templates.HeaderIncludeGuardBottom).substitute(args)) - - return "\n\n".join(sections) - - def generate_forward_declarations(self): - return """namespace JSC { -class FunctionExecutable; -class VM; - -enum class ConstructAbility : unsigned; -}""" - - def generate_section_for_object(self, object): - lines = [] - lines.append('/* %s */' % object.object_name) - lines.extend(self.generate_externs_for_object(object)) - lines.append("") - lines.extend(self.generate_macros_for_object(object)) - return '\n'.join(lines) - - def generate_externs_for_object(self, object): - lines = [] - - for function in object.functions: - function_args = { - 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', - } - - lines.append("""extern const char* s_%(codeName)s; -extern const int s_%(codeName)sLength; -extern const JSC::ConstructAbility s_%(codeName)sConstructAbility;""" % function_args) - - return lines - - def generate_macros_for_object(self, object): - args = { - 'macroPrefix': self.model().framework.setting('macro_prefix'), - 'objectMacro': object.object_name.replace('.', '').upper(), - } - - lines = [] - lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_DATA(macro) \\" % args) - for function in object.functions: - function_args = { - 'funcName': function.function_name, - 'mangledName': BuiltinsGenerator.mangledNameForFunction(function), - 'paramCount': len(function.parameters), - } - - lines.append(" macro(%(funcName)s, %(mangledName)s, %(paramCount)d) \\" % function_args) - return lines - - def generate_section_for_code_table_macro(self): - args = { - 'macroPrefix': self.model().framework.setting('macro_prefix'), - } - - lines = [] - lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_CODE(macro) \\" % args) - for function in self.model().all_functions(): - function_args = { - 'funcName': function.function_name, - 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', - } - - lines.append(" macro(%(codeName)s, %(funcName)s, s_%(codeName)sLength) \\" % function_args) - return '\n'.join(lines) - - def generate_section_for_code_name_macro(self): - args = { - 'macroPrefix': self.model().framework.setting('macro_prefix'), - } - - internal_function_names = [function.function_name for function in self.model().all_internal_functions()] - if len(internal_function_names) != len(set(internal_function_names)): - log.error("There are several internal functions with the same name. Private identifiers may clash.") - - lines = [] - lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_FUNCTION_NAME(macro) \\" % args) - unique_names = list(set([function.function_name for function in self.model().all_functions()])) - unique_names.sort() - for function_name in unique_names: - function_args = { - 'funcName': function_name, - } - - lines.append(" macro(%(funcName)s) \\" % function_args) - return '\n'.join(lines) diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_implementation.py b/Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_implementation.py deleted file mode 100644 index 094434b64..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_combined_implementation.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. -# Copyright (c) 2014 University of Washington. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - - -import logging -import re -import string -from string import Template - -from builtins_generator import BuiltinsGenerator -from builtins_model import Framework, Frameworks -from builtins_templates import BuiltinsGeneratorTemplates as Templates - -log = logging.getLogger('global') - - -class BuiltinsCombinedImplementationGenerator(BuiltinsGenerator): - def __init__(self, model): - BuiltinsGenerator.__init__(self, model) - - def output_filename(self): - return "%sBuiltins.cpp" % self.model().framework.setting('namespace') - - def generate_output(self): - args = { - 'namespace': self.model().framework.setting('namespace'), - 'macroPrefix': self.model().framework.setting('macro_prefix'), - } - - sections = [] - sections.append(self.generate_license()) - sections.append(Template(Templates.DoNotEditWarning).substitute(args)) - sections.append(self.generate_primary_header_includes()) - sections.append(self.generate_secondary_header_includes()) - sections.append(Template(Templates.NamespaceTop).substitute(args)) - for function in self.model().all_functions(): - sections.append(self.generate_embedded_code_string_section_for_function(function)) - if self.model().framework is Frameworks.JavaScriptCore: - sections.append(Template(Templates.CombinedJSCImplementationStaticMacros).substitute(args)) - elif self.model().framework is Frameworks.WebCore: - sections.append(Template(Templates.CombinedWebCoreImplementationStaticMacros).substitute(args)) - sections.append(Template(Templates.NamespaceBottom).substitute(args)) - - return "\n\n".join(sections) - - def generate_secondary_header_includes(self): - header_includes = [ - (["JavaScriptCore"], - ("JavaScriptCore", "builtins/BuiltinExecutables.h"), - ), - (["JavaScriptCore", "WebCore"], - ("JavaScriptCore", "runtime/Executable.h"), - ), - (["JavaScriptCore", "WebCore"], - ("JavaScriptCore", "runtime/JSCellInlines.h"), - ), - (["WebCore"], - ("JavaScriptCore", "runtime/StructureInlines.h"), - ), - (["WebCore"], - ("JavaScriptCore", "runtime/JSCJSValueInlines.h"), - ), - (["JavaScriptCore", "WebCore"], - ("JavaScriptCore", "runtime/VM.h"), - ), - ] - - return '\n'.join(self.generate_includes_from_entries(header_includes)) diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_header.py b/Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_header.py deleted file mode 100644 index b72a94bfe..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_header.py +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. -# Copyright (c) 2014 University of Washington. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - - -import logging -import re -import string -from string import Template - -from builtins_generator import BuiltinsGenerator -from builtins_model import Frameworks -from builtins_templates import BuiltinsGeneratorTemplates as Templates - -log = logging.getLogger('global') - - -class BuiltinsSeparateHeaderGenerator(BuiltinsGenerator): - def __init__(self, model, object): - BuiltinsGenerator.__init__(self, model) - self.object = object - - def output_filename(self): - return "%sBuiltins.h" % BuiltinsGenerator.mangledNameForObject(self.object) - - def macro_prefix(self): - return self.model().framework.setting('macro_prefix') - - def generate_output(self): - args = { - 'namespace': self.model().framework.setting('namespace'), - 'headerGuard': self.output_filename().replace('.', '_'), - 'macroPrefix': self.macro_prefix(), - 'objectName': self.object.object_name, - 'objectMacro': self.object.object_name.upper(), - } - - conditional_guard = self.object.annotations.get('conditional') - - sections = [] - sections.append(self.generate_license()) - sections.append(Template(Templates.DoNotEditWarning).substitute(args)) - sections.append(Template(Templates.HeaderIncludeGuardTop).substitute(args)) - if conditional_guard is not None: - sections.append("#if %s" % conditional_guard) - sections.append(self.generate_secondary_header_includes()) - sections.append(self.generate_forward_declarations()) - sections.append(Template(Templates.NamespaceTop).substitute(args)) - sections.append(self.generate_section_for_object(self.object)) - sections.append(self.generate_section_for_code_table_macro()) - sections.append(self.generate_section_for_code_name_macro()) - sections.append(Template(Templates.SeparateHeaderStaticMacros).substitute(args)) - if self.model().framework is Frameworks.WebCore: - sections.append(Template(Templates.SeparateHeaderWrapperBoilerplate).substitute(args)) - if self.object.annotations.get('internal'): - sections.append(Template(Templates.SeparateHeaderInternalFunctionsBoilerplate).substitute(args)) - sections.append(Template(Templates.NamespaceBottom).substitute(args)) - if conditional_guard is not None: - sections.append("#endif // %s" % conditional_guard) - sections.append(Template(Templates.HeaderIncludeGuardBottom).substitute(args)) - - return "\n\n".join(sections) - - def generate_forward_declarations(self): - return """namespace JSC { -class FunctionExecutable; -}""" - - def generate_secondary_header_includes(self): - header_includes = [ - (["WebCore"], - ("JavaScriptCore", "bytecode/UnlinkedFunctionExecutable.h"), - ), - - (["WebCore"], - ("JavaScriptCore", "builtins/BuiltinUtils.h"), - ), - - (["WebCore"], - ("JavaScriptCore", "runtime/Identifier.h"), - ), - - (["WebCore"], - ("JavaScriptCore", "runtime/JSFunction.h"), - ), - ] - - return '\n'.join(self.generate_includes_from_entries(header_includes)) - - def generate_section_for_object(self, object): - lines = [] - lines.append('/* %s */' % object.object_name) - lines.extend(self.generate_externs_for_object(object)) - lines.append("") - lines.extend(self.generate_macros_for_object(object)) - lines.append("") - lines.extend(self.generate_defines_for_object(object)) - return '\n'.join(lines) - - def generate_externs_for_object(self, object): - lines = [] - - for function in object.functions: - function_args = { - 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', - } - - lines.append("""extern const char* s_%(codeName)s; -extern const int s_%(codeName)sLength; -extern const JSC::ConstructAbility s_%(codeName)sConstructAbility;""" % function_args) - - return lines - - def generate_macros_for_object(self, object): - args = { - 'macroPrefix': self.macro_prefix(), - 'objectMacro': object.object_name.replace('.', '_').upper(), - } - - lines = [] - lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_DATA(macro) \\" % args) - for function in object.functions: - function_args = { - 'funcName': function.function_name, - 'mangledName': BuiltinsGenerator.mangledNameForFunction(function), - 'paramCount': len(function.parameters), - } - - lines.append(" macro(%(funcName)s, %(mangledName)s, %(paramCount)d) \\" % function_args) - return lines - - def generate_defines_for_object(self, object): - lines = [] - for function in object.functions: - args = { - 'macroPrefix': self.macro_prefix(), - 'objectMacro': object.object_name.replace('.', '_').upper(), - 'functionMacro': function.function_name.upper(), - } - lines.append("#define %(macroPrefix)s_BUILTIN_%(objectMacro)s_%(functionMacro)s 1" % args) - - return lines - - def generate_section_for_code_table_macro(self): - args = { - 'macroPrefix': self.model().framework.setting('macro_prefix'), - 'objectMacro': self.object.object_name.upper(), - } - - lines = [] - lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_CODE(macro) \\" % args) - for function in self.object.functions: - function_args = { - 'funcName': function.function_name, - 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', - } - - lines.append(" macro(%(codeName)s, %(funcName)s, s_%(codeName)sLength) \\" % function_args) - return '\n'.join(lines) - - def generate_section_for_code_name_macro(self): - args = { - 'macroPrefix': self.macro_prefix(), - 'objectMacro': self.object.object_name.upper(), - } - - lines = [] - lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_FUNCTION_NAME(macro) \\" % args) - unique_names = list(set([function.function_name for function in self.object.functions])) - unique_names.sort() - for function_name in unique_names: - function_args = { - 'funcName': function_name, - } - - lines.append(" macro(%(funcName)s) \\" % function_args) - return '\n'.join(lines) diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_implementation.py b/Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_implementation.py deleted file mode 100644 index 0443975da..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_generate_separate_implementation.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. -# Copyright (c) 2014 University of Washington. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - - -import logging -import re -import string -from string import Template - -from builtins_generator import BuiltinsGenerator, WK_lcfirst -from builtins_model import Framework, Frameworks -from builtins_templates import BuiltinsGeneratorTemplates as Templates - -log = logging.getLogger('global') - - -class BuiltinsSeparateImplementationGenerator(BuiltinsGenerator): - def __init__(self, model, object): - BuiltinsGenerator.__init__(self, model) - self.object = object - - def output_filename(self): - return "%sBuiltins.cpp" % BuiltinsGenerator.mangledNameForObject(self.object) - - def macro_prefix(self): - return self.model().framework.setting('macro_prefix') - - def generate_output(self): - args = { - 'namespace': self.model().framework.setting('namespace'), - 'macroPrefix': self.macro_prefix(), - 'objectMacro': self.object.object_name.upper(), - 'objectNameLC': WK_lcfirst(self.object.object_name), - } - - conditional_guard = self.object.annotations.get('conditional') - - sections = [] - sections.append(self.generate_license()) - sections.append(Template(Templates.DoNotEditWarning).substitute(args)) - sections.append(self.generate_primary_header_includes()) - if conditional_guard is not None: - sections.append("#if %s" % conditional_guard) - sections.append(self.generate_secondary_header_includes()) - sections.append(Template(Templates.NamespaceTop).substitute(args)) - for function in self.object.functions: - sections.append(self.generate_embedded_code_string_section_for_function(function)) - if self.model().framework is Frameworks.JavaScriptCore: - sections.append(Template(Templates.SeparateJSCImplementationStaticMacros).substitute(args)) - elif self.model().framework is Frameworks.WebCore: - sections.append(Template(Templates.SeparateWebCoreImplementationStaticMacros).substitute(args)) - sections.append(Template(Templates.NamespaceBottom).substitute(args)) - if conditional_guard is not None: - sections.append("#endif // %s\n" % conditional_guard) - - return "\n\n".join(sections) - - def generate_secondary_header_includes(self): - header_includes = [ - (["JavaScriptCore"], - ("JavaScriptCore", "builtins/BuiltinExecutables.h"), - ), - (["JavaScriptCore", "WebCore"], - ("JavaScriptCore", "runtime/Executable.h"), - ), - (["JavaScriptCore", "WebCore"], - ("JavaScriptCore", "runtime/JSCellInlines.h"), - ), - (["WebCore"], - ("JavaScriptCore", "runtime/StructureInlines.h"), - ), - (["WebCore"], - ("JavaScriptCore", "runtime/JSCJSValueInlines.h"), - ), - (["JavaScriptCore", "WebCore"], - ("JavaScriptCore", "runtime/VM.h"), - ), - (["WebCore"], - ("WebCore", "bindings/js/WebCoreJSClientData.h"), - ), - ] - - return '\n'.join(self.generate_includes_from_entries(header_includes)) diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_generator.py b/Source/JavaScriptCore/Scripts/builtins/builtins_generator.py deleted file mode 100644 index 21ac4c1d9..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_generator.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. -# Copyright (c) 2014 University of Washington. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -import logging -import os.path -import re -from string import Template -import json - -from builtins_model import BuiltinFunction, BuiltinObject -from builtins_templates import BuiltinsGeneratorTemplates as Templates - -log = logging.getLogger('global') - -# These match WK_lcfirst and WK_ucfirst defined in CodeGenerator.pm. -def WK_lcfirst(str): - str = str[:1].lower() + str[1:] - str = str.replace('hTML', 'html') - str = str.replace('uRL', 'url') - str = str.replace('jS', 'js') - str = str.replace('xML', 'xml') - str = str.replace('xSLT', 'xslt') - str = str.replace('cSS', 'css') - str = str.replace('rTC', 'rtc') - return str - -def WK_ucfirst(str): - str = str[:1].upper() + str[1:] - str = str.replace('Xml', 'XML') - str = str.replace('Svg', 'SVG') - return str - -class BuiltinsGenerator: - def __init__(self, model): - self._model = model - - def model(self): - return self._model - - # These methods are overridden by subclasses. - - def generate_output(self): - pass - - def output_filename(self): - pass - - - # Shared code generation methods. - def generate_license(self): - raw_license = Template(Templates.LicenseText).substitute(None) - copyrights = self._model.copyrights() - copyrights.sort() - - license_block = [] - license_block.append("/*") - for copyright in copyrights: - license_block.append(" * Copyright (c) %s" % copyright) - if len(copyrights) > 0: - license_block.append(" * ") - - for line in raw_license.split('\n'): - license_block.append(" * " + line) - - license_block.append(" */") - - return '\n'.join(license_block) - - def generate_includes_from_entries(self, entries): - includes = set() - for entry in entries: - (allowed_framework_names, data) = entry - (framework_name, header_path) = data - - if self.model().framework.name not in allowed_framework_names: - continue - if self.model().framework.name != framework_name: - includes.add("#include <%s>" % header_path) - else: - includes.add("#include \"%s\"" % os.path.basename(header_path)) - - return sorted(list(includes)) - - def generate_primary_header_includes(self): - name, _ = os.path.splitext(self.output_filename()) - return '\n'.join([ - "#include \"config.h\"", - "#include \"%s.h\"" % name, - ]) - - def generate_embedded_code_string_section_for_function(self, function): - text = function.function_source - # Wrap it in parens to avoid adding to global scope. - text = "(function " + text[text.index("("):] + ")" - embeddedSourceLength = len(text) + 1 # For extra \n. - # Lazy way to escape quotes, I think? - textLines = json.dumps(text)[1:-1].split("\\n") - # This looks scary because we need the JS source itself to have newlines. - embeddedSource = '\n'.join([' "%s\\n" \\' % line for line in textLines]) - - constructAbility = "CannotConstruct" - if function.is_constructor: - constructAbility = "CanConstruct" - - args = { - 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', - 'embeddedSource': embeddedSource, - 'embeddedSourceLength': embeddedSourceLength, - 'canConstruct': constructAbility - } - - lines = [] - lines.append("const JSC::ConstructAbility s_%(codeName)sConstructAbility = JSC::ConstructAbility::%(canConstruct)s;" % args); - lines.append("const int s_%(codeName)sLength = %(embeddedSourceLength)d;" % args); - lines.append("const char* s_%(codeName)s =\n%(embeddedSource)s\n;" % args); - return '\n'.join(lines) - - # Helper methods. - - @staticmethod - def mangledNameForObject(object): - if not isinstance(object, BuiltinObject): - raise Exception("Invalid argument passed to mangledNameForObject()") - - def toCamel(match): - str = match.group(0) - return str[1].upper() - return re.sub(r'\.[a-z]', toCamel, object.object_name, flags=re.IGNORECASE) - - - @staticmethod - def mangledNameForFunction(function): - if not isinstance(function, BuiltinFunction): - raise Exception("Invalid argument passed to mangledNameForFunction()") - - function_name = WK_ucfirst(function.function_name) - - def toCamel(match): - str = match.group(0) - return str[1].upper() - function_name = re.sub(r'\.[a-z]', toCamel, function_name, flags=re.IGNORECASE) - if function.is_constructor: - function_name = function_name + "Constructor" - - object_name = BuiltinsGenerator.mangledNameForObject(function.object) - return WK_lcfirst(object_name + function_name) diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_model.py b/Source/JavaScriptCore/Scripts/builtins/builtins_model.py deleted file mode 100755 index cdd5f9003..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_model.py +++ /dev/null @@ -1,274 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2015 Apple Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -import logging -import re -import os - -log = logging.getLogger('global') - -_FRAMEWORK_CONFIG_MAP = { - "JavaScriptCore": { - "macro_prefix": "JSC", - "namespace": "JSC", - }, - "WebCore": { - "macro_prefix": "WEBCORE", - "namespace": "WebCore", - }, -} - -functionHeadRegExp = re.compile(r"(?:function|constructor)\s+\w+\s*\(.*?\)", re.MULTILINE | re.S) -functionNameRegExp = re.compile(r"(?:function|constructor)\s+(\w+)\s*\(", re.MULTILINE | re.S) -functionIsConstructorRegExp = re.compile(r"^constructor", re.MULTILINE | re.S) -functionParameterFinder = re.compile(r"^(?:function|constructor)\s+(?:\w+)\s*\(((?:\s*\w+)?\s*(?:\s*,\s*\w+)*)?\s*\)", re.MULTILINE | re.S) - -multilineCommentRegExp = re.compile(r"\/\*.*?\*\/", re.MULTILINE | re.S) -singleLineCommentRegExp = re.compile(r"\/\/.*?\n", re.MULTILINE | re.S) -keyValueAnnotationCommentRegExp = re.compile(r"^\/\/ @(\w+)=([^=]+?)\n", re.MULTILINE | re.S) -flagAnnotationCommentRegExp = re.compile(r"^\/\/ @(\w+)[^=]*?\n", re.MULTILINE | re.S) -lineWithOnlySingleLineCommentRegExp = re.compile(r"^\s*\/\/\n", re.MULTILINE | re.S) -lineWithTrailingSingleLineCommentRegExp = re.compile(r"\s*\/\/\n", re.MULTILINE | re.S) -multipleEmptyLinesRegExp = re.compile(r"\n{2,}", re.MULTILINE | re.S) - -class ParseException(Exception): - pass - - -class Framework: - def __init__(self, name): - self._settings = _FRAMEWORK_CONFIG_MAP[name] - self.name = name - - def setting(self, key, default=''): - return self._settings.get(key, default) - - @staticmethod - def fromString(frameworkString): - if frameworkString == "JavaScriptCore": - return Frameworks.JavaScriptCore - - if frameworkString == "WebCore": - return Frameworks.WebCore - - raise ParseException("Unknown framework: %s" % frameworkString) - - -class Frameworks: - JavaScriptCore = Framework("JavaScriptCore") - WebCore = Framework("WebCore") - - -class BuiltinObject: - def __init__(self, object_name, annotations, functions): - self.object_name = object_name - self.annotations = annotations - self.functions = functions - self.collection = None # Set by the owning BuiltinsCollection - - for function in self.functions: - function.object = self - - -class BuiltinFunction: - def __init__(self, function_name, function_source, is_constructor, parameters): - self.function_name = function_name - self.function_source = function_source - self.is_constructor = is_constructor - self.parameters = parameters - self.object = None # Set by the owning BuiltinObject - - @staticmethod - def fromString(function_string): - function_source = multilineCommentRegExp.sub("", function_string) - if os.getenv("CONFIGURATION", "Debug").startswith("Debug"): - function_source = lineWithOnlySingleLineCommentRegExp.sub("", function_source) - function_source = lineWithTrailingSingleLineCommentRegExp.sub("\n", function_source) - function_source = multipleEmptyLinesRegExp.sub("\n", function_source) - - function_name = functionNameRegExp.findall(function_source)[0] - is_constructor = functionIsConstructorRegExp.match(function_source) != None - parameters = [s.strip() for s in functionParameterFinder.findall(function_source)[0].split(',')] - if len(parameters[0]) == 0: - parameters = [] - - return BuiltinFunction(function_name, function_source, is_constructor, parameters) - - def __str__(self): - interface = "%s(%s)" % (self.function_name, ', '.join(self.parameters)) - if self.is_constructor: - interface = interface + " [Constructor]" - - return interface - - -class BuiltinsCollection: - def __init__(self, framework_name): - self._copyright_lines = set() - self.objects = [] - self.framework = Framework.fromString(framework_name) - log.debug("Created new Builtins collection.") - - def parse_builtins_file(self, filename, text): - log.debug("Parsing builtins file: %s" % filename) - - parsed_copyrights = set(self._parse_copyright_lines(text)) - self._copyright_lines = self._copyright_lines.union(parsed_copyrights) - - log.debug("Found copyright lines:") - for line in self._copyright_lines: - log.debug(line) - log.debug("") - - object_annotations = self._parse_annotations(text) - - object_name, ext = os.path.splitext(os.path.basename(filename)) - log.debug("Parsing object: %s" % object_name) - - parsed_functions = self._parse_functions(text) - for function in parsed_functions: - function.object = object_name - - log.debug("Parsed functions:") - for func in parsed_functions: - log.debug(func) - log.debug("") - - new_object = BuiltinObject(object_name, object_annotations, parsed_functions) - new_object.collection = self - self.objects.append(new_object) - - def copyrights(self): - owner_to_years = dict() - copyrightYearRegExp = re.compile(r"(\d{4})[, ]{0,2}") - ownerStartRegExp = re.compile(r"[^\d, ]") - - # Returns deduplicated copyrights keyed on the owner. - for line in self._copyright_lines: - years = set(copyrightYearRegExp.findall(line)) - ownerIndex = ownerStartRegExp.search(line).start() - owner = line[ownerIndex:] - log.debug("Found years: %s and owner: %s" % (years, owner)) - if owner not in owner_to_years: - owner_to_years[owner] = set() - - owner_to_years[owner] = owner_to_years[owner].union(years) - - result = [] - - for owner, years in owner_to_years.items(): - sorted_years = list(years) - sorted_years.sort() - result.append("%s %s" % (', '.join(sorted_years), owner)) - - return result - - def all_functions(self): - result = [] - for object in self.objects: - result.extend(object.functions) - - result.sort() - return result - - def all_internal_functions(self): - result = [] - for object in [o for o in self.objects if 'internal' in o.annotations]: - result.extend(object.functions) - - result.sort() - return result - - # Private methods. - - def _parse_copyright_lines(self, text): - licenseBlock = multilineCommentRegExp.findall(text)[0] - licenseBlock = licenseBlock[:licenseBlock.index("Redistribution")] - - copyrightLines = [] - for line in licenseBlock.split("\n"): - line = line.replace("/*", "") - line = line.replace("*/", "") - line = line.replace("*", "") - line = line.replace("Copyright", "") - line = line.replace("copyright", "") - line = line.replace("(C)", "") - line = line.replace("(c)", "") - line = line.strip() - - if len(line) == 0: - continue - - copyrightLines.append(line) - - return copyrightLines - - def _parse_annotations(self, text): - annotations = {} - - for match in keyValueAnnotationCommentRegExp.finditer(text): - (key, value) = match.group(1, 2) - log.debug("Found annotation: '%s' => '%s'" % (key, value)) - if key in annotations: - raise ParseException("Duplicate annotation found: %s" % key) - - annotations[key] = value - - for match in flagAnnotationCommentRegExp.finditer(text): - key = match.group(1) - log.debug("Found annotation: '%s' => 'TRUE'" % key) - if key in annotations: - raise ParseException("Duplicate annotation found: %s" % key) - - annotations[key] = True - - return annotations - - def _parse_functions(self, text): - text = multilineCommentRegExp.sub("/**/", singleLineCommentRegExp.sub("//\n", text)) - - matches = [func for func in functionHeadRegExp.finditer(text)] - functionBounds = [] - start = 0 - end = 0 - for match in matches: - start = match.start() - if start < end: - continue - end = match.end() - while text[end] != '{': - end = end + 1 - depth = 1 - end = end + 1 - while depth > 0: - if text[end] == '{': - depth = depth + 1 - elif text[end] == '}': - depth = depth - 1 - end = end + 1 - functionBounds.append((start, end)) - - functionStrings = [text[start:end].strip() for (start, end) in functionBounds] - return map(BuiltinFunction.fromString, functionStrings) diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_templates.py b/Source/JavaScriptCore/Scripts/builtins/builtins_templates.py deleted file mode 100644 index 67cdd5df7..000000000 --- a/Source/JavaScriptCore/Scripts/builtins/builtins_templates.py +++ /dev/null @@ -1,216 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. -# Copyright (C) 2015 Canon Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -# Builtins generator templates, which can be filled with string.Template. - - -class BuiltinsGeneratorTemplates: - - LicenseText = ( - """Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -""") - - DoNotEditWarning = ( - """// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for -// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py""") - - HeaderIncludeGuardTop = ( - """#ifndef ${headerGuard} -#define ${headerGuard}""") - - HeaderIncludeGuardBottom = ( - """#endif // ${headerGuard} -""") - - NamespaceTop = ( - """namespace ${namespace} {""") - - NamespaceBottom = ( - """} // namespace ${namespace}""") - - CombinedHeaderStaticMacros = ( - """#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ - JSC::FunctionExecutable* codeName##Generator(JSC::VM&); - -${macroPrefix}_FOREACH_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) -#undef DECLARE_BUILTIN_GENERATOR""") - - SeparateHeaderStaticMacros = ( - """#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ - JSC::FunctionExecutable* codeName##Generator(JSC::VM&); - -${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) -#undef DECLARE_BUILTIN_GENERATOR""") - - CombinedJSCImplementationStaticMacros = ( - """ -#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ -JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ -{\\ - return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \ -} -${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) -#undef DEFINE_BUILTIN_GENERATOR -""") - - SeparateJSCImplementationStaticMacros = ( - """ -#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ -JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ -{\\ - return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \ -} -${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) -#undef DEFINE_BUILTIN_GENERATOR -""") - - CombinedWebCoreImplementationStaticMacros = ( - """ -#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ -JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ -{\\ - JSVMClientData* clientData = static_cast(vm.clientData); \\ - return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source()); \\ -} -${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) -#undef DEFINE_BUILTIN_GENERATOR -""") - - SeparateWebCoreImplementationStaticMacros = ( - """ -#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ -JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ -{\\ - JSVMClientData* clientData = static_cast(vm.clientData); \\ - return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source()); \\ -} -${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) -#undef DEFINE_BUILTIN_GENERATOR -""") - - SeparateHeaderWrapperBoilerplate = ( - """class ${objectName}BuiltinsWrapper : private JSC::WeakHandleOwner { -public: - explicit ${objectName}BuiltinsWrapper(JSC::VM* vm) - : m_vm(*vm) - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) -#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length))) - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) -#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS - { - } - -#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, length) \\ - JSC::UnlinkedFunctionExecutable* name##Executable(); \\ - const JSC::SourceCode& name##Source() const { return m_##name##Source; } - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) -#undef EXPOSE_BUILTIN_EXECUTABLES - - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) - - void exportNames(); - -private: - JSC::VM& m_vm; - - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) - -#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, length) \\ - JSC::SourceCode m_##name##Source;\\ - JSC::Weak m_##name##Executable; - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) -#undef DECLARE_BUILTIN_SOURCE_MEMBERS - -}; - -#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, length) \\ -inline JSC::UnlinkedFunctionExecutable* ${objectName}BuiltinsWrapper::name##Executable() \\ -{\\ - if (!m_##name##Executable)\\ - m_##name##Executable = JSC::Weak(JSC::createBuiltinExecutable(m_vm, m_##name##Source, functionName##PublicName(), s_##name##ConstructAbility), this, &m_##name##Executable);\\ - return m_##name##Executable.get();\\ -} -${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) -#undef DEFINE_BUILTIN_EXECUTABLES - -inline void ${objectName}BuiltinsWrapper::exportNames() -{ -#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) -#undef EXPORT_FUNCTION_NAME -}""") - - SeparateHeaderInternalFunctionsBoilerplate = ( - """class ${objectName}BuiltinFunctions { -public: - explicit ${objectName}BuiltinFunctions(JSC::VM& vm) : m_vm(vm) { } - - void init(JSC::JSGlobalObject&); - void visit(JSC::SlotVisitor&); - -public: - JSC::VM& m_vm; - -#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \\ - JSC::WriteBarrier m_##functionName##Function; - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS) -#undef DECLARE_BUILTIN_SOURCE_MEMBERS -}; - -inline void ${objectName}BuiltinFunctions::init(JSC::JSGlobalObject& globalObject) -{ -#define EXPORT_FUNCTION(codeName, functionName, length)\\ - m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::createBuiltinFunction(m_vm, codeName##Generator(m_vm), &globalObject)); - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(EXPORT_FUNCTION) -#undef EXPORT_FUNCTION -} - -inline void ${objectName}BuiltinFunctions::visit(JSC::SlotVisitor& visitor) -{ -#define VISIT_FUNCTION(name) visitor.append(&m_##name##Function); - ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION) -#undef VISIT_FUNCTION -} -""") diff --git a/Source/JavaScriptCore/Scripts/generate-js-builtins.py b/Source/JavaScriptCore/Scripts/generate-js-builtins.py index 554a72ccc..7a203ff08 100644 --- a/Source/JavaScriptCore/Scripts/generate-js-builtins.py +++ b/Source/JavaScriptCore/Scripts/generate-js-builtins.py @@ -31,16 +31,22 @@ import fnmatch import logging import optparse import os +import sys logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.ERROR) log = logging.getLogger('global') from lazywriter import LazyFileWriter -import builtins -from builtins import * +from wkbuiltins import * +def do_open(file, mode): + if sys.version_info.major == 2: + return open(file, mode) + else: + return open(file, mode, encoding="UTF-8") + def generate_bindings_for_builtins_files(builtins_files=[], output_path=None, concatenate_output=False, @@ -53,7 +59,7 @@ def generate_bindings_for_builtins_files(builtins_files=[], model = BuiltinsCollection(framework_name=framework_name) for filepath in builtins_files: - with open(filepath, "r") as file: + with do_open(filepath, "r") as file: file_text = file.read() file_name = os.path.basename(filepath) @@ -132,7 +138,7 @@ if __name__ == '__main__': for filepath in os.listdir(arg_options.input_directory): input_filepaths.append(os.path.join(arg_options.input_directory, filepath)) - input_filepaths = filter(lambda name: fnmatch.fnmatch(name, '*.js'), input_filepaths) + input_filepaths = sorted([name for name in input_filepaths if fnmatch.fnmatch(name, '*.js')]) options = { 'output_path': arg_options.output_directory, @@ -144,7 +150,7 @@ if __name__ == '__main__': log.debug("Generating code for builtins.") log.debug("Parsed options:") - for option, value in options.items(): + for option, value in list(options.items()): log.debug(" %s: %s" % (option, value)) log.debug("") log.debug("Input files:") diff --git a/Source/JavaScriptCore/Scripts/jsmin.py b/Source/JavaScriptCore/Scripts/jsmin.py index 372418b4d..7f110c9d3 100644 --- a/Source/JavaScriptCore/Scripts/jsmin.py +++ b/Source/JavaScriptCore/Scripts/jsmin.py @@ -28,12 +28,14 @@ import sys is_3 = sys.version_info >= (3, 0) if is_3: import io + python_text_type = str else: import StringIO try: import cStringIO except ImportError: cStringIO = None + python_text_type = basestring __all__ = ['jsmin', 'JavascriptMinify'] @@ -79,14 +81,18 @@ class JavascriptMinify(object): def write(char): # all of this is to support literal regular expressions. # sigh - if char in 'return': + if str(char) in 'return': self.return_buf += char self.is_return = self.return_buf == 'return' self.outs.write(char) if self.is_return: self.return_buf = '' - read = self.ins.read + def read(n): + char = self.ins.read(n) + if not isinstance(char, python_text_type): + raise ValueError("ERROR: The script jsmin.py can only handle text input, but it received input of type %s" % type(char)) + return char space_strings = "abcdefghijklmnopqrstuvwxyz"\ "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$\\" @@ -118,8 +124,8 @@ class JavascriptMinify(object): write(previous) elif not previous: return - elif previous >= '!': - if previous in "'\"": + elif str(previous) >= "!": + if str(previous) in "'\"": in_quote = previous write(previous) previous_non_space = previous @@ -166,7 +172,7 @@ class JavascriptMinify(object): if numslashes % 2 == 0: in_quote = '' write(''.join(quote_buf)) - elif next1 in '\r\n': + elif str(next1) in '\r\n': if previous_non_space in newlineend_strings \ or previous_non_space > '~': while 1: @@ -179,7 +185,7 @@ class JavascriptMinify(object): or next2 > '~' or next2 == '/': do_newline = True break - elif next1 < '!' and not in_re: + elif str(next1) < '!' and not in_re: if (previous_non_space in space_strings \ or previous_non_space > '~') \ and (next2 in space_strings or next2 > '~'): @@ -217,14 +223,14 @@ class JavascriptMinify(object): do_newline = False write(next1) - if not in_re and next1 in "'\"`": + if not in_re and str(next1) in "'\"`": in_quote = next1 quote_buf = [] previous = next1 next1 = next2 - if previous >= '!': + if str(previous) >= '!': previous_non_space = previous if previous == '\\': diff --git a/Source/JavaScriptCore/Scripts/make-js-file-arrays.py b/Source/JavaScriptCore/Scripts/make-js-file-arrays.py index 65056646a..d9ffb602e 100755 --- a/Source/JavaScriptCore/Scripts/make-js-file-arrays.py +++ b/Source/JavaScriptCore/Scripts/make-js-file-arrays.py @@ -21,11 +21,13 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from __future__ import print_function import io import os from optparse import OptionParser -from StringIO import StringIO -from jsmin import JavascriptMinify +import sys +from jsmin import jsmin +is_3 = sys.version_info >= (3, 0) def stringifyCodepoint(code): @@ -36,7 +38,7 @@ def stringifyCodepoint(code): def chunk(list, chunkSize): - for i in xrange(0, len(list), chunkSize): + for i in range(0, len(list), chunkSize): yield list[i:i + chunkSize] @@ -46,11 +48,11 @@ def main(): parser.add_option('-n', '--namespace', help='Namespace to use') (options, arguments) = parser.parse_args() if not options.namespace: - print 'Error: must provide a namespace' + print('Error: must provide a namespace') parser.print_usage() exit(-1) if len(arguments) < 3: - print 'Error: must provide at least 3 arguments' + print('Error: must provide at least 3 arguments') parser.print_usage() exit(-1) @@ -60,38 +62,47 @@ def main(): inputPaths = arguments[2:] headerFile = open(headerPath, 'w') - print >> headerFile, 'namespace {0:s} {{'.format(namespace) + print('namespace {0:s} {{'.format(namespace), file=headerFile) sourceFile = open(sourcePath, 'w') - print >> sourceFile, '#include "{0:s}"'.format(os.path.basename(headerPath)) - print >> sourceFile, 'namespace {0:s} {{'.format(namespace) - - jsm = JavascriptMinify() + print('#include "{0:s}"'.format(os.path.basename(headerPath)), file=sourceFile) + print('namespace {0:s} {{'.format(namespace), file=sourceFile) for inputFileName in inputPaths: - inputStream = io.FileIO(inputFileName) - outputStream = StringIO() + + if is_3: + inputStream = io.open(inputFileName, encoding='utf-8') + else: + inputStream = io.FileIO(inputFileName) + + data = inputStream.read() if not options.no_minify: - jsm.minify(inputStream, outputStream) - characters = outputStream.getvalue() + characters = jsmin(data) else: - characters = inputStream.read() + characters = data + + if is_3: + codepoints = bytearray(characters, encoding='utf-8') + else: + codepoints = list(map(ord, characters)) + + # Use the size of codepoints instead of the characters + # because UTF-8 characters may need more than one byte. + size = len(codepoints) - size = len(characters) variableName = os.path.splitext(os.path.basename(inputFileName))[0] - print >> headerFile, 'extern const char {0:s}JavaScript[{1:d}];'.format(variableName, size) - print >> sourceFile, 'const char {0:s}JavaScript[{1:d}] = {{'.format(variableName, size) + print('extern const char {0:s}JavaScript[{1:d}];'.format(variableName, size), file=headerFile) + print('const char {0:s}JavaScript[{1:d}] = {{'.format(variableName, size), file=sourceFile) - codepoints = map(ord, characters) for codepointChunk in chunk(codepoints, 16): - print >> sourceFile, ' {0:s},'.format(','.join(map(stringifyCodepoint, codepointChunk))) + print(' {0:s},'.format(','.join(map(stringifyCodepoint, codepointChunk))), file=sourceFile) - print >> sourceFile, '};' + print('};', file=sourceFile) - print >> headerFile, '}} // namespace {0:s}'.format(namespace) - print >> sourceFile, '}} // namespace {0:s}'.format(namespace) + print('}} // namespace {0:s}'.format(namespace), file=headerFile) + print('}} // namespace {0:s}'.format(namespace), file=sourceFile) if __name__ == '__main__': main() diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/__init__.py b/Source/JavaScriptCore/Scripts/wkbuiltins/__init__.py new file mode 100644 index 000000000..ffa849ea5 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/__init__.py @@ -0,0 +1,3 @@ +# Required for Python to search this directory for module files + +from .wkbuiltins import * diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_header.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_header.py new file mode 100644 index 000000000..891bd3cb4 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_header.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. +# Copyright (c) 2014 University of Washington. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + + +import logging +import re +import string +from string import Template + +from builtins_generator import BuiltinsGenerator +from builtins_templates import BuiltinsGeneratorTemplates as Templates + +log = logging.getLogger('global') + + +class BuiltinsCombinedHeaderGenerator(BuiltinsGenerator): + def __init__(self, model): + BuiltinsGenerator.__init__(self, model) + + def output_filename(self): + return "%sBuiltins.h" % self.model().framework.setting('namespace') + + def generate_output(self): + args = { + 'namespace': self.model().framework.setting('namespace'), + 'headerGuard': self.output_filename().replace('.', '_'), + 'macroPrefix': self.model().framework.setting('macro_prefix'), + } + + sections = [] + sections.append(self.generate_license()) + sections.append(Template(Templates.DoNotEditWarning).substitute(args)) + sections.append(Template(Templates.HeaderIncludeGuardTop).substitute(args)) + sections.append(self.generate_forward_declarations()) + sections.append(Template(Templates.NamespaceTop).substitute(args)) + for object in self.model().objects: + sections.append(self.generate_section_for_object(object)) + sections.append(self.generate_section_for_code_table_macro()) + sections.append(self.generate_section_for_code_name_macro()) + sections.append(Template(Templates.CombinedHeaderStaticMacros).substitute(args)) + sections.append(Template(Templates.NamespaceBottom).substitute(args)) + sections.append(Template(Templates.HeaderIncludeGuardBottom).substitute(args)) + + return "\n\n".join(sections) + + def generate_forward_declarations(self): + return """namespace JSC { +class FunctionExecutable; +class VM; + +enum class ConstructAbility : unsigned; +}""" + + def generate_section_for_object(self, object): + lines = [] + lines.append('/* %s */' % object.object_name) + lines.extend(self.generate_externs_for_object(object)) + lines.append("") + lines.extend(self.generate_macros_for_object(object)) + return '\n'.join(lines) + + def generate_externs_for_object(self, object): + lines = [] + + for function in object.functions: + function_args = { + 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', + } + + lines.append("""extern const char* s_%(codeName)s; +extern const int s_%(codeName)sLength; +extern const JSC::ConstructAbility s_%(codeName)sConstructAbility;""" % function_args) + + return lines + + def generate_macros_for_object(self, object): + args = { + 'macroPrefix': self.model().framework.setting('macro_prefix'), + 'objectMacro': object.object_name.replace('.', '').upper(), + } + + lines = [] + lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_DATA(macro) \\" % args) + for function in object.functions: + function_args = { + 'funcName': function.function_name, + 'mangledName': BuiltinsGenerator.mangledNameForFunction(function), + 'paramCount': len(function.parameters), + } + + lines.append(" macro(%(funcName)s, %(mangledName)s, %(paramCount)d) \\" % function_args) + return lines + + def generate_section_for_code_table_macro(self): + args = { + 'macroPrefix': self.model().framework.setting('macro_prefix'), + } + + lines = [] + lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_CODE(macro) \\" % args) + for function in self.model().all_functions(): + function_args = { + 'funcName': function.function_name, + 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', + } + + lines.append(" macro(%(codeName)s, %(funcName)s, s_%(codeName)sLength) \\" % function_args) + return '\n'.join(lines) + + def generate_section_for_code_name_macro(self): + args = { + 'macroPrefix': self.model().framework.setting('macro_prefix'), + } + + internal_function_names = [function.function_name for function in self.model().all_internal_functions()] + if len(internal_function_names) != len(set(internal_function_names)): + log.error("There are several internal functions with the same name. Private identifiers may clash.") + + lines = [] + lines.append("#define %(macroPrefix)s_FOREACH_BUILTIN_FUNCTION_NAME(macro) \\" % args) + unique_names = list(set([function.function_name for function in self.model().all_functions()])) + unique_names.sort() + for function_name in unique_names: + function_args = { + 'funcName': function_name, + } + + lines.append(" macro(%(funcName)s) \\" % function_args) + return '\n'.join(lines) diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_implementation.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_implementation.py new file mode 100644 index 000000000..094434b64 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_combined_implementation.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. +# Copyright (c) 2014 University of Washington. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + + +import logging +import re +import string +from string import Template + +from builtins_generator import BuiltinsGenerator +from builtins_model import Framework, Frameworks +from builtins_templates import BuiltinsGeneratorTemplates as Templates + +log = logging.getLogger('global') + + +class BuiltinsCombinedImplementationGenerator(BuiltinsGenerator): + def __init__(self, model): + BuiltinsGenerator.__init__(self, model) + + def output_filename(self): + return "%sBuiltins.cpp" % self.model().framework.setting('namespace') + + def generate_output(self): + args = { + 'namespace': self.model().framework.setting('namespace'), + 'macroPrefix': self.model().framework.setting('macro_prefix'), + } + + sections = [] + sections.append(self.generate_license()) + sections.append(Template(Templates.DoNotEditWarning).substitute(args)) + sections.append(self.generate_primary_header_includes()) + sections.append(self.generate_secondary_header_includes()) + sections.append(Template(Templates.NamespaceTop).substitute(args)) + for function in self.model().all_functions(): + sections.append(self.generate_embedded_code_string_section_for_function(function)) + if self.model().framework is Frameworks.JavaScriptCore: + sections.append(Template(Templates.CombinedJSCImplementationStaticMacros).substitute(args)) + elif self.model().framework is Frameworks.WebCore: + sections.append(Template(Templates.CombinedWebCoreImplementationStaticMacros).substitute(args)) + sections.append(Template(Templates.NamespaceBottom).substitute(args)) + + return "\n\n".join(sections) + + def generate_secondary_header_includes(self): + header_includes = [ + (["JavaScriptCore"], + ("JavaScriptCore", "builtins/BuiltinExecutables.h"), + ), + (["JavaScriptCore", "WebCore"], + ("JavaScriptCore", "runtime/Executable.h"), + ), + (["JavaScriptCore", "WebCore"], + ("JavaScriptCore", "runtime/JSCellInlines.h"), + ), + (["WebCore"], + ("JavaScriptCore", "runtime/StructureInlines.h"), + ), + (["WebCore"], + ("JavaScriptCore", "runtime/JSCJSValueInlines.h"), + ), + (["JavaScriptCore", "WebCore"], + ("JavaScriptCore", "runtime/VM.h"), + ), + ] + + return '\n'.join(self.generate_includes_from_entries(header_includes)) diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_header.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_header.py new file mode 100644 index 000000000..b72a94bfe --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_header.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. +# Copyright (c) 2014 University of Washington. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + + +import logging +import re +import string +from string import Template + +from builtins_generator import BuiltinsGenerator +from builtins_model import Frameworks +from builtins_templates import BuiltinsGeneratorTemplates as Templates + +log = logging.getLogger('global') + + +class BuiltinsSeparateHeaderGenerator(BuiltinsGenerator): + def __init__(self, model, object): + BuiltinsGenerator.__init__(self, model) + self.object = object + + def output_filename(self): + return "%sBuiltins.h" % BuiltinsGenerator.mangledNameForObject(self.object) + + def macro_prefix(self): + return self.model().framework.setting('macro_prefix') + + def generate_output(self): + args = { + 'namespace': self.model().framework.setting('namespace'), + 'headerGuard': self.output_filename().replace('.', '_'), + 'macroPrefix': self.macro_prefix(), + 'objectName': self.object.object_name, + 'objectMacro': self.object.object_name.upper(), + } + + conditional_guard = self.object.annotations.get('conditional') + + sections = [] + sections.append(self.generate_license()) + sections.append(Template(Templates.DoNotEditWarning).substitute(args)) + sections.append(Template(Templates.HeaderIncludeGuardTop).substitute(args)) + if conditional_guard is not None: + sections.append("#if %s" % conditional_guard) + sections.append(self.generate_secondary_header_includes()) + sections.append(self.generate_forward_declarations()) + sections.append(Template(Templates.NamespaceTop).substitute(args)) + sections.append(self.generate_section_for_object(self.object)) + sections.append(self.generate_section_for_code_table_macro()) + sections.append(self.generate_section_for_code_name_macro()) + sections.append(Template(Templates.SeparateHeaderStaticMacros).substitute(args)) + if self.model().framework is Frameworks.WebCore: + sections.append(Template(Templates.SeparateHeaderWrapperBoilerplate).substitute(args)) + if self.object.annotations.get('internal'): + sections.append(Template(Templates.SeparateHeaderInternalFunctionsBoilerplate).substitute(args)) + sections.append(Template(Templates.NamespaceBottom).substitute(args)) + if conditional_guard is not None: + sections.append("#endif // %s" % conditional_guard) + sections.append(Template(Templates.HeaderIncludeGuardBottom).substitute(args)) + + return "\n\n".join(sections) + + def generate_forward_declarations(self): + return """namespace JSC { +class FunctionExecutable; +}""" + + def generate_secondary_header_includes(self): + header_includes = [ + (["WebCore"], + ("JavaScriptCore", "bytecode/UnlinkedFunctionExecutable.h"), + ), + + (["WebCore"], + ("JavaScriptCore", "builtins/BuiltinUtils.h"), + ), + + (["WebCore"], + ("JavaScriptCore", "runtime/Identifier.h"), + ), + + (["WebCore"], + ("JavaScriptCore", "runtime/JSFunction.h"), + ), + ] + + return '\n'.join(self.generate_includes_from_entries(header_includes)) + + def generate_section_for_object(self, object): + lines = [] + lines.append('/* %s */' % object.object_name) + lines.extend(self.generate_externs_for_object(object)) + lines.append("") + lines.extend(self.generate_macros_for_object(object)) + lines.append("") + lines.extend(self.generate_defines_for_object(object)) + return '\n'.join(lines) + + def generate_externs_for_object(self, object): + lines = [] + + for function in object.functions: + function_args = { + 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', + } + + lines.append("""extern const char* s_%(codeName)s; +extern const int s_%(codeName)sLength; +extern const JSC::ConstructAbility s_%(codeName)sConstructAbility;""" % function_args) + + return lines + + def generate_macros_for_object(self, object): + args = { + 'macroPrefix': self.macro_prefix(), + 'objectMacro': object.object_name.replace('.', '_').upper(), + } + + lines = [] + lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_DATA(macro) \\" % args) + for function in object.functions: + function_args = { + 'funcName': function.function_name, + 'mangledName': BuiltinsGenerator.mangledNameForFunction(function), + 'paramCount': len(function.parameters), + } + + lines.append(" macro(%(funcName)s, %(mangledName)s, %(paramCount)d) \\" % function_args) + return lines + + def generate_defines_for_object(self, object): + lines = [] + for function in object.functions: + args = { + 'macroPrefix': self.macro_prefix(), + 'objectMacro': object.object_name.replace('.', '_').upper(), + 'functionMacro': function.function_name.upper(), + } + lines.append("#define %(macroPrefix)s_BUILTIN_%(objectMacro)s_%(functionMacro)s 1" % args) + + return lines + + def generate_section_for_code_table_macro(self): + args = { + 'macroPrefix': self.model().framework.setting('macro_prefix'), + 'objectMacro': self.object.object_name.upper(), + } + + lines = [] + lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_CODE(macro) \\" % args) + for function in self.object.functions: + function_args = { + 'funcName': function.function_name, + 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', + } + + lines.append(" macro(%(codeName)s, %(funcName)s, s_%(codeName)sLength) \\" % function_args) + return '\n'.join(lines) + + def generate_section_for_code_name_macro(self): + args = { + 'macroPrefix': self.macro_prefix(), + 'objectMacro': self.object.object_name.upper(), + } + + lines = [] + lines.append("#define %(macroPrefix)s_FOREACH_%(objectMacro)s_BUILTIN_FUNCTION_NAME(macro) \\" % args) + unique_names = list(set([function.function_name for function in self.object.functions])) + unique_names.sort() + for function_name in unique_names: + function_args = { + 'funcName': function_name, + } + + lines.append(" macro(%(funcName)s) \\" % function_args) + return '\n'.join(lines) diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_implementation.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_implementation.py new file mode 100644 index 000000000..0443975da --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generate_separate_implementation.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. +# Copyright (c) 2014 University of Washington. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + + +import logging +import re +import string +from string import Template + +from builtins_generator import BuiltinsGenerator, WK_lcfirst +from builtins_model import Framework, Frameworks +from builtins_templates import BuiltinsGeneratorTemplates as Templates + +log = logging.getLogger('global') + + +class BuiltinsSeparateImplementationGenerator(BuiltinsGenerator): + def __init__(self, model, object): + BuiltinsGenerator.__init__(self, model) + self.object = object + + def output_filename(self): + return "%sBuiltins.cpp" % BuiltinsGenerator.mangledNameForObject(self.object) + + def macro_prefix(self): + return self.model().framework.setting('macro_prefix') + + def generate_output(self): + args = { + 'namespace': self.model().framework.setting('namespace'), + 'macroPrefix': self.macro_prefix(), + 'objectMacro': self.object.object_name.upper(), + 'objectNameLC': WK_lcfirst(self.object.object_name), + } + + conditional_guard = self.object.annotations.get('conditional') + + sections = [] + sections.append(self.generate_license()) + sections.append(Template(Templates.DoNotEditWarning).substitute(args)) + sections.append(self.generate_primary_header_includes()) + if conditional_guard is not None: + sections.append("#if %s" % conditional_guard) + sections.append(self.generate_secondary_header_includes()) + sections.append(Template(Templates.NamespaceTop).substitute(args)) + for function in self.object.functions: + sections.append(self.generate_embedded_code_string_section_for_function(function)) + if self.model().framework is Frameworks.JavaScriptCore: + sections.append(Template(Templates.SeparateJSCImplementationStaticMacros).substitute(args)) + elif self.model().framework is Frameworks.WebCore: + sections.append(Template(Templates.SeparateWebCoreImplementationStaticMacros).substitute(args)) + sections.append(Template(Templates.NamespaceBottom).substitute(args)) + if conditional_guard is not None: + sections.append("#endif // %s\n" % conditional_guard) + + return "\n\n".join(sections) + + def generate_secondary_header_includes(self): + header_includes = [ + (["JavaScriptCore"], + ("JavaScriptCore", "builtins/BuiltinExecutables.h"), + ), + (["JavaScriptCore", "WebCore"], + ("JavaScriptCore", "runtime/Executable.h"), + ), + (["JavaScriptCore", "WebCore"], + ("JavaScriptCore", "runtime/JSCellInlines.h"), + ), + (["WebCore"], + ("JavaScriptCore", "runtime/StructureInlines.h"), + ), + (["WebCore"], + ("JavaScriptCore", "runtime/JSCJSValueInlines.h"), + ), + (["JavaScriptCore", "WebCore"], + ("JavaScriptCore", "runtime/VM.h"), + ), + (["WebCore"], + ("WebCore", "bindings/js/WebCoreJSClientData.h"), + ), + ] + + return '\n'.join(self.generate_includes_from_entries(header_includes)) diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generator.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generator.py new file mode 100644 index 000000000..21ac4c1d9 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_generator.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. +# Copyright (c) 2014 University of Washington. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +import logging +import os.path +import re +from string import Template +import json + +from builtins_model import BuiltinFunction, BuiltinObject +from builtins_templates import BuiltinsGeneratorTemplates as Templates + +log = logging.getLogger('global') + +# These match WK_lcfirst and WK_ucfirst defined in CodeGenerator.pm. +def WK_lcfirst(str): + str = str[:1].lower() + str[1:] + str = str.replace('hTML', 'html') + str = str.replace('uRL', 'url') + str = str.replace('jS', 'js') + str = str.replace('xML', 'xml') + str = str.replace('xSLT', 'xslt') + str = str.replace('cSS', 'css') + str = str.replace('rTC', 'rtc') + return str + +def WK_ucfirst(str): + str = str[:1].upper() + str[1:] + str = str.replace('Xml', 'XML') + str = str.replace('Svg', 'SVG') + return str + +class BuiltinsGenerator: + def __init__(self, model): + self._model = model + + def model(self): + return self._model + + # These methods are overridden by subclasses. + + def generate_output(self): + pass + + def output_filename(self): + pass + + + # Shared code generation methods. + def generate_license(self): + raw_license = Template(Templates.LicenseText).substitute(None) + copyrights = self._model.copyrights() + copyrights.sort() + + license_block = [] + license_block.append("/*") + for copyright in copyrights: + license_block.append(" * Copyright (c) %s" % copyright) + if len(copyrights) > 0: + license_block.append(" * ") + + for line in raw_license.split('\n'): + license_block.append(" * " + line) + + license_block.append(" */") + + return '\n'.join(license_block) + + def generate_includes_from_entries(self, entries): + includes = set() + for entry in entries: + (allowed_framework_names, data) = entry + (framework_name, header_path) = data + + if self.model().framework.name not in allowed_framework_names: + continue + if self.model().framework.name != framework_name: + includes.add("#include <%s>" % header_path) + else: + includes.add("#include \"%s\"" % os.path.basename(header_path)) + + return sorted(list(includes)) + + def generate_primary_header_includes(self): + name, _ = os.path.splitext(self.output_filename()) + return '\n'.join([ + "#include \"config.h\"", + "#include \"%s.h\"" % name, + ]) + + def generate_embedded_code_string_section_for_function(self, function): + text = function.function_source + # Wrap it in parens to avoid adding to global scope. + text = "(function " + text[text.index("("):] + ")" + embeddedSourceLength = len(text) + 1 # For extra \n. + # Lazy way to escape quotes, I think? + textLines = json.dumps(text)[1:-1].split("\\n") + # This looks scary because we need the JS source itself to have newlines. + embeddedSource = '\n'.join([' "%s\\n" \\' % line for line in textLines]) + + constructAbility = "CannotConstruct" + if function.is_constructor: + constructAbility = "CanConstruct" + + args = { + 'codeName': BuiltinsGenerator.mangledNameForFunction(function) + 'Code', + 'embeddedSource': embeddedSource, + 'embeddedSourceLength': embeddedSourceLength, + 'canConstruct': constructAbility + } + + lines = [] + lines.append("const JSC::ConstructAbility s_%(codeName)sConstructAbility = JSC::ConstructAbility::%(canConstruct)s;" % args); + lines.append("const int s_%(codeName)sLength = %(embeddedSourceLength)d;" % args); + lines.append("const char* s_%(codeName)s =\n%(embeddedSource)s\n;" % args); + return '\n'.join(lines) + + # Helper methods. + + @staticmethod + def mangledNameForObject(object): + if not isinstance(object, BuiltinObject): + raise Exception("Invalid argument passed to mangledNameForObject()") + + def toCamel(match): + str = match.group(0) + return str[1].upper() + return re.sub(r'\.[a-z]', toCamel, object.object_name, flags=re.IGNORECASE) + + + @staticmethod + def mangledNameForFunction(function): + if not isinstance(function, BuiltinFunction): + raise Exception("Invalid argument passed to mangledNameForFunction()") + + function_name = WK_ucfirst(function.function_name) + + def toCamel(match): + str = match.group(0) + return str[1].upper() + function_name = re.sub(r'\.[a-z]', toCamel, function_name, flags=re.IGNORECASE) + if function.is_constructor: + function_name = function_name + "Constructor" + + object_name = BuiltinsGenerator.mangledNameForObject(function.object) + return WK_lcfirst(object_name + function_name) diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_model.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_model.py new file mode 100644 index 000000000..47e33e6a8 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_model.py @@ -0,0 +1,277 @@ +#!/usr/bin/env python +# +# Copyright (c) 2015 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +import logging +import re +import os + +log = logging.getLogger('global') + +_FRAMEWORK_CONFIG_MAP = { + "JavaScriptCore": { + "macro_prefix": "JSC", + "namespace": "JSC", + }, + "WebCore": { + "macro_prefix": "WEBCORE", + "namespace": "WebCore", + }, +} + +functionHeadRegExp = re.compile(r"(?:function|constructor)\s+\w+\s*\(.*?\)", re.MULTILINE | re.S) +functionNameRegExp = re.compile(r"(?:function|constructor)\s+(\w+)\s*\(", re.MULTILINE | re.S) +functionIsConstructorRegExp = re.compile(r"^constructor", re.MULTILINE | re.S) +functionParameterFinder = re.compile(r"^(?:function|constructor)\s+(?:\w+)\s*\(((?:\s*\w+)?\s*(?:\s*,\s*\w+)*)?\s*\)", re.MULTILINE | re.S) + +multilineCommentRegExp = re.compile(r"\/\*.*?\*\/", re.MULTILINE | re.S) +singleLineCommentRegExp = re.compile(r"\/\/.*?\n", re.MULTILINE | re.S) +keyValueAnnotationCommentRegExp = re.compile(r"^\/\/ @(\w+)=([^=]+?)\n", re.MULTILINE | re.S) +flagAnnotationCommentRegExp = re.compile(r"^\/\/ @(\w+)[^=]*?\n", re.MULTILINE | re.S) +lineWithOnlySingleLineCommentRegExp = re.compile(r"^\s*\/\/\n", re.MULTILINE | re.S) +lineWithTrailingSingleLineCommentRegExp = re.compile(r"\s*\/\/\n", re.MULTILINE | re.S) +multipleEmptyLinesRegExp = re.compile(r"\n{2,}", re.MULTILINE | re.S) + +class ParseException(Exception): + pass + + +class Framework: + def __init__(self, name): + self._settings = _FRAMEWORK_CONFIG_MAP[name] + self.name = name + + def setting(self, key, default=''): + return self._settings.get(key, default) + + @staticmethod + def fromString(frameworkString): + if frameworkString == "JavaScriptCore": + return Frameworks.JavaScriptCore + + if frameworkString == "WebCore": + return Frameworks.WebCore + + raise ParseException("Unknown framework: %s" % frameworkString) + + +class Frameworks: + JavaScriptCore = Framework("JavaScriptCore") + WebCore = Framework("WebCore") + + +class BuiltinObject: + def __init__(self, object_name, annotations, functions): + self.object_name = object_name + self.annotations = annotations + self.functions = functions + self.collection = None # Set by the owning BuiltinsCollection + + for function in self.functions: + function.object = self + + +class BuiltinFunction: + def __init__(self, function_name, function_source, is_constructor, parameters): + self.function_name = function_name + self.function_source = function_source + self.is_constructor = is_constructor + self.parameters = parameters + self.object = None # Set by the owning BuiltinObject + + @staticmethod + def fromString(function_string): + function_source = multilineCommentRegExp.sub("", function_string) + if os.getenv("CONFIGURATION", "Debug").startswith("Debug"): + function_source = lineWithOnlySingleLineCommentRegExp.sub("", function_source) + function_source = lineWithTrailingSingleLineCommentRegExp.sub("\n", function_source) + function_source = multipleEmptyLinesRegExp.sub("\n", function_source) + + function_name = functionNameRegExp.findall(function_source)[0] + is_constructor = functionIsConstructorRegExp.match(function_source) != None + parameters = [s.strip() for s in functionParameterFinder.findall(function_source)[0].split(',')] + if len(parameters[0]) == 0: + parameters = [] + + return BuiltinFunction(function_name, function_source, is_constructor, parameters) + + def __str__(self): + interface = "%s(%s)" % (self.function_name, ', '.join(self.parameters)) + if self.is_constructor: + interface = interface + " [Constructor]" + + return interface + + def __lt__(self, other): + return self.function_name < other.function_name + + +class BuiltinsCollection: + def __init__(self, framework_name): + self._copyright_lines = set() + self.objects = [] + self.framework = Framework.fromString(framework_name) + log.debug("Created new Builtins collection.") + + def parse_builtins_file(self, filename, text): + log.debug("Parsing builtins file: %s" % filename) + + parsed_copyrights = set(self._parse_copyright_lines(text)) + self._copyright_lines = self._copyright_lines.union(parsed_copyrights) + + log.debug("Found copyright lines:") + for line in self._copyright_lines: + log.debug(line) + log.debug("") + + object_annotations = self._parse_annotations(text) + + object_name, ext = os.path.splitext(os.path.basename(filename)) + log.debug("Parsing object: %s" % object_name) + + parsed_functions = self._parse_functions(text) + for function in parsed_functions: + function.object = object_name + + log.debug("Parsed functions:") + for func in parsed_functions: + log.debug(func) + log.debug("") + + new_object = BuiltinObject(object_name, object_annotations, parsed_functions) + new_object.collection = self + self.objects.append(new_object) + + def copyrights(self): + owner_to_years = dict() + copyrightYearRegExp = re.compile(r"(\d{4})[, ]{0,2}") + ownerStartRegExp = re.compile(r"[^\d, ]") + + # Returns deduplicated copyrights keyed on the owner. + for line in self._copyright_lines: + years = set(copyrightYearRegExp.findall(line)) + ownerIndex = ownerStartRegExp.search(line).start() + owner = line[ownerIndex:] + log.debug("Found years: %s and owner: %s" % (years, owner)) + if owner not in owner_to_years: + owner_to_years[owner] = set() + + owner_to_years[owner] = owner_to_years[owner].union(years) + + result = [] + + for owner, years in list(owner_to_years.items()): + sorted_years = list(years) + sorted_years.sort() + result.append("%s %s" % (', '.join(sorted_years), owner)) + + return result + + def all_functions(self): + result = [] + for object in self.objects: + result.extend(object.functions) + + result.sort() + return result + + def all_internal_functions(self): + result = [] + for object in [o for o in self.objects if 'internal' in o.annotations]: + result.extend(object.functions) + + result.sort() + return result + + # Private methods. + + def _parse_copyright_lines(self, text): + licenseBlock = multilineCommentRegExp.findall(text)[0] + licenseBlock = licenseBlock[:licenseBlock.index("Redistribution")] + + copyrightLines = [] + for line in licenseBlock.split("\n"): + line = line.replace("/*", "") + line = line.replace("*/", "") + line = line.replace("*", "") + line = line.replace("Copyright", "") + line = line.replace("copyright", "") + line = line.replace("(C)", "") + line = line.replace("(c)", "") + line = line.strip() + + if len(line) == 0: + continue + + copyrightLines.append(line) + + return copyrightLines + + def _parse_annotations(self, text): + annotations = {} + + for match in keyValueAnnotationCommentRegExp.finditer(text): + (key, value) = match.group(1, 2) + log.debug("Found annotation: '%s' => '%s'" % (key, value)) + if key in annotations: + raise ParseException("Duplicate annotation found: %s" % key) + + annotations[key] = value + + for match in flagAnnotationCommentRegExp.finditer(text): + key = match.group(1) + log.debug("Found annotation: '%s' => 'TRUE'" % key) + if key in annotations: + raise ParseException("Duplicate annotation found: %s" % key) + + annotations[key] = True + + return annotations + + def _parse_functions(self, text): + text = multilineCommentRegExp.sub("/**/", singleLineCommentRegExp.sub("//\n", text)) + + matches = [func for func in functionHeadRegExp.finditer(text)] + functionBounds = [] + start = 0 + end = 0 + for match in matches: + start = match.start() + if start < end: + continue + end = match.end() + while text[end] != '{': + end = end + 1 + depth = 1 + end = end + 1 + while depth > 0: + if text[end] == '{': + depth = depth + 1 + elif text[end] == '}': + depth = depth - 1 + end = end + 1 + functionBounds.append((start, end)) + + functionStrings = [text[start:end].strip() for (start, end) in functionBounds] + return list(map(BuiltinFunction.fromString, functionStrings)) diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_templates.py b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_templates.py new file mode 100644 index 000000000..67cdd5df7 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/builtins_templates.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014, 2015 Apple Inc. All rights reserved. +# Copyright (C) 2015 Canon Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +# Builtins generator templates, which can be filled with string.Template. + + +class BuiltinsGeneratorTemplates: + + LicenseText = ( + """Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. +""") + + DoNotEditWarning = ( + """// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for +// builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py""") + + HeaderIncludeGuardTop = ( + """#ifndef ${headerGuard} +#define ${headerGuard}""") + + HeaderIncludeGuardBottom = ( + """#endif // ${headerGuard} +""") + + NamespaceTop = ( + """namespace ${namespace} {""") + + NamespaceBottom = ( + """} // namespace ${namespace}""") + + CombinedHeaderStaticMacros = ( + """#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ + JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +${macroPrefix}_FOREACH_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +#undef DECLARE_BUILTIN_GENERATOR""") + + SeparateHeaderStaticMacros = ( + """#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ + JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +#undef DECLARE_BUILTIN_GENERATOR""") + + CombinedJSCImplementationStaticMacros = ( + """ +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ +{\\ + return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \ +} +${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR +""") + + SeparateJSCImplementationStaticMacros = ( + """ +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ +{\\ + return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \ +} +${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR +""") + + CombinedWebCoreImplementationStaticMacros = ( + """ +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ +{\\ + JSVMClientData* clientData = static_cast(vm.clientData); \\ + return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source()); \\ +} +${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR +""") + + SeparateWebCoreImplementationStaticMacros = ( + """ +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\ +{\\ + JSVMClientData* clientData = static_cast(vm.clientData); \\ + return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source()); \\ +} +${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR +""") + + SeparateHeaderWrapperBoilerplate = ( + """class ${objectName}BuiltinsWrapper : private JSC::WeakHandleOwner { +public: + explicit ${objectName}BuiltinsWrapper(JSC::VM* vm) + : m_vm(*vm) + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length))) + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) +#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS + { + } + +#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, length) \\ + JSC::UnlinkedFunctionExecutable* name##Executable(); \\ + const JSC::SourceCode& name##Source() const { return m_##name##Source; } + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) +#undef EXPOSE_BUILTIN_EXECUTABLES + + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) + + void exportNames(); + +private: + JSC::VM& m_vm; + + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, length) \\ + JSC::SourceCode m_##name##Source;\\ + JSC::Weak m_##name##Executable; + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS + +}; + +#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, length) \\ +inline JSC::UnlinkedFunctionExecutable* ${objectName}BuiltinsWrapper::name##Executable() \\ +{\\ + if (!m_##name##Executable)\\ + m_##name##Executable = JSC::Weak(JSC::createBuiltinExecutable(m_vm, m_##name##Source, functionName##PublicName(), s_##name##ConstructAbility), this, &m_##name##Executable);\\ + return m_##name##Executable.get();\\ +} +${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) +#undef DEFINE_BUILTIN_EXECUTABLES + +inline void ${objectName}BuiltinsWrapper::exportNames() +{ +#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) +#undef EXPORT_FUNCTION_NAME +}""") + + SeparateHeaderInternalFunctionsBoilerplate = ( + """class ${objectName}BuiltinFunctions { +public: + explicit ${objectName}BuiltinFunctions(JSC::VM& vm) : m_vm(vm) { } + + void init(JSC::JSGlobalObject&); + void visit(JSC::SlotVisitor&); + +public: + JSC::VM& m_vm; + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \\ + JSC::WriteBarrier m_##functionName##Function; + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS +}; + +inline void ${objectName}BuiltinFunctions::init(JSC::JSGlobalObject& globalObject) +{ +#define EXPORT_FUNCTION(codeName, functionName, length)\\ + m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::createBuiltinFunction(m_vm, codeName##Generator(m_vm), &globalObject)); + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(EXPORT_FUNCTION) +#undef EXPORT_FUNCTION +} + +inline void ${objectName}BuiltinFunctions::visit(JSC::SlotVisitor& visitor) +{ +#define VISIT_FUNCTION(name) visitor.append(&m_##name##Function); + ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION) +#undef VISIT_FUNCTION +} +""") diff --git a/Source/JavaScriptCore/Scripts/wkbuiltins/wkbuiltins.py b/Source/JavaScriptCore/Scripts/wkbuiltins/wkbuiltins.py new file mode 100644 index 000000000..13216b3b5 --- /dev/null +++ b/Source/JavaScriptCore/Scripts/wkbuiltins/wkbuiltins.py @@ -0,0 +1,11 @@ +# This file is used to simulate the wkbuiltins/ directory when generate-js-builtins.py +# is run from JavaScriptCore framework's private headers directory, which is flattened. + +from builtins_model import * +from builtins_templates import * + +from builtins_generator import * +from builtins_generate_combined_header import * +from builtins_generate_combined_implementation import * +from builtins_generate_separate_header import * +from builtins_generate_separate_implementation import * diff --git a/Source/JavaScriptCore/disassembler/udis86/ud_opcode.py b/Source/JavaScriptCore/disassembler/udis86/ud_opcode.py index fe1833dc7..30c9f436c 100644 --- a/Source/JavaScriptCore/disassembler/udis86/ud_opcode.py +++ b/Source/JavaScriptCore/disassembler/udis86/ud_opcode.py @@ -550,10 +550,10 @@ class UdOpcodeTables(object): entries = tbl.entries() for k, e in entries: if isinstance(e, UdOpcodeTable): - self.log("%s |-<%02x> %s" % (indent, k, e)) + self.log("%s |-<%02x> %s" % (indent, int(k), e)) printWalk(e, indent + " |") elif isinstance(e, UdInsnDef): - self.log("%s |-<%02x> %s" % (indent, k, e)) + self.log("%s |-<%02x> %s" % (indent, int(k), e)) printWalk(self.root) diff --git a/Source/JavaScriptCore/generate-bytecode-files b/Source/JavaScriptCore/generate-bytecode-files index 5666a3f92..c5dab429c 100644 --- a/Source/JavaScriptCore/generate-bytecode-files +++ b/Source/JavaScriptCore/generate-bytecode-files @@ -91,7 +91,7 @@ def openOrExit(path, mode): try: return open(path, mode) except IOError as e: - print "I/O error opening {0}, ({1}): {2}".format(path, e.errno, e.strerror) + print("I/O error opening {0}, ({1}): {2}".format(path, e.errno, e.strerror)) exit(1) def hashFile(file): @@ -157,15 +157,15 @@ if __name__ == "__main__": exit(0) if bytecodeHFilename: - bytecodeHFile = openOrExit(bytecodeHFilename, "wb") + bytecodeHFile = openOrExit(bytecodeHFilename, "w") if initASMFileName: - initBytecodesFile = openOrExit(initASMFileName, "wb") + initBytecodesFile = openOrExit(initASMFileName, "w") try: bytecodeSections = json.load(bytecodeFile, encoding = "utf-8") except: - print "Unexpected error parsing {0}: {1}".format(bytecodeJSONFile, sys.exc_info()) + print("Unexpected error parsing {0}: {1}".format(bytecodeJSONFile, sys.exc_info())) if bytecodeHFilename: bytecodeHFile.write(hFileHashString) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/__init__.py b/Source/JavaScriptCore/inspector/scripts/codegen/__init__.py index 6077fa97a..bd30c817c 100644 --- a/Source/JavaScriptCore/inspector/scripts/codegen/__init__.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/__init__.py @@ -1,24 +1,24 @@ # Required for Python to search this directory for module files -from models import * -from generator import * -from cpp_generator import * -from objc_generator import * +from .models import * +from .generator import * +from .cpp_generator import * +from .objc_generator import * -from generate_cpp_alternate_backend_dispatcher_header import * -from generate_cpp_backend_dispatcher_header import * -from generate_cpp_backend_dispatcher_implementation import * -from generate_cpp_frontend_dispatcher_header import * -from generate_cpp_frontend_dispatcher_implementation import * -from generate_cpp_protocol_types_header import * -from generate_cpp_protocol_types_implementation import * -from generate_js_backend_commands import * -from generate_objc_backend_dispatcher_header import * -from generate_objc_backend_dispatcher_implementation import * -from generate_objc_configuration_header import * -from generate_objc_configuration_implementation import * -from generate_objc_conversion_helpers import * -from generate_objc_frontend_dispatcher_implementation import * -from generate_objc_header import * -from generate_objc_internal_header import * -from generate_objc_protocol_types_implementation import * +from .generate_cpp_alternate_backend_dispatcher_header import * +from .generate_cpp_backend_dispatcher_header import * +from .generate_cpp_backend_dispatcher_implementation import * +from .generate_cpp_frontend_dispatcher_header import * +from .generate_cpp_frontend_dispatcher_implementation import * +from .generate_cpp_protocol_types_header import * +from .generate_cpp_protocol_types_implementation import * +from .generate_js_backend_commands import * +from .generate_objc_backend_dispatcher_header import * +from .generate_objc_backend_dispatcher_implementation import * +from .generate_objc_configuration_header import * +from .generate_objc_configuration_implementation import * +from .generate_objc_conversion_helpers import * +from .generate_objc_frontend_dispatcher_implementation import * +from .generate_objc_header import * +from .generate_objc_internal_header import * +from .generate_objc_protocol_types_implementation import * diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator.py b/Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator.py index edd330da4..4449bade4 100644 --- a/Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator.py @@ -28,8 +28,12 @@ import logging import os.path import re -from generator import ucfirst -from models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks +try: + from .generator import ucfirst + from .models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks +except ValueError: + from generator import ucfirst, Generator + from models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks log = logging.getLogger('global') diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_alternate_backend_dispatcher_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_alternate_backend_dispatcher_header.py index 375ce05ca..ef4293171 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_alternate_backend_dispatcher_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_alternate_backend_dispatcher_header.py @@ -30,9 +30,14 @@ import string import re from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator +except ValueError: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator log = logging.getLogger('global') @@ -60,7 +65,7 @@ class CppAlternateBackendDispatcherHeaderGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(CppTemplates.AlternateDispatchersHeaderPrelude).substitute(None, **header_args)) - sections.append('\n'.join(filter(None, map(self._generate_handler_declarations_for_domain, domains)))) + sections.append('\n'.join([_f for _f in map(self._generate_handler_declarations_for_domain, domains) if _f])) sections.append(Template(CppTemplates.AlternateDispatchersHeaderPostlude).substitute(None, **header_args)) return '\n\n'.join(sections) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py index 2e5ff7a6a..0ce1174b5 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py @@ -30,10 +30,16 @@ import re import string from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator, ucfirst -from models import EnumType +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator, ucfirst + from .models import EnumType +except ValueError: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator, ucfirst + from models import EnumType log = logging.getLogger('global') @@ -46,7 +52,7 @@ class CppBackendDispatcherHeaderGenerator(Generator): return "InspectorBackendDispatchers.h" def domains_to_generate(self): - return filter(lambda domain: len(domain.commands) > 0, Generator.domains_to_generate(self)) + return [domain for domain in Generator.domains_to_generate(self) if len(domain.commands) > 0] def generate_output(self): headers = [ @@ -68,8 +74,8 @@ class CppBackendDispatcherHeaderGenerator(Generator): sections.append(self.generate_license()) sections.append(Template(CppTemplates.HeaderPrelude).substitute(None, **header_args)) sections.append(self._generate_alternate_handler_forward_declarations_for_domains(domains)) - sections.extend(map(self._generate_handler_declarations_for_domain, domains)) - sections.extend(map(self._generate_dispatcher_declarations_for_domain, domains)) + sections.extend(list(map(self._generate_handler_declarations_for_domain, domains))) + sections.extend(list(map(self._generate_dispatcher_declarations_for_domain, domains))) sections.append(Template(CppTemplates.HeaderPostlude).substitute(None, **header_args)) return "\n\n".join(sections) @@ -194,7 +200,7 @@ class CppBackendDispatcherHeaderGenerator(Generator): declarations = [] if len(domain.commands) > 0: declarations.append('private:') - declarations.extend(map(self._generate_dispatcher_declaration_for_command, domain.commands)) + declarations.extend(list(map(self._generate_dispatcher_declaration_for_command, domain.commands))) handler_args = { 'classAndExportMacro': " ".join(classComponents), diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py index 8f3df80ee..d55db71cd 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator, ucfirst -from models import ObjectType, ArrayType +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator, ucfirst + from .models import ObjectType, ArrayType +except ValueError: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator, ucfirst + from models import ObjectType, ArrayType log = logging.getLogger('global') @@ -45,7 +51,7 @@ class CppBackendDispatcherImplementationGenerator(Generator): return "InspectorBackendDispatchers.cpp" def domains_to_generate(self): - return filter(lambda domain: len(domain.commands) > 0, Generator.domains_to_generate(self)) + return [domain for domain in Generator.domains_to_generate(self) if len(domain.commands) > 0] def generate_output(self): secondary_headers = [ @@ -69,7 +75,7 @@ class CppBackendDispatcherImplementationGenerator(Generator): sections.append(self.generate_license()) sections.append(Template(CppTemplates.ImplementationPrelude).substitute(None, **header_args)) sections.append("\n".join(map(self._generate_handler_class_destructor_for_domain, self.domains_to_generate()))) - sections.extend(map(self._generate_dispatcher_implementations_for_domain, self.domains_to_generate())) + sections.extend(list(map(self._generate_dispatcher_implementations_for_domain, self.domains_to_generate()))) sections.append(Template(CppTemplates.ImplementationPostlude).substitute(None, **header_args)) return "\n\n".join(sections) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_header.py index 58a3cb925..c555c9c61 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_header.py @@ -30,10 +30,16 @@ import re import string from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator, ucfirst -from models import EnumType +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator, ucfirst + from .models import EnumType +except ValueError: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator, ucfirst + from models import EnumType log = logging.getLogger('global') @@ -46,7 +52,7 @@ class CppFrontendDispatcherHeaderGenerator(Generator): return "InspectorFrontendDispatchers.h" def domains_to_generate(self): - return filter(lambda domain: len(domain.events) > 0, Generator.domains_to_generate(self)) + return [domain for domain in Generator.domains_to_generate(self) if len(domain.events) > 0] def generate_output(self): headers = [ @@ -63,7 +69,7 @@ class CppFrontendDispatcherHeaderGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(CppTemplates.HeaderPrelude).substitute(None, **header_args)) - sections.extend(map(self._generate_dispatcher_declarations_for_domain, self.domains_to_generate())) + sections.extend(list(map(self._generate_dispatcher_declarations_for_domain, self.domains_to_generate()))) sections.append(Template(CppTemplates.HeaderPostlude).substitute(None, **header_args)) return "\n\n".join(sections) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_implementation.py index ea46aaf26..15705858f 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_frontend_dispatcher_implementation.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator, ucfirst -from models import ObjectType, ArrayType +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator, ucfirst + from .models import ObjectType, ArrayType +except: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator, ucfirst + from models import ObjectType, ArrayType log = logging.getLogger('global') @@ -45,7 +51,7 @@ class CppFrontendDispatcherImplementationGenerator(Generator): return "InspectorFrontendDispatchers.cpp" def domains_to_generate(self): - return filter(lambda domain: len(domain.events) > 0, Generator.domains_to_generate(self)) + return [domain for domain in Generator.domains_to_generate(self) if len(domain.events) > 0] def generate_output(self): secondary_headers = [ @@ -61,7 +67,7 @@ class CppFrontendDispatcherImplementationGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(CppTemplates.ImplementationPrelude).substitute(None, **header_args)) - sections.extend(map(self._generate_dispatcher_implementations_for_domain, self.domains_to_generate())) + sections.extend(list(map(self._generate_dispatcher_implementations_for_domain, self.domains_to_generate()))) sections.append(Template(CppTemplates.ImplementationPostlude).substitute(None, **header_args)) return "\n\n".join(sections) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py index 6753e2dcf..2dbda8bca 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_header.py @@ -30,10 +30,16 @@ import re import string from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator, ucfirst -from models import EnumType, ObjectType, PrimitiveType, AliasedType, ArrayType, Frameworks +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator, ucfirst + from .models import EnumType, ObjectType, PrimitiveType, AliasedType, ArrayType, Frameworks +except ValueError: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator, ucfirst + from models import EnumType, ObjectType, PrimitiveType, AliasedType, ArrayType, Frameworks log = logging.getLogger('global') @@ -80,8 +86,8 @@ class CppProtocolTypesHeaderGenerator(Generator): ' return getEnumConstantValue(static_cast(enumValue));', '}'])) - builder_sections = map(self._generate_builders_for_domain, domains) - sections.extend(filter(lambda section: len(section) > 0, builder_sections)) + builder_sections = list(map(self._generate_builders_for_domain, domains)) + sections.extend([section for section in builder_sections if len(section) > 0]) sections.append(self._generate_forward_declarations_for_binding_traits()) sections.append('} // namespace Protocol') sections.append(Template(CppTemplates.HeaderPostlude).substitute(None, **header_args)) @@ -96,8 +102,8 @@ class CppProtocolTypesHeaderGenerator(Generator): for domain in domains: declaration_types = [decl.type for decl in domain.type_declarations] - object_types = filter(lambda _type: isinstance(_type, ObjectType), declaration_types) - enum_types = filter(lambda _type: isinstance(_type, EnumType), declaration_types) + object_types = [_type for _type in declaration_types if isinstance(_type, ObjectType)] + enum_types = [_type for _type in declaration_types if isinstance(_type, EnumType)] if len(object_types) + len(enum_types) == 0: continue @@ -122,8 +128,8 @@ class CppProtocolTypesHeaderGenerator(Generator): """ % '\n\n'.join(sections) def _generate_typedefs(self, domains): - sections = map(self._generate_typedefs_for_domain, domains) - sections = filter(lambda text: len(text) > 0, sections) + sections = list(map(self._generate_typedefs_for_domain, domains)) + sections = [text for text in sections if len(text) > 0] if len(sections) == 0: return '' @@ -133,8 +139,8 @@ class CppProtocolTypesHeaderGenerator(Generator): // End of typedefs.""" % '\n\n'.join(sections) def _generate_typedefs_for_domain(self, domain): - primitive_declarations = filter(lambda decl: isinstance(decl.type, AliasedType), domain.type_declarations) - array_declarations = filter(lambda decl: isinstance(decl.type, ArrayType), domain.type_declarations) + primitive_declarations = [decl for decl in domain.type_declarations if isinstance(decl.type, AliasedType)] + array_declarations = [decl for decl in domain.type_declarations if isinstance(decl.type, ArrayType)] if len(primitive_declarations) == 0 and len(array_declarations) == 0: return '' @@ -170,7 +176,7 @@ class CppProtocolTypesHeaderGenerator(Generator): elif isinstance(type_declaration.type, ObjectType): sections.append(self._generate_class_for_object_declaration(type_declaration, domain)) - sections = filter(lambda section: len(section) > 0, sections) + sections = [section for section in sections if len(section) > 0] if len(sections) == 0: return '' @@ -184,9 +190,9 @@ class CppProtocolTypesHeaderGenerator(Generator): if len(type_declaration.type_members) == 0: return '' - enum_members = filter(lambda member: isinstance(member.type, EnumType) and member.type.is_anonymous, type_declaration.type_members) - required_members = filter(lambda member: not member.is_optional, type_declaration.type_members) - optional_members = filter(lambda member: member.is_optional, type_declaration.type_members) + enum_members = [member for member in type_declaration.type_members if isinstance(member.type, EnumType) and member.type.is_anonymous] + required_members = [member for member in type_declaration.type_members if not member.is_optional] + optional_members = [member for member in type_declaration.type_members if member.is_optional] object_name = type_declaration.type_name lines = [] @@ -244,7 +250,7 @@ class CppProtocolTypesHeaderGenerator(Generator): else: return ' ' + line - indented_lines = map(apply_indentation, self._generate_struct_for_enum_type(enum_member.member_name, enum_member.type)) + indented_lines = list(map(apply_indentation, self._generate_struct_for_enum_type(enum_member.member_name, enum_member.type))) return '\n'.join(indented_lines) def _generate_struct_for_enum_type(self, enum_name, enum_type): @@ -258,7 +264,7 @@ class CppProtocolTypesHeaderGenerator(Generator): def _generate_builder_state_enum(self, type_declaration): lines = [] - required_members = filter(lambda member: not member.is_optional, type_declaration.type_members) + required_members = [member for member in type_declaration.type_members if not member.is_optional] enum_values = [] lines.append(' enum {') @@ -323,7 +329,7 @@ class CppProtocolTypesHeaderGenerator(Generator): type_arguments = [] for domain in self.domains_to_generate(): - declarations_to_generate = filter(lambda decl: self.type_needs_shape_assertions(decl.type), domain.type_declarations) + declarations_to_generate = [decl for decl in domain.type_declarations if self.type_needs_shape_assertions(decl.type)] for type_declaration in declarations_to_generate: for type_member in type_declaration.type_members: diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py index 2c263b504..da2ff13dd 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from cpp_generator import CppGenerator -from cpp_generator_templates import CppGeneratorTemplates as CppTemplates -from generator import Generator, ucfirst -from models import AliasedType, ArrayType, EnumType, ObjectType +try: + from .cpp_generator import CppGenerator + from .cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from .generator import Generator, ucfirst + from .models import AliasedType, ArrayType, EnumType, ObjectType +except ValueError: + from cpp_generator import CppGenerator + from cpp_generator_templates import CppGeneratorTemplates as CppTemplates + from generator import Generator, ucfirst + from models import AliasedType, ArrayType, EnumType, ObjectType log = logging.getLogger('global') @@ -61,8 +67,8 @@ class CppProtocolTypesImplementationGenerator(Generator): sections.append('namespace Protocol {') sections.append(self._generate_enum_mapping()) sections.append(self._generate_open_field_names()) - builder_sections = map(self._generate_builders_for_domain, domains) - sections.extend(filter(lambda section: len(section) > 0, builder_sections)) + builder_sections = list(map(self._generate_builders_for_domain, domains)) + sections.extend([section for section in builder_sections if len(section) > 0]) sections.append('} // namespace Protocol') sections.append(Template(CppTemplates.ImplementationPostlude).substitute(None, **header_args)) @@ -81,10 +87,11 @@ class CppProtocolTypesImplementationGenerator(Generator): lines.append('}') return '\n'.join(lines) + def _generate_open_field_names(self): lines = [] for domain in self.domains_to_generate(): - for type_declaration in filter(lambda decl: Generator.type_has_open_fields(decl.type), domain.type_declarations): + for type_declaration in [decl for decl in domain.type_declarations if Generator.type_has_open_fields(decl.type)]: for type_member in sorted(type_declaration.type_members, key=lambda member: member.member_name): field_name = '::'.join(['Inspector', 'Protocol', domain.domain_name, ucfirst(type_declaration.type_name), ucfirst(type_member.member_name)]) lines.append('const char* %s = "%s";' % (field_name, type_member.member_name)) @@ -93,7 +100,7 @@ class CppProtocolTypesImplementationGenerator(Generator): def _generate_builders_for_domain(self, domain): sections = [] - declarations_to_generate = filter(lambda decl: self.type_needs_shape_assertions(decl.type), domain.type_declarations) + declarations_to_generate = [decl for decl in domain.type_declarations if self.type_needs_shape_assertions(decl.type)] for type_declaration in declarations_to_generate: for type_member in type_declaration.type_members: @@ -114,8 +121,8 @@ class CppProtocolTypesImplementationGenerator(Generator): return Template(CppTemplates.ProtocolObjectRuntimeCast).substitute(None, **args) def _generate_assertion_for_object_declaration(self, object_declaration): - required_members = filter(lambda member: not member.is_optional, object_declaration.type_members) - optional_members = filter(lambda member: member.is_optional, object_declaration.type_members) + required_members = [member for member in object_declaration.type_members if not member.is_optional] + optional_members = [member for member in object_declaration.type_members if member.is_optional] should_count_properties = not Generator.type_has_open_fields(object_declaration.type) lines = [] diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_js_backend_commands.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_js_backend_commands.py index 3392c7845..5ee806240 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_js_backend_commands.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_js_backend_commands.py @@ -29,9 +29,14 @@ import logging import string from string import Template -from generator import Generator, ucfirst -from generator_templates import GeneratorTemplates as Templates -from models import EnumType +try: + from .generator import Generator, ucfirst + from .generator_templates import GeneratorTemplates as Templates + from .models import EnumType +except ValueError: + from generator import Generator, ucfirst + from generator_templates import GeneratorTemplates as Templates + from models import EnumType log = logging.getLogger('global') @@ -45,7 +50,7 @@ class JSBackendCommandsGenerator(Generator): def domains_to_generate(self): def should_generate_domain(domain): - domain_enum_types = filter(lambda declaration: isinstance(declaration.type, EnumType), domain.type_declarations) + domain_enum_types = [declaration for declaration in domain.type_declarations if isinstance(declaration.type, EnumType)] return len(domain.commands) > 0 or len(domain.events) > 0 or len(domain_enum_types) > 0 return filter(should_generate_domain, Generator.domains_to_generate(self)) @@ -53,7 +58,7 @@ class JSBackendCommandsGenerator(Generator): def generate_output(self): sections = [] sections.append(self.generate_license()) - sections.extend(map(self.generate_domain, self.domains_to_generate())) + sections.extend(list(map(self.generate_domain, self.domains_to_generate()))) return "\n\n".join(sections) def generate_domain(self, domain): @@ -64,7 +69,7 @@ class JSBackendCommandsGenerator(Generator): lines.append('// %(domain)s.' % args) - has_async_commands = any(map(lambda command: command.is_async, domain.commands)) + has_async_commands = any([command.is_async for command in domain.commands]) if len(domain.events) > 0 or has_async_commands: lines.append('InspectorBackend.register%(domain)sDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "%(domain)s");' % args) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_header.py index d56a0b178..de63b06e3 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_header.py @@ -30,11 +30,18 @@ import string import re from string import Template -from cpp_generator import CppGenerator -from generator import Generator -from models import Frameworks -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .cpp_generator import CppGenerator + from .generator import Generator + from .models import Frameworks + from .objc_generator import ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from cpp_generator import CppGenerator + from generator import Generator + from models import Frameworks + from objc_generator import ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') @@ -47,7 +54,7 @@ class ObjCBackendDispatcherHeaderGenerator(Generator): return '%sBackendDispatchers.h' % ObjCGenerator.OBJC_PREFIX def domains_to_generate(self): - return filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), Generator.domains_to_generate(self)) + return list(filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), Generator.domains_to_generate(self))) def generate_output(self): headers = [ @@ -65,7 +72,7 @@ class ObjCBackendDispatcherHeaderGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(ObjCTemplates.BackendDispatcherHeaderPrelude).substitute(None, **header_args)) - sections.extend(map(self._generate_objc_handler_declarations_for_domain, domains)) + sections.extend(list(map(self._generate_objc_handler_declarations_for_domain, domains))) sections.append(Template(ObjCTemplates.BackendDispatcherHeaderPostlude).substitute(None, **header_args)) return '\n\n'.join(sections) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_implementation.py index 42afd99cf..20bf6567a 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_backend_dispatcher_implementation.py @@ -30,11 +30,18 @@ import string import re from string import Template -from cpp_generator import CppGenerator -from generator import Generator -from models import PrimitiveType, EnumType, AliasedType, Frameworks -from objc_generator import ObjCTypeCategory, ObjCGenerator, join_type_and_name -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .cpp_generator import CppGenerator + from .generator import Generator + from .models import PrimitiveType, EnumType, AliasedType, Frameworks + from .objc_generator import ObjCTypeCategory, ObjCGenerator, join_type_and_name + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from cpp_generator import CppGenerator + from generator import Generator + from models import PrimitiveType, EnumType, AliasedType, Frameworks + from objc_generator import ObjCTypeCategory, ObjCGenerator, join_type_and_name + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') @@ -47,7 +54,7 @@ class ObjCConfigurationImplementationGenerator(Generator): return '%sBackendDispatchers.mm' % ObjCGenerator.OBJC_PREFIX def domains_to_generate(self): - return filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), Generator.domains_to_generate(self)) + return list(filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), Generator.domains_to_generate(self))) def generate_output(self): secondary_headers = [ @@ -65,7 +72,7 @@ class ObjCConfigurationImplementationGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(ObjCTemplates.BackendDispatcherImplementationPrelude).substitute(None, **header_args)) - sections.extend(map(self._generate_handler_implementation_for_domain, domains)) + sections.extend(list(map(self._generate_handler_implementation_for_domain, domains))) sections.append(Template(ObjCTemplates.BackendDispatcherImplementationPostlude).substitute(None, **header_args)) return '\n\n'.join(sections) @@ -112,7 +119,7 @@ class ObjCConfigurationImplementationGenerator(Generator): if command.return_parameters: lines.append(' Ref resultObject = InspectorObject::create();') - required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), command.return_parameters) + required_pointer_parameters = [parameter for parameter in command.return_parameters if not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type)] for parameter in required_pointer_parameters: var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name) lines.append(' THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name)) @@ -120,7 +127,7 @@ class ObjCConfigurationImplementationGenerator(Generator): if objc_array_class and objc_array_class.startswith(ObjCGenerator.OBJC_PREFIX): lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class)) - optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), command.return_parameters) + optional_pointer_parameters = [parameter for parameter in command.return_parameters if parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type)] for parameter in optional_pointer_parameters: var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name) lines.append(' THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name)) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_header.py index 9b93f37f6..8f1d3a234 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_header.py @@ -29,9 +29,14 @@ import logging import string from string import Template -from generator import Generator -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .generator import Generator + from .objc_generator import ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from generator import Generator + from objc_generator import ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_implementation.py index 735abbca3..dad95851c 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_configuration_implementation.py @@ -29,9 +29,14 @@ import logging import string from string import Template -from generator import Generator -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .generator import Generator + from .objc_generator import ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from generator import Generator + from objc_generator import ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_conversion_helpers.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_conversion_helpers.py index c31e991e3..62ccd3672 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_conversion_helpers.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_conversion_helpers.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from generator import Generator -from models import EnumType -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .generator import Generator + from .models import EnumType + from .objc_generator import ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from generator import Generator + from models import EnumType + from objc_generator import ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_frontend_dispatcher_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_frontend_dispatcher_implementation.py index 0030ed5ee..0f2e2df84 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_frontend_dispatcher_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_frontend_dispatcher_implementation.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from cpp_generator import CppGenerator -from generator import Generator, ucfirst -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .cpp_generator import CppGenerator + from .generator import Generator, ucfirst + from .objc_generator import ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from cpp_generator import CppGenerator + from generator import Generator, ucfirst + from objc_generator import ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') @@ -45,7 +51,7 @@ class ObjCFrontendDispatcherImplementationGenerator(Generator): return '%sEventDispatchers.mm' % ObjCGenerator.OBJC_PREFIX def domains_to_generate(self): - return filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), Generator.domains_to_generate(self)) + return list(filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), Generator.domains_to_generate(self))) def generate_output(self): secondary_headers = [ @@ -62,7 +68,7 @@ class ObjCFrontendDispatcherImplementationGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(ObjCTemplates.ImplementationPrelude).substitute(None, **header_args)) - sections.extend(map(self._generate_event_dispatcher_implementations, domains)) + sections.extend(list(map(self._generate_event_dispatcher_implementations, domains))) sections.append(Template(ObjCTemplates.ImplementationPostlude).substitute(None, **header_args)) return '\n\n'.join(sections) @@ -100,7 +106,7 @@ class ObjCFrontendDispatcherImplementationGenerator(Generator): lines.append(' const FrontendRouter& router = _controller->frontendRouter();') lines.append('') - required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters) + required_pointer_parameters = [parameter for parameter in event.event_parameters if not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type)] for parameter in required_pointer_parameters: var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name) lines.append(' THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name)) @@ -108,7 +114,7 @@ class ObjCFrontendDispatcherImplementationGenerator(Generator): if objc_array_class and objc_array_class.startswith(ObjCGenerator.OBJC_PREFIX): lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class)) - optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters) + optional_pointer_parameters = [parameter for parameter in event.event_parameters if parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type)] for parameter in optional_pointer_parameters: var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name) lines.append(' THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name)) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_header.py index 7e8e61030..c00dadde8 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_header.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from generator import Generator, ucfirst -from models import ObjectType, EnumType -from objc_generator import ObjCGenerator, join_type_and_name -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .generator import Generator, ucfirst + from .models import ObjectType, EnumType + from .objc_generator import ObjCGenerator, join_type_and_name + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from generator import Generator, ucfirst + from models import ObjectType, EnumType + from objc_generator import ObjCGenerator, join_type_and_name + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') @@ -60,9 +66,9 @@ class ObjCHeaderGenerator(Generator): } domains = self.domains_to_generate() - type_domains = filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), domains) - command_domains = filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), domains) - event_domains = filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains) + type_domains = list(filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), domains)) + command_domains = list(filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), domains)) + event_domains = list(filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains)) # FIXME: Web Inspector: Reduce unnecessary enums/types generated in ObjC Protocol Interfaces # Currently we generate enums/types for all types in the type_domains. For the built-in @@ -72,11 +78,11 @@ class ObjCHeaderGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(ObjCTemplates.HeaderPrelude).substitute(None, **header_args)) - sections.append('\n'.join(filter(None, map(self._generate_forward_declarations, type_domains)))) - sections.append('\n'.join(filter(None, map(self._generate_enums, type_domains)))) - sections.append('\n'.join(filter(None, map(self._generate_types, type_domains)))) - sections.append('\n\n'.join(filter(None, map(self._generate_command_protocols, command_domains)))) - sections.append('\n\n'.join(filter(None, map(self._generate_event_interfaces, event_domains)))) + sections.append('\n'.join([_f for _f in map(self._generate_forward_declarations, type_domains) if _f])) + sections.append('\n'.join([_f for _f in map(self._generate_enums, type_domains) if _f])) + sections.append('\n'.join([_f for _f in map(self._generate_types, type_domains) if _f])) + sections.append('\n\n'.join([_f for _f in map(self._generate_command_protocols, command_domains) if _f])) + sections.append('\n\n'.join([_f for _f in map(self._generate_event_interfaces, event_domains) if _f])) sections.append(Template(ObjCTemplates.HeaderPostlude).substitute(None)) return '\n\n'.join(sections) @@ -156,8 +162,8 @@ class ObjCHeaderGenerator(Generator): objc_name = ObjCGenerator.objc_name_for_type(declaration.type) lines.append('__attribute__((visibility ("default")))') lines.append('@interface %s : %s' % (objc_name, ObjCGenerator.OBJC_JSON_OBJECT_BASE)) - required_members = filter(lambda member: not member.is_optional, declaration.type_members) - optional_members = filter(lambda member: member.is_optional, declaration.type_members) + required_members = [member for member in declaration.type_members if not member.is_optional] + optional_members = [member for member in declaration.type_members if member.is_optional] if required_members: lines.append(self._generate_init_method_for_required_members(domain, declaration, required_members)) for member in required_members: diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_internal_header.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_internal_header.py index 40802ff17..41642b323 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_internal_header.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_internal_header.py @@ -29,9 +29,14 @@ import logging import string from string import Template -from generator import Generator, ucfirst -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .generator import Generator, ucfirst + from .objc_generator import ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from generator import Generator, ucfirst + from objc_generator import ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') @@ -56,12 +61,12 @@ class ObjCInternalHeaderGenerator(Generator): } domains = self.domains_to_generate() - event_domains = filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains) + event_domains = list(filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains)) sections = [] sections.append(self.generate_license()) sections.append(Template(ObjCTemplates.GenericHeaderPrelude).substitute(None, **header_args)) - sections.append('\n\n'.join(filter(None, map(self._generate_event_dispatcher_private_interfaces, event_domains)))) + sections.append('\n\n'.join([_f for _f in map(self._generate_event_dispatcher_private_interfaces, event_domains) if _f])) sections.append(Template(ObjCTemplates.GenericHeaderPostlude).substitute(None, **header_args)) return '\n\n'.join(sections) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_protocol_types_implementation.py b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_protocol_types_implementation.py index 95b57f671..ffe6794c2 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_protocol_types_implementation.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generate_objc_protocol_types_implementation.py @@ -29,10 +29,16 @@ import logging import string from string import Template -from generator import Generator, ucfirst -from models import ObjectType -from objc_generator import ObjCGenerator -from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +try: + from .generator import Generator, ucfirst + from .models import ObjectType + from .objc_generator import ObjCTypeCategory, ObjCGenerator + from .objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates +except ValueError: + from generator import Generator, ucfirst + from models import ObjectType + from objc_generator import ObjCTypeCategory, ObjCGenerator + from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates log = logging.getLogger('global') @@ -51,7 +57,7 @@ class ObjCProtocolTypesImplementationGenerator(Generator): return '%sTypes.mm' % ObjCGenerator.OBJC_PREFIX def domains_to_generate(self): - return filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), Generator.domains_to_generate(self)) + return list(filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), Generator.domains_to_generate(self))) def generate_output(self): secondary_headers = [ @@ -69,7 +75,7 @@ class ObjCProtocolTypesImplementationGenerator(Generator): sections = [] sections.append(self.generate_license()) sections.append(Template(ObjCTemplates.ImplementationPrelude).substitute(None, **header_args)) - sections.extend(map(self.generate_type_implementations, domains)) + sections.extend(list(map(self.generate_type_implementations, domains))) sections.append(Template(ObjCTemplates.ImplementationPostlude).substitute(None, **header_args)) return '\n\n'.join(sections) @@ -84,7 +90,7 @@ class ObjCProtocolTypesImplementationGenerator(Generator): def generate_type_implementation(self, domain, declaration): lines = [] lines.append('@implementation %s' % ObjCGenerator.objc_name_for_type(declaration.type)) - required_members = filter(lambda member: not member.is_optional, declaration.type_members) + required_members = [member for member in declaration.type_members if not member.is_optional] if required_members: lines.append('') lines.append(self._generate_init_method_for_required_members(domain, declaration, required_members)) @@ -112,7 +118,7 @@ class ObjCProtocolTypesImplementationGenerator(Generator): lines.append(' return nil;') lines.append('') - required_pointer_members = filter(lambda member: ObjCGenerator.is_type_objc_pointer_type(member.type), required_members) + required_pointer_members = [member for member in required_members if ObjCGenerator.is_type_objc_pointer_type(member.type)] if required_pointer_members: for member in required_pointer_members: var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name) diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/generator.py b/Source/JavaScriptCore/inspector/scripts/codegen/generator.py index 4c8f1998e..d788d7c88 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/generator.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/generator.py @@ -29,8 +29,12 @@ import os.path import re from string import Template -from generator_templates import GeneratorTemplates as Templates -from models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks +try: + from .generator_templates import GeneratorTemplates as Templates + from .models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks +except ValueError: + from generator_templates import GeneratorTemplates as Templates + from models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks log = logging.getLogger('global') @@ -87,7 +91,7 @@ class Generator: # These methods are overridden by subclasses. def non_supplemental_domains(self): - return filter(lambda domain: not domain.is_supplemental, self.model().domains) + return [domain for domain in self.model().domains if not domain.is_supplemental] def domains_to_generate(self): return self.non_supplemental_domains() @@ -129,7 +133,7 @@ class Generator: # set of types will not be automatically regenerated on subsequent calls to # Generator.types_needing_shape_assertions(). def calculate_types_requiring_shape_assertions(self, domains): - domain_names = map(lambda domain: domain.domain_name, domains) + domain_names = [domain.domain_name for domain in domains] log.debug("> Calculating types that need shape assertions (eligible domains: %s)" % ", ".join(domain_names)) # Mutates the passed-in set; this simplifies checks to prevent infinite recursion. @@ -185,7 +189,7 @@ class Generator: for _type in all_types: if not isinstance(_type, EnumType): continue - map(self._assign_encoding_for_enum_value, _type.enum_values()) + list(map(self._assign_encoding_for_enum_value, _type.enum_values())) def _assign_encoding_for_enum_value(self, enum_value): if enum_value in self._enum_value_encodings: @@ -219,7 +223,7 @@ class Generator: return match.group(1).upper() # Split on hyphen, introduce camelcase, and force uppercasing of acronyms. - subwords = map(ucfirst, enum_value.split('-')) + subwords = list(map(ucfirst, enum_value.split('-'))) return re.sub(re.compile(regex, re.IGNORECASE), replaceCallback, "".join(subwords)) @staticmethod diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/models.py b/Source/JavaScriptCore/inspector/scripts/codegen/models.py index ec16a1291..426ab4b2b 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/models.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/models.py @@ -35,7 +35,7 @@ def ucfirst(str): def find_duplicates(l): - return [key for key, count in collections.Counter(l).items() if count > 1] + return [key for key, count in list(collections.Counter(l).items()) if count > 1] _FRAMEWORK_CONFIG_MAP = { diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/objc_generator.py b/Source/JavaScriptCore/inspector/scripts/codegen/objc_generator.py index f6dd03cb5..35b2c593a 100755 --- a/Source/JavaScriptCore/inspector/scripts/codegen/objc_generator.py +++ b/Source/JavaScriptCore/inspector/scripts/codegen/objc_generator.py @@ -24,8 +24,12 @@ # THE POSSIBILITY OF SUCH DAMAGE. import logging -from generator import Generator, ucfirst -from models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks +try: + from .generator import Generator, ucfirst + from .models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks +except ValueError: + from generator import Generator, ucfirst + from models import PrimitiveType, ObjectType, ArrayType, EnumType, AliasedType, Frameworks log = logging.getLogger('global') @@ -50,7 +54,7 @@ _OBJC_IDENTIFIER_RENAME_MAP = { 'id': 'identifier', # Page.Frame.id, Runtime.ExecutionContextDescription.id, Debugger.BreakpointAction.id } -_OBJC_IDENTIFIER_REVERSE_RENAME_MAP = dict((v, k) for k, v in _OBJC_IDENTIFIER_RENAME_MAP.iteritems()) +_OBJC_IDENTIFIER_REVERSE_RENAME_MAP = dict((v, k) for k, v in _OBJC_IDENTIFIER_RENAME_MAP.items()) class ObjCTypeCategory: diff --git a/Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py b/Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py index a1987aa90..f56d73702 100755 --- a/Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py +++ b/Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py @@ -48,8 +48,8 @@ try: # When copying generator files to JavaScriptCore's private headers on Mac, # the codegen/ module directory is flattened. So, import directly. -except ImportError, e: - # log.error(e) # Uncomment this to debug early import errors. +except ImportError as e: + #log.error(e) # Uncomment this to debug early import errors. import models from models import * from generator import * diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index 56b32563a..3b3a9ed4b 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -3671,7 +3671,7 @@ set(WebCore_BUILTINS_SOURCES ) set(BUILTINS_GENERATOR_SCRIPTS - ${JavaScriptCore_SCRIPTS_DIR}/builtins.py + ${JavaScriptCore_SCRIPTS_DIR}/wkbuiltins.py ${JavaScriptCore_SCRIPTS_DIR}/builtins_generator.py ${JavaScriptCore_SCRIPTS_DIR}/builtins_model.py ${JavaScriptCore_SCRIPTS_DIR}/builtins_templates.py diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make index 0f5a79fa4..16eba6206 100644 --- a/Source/WebCore/DerivedSources.make +++ b/Source/WebCore/DerivedSources.make @@ -1286,7 +1286,7 @@ WebCore_BUILTINS_SOURCES = \ # BUILTINS_GENERATOR_SCRIPTS = \ - $(JavaScriptCore_SCRIPTS_DIR)/builtins.py \ + $(JavaScriptCore_SCRIPTS_DIR)/wkbuiltins.py \ $(JavaScriptCore_SCRIPTS_DIR)/builtins_generator.py \ $(JavaScriptCore_SCRIPTS_DIR)/builtins_model.py \ $(JavaScriptCore_SCRIPTS_DIR)/builtins_templates.py \ diff --git a/Source/WebCore/platform/network/create-http-header-name-table b/Source/WebCore/platform/network/create-http-header-name-table index 755d22e94..3dc57a568 100755 --- a/Source/WebCore/platform/network/create-http-header-name-table +++ b/Source/WebCore/platform/network/create-http-header-name-table @@ -41,7 +41,7 @@ input_file = open(input_path) http_header_name_to_id = { } http_header_names = [] -for line in input_file.xreadlines(): +for line in input_file: http_header_name = line.strip() if not http_header_name or http_header_name[:2] == '//': continue diff --git a/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl b/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl index c3108b83e..0d01c457a 100755 --- a/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl +++ b/Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl @@ -134,6 +134,8 @@ my $esprimaLicense = readLicenseFile(File::Spec->catfile($esprimaPath, 'LICENSE' my $eslintLicense = readLicenseFile(File::Spec->catfile($eslintPath, 'LICENSE')); make_path($protocolDir, $targetResourcePath); +$python = $ENV{"PYTHON"} if defined($ENV{"PYTHON"}); + # Copy over dynamically loaded files from other frameworks, even if we aren't combining resources. copy(File::Spec->catfile($ENV{'JAVASCRIPTCORE_PRIVATE_HEADERS_DIR'}, 'InspectorBackendCommands.js'), File::Spec->catfile($protocolDir, 'InspectorBackendCommands.js')) or die "Copy of InspectorBackendCommands.js failed: $!"; diff --git a/Source/cmake/WebKitCommon.cmake b/Source/cmake/WebKitCommon.cmake index de4ac8f65..e8a972283 100644 --- a/Source/cmake/WebKitCommon.cmake +++ b/Source/cmake/WebKitCommon.cmake @@ -24,10 +24,8 @@ if (NOT HAS_RUN_WEBKIT_COMMON) # TODO Enforce version requirement for perl find_package(Perl 5.10.0 REQUIRED) + set(Python_ADDITIONAL_VERSIONS 3) find_package(PythonInterp 2.7.0 REQUIRED) - if (PYTHON_VERSION_MAJOR GREATER 2) - message(FATAL_ERROR "Python 2 is required, but Python ${PYTHON_VERSION_MAJOR} was found.") - endif () # We cannot check for RUBY_FOUND because it is set only when the full package is installed and # the only thing we need is the interpreter. Unlike Python, cmake does not provide a macro diff --git a/Tools/jhbuild/jhbuildutils.py b/Tools/jhbuild/jhbuildutils.py index c00160e7e..35c684332 100644 --- a/Tools/jhbuild/jhbuildutils.py +++ b/Tools/jhbuild/jhbuildutils.py @@ -49,7 +49,7 @@ def enter_jhbuild_environment_if_available(platform): import jhbuild.config from jhbuild.errors import FatalError config = jhbuild.config.Config(get_config_file_for_platform(platform), []) - except FatalError, exception: + except FatalError as exception: sys.stderr.write('Could not load jhbuild config file: %s\n' % exception.args[0]) return False -- cgit v1.2.1