/
gen_class.pl
82 lines (58 loc) · 1.7 KB
/
gen_class.pl
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
80
81
82
#! perl
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
# $Id$
=head1 NAME
tools/dev/gen_class.pl - Create a template PMC file
=head1 SYNOPSIS
% perl tools/dev/gen_class.pl Foo > src/classes/Foo.pmc
=head1 DESCRIPTION
Use this script to generate a template PMC file with stubs for all the
methods you need to fill in. See F<docs/vtables.pod> for more
information on adding a new PMC to Parrot.
To see what a minimal PMC looks like, create a PMC template and compile
it to C.
% perl tools/dev/gen_class.pl Foo > src/classes/foo.pmc
% perl tools/build/pmc2c.pl -c src/classes/foo.pmc
=head1 SEE ALSO
F<tools/build/pmc2c.pl>, F<docs/vtables.pod>.
=cut
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../lib";
use Parrot::Vtable;
my $vtbl = parse_vtable("$FindBin::Bin/../../vtable.tbl");
my $classname = shift
or die "No classname given!\n";
## emit file header
print <<EOF;
/* ${classname}.pmc
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* SVN Info
* \$Id\$
* Overview:
* These are the vtable functions for the $classname base class
* Data Structure and Algorithms:
* History:
* Notes:
* Please remove unneeded entries.
* References:
*/
#include "parrot/parrot.h"
pmclass $classname {
EOF
## emit method bodies
for (@$vtbl) {
my ($retval, $methname, $args) = @$_;
if ($methname eq 'type' || $methname eq 'name' || $methname =~ /prop/) {
# default.pmc handles these
next;
}
print " $retval $methname ($args) {\n";
if($retval ne 'void') {
print " return ($retval)0;\n";
}
print " }\n\n";
}
## emit file footer
print "}\n";