source: webkit/trunk/Source/WebCore/css/makeSelectorPseudoElementsMap.py

Last change on this file was 284096, checked in by [email protected], 4 years ago

Invoke build scripts with python3 explicitly
https://bugs.webkit.org/show_bug.cgi?id=231587

Reviewed by Jonathan Bedard.

Much of the work to support Python 3 was done years ago, but we need this to
actually use Python 3 on macOS.

Source/JavaScriptCore:

Python 3 no longer raises ValueError on relative module import failure, so changed
that to the correct ImportError.

  • DerivedSources.make:
  • Scripts/UpdateContents.py:
  • Scripts/cssmin.py:
  • Scripts/generate-combined-inspector-json.py:
  • Scripts/generate-js-builtins.py:
  • Scripts/inline-and-minify-stylesheets-and-scripts.py:
  • Scripts/lazywriter.py:
  • Scripts/make-js-file-arrays.py:
  • Scripts/wkbuiltins/builtins_generate_combined_header.py:
  • Scripts/wkbuiltins/builtins_generate_combined_implementation.py:
  • Scripts/wkbuiltins/builtins_generate_internals_wrapper_header.py:
  • Scripts/wkbuiltins/builtins_generate_internals_wrapper_implementation.py:
  • Scripts/wkbuiltins/builtins_generate_separate_header.py:
  • Scripts/wkbuiltins/builtins_generate_separate_implementation.py:
  • Scripts/wkbuiltins/builtins_generate_wrapper_header.py:
  • Scripts/wkbuiltins/builtins_generate_wrapper_implementation.py:
  • Scripts/wkbuiltins/builtins_generator.py:
  • Scripts/wkbuiltins/builtins_model.py:
  • Scripts/wkbuiltins/builtins_templates.py:
  • disassembler/udis86/ud_opcode.py:

(UdOpcodeTable.entries):
(UdOpcodeTables.addSSE2AVXInsn):
(itemslist): Deleted.

  • inspector/scripts/codegen/cpp_generator.py:
  • inspector/scripts/codegen/cpp_generator_templates.py:
  • inspector/scripts/codegen/generate_cpp_alternate_backend_dispatcher_header.py:
  • inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py:
  • inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py:
  • inspector/scripts/codegen/generate_cpp_frontend_dispatcher_header.py:
  • inspector/scripts/codegen/generate_cpp_frontend_dispatcher_implementation.py:
  • inspector/scripts/codegen/generate_cpp_protocol_types_header.py:
  • inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py:
  • inspector/scripts/codegen/generate_js_backend_commands.py:
  • inspector/scripts/codegen/generate_objc_backend_dispatcher_header.py:
  • inspector/scripts/codegen/generate_objc_backend_dispatcher_implementation.py:
  • inspector/scripts/codegen/generate_objc_configuration_header.py:
  • inspector/scripts/codegen/generate_objc_configuration_implementation.py:
  • inspector/scripts/codegen/generate_objc_frontend_dispatcher_implementation.py:
  • inspector/scripts/codegen/generate_objc_header.py:
  • inspector/scripts/codegen/generate_objc_internal_header.py:
  • inspector/scripts/codegen/generate_objc_protocol_type_conversions_header.py:
  • inspector/scripts/codegen/generate_objc_protocol_type_conversions_implementation.py:
  • inspector/scripts/codegen/generate_objc_protocol_types_implementation.py:
  • inspector/scripts/codegen/generator.py:
  • inspector/scripts/codegen/generator_templates.py:
  • inspector/scripts/codegen/models.py:
  • inspector/scripts/codegen/objc_generator.py:
  • inspector/scripts/codegen/objc_generator_templates.py:
  • inspector/scripts/generate-inspector-protocol-bindings.py:
  • wasm/generateWasm.py:
  • wasm/generateWasmB3IRGeneratorInlinesHeader.py:
  • wasm/generateWasmOpsHeader.py:
  • yarr/create_regex_tables:

(in): Deleted.

  • yarr/generateYarrCanonicalizeUnicode:
  • yarr/generateYarrUnicodePropertyTables.py:
  • yarr/hasher.py:

Source/WebCore:

  • DerivedSources.make:
  • css/makeSelectorPseudoClassAndCompatibilityElementMap.py:
  • css/makeSelectorPseudoElementsMap.py:
  • html/parser/create-html-entity-table:

(convert_entity_to_cpp_name): Deleted.
(convert_value_to_int): Deleted.
(offset_table_entry): Deleted.

  • platform/network/create-http-header-name-table:

(HTTPHeaderName): Deleted.

Source/WebInspectorUI:

  • Scripts/copy-user-interface-resources.pl:

Source/WebKit:

  • DerivedSources.make:
  • Scripts/generate-message-receiver.py:
  • Scripts/postprocess-header-rule:
  • Scripts/webkit/messages_unittest.py:
  • Scripts/webkit/model_unittest.py:
  • Scripts/webkit/parser_unittest.py:
  • Scripts/webkit/tests/Makefile:
