Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
code_generator_dart.CodeGeneratorDart Class Reference
Inheritance diagram for code_generator_dart.CodeGeneratorDart:

Public Member Functions

def __init__ (self, interfaces_info, cache_dir)
 
def generate_code (self, definitions, interface_name, idl_pickle_filename, only_if_changed)
 
def generate_globals (self, output_directory)
 

Public Attributes

 interfaces_info
 
 jinja_env
 

Detailed Description

Definition at line 95 of file code_generator_dart.py.

Constructor & Destructor Documentation

◆ __init__()

def code_generator_dart.CodeGeneratorDart.__init__ (   self,
  interfaces_info,
  cache_dir 
)

Definition at line 97 of file code_generator_dart.py.

97 def __init__(self, interfaces_info, cache_dir):
98 interfaces_info = interfaces_info or {}
99 self.interfaces_info = interfaces_info
100 self.jinja_env = initialize_jinja_env(cache_dir)
101
102 # Set global type info
103 idl_types.set_ancestors(
104 dict((interface_name, interface_info['ancestors'])
105 for interface_name, interface_info in interfaces_info.items()
106 if interface_info['ancestors']))
107 IdlType.set_callback_interfaces(
108 set(interface_name
109 for interface_name, interface_info in interfaces_info.items()
110 if interface_info['is_callback_interface']))
111 IdlType.set_implemented_as_interfaces(
112 dict((interface_name, interface_info['implemented_as'])
113 for interface_name, interface_info in interfaces_info.items()
114 if interface_info['implemented_as']))
115 IdlType.set_garbage_collected_types(
116 set(interface_name
117 for interface_name, interface_info in interfaces_info.items()
118 if 'GarbageCollected' in
119 interface_info['inherited_extended_attributes']))
120
def initialize_jinja_env(cache_dir)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76

Member Function Documentation

◆ generate_code()

def code_generator_dart.CodeGeneratorDart.generate_code (   self,
  definitions,
  interface_name,
  idl_pickle_filename,
  only_if_changed 
)
Returns .h/.cpp code as (header_text, cpp_text).

Definition at line 121 of file code_generator_dart.py.

122 only_if_changed):
123 """Returns .h/.cpp code as (header_text, cpp_text)."""
124 try:
125 interface = definitions.interfaces[interface_name]
126 except KeyError:
127 raise Exception('%s not in IDL definitions' % interface_name)
128
129 # Store other interfaces for introspection
130 interfaces.update(definitions.interfaces)
131
132 # Set local type info
133 IdlType.set_callback_functions(definitions.callback_functions.keys())
134 IdlType.set_enums((enum.name, enum.values)
135 for enum in definitions.enumerations.values())
136
137 # Select appropriate Jinja template and contents function
138 if interface.is_callback:
139 header_template_filename = 'callback_interface_h.template'
140 cpp_template_filename = 'callback_interface_cpp.template'
141 generate_contents = dart_callback_interface.generate_callback_interface
142 else:
143 header_template_filename = 'interface_h.template'
144 cpp_template_filename = 'interface_cpp.template'
145 generate_contents = dart_interface.generate_interface
146 header_template = self.jinja_env.get_template(header_template_filename)
147 cpp_template = self.jinja_env.get_template(cpp_template_filename)
148
149 # Generate contents (input parameters for Jinja)
150 template_contents = generate_contents(interface)
151 template_contents['code_generator'] = module_pyname
152
153 # Add includes for interface itself and any dependencies
154 interface_info = self.interfaces_info[interface_name]
155 template_contents['header_includes'].add(interface_info['include_path'])
156 template_contents['header_includes'] = sorted(
157 template_contents['header_includes'])
158 includes.update(interface_info.get('dependencies_include_paths', []))
159
160 # Remove includes that are not needed for Dart and trigger fatal
161 # compile warnings if included. These IDL files need to be
162 # imported by Dart to generate the list of events but the
163 # associated header files do not contain any code used by Dart.
164 includes.discard('core/dom/GlobalEventHandlers.h')
165 includes.discard('core/frame/DOMWindowEventHandlers.h')
166
167 template_contents['cpp_includes'] = sorted(includes)
168
169 idl_world = {'interface': None, 'callback': None}
170
171 # Load the pickle file for this IDL.
172 if os.path.isfile(idl_pickle_filename):
173 with open(idl_pickle_filename) as idl_pickle_file:
174 idl_global_data = pickle.load(idl_pickle_file)
175 idl_pickle_file.close()
176 idl_world['interface'] = idl_global_data['interface']
177 idl_world['callback'] = idl_global_data['callback']
178
179 if 'interface_name' in template_contents:
180 interface_global = {
181 'name':
182 template_contents['interface_name'],
183 'parent_interface':
184 template_contents['parent_interface'],
185 'is_active_dom_object':
186 template_contents['is_active_dom_object'],
187 'is_event_target':
188 template_contents['is_event_target'],
189 'has_resolver':
190 template_contents['interface_name'] not in
191 INTERFACES_WITHOUT_RESOLVERS,
192 'is_node':
193 template_contents['is_node'],
194 'conditional_string':
195 template_contents['conditional_string'],
196 }
197 idl_world['interface'] = interface_global
198 else:
199 callback_global = {'name': template_contents['cpp_class']}
200 idl_world['callback'] = callback_global
201
202 write_pickle_file(idl_pickle_filename, idl_world, only_if_changed)
203
204 # Render Jinja templates
205 header_text = header_template.render(template_contents)
206 cpp_text = cpp_template.render(template_contents)
207 return header_text, cpp_text
208

