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

Side by Side Diff: tools/json_schema_compiler/h_generator.py

Issue 1100333006: Make the JSON Schema compiler handle enums declared in other namespaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 6
7 from code import Code 7 from code import Code
8 from model import PropertyType 8 from model import PropertyType
9 import cpp_util 9 import cpp_util
10 import schema_util 10 import schema_util
(...skipping 23 matching lines...) Expand all
34 .Append() 34 .Append()
35 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) 35 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file)
36 .Append() 36 .Append()
37 ) 37 )
38 38
39 # Hack: for the purpose of gyp the header file will always be the source 39 # Hack: for the purpose of gyp the header file will always be the source
40 # file with its file extension replaced by '.h'. Assume so. 40 # file with its file extension replaced by '.h'. Assume so.
41 output_file = os.path.splitext(self._namespace.source_file)[0] + '.h' 41 output_file = os.path.splitext(self._namespace.source_file)[0] + '.h'
42 ifndef_name = cpp_util.GenerateIfndefName(output_file) 42 ifndef_name = cpp_util.GenerateIfndefName(output_file)
43 43
44 # Hack: tabs and windows have circular references, so only generate hard
45 # references for them (i.e. anything that can't be forward declared). In
46 # other cases, generate soft dependencies so that they can include
47 # non-optional types from other namespaces.
48 include_soft = self._namespace.name not in ('tabs', 'windows')
49
44 (c.Append('#ifndef %s' % ifndef_name) 50 (c.Append('#ifndef %s' % ifndef_name)
45 .Append('#define %s' % ifndef_name) 51 .Append('#define %s' % ifndef_name)
46 .Append() 52 .Append()
47 .Append('#include <map>') 53 .Append('#include <map>')
48 .Append('#include <string>') 54 .Append('#include <string>')
49 .Append('#include <vector>') 55 .Append('#include <vector>')
50 .Append() 56 .Append()
51 .Append('#include "base/basictypes.h"') 57 .Append('#include "base/basictypes.h"')
52 .Append('#include "base/logging.h"') 58 .Append('#include "base/logging.h"')
53 .Append('#include "base/memory/linked_ptr.h"') 59 .Append('#include "base/memory/linked_ptr.h"')
54 .Append('#include "base/memory/scoped_ptr.h"') 60 .Append('#include "base/memory/scoped_ptr.h"')
55 .Append('#include "base/values.h"') 61 .Append('#include "base/values.h"')
56 .Cblock(self._type_helper.GenerateIncludes()) 62 .Cblock(self._type_helper.GenerateIncludes(include_soft=include_soft))
57 .Append() 63 .Append()
58 ) 64 )
59 65
60 # TODO(calamity): These forward declarations should be #includes to allow 66 # Hack: we're not generating soft inclues for tabs and windows, so we need
Devlin 2015/04/23 23:26:51 typo: includes
not at google - send to devlin 2015/04/23 23:28:45 Done.
61 # $ref types from other files to be used as required params. This requires 67 # to generate forward declarations for them.
62 # some detangling of windows and tabs which will currently lead to circular 68 if not include_soft:
63 # #includes. 69 c.Cblock(self._type_helper.GenerateForwardDeclarations())
64 c.Cblock(self._type_helper.GenerateForwardDeclarations())
65 70
66 cpp_namespace = cpp_util.GetCppNamespace( 71 cpp_namespace = cpp_util.GetCppNamespace(
67 self._namespace.environment.namespace_pattern, 72 self._namespace.environment.namespace_pattern,
68 self._namespace.unix_name) 73 self._namespace.unix_name)
69 c.Concat(cpp_util.OpenNamespace(cpp_namespace)) 74 c.Concat(cpp_util.OpenNamespace(cpp_namespace))
70 c.Append() 75 c.Append()
71 if self._namespace.properties: 76 if self._namespace.properties:
72 (c.Append('//') 77 (c.Append('//')
73 .Append('// Properties') 78 .Append('// Properties')
74 .Append('//') 79 .Append('//')
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 """Builds the parameter list for a function, given an array of parameters. 393 """Builds the parameter list for a function, given an array of parameters.
389 """ 394 """
390 # |error| is populated with warnings and/or errors found during parsing. 395 # |error| is populated with warnings and/or errors found during parsing.
391 # |error| being set does not necessarily imply failure and may be 396 # |error| being set does not necessarily imply failure and may be
392 # recoverable. 397 # recoverable.
393 # For example, optional properties may have failed to parse, but the 398 # For example, optional properties may have failed to parse, but the
394 # parser was able to continue. 399 # parser was able to continue.
395 if self._generate_error_messages: 400 if self._generate_error_messages:
396 params += ('base::string16* error',) 401 params += ('base::string16* error',)
397 return ', '.join(str(p) for p in params) 402 return ', '.join(str(p) for p in params)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698