1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  
     | 
    
      #! /bin/perl -w
#
# Copyright (c) 1999 Avi Kivity
# instmac.pl --  generate template instantiations
#                derived from James Clark's instmac.m4
#
$index = 0;
$func_index = 0;
sub header
    {
    print <<__HEADER__;
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
#ifdef SP_NAMESPACE
}
#endif
__HEADER__
    }
sub instantiate
    {
    my ($class) = @_;
    print <<__INSTANTIATION__;
#ifdef __DECCXX
#pragma define_template $class
#else
#ifdef __xlC__
#pragma define($class)
#else
#ifdef SP_ANSI_CLASS_INST
template class $class;
#else
typedef $class Dummy_$index;
#endif
#endif
#endif
__INSTANTIATION__
    ++$index;
    }
sub func_instantiate
    {
    my ($a1, $a2, $a3, $a4) = @_;
    print <<__FUNC_INSTANTIATION__;
#ifdef __GNUG__
template void $a1($a2, $a3, $a4);
#else
static
void  func_$func_index ($a2 arg1, $a3 arg2, $a4 arg3) {
(void)$a1(arg1, arg2, arg3);
}
#endif
__FUNC_INSTANTIATION__
    ++$func_index;
    }
header;
while (<ARGV>)
    {
    if (/^__instantiate\((.*)\)\s*$/)
        {
        $arg = $1;
        $arg = $1 if /`(.*)'/;
        instantiate $arg;
        }
    elsif (/^__instantiate\((.*)\)\s*$/)
        {
        die "instantiate_func3 found!";
        }
    else
        {
        print;
        }
    }
 
     |