◆ generate_globals()

def code_generator_dart.CodeGeneratorDart.generate_globals (   self,
  output_directory 
)

Definition at line 210 of file code_generator_dart.py.

210 def generate_globals(self, output_directory):
211 header_template_filename = 'global_h.template'
212 cpp_template_filename = 'global_cpp.template'
213
214 # Delete the global pickle file we'll rebuild from each pickle generated
215 # for each IDL file '(%s_globals.pickle) % interface_name'.
216 global_pickle_filename = os.path.join(output_directory, 'global.pickle')
217 if os.path.isfile(global_pickle_filename):
218 os.remove(global_pickle_filename)
219
220 # List of all interfaces and callbacks for global code generation.
221 world = {'interfaces': [], 'callbacks': []}
222
223 # Load all pickled data for each interface.
224 listing = os.listdir(output_directory)
225 for filename in listing:
226 if filename.endswith('_globals.pickle'):
227 idl_filename = os.path.join(output_directory, filename)
228 with open(idl_filename) as idl_pickle_file:
229 idl_world = pickle.load(idl_pickle_file)
230 if 'interface' in idl_world:
231 # FIXME: Why are some of these None?
232 if idl_world['interface']:
233 world['interfaces'].append(idl_world['interface'])
234 if 'callbacks' in idl_world:
235 # FIXME: Why are some of these None?
236 if idl_world['callbacks']:
237 world['callbacks'].append(idl_world['callback'])
238 idl_pickle_file.close()
239
240 world['interfaces'] = sorted(world['interfaces'],
241 key=lambda x: x['name'])
242 world['callbacks'] = sorted(world['callbacks'], key=lambda x: x['name'])
243
244 template_contents = world
245 template_contents['code_generator'] = module_pyname
246
247 header_template = self.jinja_env.get_template(header_template_filename)
248 header_text = header_template.render(template_contents)
249
250 cpp_template = self.jinja_env.get_template(cpp_template_filename)
251 cpp_text = cpp_template.render(template_contents)
252 return header_text, cpp_text
253
254
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition: editor.cpp:211

Member Data Documentation

◆ interfaces_info

code_generator_dart.CodeGeneratorDart.interfaces_info

Definition at line 99 of file code_generator_dart.py.

◆ jinja_env

code_generator_dart.CodeGeneratorDart.jinja_env

Definition at line 100 of file code_generator_dart.py.


The documentation for this class was generated from the following file: