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

Side by Side Diff: Source/bindings/scripts/idl_reader.py

Issue 205873003: Refactor interface dependency resolution (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 else: 53 else:
54 self.interface_dependency_resolver = None 54 self.interface_dependency_resolver = None
55 55
56 self.parser = BlinkIDLParser(outputdir=outputdir) 56 self.parser = BlinkIDLParser(outputdir=outputdir)
57 57
58 def read_idl_definitions(self, idl_filename): 58 def read_idl_definitions(self, idl_filename):
59 """Returns an IdlDefinitions object for an IDL file, including all depen dencies.""" 59 """Returns an IdlDefinitions object for an IDL file, including all depen dencies."""
60 definitions = self.read_idl_file(idl_filename) 60 definitions = self.read_idl_file(idl_filename)
61 if not self.interface_dependency_resolver: 61 if not self.interface_dependency_resolver:
62 return definitions 62 return definitions
63 63 self.interface_dependency_resolver.resolve_dependencies(definitions)
64 interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
65 self.interface_dependency_resolver.resolve_dependencies(
66 definitions, interface_name)
67 return definitions 64 return definitions
68 65
69 def read_idl_file(self, idl_filename): 66 def read_idl_file(self, idl_filename):
70 """Returns an IdlDefinitions object for an IDL file, without any depende ncies.""" 67 """Returns an IdlDefinitions object for an IDL file, without any depende ncies.
68
69 The IdlDefinitions object is guaranteed to contain a single
70 IdlInterface; it may also contain other definitions, such as
71 callback functions and enumerations."""
71 ast = blink_idl_parser.parse_file(self.parser, idl_filename) 72 ast = blink_idl_parser.parse_file(self.parser, idl_filename)
72 if not ast: 73 if not ast:
73 raise Exception('Failed to parse %s' % idl_filename) 74 raise Exception('Failed to parse %s' % idl_filename)
74 definitions = IdlDefinitions(ast) 75 definitions = IdlDefinitions(ast)
76
77 # Validate file contents with filename convention
78 # The Blink IDL filenaming convention is that the file
79 # <interface_name>.idl MUST contain exactly 1 interface (or exception),
80 # and the interface name must agree with the file's basename,
81 # unless it is a partial interface.
82 # (e.g., 'partial interface Foo' can be in FooBar.idl).
83 number_of_interfaces = len(definitions.interfaces)
84 if number_of_interfaces != 1:
85 raise Exception(
86 'Expected exactly 1 interface in file {0}, but found {1}'
87 .format(idl_filename, number_of_interfaces))
88 interface = next(definitions.interfaces.itervalues())
89 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
90 if not interface.is_partial and interface.name != idl_file_basename:
91 raise Exception(
92 'Interface name "{0}" disagrees with IDL file basename "{1}".'
93 .format(interface.name, idl_file_basename))
94
95 # Validate extended attributes
75 if not self.extended_attribute_validator: 96 if not self.extended_attribute_validator:
76 return definitions 97 return definitions
77 98
78 try: 99 try:
79 self.extended_attribute_validator.validate_extended_attributes(defin itions) 100 self.extended_attribute_validator.validate_extended_attributes(defin itions)
80 except IDLInvalidExtendedAttributeError as error: 101 except IDLInvalidExtendedAttributeError as error:
81 raise IDLInvalidExtendedAttributeError( 102 raise IDLInvalidExtendedAttributeError(
82 """IDL ATTRIBUTE ERROR in file %s: 103 """IDL ATTRIBUTE ERROR in file %s:
83 %s 104 %s
84 If you want to add a new IDL extended attribute, please add it to 105 If you want to add a new IDL extended attribute, please add it to
85 bindings/IDLExtendedAttributes.txt 106 bindings/IDLExtendedAttributes.txt
86 and add an explanation to the Blink IDL documentation at: 107 and add an explanation to the Blink IDL documentation at:
87 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes 108 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
88 """ % (idl_filename, str(error))) 109 """ % (idl_filename, str(error)))
89 110
90 return definitions 111 return definitions
OLDNEW
« no previous file with comments | « Source/bindings/scripts/idl_definitions.py ('k') | Source/bindings/scripts/interface_dependency_resolver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698