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, features, source_file): | |
| 13 return _Generator(features, source_file).Generate() | |
| 14 | |
| 15 | |
| 16 class _Generator(object): | |
| 17 """A .cc generator for PermissionFeatures. | |
| 18 """ | |
| 19 def __init__(self, features, source_file): | |
| 20 self._feature_defs = features | |
| 21 self._source_file = source_file | |
| 22 self._source_file_filename, _ = os.path.splitext(source_file) | |
| 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('#include <map>') | |
| 41 .Append() | |
| 42 ) | |
| 43 | |
| 44 (c.Append('class PermissionFeatures {') | |
| 45 .Append(' public:') | |
| 46 .Sblock() | |
| 47 .Concat(self._GeneratePublicBody()) | |
|
not at google - send to devlin
2013/09/17 01:28:07
IIRC,
Sblock()
Concat(...)
Eblock()
can be writt
dhnishi (use Chromium)
2013/09/17 18:17:47
Cblock(...) concats another code object. I could d
| |
| 48 .Eblock() | |
| 49 .Append(' private:') | |
| 50 .Sblock() | |
| 51 .Concat(self._GeneratePrivateBody()) | |
| 52 .Eblock('};') | |
| 53 ) | |
| 54 (c.Append() | |
| 55 .Append('#endif // %s' % ifndef_name) | |
| 56 .Append() | |
| 57 ) | |
| 58 return c | |
| 59 | |
| 60 def _GeneratePublicBody(self): | |
| 61 c = Code() | |
| 62 | |
| 63 (c.Append('PermissionFeatures();') | |
| 64 .Append()) | |
| 65 | |
|
not at google - send to devlin
2013/09/17 01:28:07
on need to break the chain here?
dhnishi (use Chromium)
2013/09/17 18:17:47
Break removed.
| |
| 66 (c.Append('enum ID {') | |
| 67 .Concat(self._GenerateEnumConstants()) | |
| 68 .Eblock('};') | |
| 69 .Append() | |
| 70 ) | |
| 71 | |
| 72 # Generate the ToString function. | |
| 73 c.Append('const char* ToString(ID id);') | |
|
not at google - send to devlin
2013/09/17 01:28:07
this method can be const
dhnishi (use Chromium)
2013/09/17 18:17:47
Changed the parameter to be const.
| |
| 74 | |
| 75 # Generate the FromString function. | |
| 76 (c.Append('ID FromString(const std::string& id);') | |
|
not at google - send to devlin
2013/09/17 01:28:07
so can this method
dhnishi (use Chromium)
2013/09/17 18:17:47
Method is now const.
| |
| 77 .Append() | |
| 78 ) | |
|
not at google - send to devlin
2013/09/17 01:28:07
nor here and above. the comments are self-explanat
dhnishi (use Chromium)
2013/09/17 18:17:47
Removed the comments. Code seemed simple enough.
| |
| 79 return c | |
| 80 | |
| 81 def _GeneratePrivateBody(self): | |
| 82 c = Code() | |
| 83 | |
| 84 c.Append('std::map<std::string, PermissionFeatures::ID> _featureMap;') | |
|
not at google - send to devlin
2013/09/17 01:28:07
features_ or feature_map_ not _featureMap.
dhnishi (use Chromium)
2013/09/17 18:17:47
Opted for features_
| |
| 85 return c | |
|
not at google - send to devlin
2013/09/17 01:28:07
also this can be
return Code().Append('...')
dhnishi (use Chromium)
2013/09/17 18:17:47
Done.
| |
| 86 | |
| 87 def _GenerateEnumConstants(self): | |
| 88 c = Code() | |
| 89 | |
| 90 (c.Sblock() | |
| 91 .Append('kUnknown,') | |
| 92 ) | |
| 93 for feature in self._feature_defs: | |
| 94 c.Append('%s,' % cpp_util.ConstantName(feature.name)) | |
| 95 c.Append('kEnumBoundary') | |
| 96 | |
| 97 return c | |
| OLD | NEW |