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

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

Issue 23594008: Initial code generation for features. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 7 years, 3 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.path 5 import os.path
6 6
7 from json_parse import OrderedDict 7 from json_parse import OrderedDict
8 from memoize import memoize 8 from memoize import memoize
9 9
10 class ParseException(Exception): 10 class ParseException(Exception):
(...skipping 16 matching lines...) Expand all
27 27
28 def AddNamespace(self, json, source_file, include_compiler_options=False): 28 def AddNamespace(self, json, source_file, include_compiler_options=False):
29 """Add a namespace's json to the model and returns the namespace. 29 """Add a namespace's json to the model and returns the namespace.
30 """ 30 """
31 namespace = Namespace(json, 31 namespace = Namespace(json,
32 source_file, 32 source_file,
33 include_compiler_options=include_compiler_options) 33 include_compiler_options=include_compiler_options)
34 self.namespaces[namespace.name] = namespace 34 self.namespaces[namespace.name] = namespace
35 return namespace 35 return namespace
36 36
37 class Feature(object):
38 """ A Feature
not at google - send to devlin 2013/09/12 16:20:43 """A feature, as specified in files such as chrome
dhnishi (use Chromium) 2013/09/13 17:36:42 Done.
39
40 Properties:
41 - |name| the name of the feature
42 - |constant_name| the name of the constant equivalent to the feature
43 - |source_file| the file that contained the namespace definition
44 - |source_file_dir| the directory component of |source_file|
45 - |source_file_filename| the filename component of |source_file|
46 - |channel| the channel where the feature is released
47 - |extension_types| the types which can use the permission feature
48 - |whitelist| a list of exetnsions allowed to use the feature
49 """
50 def __init__(self, feature_name, feature_def, source_file):
51 self.name = feature_name
52 self.constant_name = self._constant_name(self.name)
not at google - send to devlin 2013/09/12 16:20:43 this is a property of the C++ code not of the abst
dhnishi (use Chromium) 2013/09/13 17:36:42 Removed from the abstract model.
53 self.unix_name = UnixName(self.name)
54 self.source_file = source_file
55 self.source_file_dir, self.source_file_filename = os.path.split(source_file)
not at google - send to devlin 2013/09/12 16:20:43 would be nice not to have source_file nor source_f
dhnishi (use Chromium) 2013/09/13 17:36:42 I don't think I had anything actually using those
56 self.channel = feature_def['channel']
57 self.extension_types = feature_def['extension_types']
58 self.whitelist = feature_def.get('whitelist')
59
60 def _constant_name(self, target):
not at google - send to devlin 2013/09/12 16:20:43 (move this into cpp_util.py if something like that
dhnishi (use Chromium) 2013/09/13 17:36:42 Done.
61 return ('k' + ''.join(word[0].upper() + word[1:]
62 for word in target.replace('.', ' ').split()))
63
37 class Namespace(object): 64 class Namespace(object):
38 """An API namespace. 65 """An API namespace.
39 66
40 Properties: 67 Properties:
41 - |name| the name of the namespace 68 - |name| the name of the namespace
42 - |description| the description of the namespace 69 - |description| the description of the namespace
43 - |unix_name| the unix_name of the namespace 70 - |unix_name| the unix_name of the namespace
44 - |source_file| the file that contained the namespace definition 71 - |source_file| the file that contained the namespace definition
45 - |source_file_dir| the directory component of |source_file| 72 - |source_file_dir| the directory component of |source_file|
46 - |source_file_filename| the filename component of |source_file| 73 - |source_file_filename| the filename component of |source_file|
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 def _GetPlatforms(json): 511 def _GetPlatforms(json):
485 if 'platforms' not in json: 512 if 'platforms' not in json:
486 return None 513 return None
487 platforms = [] 514 platforms = []
488 for platform_name in json['platforms']: 515 for platform_name in json['platforms']:
489 for platform_enum in _Enum.GetAll(Platforms): 516 for platform_enum in _Enum.GetAll(Platforms):
490 if platform_name == platform_enum.name: 517 if platform_name == platform_enum.name:
491 platforms.append(platform_enum) 518 platforms.append(platform_enum)
492 break 519 break
493 return platforms 520 return platforms
521
not at google - send to devlin 2013/09/12 16:20:43 no blank line?
dhnishi (use Chromium) 2013/09/13 17:36:42 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698