Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
code_generator_dart Namespace Reference

Classes

class  CodeGeneratorDart
 

Functions

 initialize_jinja_env (cache_dir)
 
 conditional_if_endif (code, conditional_string)
 
 runtime_enabled_if (code, runtime_enabled_function_name)
 
 main (argv)
 

Variables

 module_path
 
 module_filename
 
 third_party_dir
 
 templates_dir = os.path.normpath(os.path.join(module_path, 'templates'))
 
str module_pyname = os.path.splitext(module_filename)[0] + '.py'
 
 dart_script_path = os.path.dirname(os.path.abspath(__file__))
 
 script_path
 
 INTERFACES_WITHOUT_RESOLVERS
 

Detailed Description

Generate Blink C++ bindings (.h and .cpp files) for use by Dart:HTML.

If run itself, caches Jinja templates (and creates dummy file for build,
since cache filenames are unpredictable and opaque).

This module is *not* concurrency-safe without care: bytecode caching creates
a race condition on cache *write* (crashes if one process tries to read a
partially-written cache). However, if you pre-cache the templates (by running
the module itself), then you can parallelize compiling individual files, since
cache *reading* is safe.

Input: An object of class IdlDefinitions, containing an IDL interface X
Output: DartX.h and DartX.cpp

Design doc: http://www.chromium.org/developers/design-documents/idl-compiler

Function Documentation

◆ conditional_if_endif()

code_generator_dart.conditional_if_endif (   code,
  conditional_string 
)

Definition at line 273 of file code_generator_dart.py.

273def conditional_if_endif(code, conditional_string):
274 # Jinja2 filter to generate if/endif directive blocks
275 if not conditional_string:
276 return code
277 return ('#if %s\n' % conditional_string + code +
278 '#endif // %s\n' % conditional_string)
279
280
281# [RuntimeEnabled]

◆ initialize_jinja_env()

code_generator_dart.initialize_jinja_env (   cache_dir)

Definition at line 255 of file code_generator_dart.py.

255def initialize_jinja_env(cache_dir):
256 jinja_env = jinja2.Environment(
257 loader=jinja2.FileSystemLoader(templates_dir),
258 # Bytecode cache is not concurrency-safe unless pre-cached:
259 # if pre-cached this is read-only, but writing creates a race condition.
260 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
261 keep_trailing_newline=True, # newline-terminate generated files
262 lstrip_blocks=True, # so can indent control flow tags
263 trim_blocks=True)
264 jinja_env.filters.update({
265 'blink_capitalize': DartUtilities.capitalize,
266 'conditional': conditional_if_endif,
267 'runtime_enabled': runtime_enabled_if,
268 })
269 return jinja_env
270
271
272# [Conditional]

◆ main()

code_generator_dart.main (   argv)

Definition at line 294 of file code_generator_dart.py.

294def main(argv):
295 # If file itself executed, cache templates
296 try:
297 cache_dir = argv[1]
298 dummy_filename = argv[2]
299 except IndexError as err:
300 print('Usage: %s OUTPUT_DIR DUMMY_FILENAME' % argv[0])
301 return 1
302
303 # Cache templates
304 jinja_env = initialize_jinja_env(cache_dir)
305 template_filenames = [
306 filename for filename in os.listdir(templates_dir)
307 # Skip .svn, directories, etc.
308 if filename.endswith(('.cpp', '.h', '.template'))
309 ]
310 for template_filename in template_filenames:
311 jinja_env.get_template(template_filename)
312
313 # Create a dummy file as output for the build system,
314 # since filenames of individual cache files are unpredictable and opaque
315 # (they are hashes of the template path, which varies based on environment)
316 with open(dummy_filename, 'w') as dummy_file:
317 pass # |open| creates or touches the file
318
319
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1

◆ runtime_enabled_if()

code_generator_dart.runtime_enabled_if (   code,
  runtime_enabled_function_name 
)

Definition at line 282 of file code_generator_dart.py.

282def runtime_enabled_if(code, runtime_enabled_function_name):
283 if not runtime_enabled_function_name:
284 return code
285 # Indent if statement to level of original code
286 indent = re.match(' *', code).group(0)
287 return ('%sif (%s())\n' % (indent, runtime_enabled_function_name) +
288 ' %s' % code)
289
290

Variable Documentation

◆ dart_script_path

code_generator_dart.dart_script_path = os.path.dirname(os.path.abspath(__file__))

Definition at line 73 of file code_generator_dart.py.

◆ INTERFACES_WITHOUT_RESOLVERS

code_generator_dart.INTERFACES_WITHOUT_RESOLVERS
Initial value:
1= frozenset([
2 'TypeConversions', 'GCObservation', 'InternalProfilers',
3 'InternalRuntimeFlags', 'InternalSettings', 'InternalSettingsGenerated',
4 'Internals', 'LayerRect', 'LayerRectList', 'MallocStatistics',
5 'TypeConversions'
6])

Definition at line 87 of file code_generator_dart.py.

◆ module_filename

code_generator_dart.module_filename

Definition at line 58 of file code_generator_dart.py.

◆ module_path

code_generator_dart.module_path

Definition at line 58 of file code_generator_dart.py.

◆ module_pyname

str code_generator_dart.module_pyname = os.path.splitext(module_filename)[0] + '.py'

Definition at line 65 of file code_generator_dart.py.

◆ script_path

code_generator_dart.script_path
Initial value:
1= os.path.join(
2 os.path.dirname(os.path.dirname(dart_script_path)), 'scripts')

Definition at line 74 of file code_generator_dart.py.

◆ templates_dir

code_generator_dart.templates_dir = os.path.normpath(os.path.join(module_path, 'templates'))

Definition at line 62 of file code_generator_dart.py.

◆ third_party_dir

code_generator_dart.third_party_dir
Initial value:
1= os.path.normpath(
2 os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pardir,
3 os.pardir))

Definition at line 59 of file code_generator_dart.py.