summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/h_generator.py
diff options
context:
space:
mode:
authorDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-12 23:45:38 +0000
committerDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-12 23:45:38 +0000
commitbee7a793dee719a5edac218149ddccfda9d07eb3 (patch)
tree35df7a832a981069c0cd6a778ee81c0a3a436f22 /tools/json_schema_compiler/h_generator.py
parenta176567bf59ee074eb4c404c989baf4e25e2e2cc (diff)
downloadchromium_src-bee7a793dee719a5edac218149ddccfda9d07eb3.zip
chromium_src-bee7a793dee719a5edac218149ddccfda9d07eb3.tar.gz
chromium_src-bee7a793dee719a5edac218149ddccfda9d07eb3.tar.bz2
Add optional schema compiler error messages and unit tests.
Provides the ability to generate error messages within schema-compiled code for ease of debugging. Error messages may be disabled by adding a 'generate_error_messages' property to json schema, e.g. "generate_error_messages": false Error generation mostly written by Aaron Jacobs (https://codereview.chromium.org/16462004/). BUG=234834 Review URL: https://chromiumcodereview.appspot.com/22228002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/h_generator.py')
-rw-r--r--tools/json_schema_compiler/h_generator.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index 6241b4e..9a348fe 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -26,6 +26,8 @@ class _Generator(object):
self._cpp_namespace = cpp_namespace
self._target_namespace = (
self._type_helper.GetCppNamespaceName(self._namespace))
+ self._generate_error_messages = namespace.compiler_options.get(
+ 'generate_error_messages', False)
def Generate(self):
"""Generates a Code object with the .h for a single namespace.
@@ -228,15 +230,15 @@ class _Generator(object):
(c.Append()
.Comment('Populates a %s object from a base::Value. Returns'
' whether |out| was successfully populated.' % classname)
- .Append('static bool Populate(const base::Value& value, '
- '%(classname)s* out);')
+ .Append('static bool Populate(%s);' % self._GenerateParams(
+ ('const base::Value& value', '%s* out' % classname)))
)
if is_toplevel:
(c.Append()
.Comment('Creates a %s object from a base::Value, or NULL on '
'failure.' % classname)
- .Append('static scoped_ptr<%(classname)s> '
- 'FromValue(const base::Value& value);')
+ .Append('static scoped_ptr<%s> FromValue(%s);' % (
+ classname, self._GenerateParams(('const base::Value& value',))))
)
if type_.origin.from_client:
value_type = ('base::Value'
@@ -323,7 +325,8 @@ class _Generator(object):
c = Code()
(c.Sblock('struct Params {')
- .Append('static scoped_ptr<Params> Create(const base::ListValue& args);')
+ .Append('static scoped_ptr<Params> Create(%s);' % self._GenerateParams(
+ ('const base::ListValue& args',)))
.Append('~Params();')
.Append()
.Cblock(self._GenerateTypes(p.type_ for p in function.params))
@@ -385,3 +388,10 @@ class _Generator(object):
.Append('} // namespace Results')
)
return c
+
+ def _GenerateParams(self, params):
+ """Builds the parameter list for a function, given an array of parameters.
+ """
+ if self._generate_error_messages:
+ params += ('std::string* error = NULL',)
+ return ', '.join(str(p) for p in params)