| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import subprocess | 3 import subprocess |
| 4 import sys | 4 import sys |
| 5 | 5 |
| 6 import css_properties | 6 import css_properties |
| 7 import json5_generator | 7 import json5_generator |
| 8 import license | 8 import license |
| 9 | 9 |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 #include "wtf/text/AtomicString.h" | 89 #include "wtf/text/AtomicString.h" |
| 90 #include "wtf/text/WTFString.h" | 90 #include "wtf/text/WTFString.h" |
| 91 | 91 |
| 92 #ifdef _MSC_VER | 92 #ifdef _MSC_VER |
| 93 // Disable the warnings from casting a 64-bit pointer to 32-bit long | 93 // Disable the warnings from casting a 64-bit pointer to 32-bit long |
| 94 // warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long' | 94 // warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long' |
| 95 // warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long' | 95 // warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long' |
| 96 #pragma warning(disable : 4302 4311) | 96 #pragma warning(disable : 4302 4311) |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 #if defined(__clang__) | |
| 100 #pragma clang diagnostic push | |
| 101 // TODO(thakis): Remove once we use a gperf that no longer produces "register". | |
| 102 #pragma clang diagnostic ignored "-Wdeprecated-register" | |
| 103 #endif | |
| 104 | |
| 105 namespace blink { | 99 namespace blink { |
| 106 static const char propertyNameStringsPool[] = { | 100 static const char propertyNameStringsPool[] = { |
| 107 %(property_name_strings)s | 101 %(property_name_strings)s |
| 108 }; | 102 }; |
| 109 | 103 |
| 110 static const unsigned short propertyNameStringsOffsets[] = { | 104 static const unsigned short propertyNameStringsOffsets[] = { |
| 111 %(property_name_offsets)s | 105 %(property_name_offsets)s |
| 112 }; | 106 }; |
| 113 | 107 |
| 114 %%} | 108 %%} |
| 115 %%struct-type | 109 %%struct-type |
| 116 struct Property; | 110 struct Property; |
| 117 %%omit-struct-type | 111 %%omit-struct-type |
| 118 %%language=C++ | 112 %%language=C++ |
| 119 %%readonly-tables | 113 %%readonly-tables |
| 120 %%global-table | 114 %%global-table |
| 121 %%compare-strncmp | 115 %%compare-strncmp |
| 122 %%define class-name %(class_name)sHash | 116 %%define class-name %(class_name)sHash |
| 123 %%define lookup-function-name findPropertyImpl | 117 %%define lookup-function-name findPropertyImpl |
| 124 %%define hash-function-name property_hash_function | 118 %%define hash-function-name property_hash_function |
| 125 %%define slot-name nameOffset | 119 %%define slot-name nameOffset |
| 126 %%define word-array-name property_word_list | 120 %%define word-array-name property_word_list |
| 127 %%enum | 121 %%enum |
| 128 %%%% | 122 %%%% |
| 129 %(property_to_enum_map)s | 123 %(property_to_enum_map)s |
| 130 %%%% | 124 %%%% |
| 131 | 125 const Property* findProperty(register const char* str, register unsigned int len
) |
| 132 #if defined(__clang__) | 126 { |
| 133 #pragma clang diagnostic pop | 127 return %(class_name)sHash::findPropertyImpl(str, len); |
| 134 #endif | |
| 135 | |
| 136 const Property* findProperty(const char* str, unsigned int len) { | |
| 137 return %(class_name)sHash::findPropertyImpl(str, len); | |
| 138 } | 128 } |
| 139 | 129 |
| 140 const char* getPropertyName(CSSPropertyID id) { | 130 const char* getPropertyName(CSSPropertyID id) |
| 141 DCHECK(isCSSPropertyIDWithName(id)); | 131 { |
| 142 int index = id - firstCSSProperty; | 132 DCHECK(isCSSPropertyIDWithName(id)); |
| 143 return propertyNameStringsPool + propertyNameStringsOffsets[index]; | 133 int index = id - firstCSSProperty; |
| 134 return propertyNameStringsPool + propertyNameStringsOffsets[index]; |
| 144 } | 135 } |
| 145 | 136 |
| 146 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) { | 137 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) |
| 147 DCHECK(isCSSPropertyIDWithName(id)); | 138 { |
| 148 int index = id - firstCSSProperty; | 139 DCHECK(isCSSPropertyIDWithName(id)); |
| 149 static AtomicString* propertyStrings = | 140 int index = id - firstCSSProperty; |
| 150 new AtomicString[lastUnresolvedCSSProperty]; // Leaked. | 141 static AtomicString* propertyStrings = new AtomicString[lastUnresolvedCSSPro
perty]; // Intentionally never destroyed. |
| 151 AtomicString& propertyString = propertyStrings[index]; | 142 AtomicString& propertyString = propertyStrings[index]; |
| 152 if (propertyString.isNull()) { | 143 if (propertyString.isNull()) |
| 153 propertyString = AtomicString(propertyNameStringsPool + | 144 propertyString = AtomicString(propertyNameStringsPool + propertyNameStri
ngsOffsets[index]); |
| 154 propertyNameStringsOffsets[index]); | 145 return propertyString; |
| 155 } | |
| 156 return propertyString; | |
| 157 } | 146 } |
| 158 | 147 |
| 159 String getPropertyNameString(CSSPropertyID id) { | 148 String getPropertyNameString(CSSPropertyID id) |
| 160 // We share the StringImpl with the AtomicStrings. | 149 { |
| 161 return getPropertyNameAtomicString(id).getString(); | 150 // We share the StringImpl with the AtomicStrings. |
| 151 return getPropertyNameAtomicString(id).getString(); |
| 162 } | 152 } |
| 163 | 153 |
| 164 String getJSPropertyName(CSSPropertyID id) { | 154 String getJSPropertyName(CSSPropertyID id) |
| 165 char result[maxCSSPropertyNameLength + 1]; | 155 { |
| 166 const char* cssPropertyName = getPropertyName(id); | 156 char result[maxCSSPropertyNameLength + 1]; |
| 167 const char* propertyNamePointer = cssPropertyName; | 157 const char* cssPropertyName = getPropertyName(id); |
| 168 if (!propertyNamePointer) | 158 const char* propertyNamePointer = cssPropertyName; |
| 169 return emptyString; | 159 if (!propertyNamePointer) |
| 160 return emptyString; |
| 170 | 161 |
| 171 char* resultPointer = result; | 162 char* resultPointer = result; |
| 172 while (char character = *propertyNamePointer++) { | 163 while (char character = *propertyNamePointer++) { |
| 173 if (character == '-') { | 164 if (character == '-') { |
| 174 char nextCharacter = *propertyNamePointer++; | 165 char nextCharacter = *propertyNamePointer++; |
| 175 if (!nextCharacter) | 166 if (!nextCharacter) |
| 176 break; | 167 break; |
| 177 character = (propertyNamePointer - 2 != cssPropertyName) | 168 character = (propertyNamePointer - 2 != cssPropertyName) ? toASCIIUp
per(nextCharacter) : nextCharacter; |
| 178 ? toASCIIUpper(nextCharacter) : nextCharacter; | 169 } |
| 170 *resultPointer++ = character; |
| 179 } | 171 } |
| 180 *resultPointer++ = character; | 172 *resultPointer = '\\0'; |
| 181 } | 173 return String(result); |
| 182 *resultPointer = '\\0'; | |
| 183 return String(result); | |
| 184 } | 174 } |
| 185 | 175 |
| 186 CSSPropertyID cssPropertyID(const String& string) | 176 CSSPropertyID cssPropertyID(const String& string) |
| 187 { | 177 { |
| 188 return resolveCSSPropertyID(unresolvedCSSPropertyID(string)); | 178 return resolveCSSPropertyID(unresolvedCSSPropertyID(string)); |
| 189 } | 179 } |
| 190 | 180 |
| 191 } // namespace blink | 181 } // namespace blink |
| 192 """ | 182 """ |
| 193 | 183 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 # CalledProcessError like subprocess would do when shell=True is set. | 238 # CalledProcessError like subprocess would do when shell=True is set. |
| 249 try: | 239 try: |
| 250 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s
ubprocess.PIPE, universal_newlines=True) | 240 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s
ubprocess.PIPE, universal_newlines=True) |
| 251 return gperf.communicate(gperf_input)[0] | 241 return gperf.communicate(gperf_input)[0] |
| 252 except OSError: | 242 except OSError: |
| 253 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') | 243 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') |
| 254 | 244 |
| 255 | 245 |
| 256 if __name__ == "__main__": | 246 if __name__ == "__main__": |
| 257 json5_generator.Maker(CSSPropertyNamesWriter).main() | 247 json5_generator.Maker(CSSPropertyNamesWriter).main() |
| OLD | NEW |