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

Side by Side Diff: client/dom/scripts/dartgenerator.py

Issue 9706084: Add conditional feature to templates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 8 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
« no previous file with comments | « client/dom/scripts/all_tests.py ('k') | client/dom/scripts/dartgenerator_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module generates Dart APIs from the IDL database.""" 6 """This module generates Dart APIs from the IDL database."""
7 7
8 import emitter 8 import emitter
9 import idlnode 9 import idlnode
10 import logging 10 import logging
11 import multiemitter 11 import multiemitter
12 import os 12 import os
13 import re 13 import re
14 import shutil 14 import shutil
15 from generator import * 15 from generator import *
16 from systembase import * 16 from systembase import *
17 from systemfrog import * 17 from systemfrog import *
18 from systemhtml import * 18 from systemhtml import *
19 from systeminterface import * 19 from systeminterface import *
20 from systemnative import * 20 from systemnative import *
21 from systemwrapping import * 21 from systemwrapping import *
22 from templateloader import TemplateLoader
22 23
23 _logger = logging.getLogger('dartgenerator') 24 _logger = logging.getLogger('dartgenerator')
24 25
25 def MergeNodes(node, other): 26 def MergeNodes(node, other):
26 node.operations.extend(other.operations) 27 node.operations.extend(other.operations)
27 for attribute in other.attributes: 28 for attribute in other.attributes:
28 if not node.has_attribute(attribute): 29 if not node.has_attribute(attribute):
29 node.attributes.append(attribute) 30 node.attributes.append(attribute)
30 31
31 node.constants.extend(other.constants) 32 node.constants.extend(other.constants)
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 frog_system = FrogSystem( 276 frog_system = FrogSystem(
276 TemplateLoader(self._template_dir, ['dom/frog', 'dom', '']), 277 TemplateLoader(self._template_dir, ['dom/frog', 'dom', '']),
277 self._database, self._emitters, self._output_dir) 278 self._database, self._emitters, self._output_dir)
278 279
279 frog_system._interface_system = interface_system 280 frog_system._interface_system = interface_system
280 self._systems.append(frog_system) 281 self._systems.append(frog_system)
281 282
282 if 'htmlfrog' in systems: 283 if 'htmlfrog' in systems:
283 html_system = HtmlFrogSystem( 284 html_system = HtmlFrogSystem(
284 TemplateLoader(self._template_dir, 285 TemplateLoader(self._template_dir,
285 ['html/frog', 'html/impl', 'html', '']), 286 ['html/frog', 'html/impl', 'html', ''],
287 {'DARTIUM': False, 'FROG': True}),
286 self._database, self._emitters, self._output_dir, self) 288 self._database, self._emitters, self._output_dir, self)
287 289
288 html_system._interface_system = html_interface_system 290 html_system._interface_system = html_interface_system
289 self._systems.append(html_system) 291 self._systems.append(html_system)
290 292
291 if 'htmldartium' in systems: 293 if 'htmldartium' in systems:
292 html_system = HtmlDartiumSystem( 294 html_system = HtmlDartiumSystem(
293 TemplateLoader(self._template_dir, 295 TemplateLoader(self._template_dir,
294 ['html/dartium', 'html/impl', 'html', '']), 296 ['html/dartium', 'html/impl', 'html', ''],
297 {'DARTIUM': True, 'FROG': False}),
295 self._database, self._emitters, self._output_dir, self) 298 self._database, self._emitters, self._output_dir, self)
296 299
297 html_system._interface_system = html_interface_system 300 html_system._interface_system = html_interface_system
298 self._systems.append(html_system) 301 self._systems.append(html_system)
299 302
300 # Collect interfaces 303 # Collect interfaces
301 interfaces = [] 304 interfaces = []
302 for interface in database.GetInterfaces(): 305 for interface in database.GetInterfaces():
303 if not MatchSourceFilter(source_filter, interface): 306 if not MatchSourceFilter(source_filter, interface):
304 # Skip this interface since it's not present in the required source 307 # Skip this interface since it's not present in the required source
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 setters = {} 539 setters = {}
537 for attr in attributes: 540 for attr in attributes:
538 if attr.is_fc_getter: 541 if attr.is_fc_getter:
539 getters[attr.id] = attr 542 getters[attr.id] = attr
540 elif attr.is_fc_setter and 'Replaceable' not in attr.ext_attrs: 543 elif attr.is_fc_setter and 'Replaceable' not in attr.ext_attrs:
541 setters[attr.id] = attr 544 setters[attr.id] = attr
542 return [(getters.get(id), setters.get(id)) for id in names] 545 return [(getters.get(id), setters.get(id)) for id in names]
543 546
544 # ------------------------------------------------------------------------------ 547 # ------------------------------------------------------------------------------
545 548
546 class TemplateLoader(object):
547 """Loads template files from a path."""
548
549 def __init__(self, root, subpaths):
550 """Initializes loader.
551
552 Args:
553 root - a string, the directory under which the templates are stored.
554 subpaths - a list of strings, subpaths of root in search order.
555 """
556 self._root = root
557 self._subpaths = subpaths
558 self._cache = {}
559
560 def TryLoad(self, name):
561 """Returns content of template file as a string, or None of not found."""
562 if name in self._cache:
563 return self._cache[name]
564
565 for subpath in self._subpaths:
566 template_file = os.path.join(self._root, subpath, name)
567 if os.path.exists(template_file):
568 template = ''.join(open(template_file).readlines())
569 self._cache[name] = template
570 return template
571
572 return None
573
574 def Load(self, name):
575 """Returns contents of template file as a string, or raises an exception."""
576 template = self.TryLoad(name)
577 if template is not None: # Can be empty string
578 return template
579 raise Exception("Could not find template '%s' on %s / %s" % (
580 name, self._root, self._subpaths))
581
582 # ------------------------------------------------------------------------------
583
584 class DummyImplementationSystem(System): 549 class DummyImplementationSystem(System):
585 """Generates a dummy implementation for use by the editor analysis. 550 """Generates a dummy implementation for use by the editor analysis.
586 551
587 All the code comes from hand-written library files. 552 All the code comes from hand-written library files.
588 """ 553 """
589 554
590 def __init__(self, templates, database, emitters, output_dir): 555 def __init__(self, templates, database, emitters, output_dir):
591 super(DummyImplementationSystem, self).__init__( 556 super(DummyImplementationSystem, self).__init__(
592 templates, database, emitters, output_dir) 557 templates, database, emitters, output_dir)
593 factory_providers_file = os.path.join(self._output_dir, 'src', 'dummy', 558 factory_providers_file = os.path.join(self._output_dir, 'src', 'dummy',
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 pass 625 pass
661 626
662 def AddTypedArrayConstructors(self, element_type): 627 def AddTypedArrayConstructors(self, element_type):
663 pass 628 pass
664 629
665 def AddOperation(self, info): 630 def AddOperation(self, info):
666 pass 631 pass
667 632
668 def AddEventAttributes(self, event_attrs): 633 def AddEventAttributes(self, event_attrs):
669 pass 634 pass
OLDNEW
« no previous file with comments | « client/dom/scripts/all_tests.py ('k') | client/dom/scripts/dartgenerator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698