| 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..2b407ca16d0f1867a05ba4567fb3c67b4988394e
|
| --- /dev/null
|
| +++ b/tools/json_schema_compiler/features_h_generator.py
|
| @@ -0,0 +1,83 @@
|
| +# 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, features, source_file):
|
| + return _Generator(features, source_file).Generate()
|
| +
|
| +
|
| +class _Generator(object):
|
| + """A .cc generator for PermissionFeatures.
|
| + """
|
| + def __init__(self, features, source_file):
|
| + self._feature_defs = cpp_util.RemoveFeatureDuplicates(features)
|
| + self._source_file = source_file
|
| + self._source_file_filename, _ = os.path.splitext(source_file)
|
| +
|
| + 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('#include <map>')
|
| +
|
| + (c.Append('class PermissionFeatures {')
|
| + .Append(' public:')
|
| + .Sblock()
|
| + .Concat(self._GenerateBody())
|
| + .Eblock('};')
|
| + )
|
| + (c.Append()
|
| + .Append('#endif // %s' % ifndef_name)
|
| + .Append()
|
| + )
|
| + return c
|
| +
|
| + def _GenerateBody(self):
|
| + c = Code()
|
| +
|
| + (c.Append('PermissionFeatures();')
|
| + .Append())
|
| +
|
| + (c.Append('enum ID {')
|
| + .Concat(self._GenerateEnumConstants())
|
| + .Eblock('};')
|
| + .Append()
|
| + )
|
| +
|
| + # Generate the ToString function.
|
| + c.Append('static const char* ToString(ID id);')
|
| +
|
| + # Generate the FromString function.
|
| + c.Append('static ID FromString(const std::string& id);')
|
| + return c
|
| +
|
| + def _GenerateEnumConstants(self):
|
| + c = Code()
|
| +
|
| + (c.Sblock()
|
| + .Append('kUnknown,')
|
| + )
|
| + for feature in self._feature_defs:
|
| + c.Append('%s,' % cpp_util.ConstantName(feature.name))
|
| + c.Append('kEnumBoundary')
|
| +
|
| + return c
|
|
|