Index: tools/json_schema_compiler/features_h_generator.py |
diff --git a/tools/json_schema_compiler/features_h_generator.py b/tools/json_schema_compiler/features_h_generator.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..309af6da7ab2a21dec027859bbedf8f9b7e4de8f |
--- /dev/null |
+++ b/tools/json_schema_compiler/features_h_generator.py |
@@ -0,0 +1,72 @@ |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os.path |
+ |
+from code import Code |
+import cpp_util |
+ |
+ |
+class HGenerator(object): |
+ def Generate(self, permission_defs, source_file): |
+ return _Generator(permission_defs, source_file).Generate() |
+ |
+ |
+class _Generator(object): |
+ """A .cc generator for PermissionFeatures. |
+ """ |
+ def __init__(self, permission_defs, source_file): |
+ self._feature_defs = cpp_util.RemoveFeatureDuplicates(permission_defs) |
not at google - send to devlin
2013/09/12 16:20:43
why are there duplicates?
|features| is a simpler
dhnishi (use Chromium)
2013/09/13 17:36:42
The same feature may be defined multiple times for
not at google - send to devlin
2013/09/13 21:37:51
Ah right.
So that's actually something that we ne
|
+ self._source_file = source_file |
+ self._source_file_filename = os.path.splitext(source_file)[0] |
+ |
+ def Generate(self): |
+ """Generates a Code object for PermissionFeatures. |
+ """ |
+ c = Code() |
+ (c.Append(cpp_util.CHROMIUM_LICENSE) |
+ .Append() |
+ .Append(cpp_util.GENERATED_FEATURE_MESSAGE % self._source_file) |
+ .Append() |
+ ) |
+ ifndef_name = cpp_util.GenerateIfndefName(self._source_file_filename, |
+ "PermissionFeatures") |
+ (c.Append('#ifndef %s' % ifndef_name) |
+ .Append('#define %s' % ifndef_name) |
+ .Append() |
+ ) |
+ |
+ (c.Append('class PermissionFeatures {') |
+ .Sblock(None, 1) |
+ .Append('public:') |
+ .Sblock(None, 1) |
not at google - send to devlin
2013/09/12 16:20:43
rather than making changes to code.py and doing, t
dhnishi (use Chromium)
2013/09/13 17:36:42
Done.
|
+ ) |
+ |
+ # Generate the ID enum. |
+ (c.Append('// Replaces APIPermission::ID') |
not at google - send to devlin
2013/09/12 16:20:43
these comments were to you, I didn't mean to gener
dhnishi (use Chromium)
2013/09/13 17:36:42
Whoops, haha. Removed.
|
+ .Append('enum ID {') |
+ .Sblock() |
+ .Append('kUnknown,') |
+ ) |
+ for feature in self._feature_defs: |
+ c.Append('%s,' % feature.constant_name) |
+ (c.Append('kEnumBoundary') |
+ .Eblock() |
+ .Append('};') |
+ .Append() |
not at google - send to devlin
2013/09/12 16:20:43
likewise, pull the enum list generation into anoth
dhnishi (use Chromium)
2013/09/13 17:36:42
Done.
|
+ ) |
+ |
+ # Generate the ToString function. |
+ c.Append('static std::string ToString(ID id);') |
not at google - send to devlin
2013/09/12 16:20:43
return const char* from these methods.
dhnishi (use Chromium)
2013/09/13 17:36:42
Done.
|
+ |
+ # Generate the FromString function. |
+ c.Append('static ID FromString(const std::string& id);') |
+ |
+ (c.Eblock(None, 1) # public |
+ .Eblock(None, 1) # class PermissionFeatures |
not at google - send to devlin
2013/09/12 16:20:43
don't think you need these to be so complicated
dhnishi (use Chromium)
2013/09/13 17:36:42
Removed the EBlock change.
Done.
|
+ .Append('};') |
+ .Append('#endif // %s' % ifndef_name) |
+ .Append() |
+ ) |
+ return c |