* support-test-*.cs: Rename from test-*-p2.cs.
[mono.git] / mcs / class / PresentationFramework / System.Windows.Serialization / data-classes-builder.pl
1 open FILE, "data-classes.txt";
2
3 %classes;
4
5 while ($line = <FILE>) {
6         chop $line;
7         $properties = "";
8         $magicprops = "";
9         if (index($line, ":") == -1) {
10                 $class = $line;
11                 if (index($line, ";") != -1) {
12                         $class = substr($line, 0, index($line, ";"));
13                         $magicprops = substr($line, index($line, ";") + 2);
14                         print "$class: $magicprops\n";
15                 }
16         } else {
17                 $class = substr($line, 0, index($line, ":"));
18                 $properties = substr($line, index($line, ":") + 2);
19                 if (index($properties, ";") != -1) {
20                         $magicprops = substr($properties, index($properties, ";") + 2);
21                         $properties = substr($properties, 0, index($properties, ";"));
22                 }
23         }
24         if ($line =~ m/Xaml[^(]+\(/) {
25                 $parent = $class;
26                 $parent =~ s/(Xaml[^(]+)\(([^)]+)\).*/\2/;
27                 $clname = $class;
28                 $clname =~ s/(Xaml[^(]+)\(([^)]+)\).*/\1/;
29                 $class = $clname;
30         } else {
31                 $parent = "XamlNode";
32         }
33         $classes{$class} = { parent => $parent, 
34                         properties => $properties,
35                         magicprops => $magicprops };
36 }
37
38 sub get_parent {
39         my $x = shift;
40         return $classes{$x}->{"parent"};
41 }
42 sub get_properties {
43         my $x = shift;
44         return $classes{$x}->{"properties"};
45 }
46 sub get_magic_properties {
47         my $x = shift;
48         return $classes{$x}->{"magicprops"};
49 }
50
51
52 sub get_extended_params_list {
53         my $x = shift;
54         my $params = "";
55         while ($x ne "XamlNode") {
56                 $x = &get_parent($x);
57                 $params = &get_properties($x) . ", " . $params;
58                 $params =~ s/, $//;
59         }
60         $params =~ s/^XamlNodeType tokenType, //;
61         return $params;
62 }
63
64 sub has_parent {
65         my $x = shift;
66         my $parent = shift;
67         while ($x ne "object") {
68                 if ($x eq $parent) {
69                         return 1;
70                 }
71                 $x = &get_parent($x);
72         }
73         return 0;
74 }
75
76 for $class (keys %classes) {
77         print "$class.cs\n";
78         open X, ">$class.cs";
79         print X "// THIS FILE AUTOMATICALLY GENERATED BY data-classes-builder.pl\n";
80         print X "// EDITING IS PROBABLY UNWISE\n";
81         print X "namespace System.Windows.Serialization {\n";
82         print X "using System;\n";
83         print X "using System.Reflection;\n";
84         print X "using System.Windows;\n";
85         $parent = &get_parent($class);
86
87         $props = &get_properties($class);
88         @propl = split /, /, $props;
89
90         $eprops = &get_extended_params_list($class);
91         @epropl = split /, /, $eprops;
92
93         $allprops = $eprops;
94         $allprops .= ", $props" unless ($props eq "");
95         @allpropl = split /, /, $allprops;
96         my @allpropl2 = @allpropl;
97         for $prop (@allpropl2) {
98                 $prop =~ s/^\+//;
99         }
100         $allprops = join ", ", @allpropl2;
101
102         $mprops = &get_magic_properties($class);
103         @mpropl = split /, /, $mprops;
104
105         $xamlnodetype = "$class";
106         $xamlnodetype =~ s/^Xaml(.+)Node$/\1/;
107         $xamlnodetype = "XamlNodeType.$xamlnodetype";
108
109         print X "public class $class : " . $parent . " { \n";
110
111         # member variables
112         for $prop (@propl) {
113                 next if $prop =~ m/^\+/;
114                 print X "\tprivate $prop;\n";
115         }
116         for $prop (@mpropl) {
117                 next if $prop =~ m/^\+/;
118                 $x = $prop;
119                 $x =~ s/ / _/;
120                 print X "\tprivate $x;\n";
121         }
122         print X "\n\n";
123
124         # constructor
125         if ($class eq "XamlNode") {
126                 print X "\tpublic $class($props)\n";
127                 print X "\t{\n";
128                 for $prop (@propl) {
129                         $propname = substr($prop, index($prop, " ") + 1);
130                         print X "\t\tthis.$propname = $propname;\n";
131                 }
132                 print X "\t}\n";
133         } else {
134                 print X "\tpublic $class($allprops)\n";
135                 print X "\t\t: this(";
136                 my @allpropnames;
137                 push @allpropnames, $xamlnodetype;
138                 for $prop (@allpropl) {
139                         push @allpropnames, substr($prop, index($prop, " ") + 1);
140                 }
141                 print X (join ", ", @allpropnames);
142                 print X ")\n\t{}\n\n\n";
143
144                 print X "\tinternal $class(XamlNodeType type, $allprops)\n";
145
146                 my @epropnamel;
147                 for $prop (@epropl) {
148                         push @epropnamel, substr($prop, index($prop, " ") + 1);
149                 }
150                 $epropnames = join ", ", @epropnamel;
151                 print X "\t\t: base(type, $epropnames)\n";
152                 print X "\t{\n";
153                 for $prop (@propl) {
154                         $propname = substr($prop, index($prop, " ") + 1);
155                         if ($prop =~ m/^\+/) {
156                                 $func = substr($propname, 0, 1);
157                                 $func =~ tr/a-z/A-Z/;
158                                 $func = "set$func" . substr($propname, 1);
159                                 print X "\t\tthis.$func($propname);\n";
160                         } else {
161                                 print X "\t\tthis.$propname = $propname;\n";
162                         }
163                 }
164                 print X "\t}\n";
165         }
166
167         #property accessors
168         for $prop (@propl) {
169                 $proptype = substr($prop, 0, index($prop, " "));
170                 $fieldname = substr($prop, index($prop, " ") + 1);
171
172                 $propname = substr($fieldname, 0, 1);
173                 $propname =~ tr/a-z/A-Z/;
174                 $propname .= substr($fieldname, 1);
175
176                 if ($proptype =~ m/^\+/) {
177                         next;
178                 }
179
180                 print X "\n\tpublic $proptype $propname {\n";
181                 print X "\t\tget { return $fieldname; }\n";
182                 print X "\t}\n";
183         }
184         for $prop (@mpropl) {
185                 $proptype = substr($prop, 0, index($prop, " "));
186                 $propname = substr($prop, index($prop, " ") + 1);
187                 $fieldname = "_$propname";
188
189                 if ($propname =~ m/^[a-z]/) {
190                         $access = "internal";
191                 } else {
192                         $access = "public";
193                 }
194
195                 print X "\n\t$access $proptype $propname {\n";
196                 print X "\t\tget { return $fieldname; }\n";
197                 print X "\t}\n";
198                 print X "\n\tinternal void set$propname($proptype v) {\n";
199                 print X "\t\t$fieldname = v;\n";
200                 print X "\t}\n";
201         }
202         print X "}\n}\n\n";
203         close X;
204 }