Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 9491002: json_schema_compiler: any, additionalProperties, functions on types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove whitespace Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/h_generator.py
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index 3af7ccf3c1eba6f723653f75896fba339c6ba81f..fbff46235b4cbfeb9e4cf59e42f0c74fa3662326 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -38,6 +38,7 @@ class HGenerator(object):
.Append('#include "base/memory/linked_ptr.h"')
.Append('#include "base/memory/scoped_ptr.h"')
.Append('#include "base/values.h"')
+ .Append('#include "tools/json_schema_compiler/any.h"')
.Append()
)
@@ -76,8 +77,7 @@ class HGenerator(object):
(c.Concat(self._GenerateFunction(function))
.Append()
)
- (c.Append()
- .Concat(self._cpp_type_generator.GetNamespaceEnd())
+ (c.Concat(self._cpp_type_generator.GetNamespaceEnd())
.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
.Append()
.Append('#endif // %s' % ifndef_name)
@@ -123,33 +123,46 @@ class HGenerator(object):
"""
classname = cpp_util.Classname(type_.name)
c = code.Code()
- if type_.description:
- c.Comment(type_.description)
- (c.Sblock('struct %(classname)s {')
- .Append('~%(classname)s();')
- .Append('%(classname)s();')
- .Append()
- .Concat(self._GeneratePropertyStructures(type_.properties.values()))
- .Concat(self._GenerateFields(type_.properties.values()))
- )
- if type_.from_json:
- (c.Comment('Populates a %s object from a Value. Returns'
- ' whether |out| was successfully populated.' % classname)
- .Append('static bool Populate(const Value& value, %(classname)s* out);')
- .Append()
+ # Functions on types cannot have properties on them and are not
+ # instantiable because they're dealt with renderer side.
not at google - send to devlin 2012/02/28 22:41:17 See my comment about this comment in model.py. Ma
calamity 2012/03/01 04:47:09 Done.
+ if type_.functions:
+ assert not type_.properties
not at google - send to devlin 2012/02/28 22:41:17 Also: again, asserts are for internal errors not e
calamity 2012/03/01 04:47:09 Done.
+ c.Sblock('namespace %(classname)s {')
+ for function in type_.functions.values():
+ (c.Concat(self._GenerateFunction(function))
+ .Append()
+ )
+ c.Eblock('}')
+ else:
+ if type_.description:
+ c.Comment(type_.description)
+ (c.Sblock('struct %(classname)s {')
+ .Append('~%(classname)s();')
+ .Append('%(classname)s();')
+ .Append()
+ .Concat(self._GeneratePropertyStructures(type_.properties.values()))
+ .Concat(self._GenerateFields(type_.properties.values()))
)
+ if type_.from_json:
+ (c.Comment('Populates a %s object from a Value. Returns'
+ ' whether |out| was successfully populated.' % classname)
+ .Append(
+ 'static bool Populate(const Value& value, %(classname)s* out);')
+ .Append()
+ )
+
+ if type_.from_client:
+ (c.Comment('Returns a new DictionaryValue representing the'
+ ' serialized form of this %s object. Passes '
+ 'ownership to caller.' % classname)
+ .Append('scoped_ptr<DictionaryValue> ToValue() const;')
+ )
- if type_.from_client:
- (c.Comment('Returns a new DictionaryValue representing the'
- ' serialized form of this %s object. Passes '
- 'ownership to caller.' % classname)
- .Append('scoped_ptr<DictionaryValue> ToValue() const;')
+ (c.Eblock()
+ .Sblock(' private:')
+ .Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);')
+ .Eblock('};')
)
- (c.Eblock()
- .Sblock(' private:')
- .Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);')
- .Eblock('};')
- )
c.Substitute({'classname': classname})
return c
@@ -234,6 +247,10 @@ class HGenerator(object):
for param in self._cpp_type_generator.GetExpandedChoicesInParams(params):
if param.description:
c.Comment(param.description)
+ if param.type_ == PropertyType.ANY:
+ c.Comment("Value* Result::Create(Value*) not generated "
+ "because it's redundant.")
Yoyo Zhou 2012/02/28 22:23:41 nit: indent to paren
calamity 2012/03/01 04:47:09 Done.
+ continue
c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration(
param, self._cpp_type_generator.GetType(param)))
c.Eblock('};')

Powered by Google App Engine
This is Rietveld 408576698