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