ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/genacc
Revision: 1.6
Committed: Sun Dec 31 10:28:36 2006 UTC (17 years, 5 months ago) by root
Branch: MAIN
Changes since 1.5: +1 -0 lines
Log Message:
different interface design for c++/perl map handling, some random map framework

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3 root 1.4 # actually geninterface
4    
5 root 1.1 my $class = shift;
6     my $curclass = "";
7 root 1.3 my (@scalar_member, @array_member);
8 root 1.1
9     for my $file (@ARGV) {
10     open my $fh, "<:utf8", $file
11     or die "$file: $!";
12    
13     while (<$fh>) {
14 root 1.6 next if /^\s*\//; # skip lines starting with /
15 root 1.5 if ($curclass eq $class) {
16     while (/ACC\s*\(R([WO])\s*,\s*([^)\]]+)(?:\[(\S+)\])?\)/g) {
17     if ($3) {
18     push @array_member, [$1, $2, $3];
19     } else {
20     push @scalar_member, [$1, $2];
21     }
22     }
23     if (/MTH \s+ ([^(]*?) \s* ([A-Za-z_0-9]+) \s* \(([^)]*)\)/x) {
24     push @method_member, [$1, $2, $3];
25 root 1.3 }
26 root 1.1 }
27 root 1.4 while (/INTERFACE_CLASS\s*\((\S+)\)/g) {
28 root 1.1 $curclass = $1;
29     }
30     }
31     }
32    
33 root 1.5 for (@method_member) {
34     my ($rettype, $name, $params) = @$_;
35    
36     if ($rettype =~ s/static\s+//) {
37     my $args = join ", ", $params =~ m/.*?([a-zA-Z_0-9]+)(?:,\s*|$)/g;
38     if ($rettype ne "void") {
39     print "$rettype\n$name ($params)\n",
40     "\tCODE:\n",
41     "\tRETVAL = $class\::$name ($args);\n",
42     "\tOUTPUT:\n",
43     "\tRETVAL\n";
44     } else {
45     print "$rettype\n$name ($params)\n",
46     "\tCODE:\n",
47     "\t$class\::$name ($args);\n",
48     }
49     } else {
50     print "$rettype\n$class\::$name ($params)\n";
51     }
52    
53     print "\n";
54     }
55    
56 root 1.3 if (@scalar_member) {
57     print "SV *$scalar_member[0][1] ($class *self, SV *newval = 0)\n";
58     print "\tPROTOTYPE: \$;\$\n";
59    
60     if (@scalar_member > 1) {
61     print "\tALIAS:\n";
62     for (1 .. $#scalar_member) {
63     print "\t\t$scalar_member[$_][1]\t= $_\n";
64     }
65     }
66 root 1.1
67 root 1.3 print "\tCODE:\n";
68    
69     # read
70     print "\tif (GIMME_V == G_VOID)\n",
71     "\t RETVAL = &PL_sv_undef;\n",
72     "\telse\n",
73     "\t switch (ix)\n",
74     "\t {\n",
75     (map "\t case $_: RETVAL = to_sv (self->$scalar_member[$_][1]); break;\n",
76     0 .. $#scalar_member),
77     "\t default: croak (\"scalar_member is write-only\");\n",
78     "\t };\n";
79 root 1.1
80 root 1.3 # write
81     print "\tif (newval)\n",
82     "\t switch (ix)\n",
83     "\t {\n",
84     (map "\t case $_: sv_to (newval, self->$scalar_member[$_][1]); break;\n",
85     grep $scalar_member[$_][0] eq "W",
86     0 .. $#scalar_member),
87     "\t default: croak (\"scalar_member is read-only\");\n",
88     "\t };\n";
89    
90     print "\tOUTPUT: RETVAL\n\n";
91     }
92    
93     if (@array_member) {
94     print "SV *$array_member[0][1] ($class *self, int idx, SV *newval = 0)\n";
95     print "\tPROTOTYPE: \$;\$\n";
96    
97     if (@array_member > 1) {
98     print "\tALIAS:\n";
99     for (1 .. $#array_member) {
100     print "\t\t$array_member[$_][1]\t= $_\n";
101     }
102 root 1.1 }
103    
104 root 1.3 print "\tCODE:\n";
105    
106     print "\tif (idx < 0) croak (\"negative array index\");\n";
107    
108     # range
109     print "\t switch (ix)\n",
110     "\t {\n",
111     (map "\t case $_: if (idx >= $array_member[$_][2]) croak (\"array index out of bounds\"); break;\n",
112     0 .. $#array_member),
113     "\t };\n";
114 root 1.1
115     # read
116 root 1.3 print "\tif (GIMME_V == G_VOID)\n",
117     "\t RETVAL = &PL_sv_undef;\n",
118     "\telse\n",
119     "\t switch (ix)\n",
120     "\t {\n",
121     (map "\t case $_: RETVAL = to_sv (self->$array_member[$_][1] [idx]); break;\n",
122     0 .. $#array_member),
123     "\t default: croak (\"array_member is write-only\");\n",
124     "\t };\n";
125 root 1.1
126     # write
127 root 1.3 print "\tif (newval)\n",
128     "\t switch (ix)\n",
129     "\t {\n",
130     (map "\t case $_: sv_to (newval, self->$array_member[$_][1] [idx]); break;\n",
131     grep $array_member[$_][0] eq "W",
132     0 .. $#array_member),
133     "\t default: croak (\"array_member is read-only\");\n",
134     "\t };\n";
135 root 1.1
136 root 1.3 print "\tOUTPUT: RETVAL\n\n";
137     }
138 root 1.1