| 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 13 matching lines...) Expand all Loading... |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 import os.path | 30 import os.path |
| 31 import sys | 31 import sys |
| 32 | 32 |
| 33 import in_generator | 33 import in_generator |
| 34 import license | |
| 35 import make_runtime_features | 34 import make_runtime_features |
| 36 | 35 |
| 37 | 36 |
| 38 IDL_TEMPLATE = """ | |
| 39 %(license)s | |
| 40 [ | |
| 41 ImplementationLacksVTable | |
| 42 ] interface %(class_name)s { | |
| 43 %(attribute_declarations)s | |
| 44 }; | |
| 45 """ | |
| 46 | |
| 47 HEADER_TEMPLATE = """%(license)s | |
| 48 #ifndef %(class_name)s_h | |
| 49 #define %(class_name)s_h | |
| 50 | |
| 51 #include "RuntimeEnabledFeatures.h" | |
| 52 #include "wtf/PassRefPtr.h" | |
| 53 #include "wtf/RefPtr.h" | |
| 54 #include "wtf/RefCounted.h" | |
| 55 | |
| 56 namespace WebCore { | |
| 57 | |
| 58 class %(class_name)s : public RefCounted<%(class_name)s> { | |
| 59 public: | |
| 60 static PassRefPtr<%(class_name)s> create() | |
| 61 { | |
| 62 return adoptRef(new %(class_name)s); | |
| 63 } | |
| 64 | |
| 65 %(method_declarations)s | |
| 66 | |
| 67 private: | |
| 68 %(class_name)s() { } | |
| 69 }; | |
| 70 | |
| 71 } // namespace WebCore | |
| 72 | |
| 73 #endif // %(class_name)s_h | |
| 74 """ | |
| 75 | |
| 76 # We want exactly the same parsing as RuntimeFeatureWriter | 37 # We want exactly the same parsing as RuntimeFeatureWriter |
| 77 # but generate different files. | 38 # but generate different files. |
| 78 class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter): | 39 class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter): |
| 79 class_name = "InternalRuntimeFlags" | 40 class_name = "InternalRuntimeFlags" |
| 80 | 41 |
| 81 def __init__(self, *args, **kwargs): | |
| 82 make_runtime_features.RuntimeFeatureWriter.__init__(self, *args, **kwarg
s) | |
| 83 for feature in self._all_features: | |
| 84 feature['idl_attributes'] = "[Conditional=%(condition)s]" % feature
if feature['condition'] else "" | |
| 85 | |
| 86 def _attribute_declaration(self, feature): | |
| 87 # Currently assuming that runtime flags cannot be changed after startup | |
| 88 # it's possible that some can be and should be conditionally readonly. | |
| 89 return " %(idl_attributes)s readonly attribute boolean %(first_lowere
d_name)sEnabled;" % feature | |
| 90 | |
| 91 def generate_idl(self): | 42 def generate_idl(self): |
| 92 return IDL_TEMPLATE % { | 43 return { |
| 93 'class_name' : self.class_name, | 44 'features': self._features, |
| 94 'license' : license.license_for_generated_cpp(), | |
| 95 'attribute_declarations': "\n".join(map(self._attribute_declaration,
self._non_custom_features)) | |
| 96 } | 45 } |
| 97 | 46 |
| 98 def _method_declaration(self, feature): | |
| 99 # Setting after startup does not work for most runtime flags, but we | |
| 100 # could add an option to print setters for ones which do: | |
| 101 # void set%(name)sEnabled(bool isEnabled) { RuntimeEnabledFeatures::set%
(name)sEnabled(isEnabled); } | |
| 102 # If we do that, we also need to respect Internals::resetToConsistentSta
te. | |
| 103 declaration = """ bool %(first_lowered_name)sEnabled() { return Runti
meEnabledFeatures::%(first_lowered_name)sEnabled(); } | |
| 104 """ % feature | |
| 105 return self.wrap_with_condition(declaration, feature['condition']) | |
| 106 | |
| 107 def generate_header(self): | 47 def generate_header(self): |
| 108 return HEADER_TEMPLATE % { | 48 return { |
| 109 'class_name' : self.class_name, | 49 'features': self._features, |
| 110 'license' : license.license_for_generated_cpp(), | 50 'feature_sets': self._feature_sets(), |
| 111 'method_declarations' : "\n".join(map(self._method_declaration, self
._non_custom_features)), | |
| 112 } | 51 } |
| 113 | 52 |
| 114 def generate_implementation(self): | 53 def generate_implementation(self): |
| 115 return None | 54 return None |
| 116 | 55 |
| 117 | 56 |
| 118 if __name__ == "__main__": | 57 if __name__ == "__main__": |
| 119 in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv) | 58 in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv) |
| OLD | NEW |