1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
#!/usr/bin/env python
#
# Copyright (C) 2014 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 os
import sys
def enumerablePseudoType(stringPseudoType):
output = ['CSSSelector::PseudoElement']
if stringPseudoType.endswith('('):
stringPseudoType = stringPseudoType[:-1]
webkitPrefix = '-webkit-'
if (stringPseudoType.startswith(webkitPrefix)):
stringPseudoType = stringPseudoType[len(webkitPrefix):]
khtmlPrefix = '-khtml-'
if (stringPseudoType.startswith(khtmlPrefix)):
stringPseudoType = stringPseudoType[len(khtmlPrefix):]
substring_start = 0
next_dash_position = stringPseudoType.find('-')
while (next_dash_position != -1):
output.append(stringPseudoType[substring_start].upper())
output.append(stringPseudoType[substring_start + 1:next_dash_position])
substring_start = next_dash_position + 1
next_dash_position = stringPseudoType.find('-', substring_start)
output.append(stringPseudoType[substring_start].upper())
output.append(stringPseudoType[substring_start + 1:])
return ''.join(output)
def expand_ifdef_condition(condition):
return condition.replace('(', '_').replace(')', '')
output_file = open('SelectorPseudoElementTypeMap.gperf', 'w')
output_file.write("""
%{
/*
* Copyright (C) 2014 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.
*/
// This file is automatically generated from SelectorPseudoTypeMap.in by makeprop, do not edit by hand.
#include "config.h"
#include "SelectorPseudoTypeMap.h"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wdeprecated-register"
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
#endif
namespace WebCore {
struct SelectorPseudoTypeEntry {
const char* name;
CSSSelector::PseudoElementType type;
};
%}
%struct-type
%define initializer-suffix ,CSSSelector::PseudoElementUnknown
%define class-name SelectorPseudoElementTypeMapHash
%omit-struct-type
%language=C++
%readonly-tables
%global-table
%compare-strncmp
%enum
struct SelectorPseudoTypeEntry;
%%
""")
webcore_defines = [i.strip() for i in sys.argv[-1].split(' ')]
longest_keyword = 0
ignore_until_endif = False
input_file = open(sys.argv[1], 'r')
for line in input_file:
line = line.strip()
if not line:
continue
if line.startswith('#if '):
condition = line[4:].strip()
if expand_ifdef_condition(condition) not in webcore_defines:
ignore_until_endif = True
continue
if line.startswith('#endif'):
ignore_until_endif = False
continue
if ignore_until_endif:
continue
keyword_definition = line.split(',')
if len(keyword_definition) == 1:
keyword = keyword_definition[0].strip()
pseudo_element_enum_value = enumerablePseudoType(keyword)
else:
keyword = keyword_definition[0].strip()
pseudo_element_enum_value = "CSSSelector::" + keyword_definition[1].strip()
output_file.write('"%s", %s\n' % (keyword, pseudo_element_enum_value))
longest_keyword = max(longest_keyword, len(keyword))
output_file.write("""%%
static inline CSSSelector::PseudoElementType parsePseudoElementString(const LChar* characters, unsigned length)
{
if (const SelectorPseudoTypeEntry* entry = SelectorPseudoElementTypeMapHash::in_word_set(reinterpret_cast<const char*>(characters), length))
return entry->type;
return CSSSelector::PseudoElementUnknown;
}""")
output_file.write("""
static inline CSSSelector::PseudoElementType parsePseudoElementString(const UChar* characters, unsigned length)
{
const unsigned maxKeywordLength = %s;
LChar buffer[maxKeywordLength];
if (length > maxKeywordLength)
return CSSSelector::PseudoElementUnknown;
for (unsigned i = 0; i < length; ++i) {
UChar character = characters[i];
if (character & ~0xff)
return CSSSelector::PseudoElementUnknown;
buffer[i] = static_cast<LChar>(character);
}
return parsePseudoElementString(buffer, length);
}
""" % longest_keyword)
output_file.write("""
CSSSelector::PseudoElementType parsePseudoElementString(const StringImpl& pseudoTypeString)
{
if (pseudoTypeString.is8Bit())
return parsePseudoElementString(pseudoTypeString.characters8(), pseudoTypeString.length());
return parsePseudoElementString(pseudoTypeString.characters16(), pseudoTypeString.length());
}
} // namespace WebCore
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
""")
output_file.close()
gperf_command = 'gperf'
if 'GPERF' in os.environ:
gperf_command = os.environ['GPERF']
gperf_return = os.system("%s --key-positions=\"*\" -m 10 -s 2 SelectorPseudoElementTypeMap.gperf --output-file=SelectorPseudoElementTypeMap.cpp" % gperf_command)
if gperf_return != 0:
print("Error when generating SelectorPseudoElementTypeMap.cpp from SelectorPseudoElementTypeMap.gperf :(")
sys.exit(gperf_return)
|