| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 present if |
| 53 |include_compiler_options| is True | 53 |include_compiler_options| is True |
| 54 - |generate_error_messages| if error messages should be generated |
| 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'] |
| 57 self.unix_name = UnixName(self.name) | 58 self.unix_name = UnixName(self.name) |
| 58 self.source_file = source_file | 59 self.source_file = source_file |
| 59 self.source_file_dir, self.source_file_filename = os.path.split(source_file) | 60 self.source_file_dir, self.source_file_filename = os.path.split(source_file) |
| 60 self.parent = None | 61 self.parent = None |
| 61 self.platforms = _GetPlatforms(json) | 62 self.platforms = _GetPlatforms(json) |
| 62 toplevel_origin = Origin(from_client=True, from_json=True) | 63 toplevel_origin = Origin(from_client=True, from_json=True) |
| 63 self.types = _GetTypes(self, json, self, toplevel_origin) | 64 self.types = _GetTypes(self, json, self, toplevel_origin) |
| 64 self.functions = _GetFunctions(self, json, self) | 65 self.functions = _GetFunctions(self, json, self) |
| 65 self.events = _GetEvents(self, json, self) | 66 self.events = _GetEvents(self, json, self) |
| 66 self.properties = _GetProperties(self, json, self, toplevel_origin) | 67 self.properties = _GetProperties(self, json, self, toplevel_origin) |
| 67 if include_compiler_options: | 68 if include_compiler_options: |
| 68 self.compiler_options = json.get('compiler_options', {}) | 69 self.compiler_options = json.get('compiler_options', {}) |
| 70 self.generate_error_messages = json.get('generate_error_messages', False) |
| 69 | 71 |
| 70 class Origin(object): | 72 class Origin(object): |
| 71 """Stores the possible origin of model object as a pair of bools. These are: | 73 """Stores the possible origin of model object as a pair of bools. These are: |
| 72 | 74 |
| 73 |from_client| indicating that instances can originate from users of | 75 |from_client| indicating that instances can originate from users of |
| 74 generated code (for example, function results), or | 76 generated code (for example, function results), or |
| 75 |from_json| indicating that instances can originate from the JSON (for | 77 |from_json| indicating that instances can originate from the JSON (for |
| 76 example, function parameters) | 78 example, function parameters) |
| 77 | 79 |
| 78 It is possible for model objects to originate from both the client and json, | 80 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): | 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 |