OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 enabled_condition += " && is%sEnabled" % dependant_name | 90 enabled_condition += " && is%sEnabled" % dependant_name |
91 feature['enabled_condition'] = enabled_condition | 91 feature['enabled_condition'] = enabled_condition |
92 self._non_custom_features = filter(lambda feature: not feature['custom']
, self._all_features) | 92 self._non_custom_features = filter(lambda feature: not feature['custom']
, self._all_features) |
93 | 93 |
94 def _lower_first(self, string): | 94 def _lower_first(self, string): |
95 lowered = string[0].lower() + string[1:] | 95 lowered = string[0].lower() + string[1:] |
96 lowered = lowered.replace("cSS", "css") | 96 lowered = lowered.replace("cSS", "css") |
97 lowered = lowered.replace("iME", "ime") | 97 lowered = lowered.replace("iME", "ime") |
98 return lowered | 98 return lowered |
99 | 99 |
100 def _wrap_with_condition(self, string, condition): | |
101 if not condition: | |
102 return string | |
103 return "#if ENABLE(%(condition)s)\n%(string)s\n#endif" % { 'condition' :
condition, 'string' : string } | |
104 | |
105 def _method_declaration(self, feature): | 100 def _method_declaration(self, feature): |
106 if feature['custom']: | 101 if feature['custom']: |
107 return " static bool %(first_lowered_name)sEnabled();\n" % featur
e | 102 return " static bool %(first_lowered_name)sEnabled();\n" % featur
e |
108 unconditional = """ static void set%(name)sEnabled(bool isEnabled) {
is%(name)sEnabled = isEnabled; } | 103 unconditional = """ static void set%(name)sEnabled(bool isEnabled) {
is%(name)sEnabled = isEnabled; } |
109 static bool %(first_lowered_name)sEnabled() { return %(enabled_condition)s;
} | 104 static bool %(first_lowered_name)sEnabled() { return %(enabled_condition)s;
} |
110 """ | 105 """ |
111 conditional = "#if ENABLE(%(condition)s)\n" + unconditional + """#else | 106 conditional = "#if ENABLE(%(condition)s)\n" + unconditional + """#else |
112 static void set%(name)sEnabled(bool) { } | 107 static void set%(name)sEnabled(bool) { } |
113 static bool %(first_lowered_name)sEnabled() { return false; } | 108 static bool %(first_lowered_name)sEnabled() { return false; } |
114 #endif | 109 #endif |
115 """ | 110 """ |
116 template = conditional if feature['condition'] else unconditional | 111 template = conditional if feature['condition'] else unconditional |
117 return template % feature | 112 return template % feature |
118 | 113 |
119 def _storage_declarations(self, feature): | 114 def _storage_declarations(self, feature): |
120 declaration = " static bool is%(name)sEnabled;" % feature | 115 declaration = " static bool is%(name)sEnabled;" % feature |
121 return self._wrap_with_condition(declaration, feature['condition']) | 116 return self.wrap_with_condition(declaration, feature['condition']) |
122 | 117 |
123 def generate_header(self): | 118 def generate_header(self): |
124 return HEADER_TEMPLATE % { | 119 return HEADER_TEMPLATE % { |
125 'class_name' : self.class_name, | 120 'class_name' : self.class_name, |
126 'license' : license.license_for_generated_cpp(), | 121 'license' : license.license_for_generated_cpp(), |
127 'method_declarations' : "\n".join(map(self._method_declaration, self
._all_features)), | 122 'method_declarations' : "\n".join(map(self._method_declaration, self
._all_features)), |
128 'storage_declarations' : "\n".join(map(self._storage_declarations, s
elf._non_custom_features)), | 123 'storage_declarations' : "\n".join(map(self._storage_declarations, s
elf._non_custom_features)), |
129 } | 124 } |
130 | 125 |
131 def _storage_definition(self, feature): | 126 def _storage_definition(self, feature): |
132 definition = "bool RuntimeEnabledFeatures::is%(name)sEnabled = %(default
)s;" % feature | 127 definition = "bool RuntimeEnabledFeatures::is%(name)sEnabled = %(default
)s;" % feature |
133 return self._wrap_with_condition(definition, feature['condition']) | 128 return self.wrap_with_condition(definition, feature['condition']) |
134 | 129 |
135 def generate_implementation(self): | 130 def generate_implementation(self): |
136 return IMPLEMENTATION_TEMPLATE % { | 131 return IMPLEMENTATION_TEMPLATE % { |
137 'class_name' : self.class_name, | 132 'class_name' : self.class_name, |
138 'license' : license.license_for_generated_cpp(), | 133 'license' : license.license_for_generated_cpp(), |
139 'storage_definitions' : "\n".join(map(self._storage_definition, self
._non_custom_features)), | 134 'storage_definitions' : "\n".join(map(self._storage_definition, self
._non_custom_features)), |
140 } | 135 } |
141 | 136 |
142 | 137 |
143 if __name__ == "__main__": | 138 if __name__ == "__main__": |
144 in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) | 139 in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) |
OLD | NEW |