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

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 22228002: Add optional schema compiler error messages (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Templates. Created 7 years, 4 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 6241b4e3b32a5f31683eda5b7e1af99c58771d64..9a348fe51dc95741ed3cdeb2eea6ccce2e46fb41 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)

Powered by Google App Engine
This is Rietveld 408576698