File size: 7.2 KB
Line 
1#!/usr/bin/env python3
2#
3# Copyright (C) 2014 Apple Inc. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24# THE POSSIBILITY OF SUCH DAMAGE.
25
26import os
27import sys
28import subprocess
29
30
31def enumerablePseudoType(stringPseudoType):
32 output = ['CSSSelector::PseudoElement']
33
34 if stringPseudoType.endswith('('):
35 stringPseudoType = stringPseudoType[:-1]
36
37 webkitPrefix = '-webkit-'
38 if (stringPseudoType.startswith(webkitPrefix)):
39 stringPseudoType = stringPseudoType[len(webkitPrefix):]
40
41 khtmlPrefix = '-khtml-'
42 if (stringPseudoType.startswith(khtmlPrefix)):
43 stringPseudoType = stringPseudoType[len(khtmlPrefix):]
44
45 substring_start = 0
46 next_dash_position = stringPseudoType.find('-')
47 while (next_dash_position != -1):
48 output.append(stringPseudoType[substring_start].upper())
49 output.append(stringPseudoType[substring_start + 1:next_dash_position])
50 substring_start = next_dash_position + 1
51 next_dash_position = stringPseudoType.find('-', substring_start)
52
53 output.append(stringPseudoType[substring_start].upper())
54 output.append(stringPseudoType[substring_start + 1:])
55 return ''.join(output)
56
57
58def expand_ifdef_condition(condition):
59 return condition.replace('(', '_').replace(')', '')
60
61output_file = open('SelectorPseudoElementTypeMap.gperf', 'w')
62
63output_file.write("""
64%{
65/*
66 * Copyright (C) 2014 Apple Inc. All rights reserved.
67 *
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions
70 * are met:
71 * 1. Redistributions of source code must retain the above copyright
72 * notice, this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright
74 * notice, this list of conditions and the following disclaimer in the
75 * documentation and/or other materials provided with the distribution.
76 *
77 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
78 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
79 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
80 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
81 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
82 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
83 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
84 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
85 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
86 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
87 * THE POSSIBILITY OF SUCH DAMAGE.
88 */
89
90// This file is automatically generated from SelectorPseudoTypeMap.in by makeprop, do not edit by hand.
91
92#include "config.h"
93#include "SelectorPseudoTypeMap.h"
94
95IGNORE_WARNINGS_BEGIN("implicit-fallthrough")
96
97// Older versions of gperf like to use the `register` keyword.
98#define register
99
100namespace WebCore {
101
102struct SelectorPseudoTypeEntry {
103 const char* name;
104 CSSSelector::PseudoElementType type;
105};
106
107%}
108%struct-type
109%define initializer-suffix ,CSSSelector::PseudoElementUnknown
110%define class-name SelectorPseudoElementTypeMapHash
111%omit-struct-type
112%language=C++
113%readonly-tables
114%global-table
115%compare-strncmp
116%enum
117
118struct SelectorPseudoTypeEntry;
119
120%%
121""")
122
123webcore_defines = [i.strip() for i in sys.argv[-1].split(' ')]
124
125longest_keyword = 0
126
127ignore_until_endif = False
128input_file = open(sys.argv[1], 'r')
129for line in input_file:
130 line = line.strip()
131 if not line:
132 continue
133
134 if line.startswith('#if '):
135 condition = line[4:].strip()
136 if expand_ifdef_condition(condition) not in webcore_defines:
137 ignore_until_endif = True
138 continue
139
140 if line.startswith('#endif'):
141 ignore_until_endif = False
142 continue
143
144 if ignore_until_endif:
145 continue
146
147 keyword_definition = line.split(',')
148 if len(keyword_definition) == 1:
149 keyword = keyword_definition[0].strip()
150 pseudo_element_enum_value = enumerablePseudoType(keyword)
151 else:
152 keyword = keyword_definition[0].strip()
153 pseudo_element_enum_value = "CSSSelector::" + keyword_definition[1].strip()
154
155 output_file.write('"%s", %s\n' % (keyword, pseudo_element_enum_value))
156 longest_keyword = max(longest_keyword, len(keyword))
157
158output_file.write("""%%
159
160static inline CSSSelector::PseudoElementType parsePseudoElementString(const LChar* characters, unsigned length)
161{
162 if (const SelectorPseudoTypeEntry* entry = SelectorPseudoElementTypeMapHash::in_word_set(reinterpret_cast<const char*>(characters), length))
163 return entry->type;
164 return CSSSelector::PseudoElementUnknown;
165}""")
166
167output_file.write("""
168
169static inline CSSSelector::PseudoElementType parsePseudoElementString(const UChar* characters, unsigned length)
170{
171 const unsigned maxKeywordLength = %s;
172 LChar buffer[maxKeywordLength];
173 if (length > maxKeywordLength)
174 return CSSSelector::PseudoElementUnknown;
175
176 for (unsigned i = 0; i < length; ++i) {
177 UChar character = characters[i];
178 if (!isLatin1(character))
179 return CSSSelector::PseudoElementUnknown;
180
181 buffer[i] = static_cast<LChar>(character);
182 }
183 return parsePseudoElementString(buffer, length);
184}
185""" % longest_keyword)
186
187output_file.write("""
188CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString)
189{
190 if (pseudoTypeString.is8Bit())
191 return parsePseudoElementString(pseudoTypeString.characters8(), pseudoTypeString.length());
192 return parsePseudoElementString(pseudoTypeString.characters16(), pseudoTypeString.length());
193}
194
195} // namespace WebCore
196
197IGNORE_WARNINGS_END
198
199""")
200output_file.close()
201
202gperf_command = sys.argv[2]
203if 'GPERF' in os.environ:
204 gperf_command = os.environ['GPERF']
205
206if subprocess.call([gperf_command, '--key-positions=*', '-m', '10', '-s', '2', 'SelectorPseudoElementTypeMap.gperf', '--output-file=SelectorPseudoElementTypeMap.cpp']) != 0:
207 print("Error when generating SelectorPseudoElementTypeMap.cpp from SelectorPseudoElementTypeMap.gperf :(")
208 sys.exit(gperf_return)
Note: See TracBrowser for help on using the repository browser.