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 |
|
---|
26 | import os
|
---|
27 | import sys
|
---|
28 | import subprocess
|
---|
29 |
|
---|
30 |
|
---|
31 | def 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 |
|
---|
58 | def expand_ifdef_condition(condition):
|
---|
59 | return condition.replace('(', '_').replace(')', '')
|
---|
60 |
|
---|
61 | output_file = open('SelectorPseudoElementTypeMap.gperf', 'w')
|
---|
62 |
|
---|
63 | output_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 |
|
---|
95 | IGNORE_WARNINGS_BEGIN("implicit-fallthrough")
|
---|
96 |
|
---|
97 | // Older versions of gperf like to use the `register` keyword.
|
---|
98 | #define register
|
---|
99 |
|
---|
100 | namespace WebCore {
|
---|
101 |
|
---|
102 | struct 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 |
|
---|
118 | struct SelectorPseudoTypeEntry;
|
---|
119 |
|
---|
120 | %%
|
---|
121 | """)
|
---|
122 |
|
---|
123 | webcore_defines = [i.strip() for i in sys.argv[-1].split(' ')]
|
---|
124 |
|
---|
125 | longest_keyword = 0
|
---|
126 |
|
---|
127 | ignore_until_endif = False
|
---|
128 | input_file = open(sys.argv[1], 'r')
|
---|
129 | for 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 |
|
---|
158 | output_file.write("""%%
|
---|
159 |
|
---|
160 | static 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 |
|
---|
167 | output_file.write("""
|
---|
168 |
|
---|
169 | static 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 |
|
---|
187 | output_file.write("""
|
---|
188 | CSSSelector::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 |
|
---|
197 | IGNORE_WARNINGS_END
|
---|
198 |
|
---|
199 | """)
|
---|
200 | output_file.close()
|
---|
201 |
|
---|
202 | gperf_command = sys.argv[2]
|
---|
203 | if 'GPERF' in os.environ:
|
---|
204 | gperf_command = os.environ['GPERF']
|
---|
205 |
|
---|
206 | if 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)
|
---|