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

Side by Side Diff: sky/engine/bindings/scripts/idl_reader.py

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
(Empty)
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 """Read an IDL file or complete IDL interface, producing an IdlDefinitions objec t.
30
31 Design doc:
32 http://www.chromium.org/developers/design-documents/idl-compiler#TOC-Front-end
33 """
34
35 import os
36
37 import blink_idl_parser
38 from blink_idl_parser import BlinkIDLParser
39 from idl_definitions import IdlDefinitions
40 from idl_validator import EXTENDED_ATTRIBUTES_RELATIVE_PATH, IDLInvalidExtendedA ttributeError, IDLExtendedAttributeValidator
41 from interface_dependency_resolver import InterfaceDependencyResolver
42
43
44 class IdlReader(object):
45 def __init__(self, interfaces_info=None, outputdir=''):
46 self.extended_attribute_validator = IDLExtendedAttributeValidator()
47
48 if interfaces_info:
49 self.interface_dependency_resolver = InterfaceDependencyResolver(int erfaces_info, self)
50 else:
51 self.interface_dependency_resolver = None
52
53 self.parser = BlinkIDLParser(outputdir=outputdir)
54
55 def read_idl_definitions(self, idl_filename):
56 """Returns an IdlDefinitions object for an IDL file, including all depen dencies."""
57 definitions = self.read_idl_file(idl_filename)
58 if not self.interface_dependency_resolver:
59 return definitions
60 self.interface_dependency_resolver.resolve_dependencies(definitions)
61 return definitions
62
63 def read_idl_file(self, idl_filename):
64 """Returns an IdlDefinitions object for an IDL file, without any depende ncies.
65
66 The IdlDefinitions object is guaranteed to contain a single
67 IdlInterface; it may also contain other definitions, such as
68 callback functions and enumerations."""
69 ast = blink_idl_parser.parse_file(self.parser, idl_filename)
70 if not ast:
71 raise Exception('Failed to parse %s' % idl_filename)
72 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
73 definitions = IdlDefinitions(idl_file_basename, ast)
74
75 # Validate file contents with filename convention
76 # The Blink IDL filenaming convention is that the file
77 # <definition_name>.idl MUST contain exactly 1 definition
78 # (interface, dictionary or exception), and the definition name must
79 # agree with the file's basename, unless it is a partial definition.
80 # (e.g., 'partial interface Foo' can be in FooBar.idl).
81 targets = (definitions.interfaces.values() +
82 definitions.dictionaries.values())
83 number_of_targets = len(targets)
84 if number_of_targets != 1:
85 raise Exception(
86 'Expected exactly 1 definition in file {0}, but found {1}'
87 .format(idl_filename, number_of_targets))
88 target = targets[0]
89 if not target.is_partial and target.name != idl_file_basename:
90 raise Exception(
91 'Definition name "{0}" disagrees with IDL file basename "{1}".'
92 .format(target.name, idl_file_basename))
93
94 # Validate extended attributes
95 if not self.extended_attribute_validator:
96 return definitions
97
98 try:
99 self.extended_attribute_validator.validate_extended_attributes(defin itions)
100 except IDLInvalidExtendedAttributeError as error:
101 raise IDLInvalidExtendedAttributeError("""
102 IDL ATTRIBUTE ERROR in file:
103 %s:
104 %s
105 If you want to add a new IDL extended attribute, please add it to:
106 %s
107 and add an explanation to the Blink IDL documentation at:
108 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
109 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH))
110
111 return definitions
OLDNEW
« no previous file with comments | « sky/engine/bindings/scripts/idl_definitions.py ('k') | sky/engine/bindings/scripts/idl_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698