OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import os.path | 3 import os.path |
4 import re | 4 import re |
5 import subprocess | 5 import subprocess |
6 import sys | 6 import sys |
7 | 7 |
8 from in_file import InFile | 8 from in_file import InFile |
9 import in_generator | 9 import in_generator |
10 import license | 10 import license |
11 | 11 |
12 | 12 |
13 HEADER_TEMPLATE = """ | 13 HEADER_TEMPLATE = """ |
14 %(license)s | 14 %(license)s |
15 | 15 |
16 #ifndef %(class_name)s_h | 16 #ifndef %(class_name)s_h |
17 #define %(class_name)s_h | 17 #define %(class_name)s_h |
18 | 18 |
19 #include "core/css/CSSParserMode.h" | 19 #include "core/css/CSSParserMode.h" |
20 #include "wtf/HashFunctions.h" | 20 #include "wtf/HashFunctions.h" |
21 #include "wtf/HashTraits.h" | 21 #include "wtf/HashTraits.h" |
22 #include <string.h> | 22 #include <string.h> |
23 | 23 |
24 namespace WTF { | 24 namespace WTF { |
25 class AtomicString; | 25 class AtomicString; |
26 class String; | 26 class String; |
27 } | 27 } |
28 | 28 |
29 namespace WebCore { | 29 namespace blink { |
30 | 30 |
31 enum CSSPropertyID { | 31 enum CSSPropertyID { |
32 CSSPropertyInvalid = 0, | 32 CSSPropertyInvalid = 0, |
33 %(property_enums)s | 33 %(property_enums)s |
34 }; | 34 }; |
35 | 35 |
36 const int firstCSSProperty = %(first_property_id)s; | 36 const int firstCSSProperty = %(first_property_id)s; |
37 const int numCSSProperties = %(properties_count)s; | 37 const int numCSSProperties = %(properties_count)s; |
38 const int lastCSSProperty = %(last_property_id)d; | 38 const int lastCSSProperty = %(last_property_id)d; |
39 const size_t maxCSSPropertyNameLength = %(max_name_length)d; | 39 const size_t maxCSSPropertyNameLength = %(max_name_length)d; |
40 | 40 |
41 const char* getPropertyName(CSSPropertyID); | 41 const char* getPropertyName(CSSPropertyID); |
42 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); | 42 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); |
43 WTF::String getPropertyNameString(CSSPropertyID); | 43 WTF::String getPropertyNameString(CSSPropertyID); |
44 WTF::String getJSPropertyName(CSSPropertyID); | 44 WTF::String getJSPropertyName(CSSPropertyID); |
45 bool isInternalProperty(CSSPropertyID id); | 45 bool isInternalProperty(CSSPropertyID id); |
46 | 46 |
47 inline CSSPropertyID convertToCSSPropertyID(int value) | 47 inline CSSPropertyID convertToCSSPropertyID(int value) |
48 { | 48 { |
49 ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == C
SSPropertyInvalid); | 49 ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == C
SSPropertyInvalid); |
50 return static_cast<CSSPropertyID>(value); | 50 return static_cast<CSSPropertyID>(value); |
51 } | 51 } |
52 | 52 |
53 } // namespace WebCore | 53 } // namespace blink |
54 | 54 |
55 namespace WTF { | 55 namespace WTF { |
56 template<> struct DefaultHash<WebCore::CSSPropertyID> { typedef IntHash<unsigned
> Hash; }; | 56 template<> struct DefaultHash<blink::CSSPropertyID> { typedef IntHash<unsigned>
Hash; }; |
57 template<> struct HashTraits<WebCore::CSSPropertyID> : GenericHashTraits<WebCore
::CSSPropertyID> { | 57 template<> struct HashTraits<blink::CSSPropertyID> : GenericHashTraits<blink::CS
SPropertyID> { |
58 static const bool emptyValueIsZero = true; | 58 static const bool emptyValueIsZero = true; |
59 static const bool needsDestruction = false; | 59 static const bool needsDestruction = false; |
60 static void constructDeletedValue(WebCore::CSSPropertyID& slot) { slot = sta
tic_cast<WebCore::CSSPropertyID>(WebCore::lastCSSProperty + 1); } | 60 static void constructDeletedValue(blink::CSSPropertyID& slot) { slot = stati
c_cast<blink::CSSPropertyID>(blink::lastCSSProperty + 1); } |
61 static bool isDeletedValue(WebCore::CSSPropertyID value) { return value == (
WebCore::lastCSSProperty + 1); } | 61 static bool isDeletedValue(blink::CSSPropertyID value) { return value == (bl
ink::lastCSSProperty + 1); } |
62 }; | 62 }; |
63 } | 63 } |
64 | 64 |
65 #endif // %(class_name)s_h | 65 #endif // %(class_name)s_h |
66 """ | 66 """ |
67 | 67 |
68 GPERF_TEMPLATE = """ | 68 GPERF_TEMPLATE = """ |
69 %%{ | 69 %%{ |
70 %(license)s | 70 %(license)s |
71 | 71 |
72 #include "config.h" | 72 #include "config.h" |
73 #include "%(class_name)s.h" | 73 #include "%(class_name)s.h" |
74 #include "core/css/HashTools.h" | 74 #include "core/css/HashTools.h" |
75 #include <string.h> | 75 #include <string.h> |
76 | 76 |
77 #include "wtf/ASCIICType.h" | 77 #include "wtf/ASCIICType.h" |
78 #include "wtf/text/AtomicString.h" | 78 #include "wtf/text/AtomicString.h" |
79 #include "wtf/text/WTFString.h" | 79 #include "wtf/text/WTFString.h" |
80 | 80 |
81 namespace WebCore { | 81 namespace blink { |
82 static const char propertyNameStringsPool[] = { | 82 static const char propertyNameStringsPool[] = { |
83 %(property_name_strings)s | 83 %(property_name_strings)s |
84 }; | 84 }; |
85 | 85 |
86 static const unsigned short propertyNameStringsOffsets[] = { | 86 static const unsigned short propertyNameStringsOffsets[] = { |
87 %(property_name_offsets)s | 87 %(property_name_offsets)s |
88 }; | 88 }; |
89 | 89 |
90 %%} | 90 %%} |
91 %%struct-type | 91 %%struct-type |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 bool isInternalProperty(CSSPropertyID id) | 167 bool isInternalProperty(CSSPropertyID id) |
168 { | 168 { |
169 switch (id) { | 169 switch (id) { |
170 %(internal_properties)s | 170 %(internal_properties)s |
171 return true; | 171 return true; |
172 default: | 172 default: |
173 return false; | 173 return false; |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 } // namespace WebCore | 177 } // namespace blink |
178 """ | 178 """ |
179 | 179 |
180 | 180 |
181 class CSSPropertiesWriter(in_generator.Writer): | 181 class CSSPropertiesWriter(in_generator.Writer): |
182 class_name = "CSSPropertyNames" | 182 class_name = "CSSPropertyNames" |
183 defaults = { | 183 defaults = { |
184 'alias_for': None, | 184 'alias_for': None, |
185 'is_internal': False, | 185 'is_internal': False, |
186 } | 186 } |
187 | 187 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 247 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
248 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 248 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
249 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 249 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
250 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 250 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
251 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) | 251 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) |
252 return gperf.communicate(gperf_input)[0] | 252 return gperf.communicate(gperf_input)[0] |
253 | 253 |
254 | 254 |
255 if __name__ == "__main__": | 255 if __name__ == "__main__": |
256 in_generator.Maker(CSSPropertiesWriter).main(sys.argv) | 256 in_generator.Maker(CSSPropertiesWriter).main(sys.argv) |
OLD | NEW |