Synopsis - Synopsis/Processors/TemplateLinker.py

File: Synopsis/Processors/TemplateLinker.py

     1#
     2# Copyright (C) 2008 Stefan Seefeld
     3# All rights reserved.
     4# Licensed to the public under the terms of the GNU LGPL (>= 2),
     5# see the file COPYING for details.
     6#
     7
     8from Synopsis.Processor import *
     9from Synopsis import ASG
    10
    11class TemplateLinker(Processor, ASG.Visitor):
    12    """Link template specializations to their primary templates, and vice versa."""
    13
    14    def process(self, ir, **kwds):
    15
    16        self.set_parameters(kwds)
    17        self.ir = self.merge_input(ir)
    18
    19        for d in ir.asg.declarations:
    20            d.accept(self)
    21        return self.output_and_return_ir()
    22
    23    def link(self, d):
    24
    25        if d.is_template_specialization:
    26            primary_name = d.name[:-1] + (d.name[-1].split('<')[0].strip(),)
    27            primary = self.ir.asg.types.get(primary_name)
    28            d.primary_template = primary_name
    29            if (type(primary) is ASG.DeclaredTypeId and
    30                d.name not in primary.declaration.specializations):
    31                primary.declaration.specializations.append(d.name)
    32
    33    visit_forward = link
    34    visit_class = link
    35    visit_class_template = link
    36

Generated on Thu Apr 16 16:27:14 2009 by
synopsis (version devel)