OLD | NEW |
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 21 matching lines...) Expand all Loading... |
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 Namespace(object): | 37 class Namespace(object): |
38 """An API namespace. | 38 """An API namespace. |
39 | 39 |
40 Properties: | 40 Properties: |
41 - |name| the name of the namespace | 41 - |name| the name of the namespace |
| 42 - |description| the description of the namespace |
42 - |unix_name| the unix_name of the namespace | 43 - |unix_name| the unix_name of the namespace |
43 - |source_file| the file that contained the namespace definition | 44 - |source_file| the file that contained the namespace definition |
44 - |source_file_dir| the directory component of |source_file| | 45 - |source_file_dir| the directory component of |source_file| |
45 - |source_file_filename| the filename component of |source_file| | 46 - |source_file_filename| the filename component of |source_file| |
46 - |platforms| if not None, the list of platforms that the namespace is | 47 - |platforms| if not None, the list of platforms that the namespace is |
47 available to | 48 available to |
48 - |types| a map of type names to their model.Type | 49 - |types| a map of type names to their model.Type |
49 - |functions| a map of function names to their model.Function | 50 - |functions| a map of function names to their model.Function |
50 - |events| a map of event names to their model.Function | 51 - |events| a map of event names to their model.Function |
51 - |properties| a map of property names to their model.Property | 52 - |properties| a map of property names to their model.Property |
52 - |compiler_options| the compiler_options dict, only present if | 53 - |compiler_options| the compiler_options dict, only present if |
53 |include_compiler_options| is True | 54 |include_compiler_options| is True |
54 """ | 55 """ |
55 def __init__(self, json, source_file, include_compiler_options=False): | 56 def __init__(self, json, source_file, include_compiler_options=False): |
56 self.name = json['namespace'] | 57 self.name = json['namespace'] |
| 58 self.description = json.get('description', None) |
57 self.unix_name = UnixName(self.name) | 59 self.unix_name = UnixName(self.name) |
58 self.source_file = source_file | 60 self.source_file = source_file |
59 self.source_file_dir, self.source_file_filename = os.path.split(source_file) | 61 self.source_file_dir, self.source_file_filename = os.path.split(source_file) |
60 self.parent = None | 62 self.parent = None |
61 self.platforms = _GetPlatforms(json) | 63 self.platforms = _GetPlatforms(json) |
62 toplevel_origin = Origin(from_client=True, from_json=True) | 64 toplevel_origin = Origin(from_client=True, from_json=True) |
63 self.types = _GetTypes(self, json, self, toplevel_origin) | 65 self.types = _GetTypes(self, json, self, toplevel_origin) |
64 self.functions = _GetFunctions(self, json, self) | 66 self.functions = _GetFunctions(self, json, self) |
65 self.events = _GetEvents(self, json, self) | 67 self.events = _GetEvents(self, json, self) |
66 self.properties = _GetProperties(self, json, self, toplevel_origin) | 68 self.properties = _GetProperties(self, json, self, toplevel_origin) |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 def _GetPlatforms(json): | 470 def _GetPlatforms(json): |
469 if 'platforms' not in json: | 471 if 'platforms' not in json: |
470 return None | 472 return None |
471 platforms = [] | 473 platforms = [] |
472 for platform_name in json['platforms']: | 474 for platform_name in json['platforms']: |
473 for platform_enum in _Enum.GetAll(Platforms): | 475 for platform_enum in _Enum.GetAll(Platforms): |
474 if platform_name == platform_enum.name: | 476 if platform_name == platform_enum.name: |
475 platforms.append(platform_enum) | 477 platforms.append(platform_enum) |
476 break | 478 break |
477 return platforms | 479 return platforms |
OLD | NEW |