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