| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 - |unix_name| the unix_name of the namespace | 42 - |unix_name| the unix_name of the namespace |
| 43 - |source_file| the file that contained the namespace definition | 43 - |source_file| the file that contained the namespace definition |
| 44 - |source_file_dir| the directory component of |source_file| | 44 - |source_file_dir| the directory component of |source_file| |
| 45 - |source_file_filename| the filename component of |source_file| | 45 - |source_file_filename| the filename component of |source_file| |
| 46 - |platforms| if not None, the list of platforms that the namespace is | 46 - |platforms| if not None, the list of platforms that the namespace is |
| 47 available to | 47 available to |
| 48 - |types| a map of type names to their model.Type | 48 - |types| a map of type names to their model.Type |
| 49 - |functions| a map of function names to their model.Function | 49 - |functions| a map of function names to their model.Function |
| 50 - |events| a map of event names to their model.Function | 50 - |events| a map of event names to their model.Function |
| 51 - |properties| a map of property names to their model.Property | 51 - |properties| a map of property names to their model.Property |
| 52 - |compiler_options| the compiler_options dict, only present if | 52 - |compiler_options| the compiler_options dict, only not empty if |
| 53 |include_compiler_options| is True | 53 |include_compiler_options| is True |
| 54 """ | 54 """ |
| 55 def __init__(self, json, source_file, include_compiler_options=False): | 55 def __init__(self, json, source_file, include_compiler_options=False): |
| 56 self.name = json['namespace'] | 56 self.name = json['namespace'] |
| 57 self.unix_name = UnixName(self.name) | 57 self.unix_name = UnixName(self.name) |
| 58 self.source_file = source_file | 58 self.source_file = source_file |
| 59 self.source_file_dir, self.source_file_filename = os.path.split(source_file) | 59 self.source_file_dir, self.source_file_filename = os.path.split(source_file) |
| 60 self.parent = None | 60 self.parent = None |
| 61 self.platforms = _GetPlatforms(json) | 61 self.platforms = _GetPlatforms(json) |
| 62 toplevel_origin = Origin(from_client=True, from_json=True) | 62 toplevel_origin = Origin(from_client=True, from_json=True) |
| 63 self.types = _GetTypes(self, json, self, toplevel_origin) | 63 self.types = _GetTypes(self, json, self, toplevel_origin) |
| 64 self.functions = _GetFunctions(self, json, self) | 64 self.functions = _GetFunctions(self, json, self) |
| 65 self.events = _GetEvents(self, json, self) | 65 self.events = _GetEvents(self, json, self) |
| 66 self.properties = _GetProperties(self, json, self, toplevel_origin) | 66 self.properties = _GetProperties(self, json, self, toplevel_origin) |
| 67 if include_compiler_options: | 67 self.compiler_options = (json.get('compiler_options', {}) |
| 68 self.compiler_options = json.get('compiler_options', {}) | 68 if include_compiler_options else {}) |
| 69 | 69 |
| 70 class Origin(object): | 70 class Origin(object): |
| 71 """Stores the possible origin of model object as a pair of bools. These are: | 71 """Stores the possible origin of model object as a pair of bools. These are: |
| 72 | 72 |
| 73 |from_client| indicating that instances can originate from users of | 73 |from_client| indicating that instances can originate from users of |
| 74 generated code (for example, function results), or | 74 generated code (for example, function results), or |
| 75 |from_json| indicating that instances can originate from the JSON (for | 75 |from_json| indicating that instances can originate from the JSON (for |
| 76 example, function parameters) | 76 example, function parameters) |
| 77 | 77 |
| 78 It is possible for model objects to originate from both the client and json, | 78 It is possible for model objects to originate from both the client and json, |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 def _GetPlatforms(json): | 468 def _GetPlatforms(json): |
| 469 if 'platforms' not in json: | 469 if 'platforms' not in json: |
| 470 return None | 470 return None |
| 471 platforms = [] | 471 platforms = [] |
| 472 for platform_name in json['platforms']: | 472 for platform_name in json['platforms']: |
| 473 for platform_enum in _Enum.GetAll(Platforms): | 473 for platform_enum in _Enum.GetAll(Platforms): |
| 474 if platform_name == platform_enum.name: | 474 if platform_name == platform_enum.name: |
| 475 platforms.append(platform_enum) | 475 platforms.append(platform_enum) |
| 476 break | 476 break |
| 477 return platforms | 477 return platforms |
| OLD | NEW |