Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import os.path | |
| 6 | |
| 7 from code import Code | |
| 8 import cpp_util | |
| 9 | |
| 10 | |
| 11 class HGenerator(object): | |
| 12 def Generate(self, permission_defs, source_file): | |
| 13 return _Generator(permission_defs, source_file).Generate() | |
| 14 | |
| 15 | |
| 16 class _Generator(object): | |
| 17 """A .cc generator for PermissionFeatures. | |
| 18 """ | |
| 19 def __init__(self, permission_defs, source_file): | |
| 20 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
| |
| 21 self._source_file = source_file | |
| 22 self._source_file_filename = os.path.splitext(source_file)[0] | |
| 23 | |
| 24 def Generate(self): | |
| 25 """Generates a Code object for PermissionFeatures. | |
| 26 """ | |
| 27 c = Code() | |
| 28 (c.Append(cpp_util.CHROMIUM_LICENSE) | |
| 29 .Append() | |
| 30 .Append(cpp_util.GENERATED_FEATURE_MESSAGE % self._source_file) | |
| 31 .Append() | |
| 32 ) | |
| 33 ifndef_name = cpp_util.GenerateIfndefName(self._source_file_filename, | |
| 34 "PermissionFeatures") | |
| 35 (c.Append('#ifndef %s' % ifndef_name) | |
| 36 .Append('#define %s' % ifndef_name) | |
| 37 .Append() | |
| 38 ) | |
| 39 | |
| 40 (c.Append('class PermissionFeatures {') | |
| 41 .Sblock(None, 1) | |
| 42 .Append('public:') | |
| 43 .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.
| |
| 44 ) | |
| 45 | |
| 46 # Generate the ID enum. | |
| 47 (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.
| |
| 48 .Append('enum ID {') | |
| 49 .Sblock() | |
| 50 .Append('kUnknown,') | |
| 51 ) | |
| 52 for feature in self._feature_defs: | |
| 53 c.Append('%s,' % feature.constant_name) | |
| 54 (c.Append('kEnumBoundary') | |
| 55 .Eblock() | |
| 56 .Append('};') | |
| 57 .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.
| |
| 58 ) | |
| 59 | |
| 60 # Generate the ToString function. | |
| 61 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.
| |
| 62 | |
| 63 # Generate the FromString function. | |
| 64 c.Append('static ID FromString(const std::string& id);') | |
| 65 | |
| 66 (c.Eblock(None, 1) # public | |
| 67 .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.
| |
| 68 .Append('};') | |
| 69 .Append('#endif // %s' % ifndef_name) | |
| 70 .Append() | |
| 71 ) | |
| 72 return c | |
| OLD | NEW |