/usr/lib/x86_64-linux-gnu/glibmm-2.4/proc/pm/Output.pm is in libglibmm-2.4-dev 2.39.93-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 | # Gtkmmproc Output module
#
# Copyright 2001 Free Software Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
package Output;
use strict;
use open IO => ":utf8";
use Function qw(FLAG_PARAM_OPTIONAL FLAG_PARAM_OUTPUT);
use DocsParser;
BEGIN { @Namespace::ISA=qw(main); }
# $objOutputter new()
sub new
{
my ($m4path, $macrodirs) = @_;
my $self = {};
bless $self;
$$self{out} = [];
$$self{source} = "";
$$self{tmpdir} = File::Spec->tmpdir();
$$self{destdir} = "";
$$self{objDefsParser} = undef; # It will be set in set_defsparser()
$$self{m4path} = $m4path;
$$self{m4args} = "-I";
$$self{m4args} .= join(" -I", @$macrodirs);
return $self;
}
sub set_defsparser($$)
{
my ($self, $objDefsParser) = @_;
$$self{objDefsParser} = $objDefsParser; #Remember it so that we can use it in our output methods.
}
sub m4args_append($$)
{
my ($self, $str) = @_;
$$self{m4args} .= $str;
}
sub append($$)
{
my ($self, $str) = @_;
push(@{$$self{out}}, $str);
}
# void output_wrap_failed($cname, $error)
# Puts a comment in the header about the error during code-generation.
sub output_wrap_failed($$$)
{
my ($self, $cname, $error) = @_;
my $str = sprintf("//gtkmmproc error: %s : %s", $cname, $error);
print STDERR "Output.pm: $main::source: $cname : $error\n";
$self->append($str);
}
sub error
{
my $format=shift @_;
printf STDERR "Output.pm: $main::source: $format",@_;
}
sub ifdef($$)
{
my ($self, $ifdef) = @_;
if ($ifdef)
{
$self->append("\n#ifdef $ifdef\n");
}
}
sub endif($$)
{
my ($self, $ifdef) = @_;
if ($ifdef)
{
$self->append("\n#endif // $ifdef\n");
}
}
### Convert _WRAP to a virtual
# _VFUNC_H(signame,rettype,`<cppargs>')
# _VFUNC_PH(gtkname,crettype,cargs and names)
# void output_wrap_vfunc_h($filename, $line_num, $objCppfunc, $objCDefsFunc)
sub output_wrap_vfunc_h($$$$$$)
{
my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc, $ifdef) = @_;
#Old code. We removed _VFUNC_H from the .m4 file
# my $str = sprintf("_VFUNC_H(%s,%s,\`%s\',%s)dnl\n",
# $$objCppfunc{name},
# $$objCppfunc{rettype},
# $objCppfunc->args_types_and_names(),
# $objCppfunc->get_is_const()
# );
# $self->append($str);
$self->ifdef($ifdef);
# Prepend a Doxygen @throws directive to the declaration if the virtual
# function throws an error.
if($$objCDefsFunc{throw_any_errors})
{
$self->append('/// @throws Glib::Error.' . "\n");
}
my $cppVfuncDecl = "virtual " . $$objCppfunc{rettype} . " " . $$objCppfunc{name} . "(" . $objCppfunc->args_types_and_names() . ")";
if($objCppfunc->get_is_const())
{
$cppVfuncDecl .= " const";
}
$self->append(" $cppVfuncDecl;\n");
$self->endif($ifdef);
#The default callback, which will call *_vfunc, which will then call the base default callback.
#Declares the callback in the private *Class class and sets it in the class_init function.
my $str = sprintf("_VFUNC_PH(%s,%s,\`%s\',%s)dnl\n",
$$objCDefsFunc{name},
$$objCDefsFunc{rettype},
$objCDefsFunc->args_types_and_names(),
$ifdef
);
$self->append($str);
}
# _VFUNC_CC(signame,gtkname,rettype,crettype,`<cppargs>',`<cargs>')
sub output_wrap_vfunc_cc($$$$$$$$)
{
my ($self, $filename, $line_num, $objCppfunc, $objCFunc,
$custom_vfunc, $custom_vfunc_callback, $ifdef) = @_;
my $cname = $$objCFunc{name};
my $errthrow = "";
if($$objCFunc{throw_any_errors})
{
$errthrow = "errthrow"
}
# e.g. Gtk::Button::draw_indicator:
#Use a different macro for Interfaces, to generate an extra convenience method.
if (!$custom_vfunc)
{
my $refreturn = "";
$refreturn = "refreturn" if($$objCppfunc{rettype_needs_ref});
my $returnValue = $$objCppfunc{return_value};
my ($conversions, $declarations, $initializations) =
convert_args_cpp_to_c($objCppfunc, $objCFunc, 0, $line_num, $errthrow);
my $no_slot_copy = "";
$no_slot_copy = "no_slot_copy" if ($$objCppfunc{no_slot_copy});
my $str = sprintf("_VFUNC_CC(%s,%s,%s,%s,\`%s\',\`%s\',%s,%s,%s,%s,%s,%s,%s,%s)dnl\n",
$$objCppfunc{name},
$cname,
$$objCppfunc{rettype},
$$objCFunc{rettype},
$objCppfunc->args_types_and_names(),
$conversions,
$objCppfunc->get_is_const(),
$refreturn,
$ifdef,
$errthrow,
$$objCppfunc{slot_type},
$$objCppfunc{slot_name},
$no_slot_copy,
$returnValue);
$self->append($str);
}
# e.g. Gtk::ButtonClass::draw_indicator():
if (!$custom_vfunc_callback)
{
my $refreturn_ctype = "";
$refreturn_ctype = "refreturn_ctype" if($$objCFunc{rettype_needs_ref});
# Get the conversions.
my $conversions =
convert_args_c_to_cpp($objCFunc, $objCppfunc, $line_num);
my $returnValue = $$objCppfunc{return_value};
my $str = sprintf("_VFUNC_PCC(%s,%s,%s,%s,\`%s\',\`%s\',\`%s\',%s,%s,%s,%s,%s,%s,%s)dnl\n",
$$objCppfunc{name},
$cname,
$$objCppfunc{rettype},
$$objCFunc{rettype},
$objCFunc->args_types_and_names(),
$objCFunc->args_names_only(),
$conversions,
${$objCFunc->get_param_names()}[0],
$refreturn_ctype,
$ifdef,
$errthrow,
$$objCppfunc{slot_type},
$$objCppfunc{c_data_param_name},
$returnValue);
$self->append($str);
}
}
### Convert _WRAP to a signal
# _SIGNAL_H(signame,rettype, `<cppargs>', ifdef)
# _SIGNAL_PH(gtkname,crettype, cargs and names, ifdef, deprecated)
# void output_wrap_default_signal_handler_h($filename, $line_num, $objCppfunc,
# $objCDefsFunc, $ifdef, $deprecated)
sub output_wrap_default_signal_handler_h($$$$$$$)
{
my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc, $ifdef, $deprecated) = @_;
# The default signal handler is a virtual function.
# It's not hidden by deprecation, since that would break ABI.
my $str = sprintf("_SIGNAL_H(%s,%s,\`%s\',%s)dnl\n",
$$objCppfunc{name},
$$objCppfunc{rettype},
$objCppfunc->args_types_and_names(),
$ifdef
);
$self->append($str);
#The default callback, which will call on_* or the base default callback.
#Declares the callback in the private *Class class and sets it in the class_init function.
#This is hidden by deprecation.
$str = sprintf("_SIGNAL_PH(%s,%s,\`%s\',%s,%s)dnl\n",
$$objCDefsFunc{name},
$$objCDefsFunc{rettype},
$objCDefsFunc->args_types_and_names(),
$ifdef,
$deprecated
);
$self->append($str);
}
# _SIGNAL_CC(signame, gtkname, rettype, crettype,`<cppargs>',`<cargs>', const, refreturn, ifdef)
sub output_wrap_default_signal_handler_cc($$$$$$$$$)
{
my ($self, $filename, $line_num, $objCppfunc, $objDefsSignal, $bImplement,
$bCustomCCallback, $bRefreturn, $ifdef, $deprecated) = @_;
my $cname = $$objDefsSignal{name};
# $cname = $1 if ($args[3] =~ /"(.*)"/); #TODO: What's this about?
# e.g. Gtk::Button::on_clicked:
if($bImplement eq 1)
{
my $refreturn = "";
$refreturn = "refreturn" if($bRefreturn eq 1);
my ($conversions, $declarations, $initializations) =
convert_args_cpp_to_c($objCppfunc, $objDefsSignal, 0, $line_num);
# The default signal handler is a virtual function.
# It's not hidden by deprecation, since that would break ABI.
my $str = sprintf("_SIGNAL_CC(%s,%s,%s,%s,\`%s\',\`%s\',%s,%s,%s)dnl\n",
$$objCppfunc{name},
$cname,
$$objCppfunc{rettype},
$$objDefsSignal{rettype},
$objCppfunc->args_types_and_names(),
$conversions,
$$objCppfunc{const},
$refreturn,
$ifdef);
$self->append($str);
}
# e.g. Gtk::ButtonClass::on_clicked():
#Callbacks always take the object instance as the first argument:
# my $arglist_names = "object";
# my $arglist_names_extra = $objDefsSignal->args_names_only();
# if ($arglist_names_extra)
# {
# $arglist_names .= ", ";
# $arglist_names .= $arglist_names_extra;
# }
if($bCustomCCallback ne 1)
{
my $conversions =
convert_args_c_to_cpp($objDefsSignal, $objCppfunc, $line_num);
#This is hidden by deprecation.
my $str = sprintf("_SIGNAL_PCC(%s,%s,%s,%s,\`%s\',\`%s\',\`%s\',\`%s\',%s,%s)dnl\n",
$$objCppfunc{name},
$cname,
$$objCppfunc{rettype},
$$objDefsSignal{rettype},
$objDefsSignal->args_types_and_names(),
$objDefsSignal->args_names_only(),
$conversions,
${$objDefsSignal->get_param_names()}[0],
$ifdef,
$deprecated);
$self->append($str);
}
}
### Convert _WRAP to a method
# _METHOD(cppname,cname,cpprettype,crettype,arglist,cargs,const)
# void output_wrap_meth($filename, $line_num, $objCppFunc, $objCDefsFunc, $cppMethodDecl, $documentation, $ifdef)
sub output_wrap_meth($$$$$$$)
{
my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc, $cppMethodDecl, $documentation, $ifdef) = @_;
my $objDefsParser = $$self{objDefsParser};
my $cpp_param_names = $$objCppfunc{param_names};
my $cpp_param_types = $$objCppfunc{param_types};
my $c_param_name_mappings = $$objCppfunc{param_mappings};
my $num_args_list = $objCppfunc->get_num_possible_args_list();
my $output_var_name;
my $output_var_type;
if(defined($$c_param_name_mappings{"OUT"}))
{
$output_var_name = $$cpp_param_names[$$c_param_name_mappings{"OUT"}];
$output_var_type = $$cpp_param_types[$$c_param_name_mappings{"OUT"}];
}
for(my $arg_list = 0; $arg_list < $num_args_list; $arg_list++)
{
# Allow the generated .h/.cc code to have an #ifndef around it, and add
# deprecation docs to the generated documentation.
my $deprecated = "";
if($$objCDefsFunc{deprecated})
{
$deprecated = "deprecated";
}
#Declaration:
if($deprecated ne "")
{
$self->append("\n_DEPRECATE_IFDEF_START");
}
$self->ifdef($ifdef);
if($arg_list == 0)
{
# Doxygen documentation before the method declaration:
$self->output_wrap_meth_docs_only($filename, $line_num, $documentation);
}
else
{
$self->append("\n\n /// A $$objCppfunc{name}() convenience overload.\n");
}
$self->append(" " . $objCppfunc->get_declaration($arg_list));
$self->endif($ifdef);
if($deprecated ne "")
{
$self->append("\n_DEPRECATE_IFDEF_END\n");
}
my $refneeded = "";
if($$objCDefsFunc{rettype_needs_ref})
{
$refneeded = "refreturn"
}
my $errthrow = "";
if($$objCDefsFunc{throw_any_errors})
{
$errthrow = "errthrow"
}
my $constversion = ""; #Whether it is just a const overload (so it can reuse code)
if($$objCDefsFunc{constversion})
{
$constversion = "constversion"
}
#Implementation:
my $str;
if ($$objCppfunc{static}) {
my ($conversions, $declarations, $initializations) =
convert_args_cpp_to_c($objCppfunc, $objCDefsFunc, 1, $line_num,
$errthrow, $arg_list); #1 means it's static, so it has 'object'.
my $no_slot_copy = "";
my $slot_type = "";
my $slot_name = "";
# A slot may be optional so if it is signaled by
# convert_args_cpp_to_c() to not be included, then don't.
if ($$objCppfunc{include_slot})
{
$slot_type = $$objCppfunc{slot_type};
$slot_name = $$objCppfunc{slot_name};
$no_slot_copy = "no_slot_copy" if ($$objCppfunc{no_slot_copy});
}
$str = sprintf("_STATIC_METHOD(%s,%s,\`%s\',%s,\`%s\',\`%s\',\`%s\',\`%s\',%s,%s,%s,%s,%s,%s,`%s',`%s',`%s',%s)dnl\n",
$$objCppfunc{name},
$$objCDefsFunc{c_name},
$$objCppfunc{rettype},
$objCDefsFunc->get_return_type_for_methods(),
$objCppfunc->args_types_and_names($arg_list),
$declarations,
$conversions,
$initializations,
$refneeded,
$errthrow,
$deprecated,
$ifdef,
$output_var_name,
$output_var_type,
$slot_type,
$slot_name,
$no_slot_copy,
$line_num
);
} else {
my ($conversions, $declarations, $initializations) =
convert_args_cpp_to_c($objCppfunc, $objCDefsFunc, 0, $line_num,
$errthrow, $arg_list);
my $no_slot_copy = "";
my $slot_type = "";
my $slot_name = "";
# A slot may be optional so if it is signaled by
# convert_args_cpp_to_c() to not be included, then don't.
if ($$objCppfunc{include_slot})
{
$slot_type = $$objCppfunc{slot_type};
$slot_name = $$objCppfunc{slot_name};
$no_slot_copy = "no_slot_copy" if ($$objCppfunc{no_slot_copy});
}
$str = sprintf("_METHOD(%s,%s,\`%s\',%s,\`%s\',\`%s\',\`%s\',\`%s\',%s,%s,%s,%s,%s,\`%s\',%s,%s,%s,`%s',`%s',`%s',%s)dnl\n",
$$objCppfunc{name},
$$objCDefsFunc{c_name},
$$objCppfunc{rettype},
$objCDefsFunc->get_return_type_for_methods(),
$objCppfunc->args_types_and_names($arg_list),
$declarations,
$conversions,
$initializations,
$$objCppfunc{const},
$refneeded,
$errthrow,
$deprecated,
$constversion,
$objCppfunc->args_names_only($arg_list),
$ifdef,
$output_var_name,
$output_var_type,
$slot_type,
$slot_name,
$no_slot_copy,
$line_num
);
}
$self->append($str);
}
}
### Convert _WRAP to a method
# _METHOD(cppname,cname,cpprettype,crettype,arglist,cargs,const)
# void output_wrap_meth($filename, $line_num, $documentation)
sub output_wrap_meth_docs_only($$$$)
{
my ($self, $filename, $line_num, $documentation) = @_;
my $objDefsParser = $$self{objDefsParser};
# Doxygen documentation before the method declaration:
$self->append("\n${documentation}");
}
### Convert _WRAP_CTOR to a ctor
# _METHOD(cppname,cname,cpprettype,crettype,arglist,cargs,const)
# void output_wrap_ctor($filename, $line_num, $objCppFunc, $objCDefsFunc, $cppMethodDecl)
sub output_wrap_ctor($$$$$)
{
my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc, $cppMethodDecl) = @_;
my $objDefsParser = $$self{objDefsParser};
my $num_args_list = $objCppfunc->get_num_possible_args_list();
for(my $arg_list = 0; $arg_list < $num_args_list; $arg_list++)
{
if ($arg_list > 0)
{
$self->append("\n\n /// A $$objCppfunc{name}() convenience overload.\n");
}
#Ctor Declaration:
#TODO: Add explicit.
$self->append(" explicit " . $objCppfunc->get_declaration($arg_list) . "\n");
my $errthrow = "";
if($$objCDefsFunc{throw_any_errors})
{
$errthrow = "errthrow";
}
#Implementation:
my $str = sprintf("_CTOR_IMPL(%s,%s,\`%s\',\`%s\')dnl\n",
$$objCppfunc{name},
$$objCDefsFunc{c_name},
$objCppfunc->args_types_and_names($arg_list),
get_ctor_properties($objCppfunc, $objCDefsFunc, $line_num, $errthrow, $arg_list)
);
$self->append($str);
}
}
sub output_wrap_create($$$)
{
my ($self, $args_type_and_name_with_default_values, $objWrapParser) = @_;
#Re-use Function in a very hacky way, to separate the argument types_and_names.
my $fake_decl = "void fake_func(" . $args_type_and_name_with_default_values . ")";
my $objFunction = &Function::new($fake_decl, $objWrapParser);
my $num_args_list = $objFunction->get_num_possible_args_list();
for(my $arg_list = 0; $arg_list < $num_args_list; $arg_list++)
{
my $args_names_only = $objFunction->args_names_only($arg_list);
my $args_type_and_name_hpp =
$objFunction->args_types_and_names_with_default_values($arg_list);
my $args_type_and_name_cpp = $objFunction->args_types_and_names($arg_list);
if ($arg_list > 0) {
$self->append("\n /// A create() convenience overload.");
}
my $str = sprintf("_CREATE_METHOD(\`%s\',\`%s\',\`%s\')dnl\n",
$args_type_and_name_hpp, , $args_type_and_name_cpp, $args_names_only);
$self->append($str)
}
}
# void output_wrap_sig_decl($filename, $line_num, $objCSignal, $objCppfunc, $signal_name, $bCustomCCallback, $ifdef, $commentblock, $deprecated, $deprecation_docs)
# custom_signalproxy_name is "" when no type conversion is required - a normal templates SignalProxy will be used instead.
sub output_wrap_sig_decl($$$$$$$$$$)
{
my ($self, $filename, $line_num, $objCSignal, $objCppfunc, $signal_name, $bCustomCCallback, $ifdef, $commentblock, $deprecated, $deprecation_docs) = @_;
# _SIGNAL_PROXY(c_signal_name, c_return_type, `<c_arg_types_and_names>',
# cpp_signal_name, cpp_return_type, `<cpp_arg_types>',`<c_args_to_cpp>',
# refdoc_comment)
# Get the signal name with underscores only (to look up docs -- they are
# stored that way).
my $underscored_signal_name = $signal_name;
$underscored_signal_name =~ s/-/_/g;
# Get the existing signal documentation from the parsed docs.
my $documentation =
DocsParser::lookup_documentation("$$objCSignal{class}::$underscored_signal_name", $deprecation_docs);
# Create a merged Doxygen comment block for the signal from the looked up
# docs (the block will also contain a prototype of the slot as an example).
my $doxycomment = $objCppfunc->get_refdoc_comment($documentation);
# If there was already a previous doxygen comment, we want to merge this
# one with the previous so it is one big comment. If
# $commentblock is not emtpy, it contains the previous doxygen comment without
# opening and closing tokens (/** and */).
if($commentblock ne "")
{
# Strip leading whitespace
$doxycomment =~ s/^\s+//;
# We don't have something to add, so just use $commentblock with
# opening and closing tokens added.
if($doxycomment eq "")
{
$doxycomment = ' /**' . $commentblock . "\n */";
}
else
{
# Merge the two comments, but remove the first three characters from the
# second comment (/**) that mark the beginning of the comment.
$doxycomment = substr($doxycomment, 3);
$doxycomment =~ s/^\s+//;
$doxycomment = ' /**' . $commentblock . "\n *\n " . $doxycomment;
}
}
my $conversions =
convert_args_c_to_cpp($objCSignal, $objCppfunc, $line_num);
my $str = sprintf("_SIGNAL_PROXY(%s,%s,\`%s\',%s,%s,\`%s\',\`%s\',\`%s\',%s,\`%s\',%s)dnl\n",
$signal_name,
$$objCSignal{rettype},
$objCSignal->args_types_and_names_without_object(),
$$objCppfunc{name},
$$objCppfunc{rettype},
$objCppfunc->args_types_only(),
$conversions,
$bCustomCCallback, #When this is true, it will not write the *_callback implementation for you.
$deprecated,
$doxycomment,
$ifdef
);
$self->append($str);
}
# void output_wrap_enum($filename, $line_num, $cpp_type, $c_type, $comment, @flags)
sub output_wrap_enum($$$$$$$)
{
my ($self, $filename, $line_num, $cpp_type, $c_type, $comment, @flags) = @_;
my $objEnum = GtkDefs::lookup_enum($c_type);
if(!$objEnum)
{
$self->output_wrap_failed($c_type, "enum defs lookup failed.");
return;
}
$objEnum->beautify_values();
my $no_gtype = "";
my $elements = $objEnum->build_element_list(\@flags, \$no_gtype, " ");
if(!$elements)
{
$self->output_wrap_failed($c_type, "unknown _WRAP_ENUM() flag");
return;
}
my $value_suffix = "Enum";
$value_suffix = "Flags" if($$objEnum{flags});
# Get the enum documentation from the parsed docs.
my $enum_docs =
DocsParser::lookup_enum_documentation("$c_type", "$cpp_type", \@flags);
# Remove initial Doxygen comment block start ('/**') from the enum docs
# to merge the passed in Doxygen comment block.
$enum_docs =~ s/\/\*\*\s+//g;
# Make sure indentation of passed in comment is correct.
$comment =~ s/\n\s*\*/\n */g;
# Merge the passed in comment to the existing enum documentation.
$comment = $comment . "\n * " . $enum_docs;
my $str = sprintf("_ENUM(%s,%s,%s,\`%s\',\`%s\',\`%s\')dnl\n",
$cpp_type,
$c_type,
$value_suffix,
$elements,
$no_gtype,
$comment
);
$self->append($str);
}
sub output_wrap_enum_docs_only($$$$$$$)
{
my ($self, $filename, $line_num, $module_canonical, $cpp_type, $c_type,
$comment, @flags) = @_;
# Get the existing enum description from the parsed docs.
my $enum_docs =
DocsParser::lookup_enum_documentation("$c_type", "$cpp_type", \@flags);
if($enum_docs eq "")
{
$self->output_wrap_failed($c_type, "failed to find documentation.");
return;
}
# Include the enum docs in the module's enum docs group.
$enum_docs .= "\n * \@ingroup ${module_canonical}Enums\n";
# Remove initial Doxygen comment block start ('/**') from the enum docs
# to merge the passed in Doxygen comment block.
$enum_docs =~ s/\/\*\*\s+//g;
# Merge the passed in comment to the existing enum documentation.
$comment = "\/\*\* " . $comment . "\n * " . $enum_docs . "\n */\n";
# Make sure indentation of passed in comment is correct.
$comment =~ s/\n\s*\*/\n */g;
$self->append($comment);
}
# void output_wrap_gerror($filename, $line_num, $cpp_type, $c_enum, $domain, @flags)
sub output_wrap_gerror($$$$$$$)
{
my ($self, $filename, $line_num, $cpp_type, $c_enum, $domain, @flags) = @_;
my $objDefsParser = $$self{objDefsParser};
my $objEnum = GtkDefs::lookup_enum($c_enum);
if(!$objEnum)
{
$self->output_wrap_failed($c_enum, "enum defs lookup failed.");
return;
}
# Shouldn't happen, and if it does, I'd like to know that.
warn if($$objEnum{flags});
$objEnum->beautify_values();
# cut off the module prefix, e.g. GDK_
my $prefix = $domain;
$prefix =~ s/^[^_]+_//;
# Chop off the domain prefix, because we put the enum into the class.
unshift(@flags, "s#^${prefix}_##");
my $no_gtype = "";
my $elements = $objEnum->build_element_list(\@flags, \$no_gtype, " ");
my $str = sprintf("_GERROR(%s,%s,%s,\`%s\',%s)dnl\n",
$cpp_type,
$c_enum,
$domain,
$elements,
$no_gtype
);
$self->append($str);
}
# _PROPERTY_PROXY(name, cpp_type)
# void output_wrap_property($filename, $line_num, $name, $cpp_type, $deprecated, $deprecation_docs)
sub output_wrap_property($$$$$$$$)
{
my ($self, $filename, $line_num, $name, $cpp_type, $c_class, $deprecated, $deprecation_docs) = @_;
my $objDefsParser = $$self{objDefsParser};
my $objProperty = GtkDefs::lookup_property($c_class, $name);
if($objProperty eq 0) #If the lookup failed:
{
$self->output_wrap_failed($name, "property defs lookup failed.");
}
else
{
# We use a suffix to specify a particular Glib::PropertyProxy* class.
my $proxy_suffix = "";
# Read/Write:
if($objProperty->get_construct_only() eq 1)
{
# construct-only functions can be read, but not written.
$proxy_suffix = "_ReadOnly";
if($objProperty->get_readable() ne 1)
{
$self->output_wrap_failed($name, "attempt to wrap write-only and construct-only property.");
return;
}
}
elsif($objProperty->get_readable() ne 1)
{
$proxy_suffix = "_WriteOnly";
}
elsif($objProperty->get_writable() ne 1)
{
$proxy_suffix = "_ReadOnly";
}
# Convert - to _ so we can use it in C++ method and variable names:
my $name_underscored = $name;
$name_underscored =~ tr/-/_/;
# Get the property documentation, if any, and add m4 quotes.
my $documentation = $objProperty->get_docs($deprecation_docs);
add_m4_quotes(\$documentation) if ($documentation ne "");
#Declaration:
if($deprecated ne "")
{
$self->append("\n_DEPRECATE_IFDEF_START\n");
}
my $str = sprintf("_PROPERTY_PROXY(%s,%s,%s,%s,%s,`%s')dnl\n",
$name,
$name_underscored,
$cpp_type,
$proxy_suffix,
$deprecated,
$documentation
);
$self->append($str);
$self->append("\n");
# If the property is not already read-only, and the property can be read,
# then add a second const accessor for a read-only propertyproxy:
if( ($proxy_suffix ne "_ReadOnly") && ($objProperty->get_readable()) )
{
my $str = sprintf("_PROPERTY_PROXY(%s,%s,%s,%s,%s,`%s')dnl\n",
$name,
$name_underscored,
$cpp_type,
"_ReadOnly",
$deprecated,
$documentation
);
$self->append($str);
}
if($deprecated ne "")
{
$self->append("\n_DEPRECATE_IFDEF_END");
}
}
}
sub add_m4_quotes($)
{
my ($text) = @_;
# __BT__ and __FT__ are M4 macros defined in the base.m4 file that produce
# a "`" and a "'" resp. without M4 errors.
my %m4_quotes = (
"`" => "'__BT__`",
"'" => "'__FT__`",
);
$$text =~ s/([`'])/$m4_quotes{$1}/g;
$$text = "`" . $$text . "'";
}
# void output_temp_g1($module, $glibmm_version) e.g. output_temp_g1(gtkmm, 2.38.0)
sub output_temp_g1($$$)
{
my ($self, $module, $glibmm_version) = @_;
# Write out *.g1 temporary file
open(FILE, '>', "$$self{tmpdir}/gtkmmproc_$$.g1"); # $$ is the Process ID
print FILE "include(base.m4)dnl\n";
my $module_canonical = Util::string_canonical($module); #In case there is a / character in the module.
print FILE "_START($$self{source},$module,$module_canonical,$glibmm_version)dnl\n";
print FILE join("", @{$$self{out}});
print FILE "_END()\n";
close(FILE);
}
sub make_g2_from_g1($)
{
my ($self) = @_;
# Execute m4 to get *.g2 file:
system("$$self{m4path} $$self{m4args} \"$$self{tmpdir}/gtkmmproc_$$.g1\" > \"$$self{tmpdir}/gtkmmproc_$$.g2\"");
return ($? >> 8);
}
# void write_sections_to_files()
# This is where we snip the /tmp/gtkmmproc*.g2 file into sections (,h, .cc, _private.h)
sub write_sections_to_files()
{
my ($self) = @_;
my $fname_h = "$$self{destdir}/$$self{source}.h";
my $fname_ph = "$$self{destdir}/private/$$self{source}_p.h";
my $fname_cc = "$$self{destdir}/$$self{source}.cc";
open(INPUT, '<', "$$self{tmpdir}/gtkmmproc_$$.g2"); # $$ is the process ID.
# open temporary file for each section
open(OUTPUT_H, '>', "$fname_h.tmp");
open(OUTPUT_PH, '>', "$fname_ph.tmp");
open(OUTPUT_CC, '>', "$fname_cc.tmp");
my $oldfh = select(OUTPUT_H);
my $blank = 0;
while(<INPUT>)
{
# section switching
if(/^#S 0/) { select(OUTPUT_H); next; }
if(/^#S 1/) { select(OUTPUT_PH); next; }
if(/^#S 2/) { select(OUTPUT_CC); next; }
# get rid of bogus blank lines
if(/^\s*$/) { ++$blank; } else { $blank = 0; }
next if($blank > 2);
print $_;
}
select($oldfh);
close(INPUT);
close(OUTPUT_H);
close(OUTPUT_PH);
close(OUTPUT_CC);
foreach($fname_h, $fname_ph, $fname_cc)
{
# overwrite the source file only if it has actually changed
# Win32 does fail at this, so we do the two steps separately:
#system("cmp -s '$_.tmp' '$_' || cp '$_.tmp' '$_'" ; rm -f '$_.tmp');
system("cmp -s '$_.tmp' '$_' || cp '$_.tmp' '$_'");
system("rm -f '$_.tmp'");
}
}
sub remove_temp_files($)
{
my ($self) = @_;
system("rm -f \"$$self{tmpdir}/gtkmmproc_$$.g1\"");
system("rm -f \"$$self{tmpdir}/gtkmmproc_$$.g2\"");
}
# procedure for generating CONVERT macros, C declarations (for C output
# variables), and INITIALIZE macros (to set the corresponding C++ parameters
# from the C output parameters) for the specified argument list
# (string, string, string) convert_args_cpp_to_c($objCppfunc, $objCDefsFunc, $static, $wrap_line_number,$automatic_error, $index = 0)
# The return is an array of 3 strings: The _CONVERT macros, the C declarations
# and the _INITIALIZE macros.
# The optional index specifies which arg list out of the possible combination
# of arguments based on whether any arguments are optional. index = 0 ==> all
# the arguments.
sub convert_args_cpp_to_c($$$$$)
{
my ($objCppfunc, $objCDefsFunc, $static, $wrap_line_number, $automatic_error, $index) = @_;
$automatic_error = "" unless defined $automatic_error;
$index = 0 unless defined $index;
my $cpp_param_names = $$objCppfunc{param_names};
my $cpp_param_types = $$objCppfunc{param_types};
my $cpp_param_flags = $$objCppfunc{param_flags};
my $c_param_name_mappings = $$objCppfunc{param_mappings};
my $c_param_types = $$objCDefsFunc{param_types};
my $c_param_names = $$objCDefsFunc{param_names};
my @conversions = ();
my @declarations = ();
my @initializations = ();
my $num_c_args_expected = scalar(@{$c_param_types});
if( !($static) ) { $num_c_args_expected--; } #The cpp method will need an Object* paramater at the start.
my $num_cpp_args = scalar(@{$cpp_param_types});
my $has_output_param = 0;
my $output_param_index;
# See if there is an output parameter. If so, temporarily decrement the
# number of C++ arguments so that the possible GError addition works and
# note the existence.
if(defined($$c_param_name_mappings{"OUT"}))
{
$num_cpp_args--;
$has_output_param = 1;
$output_param_index = $$c_param_name_mappings{"OUT"};
}
else
{
# Check for possible void return mismatch (warn if the option was
# specified to gmmproc at the command line).
if($main::return_mismatches &&
$$objCppfunc{rettype} eq "void" && $$objCDefsFunc{rettype} ne "void")
{
Output::error(
"void return of $$objCppfunc{name}() does not match the "
. "$$objCDefsFunc{rettype} return type.\n");
}
}
# add implicit last error parameter;
if ( $automatic_error ne "" &&
$num_cpp_args == ($num_c_args_expected - 1) &&
${$c_param_types}[-1] eq "GError**" )
{
$num_cpp_args++;
$cpp_param_names = [@{$cpp_param_names},"gerror"];
$cpp_param_types = [@{$cpp_param_types},"GError*&"];
$cpp_param_flags = [@{$cpp_param_flags}, 0];
# Map from the C gerror param name to the newly added C++ param index.
# The correct C++ index to map to (from the C name) depends on if there
# is an output parameter since it will be readded.
my $cpp_index = $num_cpp_args - 1;
$cpp_index++ if($has_output_param);
$$c_param_name_mappings{@$c_param_names[$num_c_args_expected]} = $cpp_index;
}
# If the method has a slot temporarily decrement the C arg count when
# comparing the C++ and C argument count because the C function would
# have a final 'gpointer data' parameter.
$num_c_args_expected-- if ($$objCppfunc{slot_name});
if ( $num_cpp_args != $num_c_args_expected )
{
Output::error( "convert_args_cpp_to_c(): Incorrect number of arguments. (%d != %d)\n",
$num_cpp_args,
$num_c_args_expected );
$objCppfunc->dump();
$objCDefsFunc->dump();
return ("", "", "");
}
# Reincrement the expected C argument count if there is a slot.
$num_c_args_expected++ if ($$objCppfunc{slot_name});
# If there is an output parameter it must be processed so re-increment (now)
# the number of C++ arguments.
$num_cpp_args++ if($has_output_param);
# Get the desired argument list combination.
my $possible_arg_list = $$objCppfunc{possible_args_list}[$index];
# Tells if slot code should be included or not based on if a slot
# parameter is optional.
$$objCppfunc{include_slot} = 0;
# Loop through the parameters:
my $i;
my $cpp_param_max = $num_cpp_args;
# if( !($static) ) { $cpp_param_max++; }
for ($i = 0; $i < $cpp_param_max; $i++)
{
# Skip the output parameter because it is handled in output_wrap_meth().
next if($has_output_param && $i == $output_param_index);
#index of C parameter:
my $iCParam = $i;
if( !($static) ) { $iCParam++; }
# Account for a possible C++ output param in the C++ arg list.
$iCParam-- if($has_output_param && $i > $output_param_index);
my $c_param_name = @$c_param_names[$iCParam];
my $cpp_param_index = $i;
$cpp_param_index = $$c_param_name_mappings{$c_param_name} if(defined($$c_param_name_mappings{$c_param_name}));
my $cppParamType = $$cpp_param_types[$cpp_param_index];
$cppParamType =~ s/ &/&/g; #Remove space between type and &
$cppParamType =~ s/ \*/*/g; #Remove space between type and *
my $cppParamName = $$cpp_param_names[$cpp_param_index];
my $cParamType = $$c_param_types[$iCParam];
if(!($possible_arg_list =~ /\b$cpp_param_index\b/))
{
# If the C++ index is not found in the list of desired parameters, pass
# NULL to the C func unless the param is not optional (applies to a
# possibly added GError parameter).
if (($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_OPTIONAL))
{
push(@conversions, "0");
next;
}
}
if ($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_OUTPUT)
{
# Get a generic name for the C output parameter name.
my $cOutputParamName = "g_" . $$c_param_names[$iCParam];
my $cOutputParamType = $cParamType;
# Remove a possible final '*' from the output parameter type because it
# will be passed by C reference (&name).
$cOutputParamType =~ s/\*$//;
# Only initialize pointers to zero. Otherwise, use the default
# constructor of the type.
my $initialization = "";
if($cOutputParamType =~ /\*$/)
{
$initialization = " = 0";
}
else
{
$initialization = " = $cOutputParamType()";
}
push(@declarations, " $cOutputParamType $cOutputParamName$initialization;");
push(@conversions, "&" . $cOutputParamName);
push(@initializations, sprintf("_INITIALIZE(\`%s\',%s,%s,%s,%s);",
$cppParamType,
$cOutputParamType,
$cppParamName,
$cOutputParamName,
$wrap_line_number));
next;
}
# If dealing with a slot.
if ($$objCppfunc{slot_name} eq $cppParamName)
{
if ($$objCppfunc{slot_callback})
{
# The conversion for the slot is the address of the callback.
push(@conversions, "&" . $$objCppfunc{slot_callback});
}
else
{
Output::error(
"convert_args_cpp_to_c(): Missing a slot callback. " .
"Specify it with the 'slot_callback' option.\n",);
$objCppfunc->dump();
$objCDefsFunc->dump();
return ("", "", "");
}
# Get the slot type without the const and the & and store it so
# it can be passed to the m4 _*METHOD macros.
$cppParamType =~ /^const\s+(.*)&/;
$$objCppfunc{slot_type} = $1;
# Signal that the slot code should be included.
$$objCppfunc{include_slot} = 1;
next;
}
if ($cppParamType ne $cParamType) #If a type conversion is needed.
{
my $std_conversion = sprintf("_CONVERT(%s,%s,%s,%s)",
$cppParamType,
$cParamType,
$cppParamName,
$wrap_line_number);
if (($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_OPTIONAL) &&
$cppParamType =~ /^(const\s+)?(std::string|Glib::ustring)&?/)
{
push(@conversions, "$cppParamName.empty() ? 0 : " . $std_conversion);
}
else
{
push(@conversions, $std_conversion);
}
}
else
{
push(@conversions, $cppParamName);
}
}
# Append the final slot copy parameter to the C function if the method
# has a slot. The m4 macros assume that that parameter name is
# "slot_copy". The m4 macros will either copy the slot to the
# "slot_copy variable or set it to the address of the slot itself if
# the slot should not be copied.
if ($$objCppfunc{slot_name})
{
if ($$objCppfunc{include_slot})
{
push(@conversions, "slot_copy");
}
else
{
push(@conversions, "0")
}
}
return ( join(", ", @conversions), join("\n", @declarations),
join("\n ", @initializations) );
}
# procedure for generating CONVERT macros
# Ignores the first C 'self' argument.
# $string convert_args_c_to_cpp($objCDefsFunc, $objCppFunc, $wrap_line_number)
sub convert_args_c_to_cpp($$$)
{
my ($objCDefsFunc, $objCppfunc, $wrap_line_number) = @_;
my $cpp_param_names = $$objCppfunc{param_names};
my $cpp_param_types = $$objCppfunc{param_types};
my $c_param_types = $$objCDefsFunc{param_types};
my $c_param_names = $$objCDefsFunc{param_names};
# This variable stores the C++ parameter mappings from the C++
# index to the C param name if the mappings exist.
my %cpp_index_param_mappings;
# Fill the index to param names mappings from the c param names to index
# mappings variable above.
@cpp_index_param_mappings{values %{$$objCppfunc{param_mappings}}}
= keys %{$$objCppfunc{param_mappings}};
my @result;
my $num_c_args = scalar(@{$c_param_types});
# If the the function has been marked as a function that throws errors
# (Glib::Error) don't count the last GError** argument.
$num_c_args-- if($$objCDefsFunc{throw_any_errors});
my $num_cpp_args = scalar(@{$cpp_param_types});
# If the method has a slot temporarily increment the C++ arg count when
# comparing the C++ and C argument count because the C function would
# have a final 'gpointer data' parameter and the C++ method would not.
$num_cpp_args++ if ($$objCppfunc{slot_name});
if ( ($num_cpp_args + 1) != $num_c_args )
{
Output::error( "convert_args_c_to_cpp(): Incorrect number of arguments. (%d != %d)\n",
$num_cpp_args + 1,
$num_c_args);
$objCppfunc->dump();
$objCDefsFunc->dump();
return "";
}
# Re-decrement the expected C++ argument count if there is a slot.
$num_cpp_args-- if ($$objCppfunc{slot_name});
# Loop through the C++ parameters:
my $i;
my $cpp_param_max = $num_cpp_args;
for ($i = 0; $i < $cpp_param_max; $i++)
{
my $cParamName = "";
my $c_index = 0;
if (defined $cpp_index_param_mappings{$i})
{
# If a mapping exists from the current index to a C param name,
# use that C param for the conversion.
$cParamName = $cpp_index_param_mappings{$i};
# Get the C index based on the C param name.
++$c_index until $$c_param_names[$c_index] eq $cParamName;
}
else
{
# If no mapping exists, the C index is the C++ index + 1 (to skip
# The 'self' argument of the C function).
$c_index = $i + 1;
$cParamName = $$c_param_names[$c_index];
}
my $cParamType = $$c_param_types[$c_index];
my $cppParamName = $$cpp_param_names[$i];
my $cppParamType = $$cpp_param_types[$i];
$cppParamType =~ s/ &/&/g; #Remove space between type and &.
$cppParamType =~ s/ \*/*/g; #Remove space between type and *
if ($$objCppfunc{slot_name})
{
# If the current parameter is the slot parameter insert the
# derefenced name of the variable containing the slot which is
# assumed to be '*slot'. The m4 macro is responsible for ensuring
# that the variable is declared and the slot in the 'user_data' C
# param is placed in the variable.
if ($$objCppfunc{slot_name} eq $cppParamName)
{
push(@result, "*slot");
# Get the slot type without the const and the '&' and store it so
# it can be passed to the m4 macro.
$cppParamType =~ /^const\s+(.*)&/;
# If the type does not contain
# any '::' then assume that it is in the library standard namespace
# by prepending '__NAMESPACE__::' to it which the m4 macros will
# translate to the library namespace.
my $plainCppParamType = $1;
$plainCppParamType = "__NAMESPACE__::" . $plainCppParamType
if (!($plainCppParamType =~ /::/));
$$objCppfunc{slot_type} = $plainCppParamType;
# Store the name of the C data parameter so it can be passed
# to the m4 macro so it can extract the slot.
$$objCppfunc{c_data_param_name} = $$c_param_names[$num_c_args - 1];
next;
}
}
if ($cParamType ne $cppParamType) #If a type conversion is needed.
{
push(@result, sprintf("_CONVERT(%s,%s,%s,%s)\n",
$cParamType,
$cppParamType,
$cParamName,
$wrap_line_number) );
}
else
{
push(@result, $cParamName);
}
}
return join(", ",@result);
}
# generates the XXX in g_object_new(get_type(), XXX): A list of property names
# and values. Uses the cpp arg name as the property name.
#
# - The optional index specifies which arg list out of the possible combination
# of arguments based on whether any arguments are optional. index = 0 ==> all
# the arguments.
#
# - The errthrow parameter tells if the C new function has a final GError**
# parameter. That parameter is ignored since it will not form part of the
# property list.
#
# $string get_ctor_properties($objCppfunc, $objCDefsFunc, $wrap_line_number, $errthrow, $index = 0)
sub get_ctor_properties($$$$$$)
{
my ($objCppfunc, $objCDefsFunc, $wrap_line_number, $errthrow, $index) = @_;
$index = 0 unless defined $index;
my $cpp_param_names = $$objCppfunc{param_names};
my $cpp_param_types = $$objCppfunc{param_types};
my $cpp_param_flags = $$objCppfunc{param_flags};
my $c_param_name_mappings = $$objCppfunc{param_mappings};
my $c_param_types = $$objCDefsFunc{param_types};
my $c_param_names = $$objCDefsFunc{param_names};
my @result;
my $num_args = scalar(@{$c_param_types});
# If the C function has a final GError** parameter, ignore it.
$num_args-- if ($errthrow eq "errthrow");
my $num_cpp_args = scalar(@{$cpp_param_types});
if ( $num_cpp_args != $num_args )
{
Output::error("get_ctor_properties(): Incorrect number of arguments. (%d != %d)\n",
$num_cpp_args,
$num_args );
return "";
}
# Get the desired argument list combination.
my $possible_arg_list = $$objCppfunc{possible_args_list}[$index];
# Loop through the parameters:
my $i = 0;
for ($i = 0; $i < $num_args; $i++)
{
my $c_param_name = @$c_param_names[$i];
my $cpp_param_index = $i;
$cpp_param_index = $$c_param_name_mappings{$c_param_name} if(defined($$c_param_name_mappings{$c_param_name}));
my $cppParamType = $$cpp_param_types[$cpp_param_index];
$cppParamType =~ s/ &/&/g; #Remove space between type and &
$cppParamType =~ s/ \*/*/g; #Remove space between type and *
my $cppParamName = $$cpp_param_names[$cpp_param_index];
my $cParamType = $$c_param_types[$i];
# Property name:
push(@result, "\"" . $cppParamName . "\"");
if(!($possible_arg_list =~ /\b$cpp_param_index\b/))
{
# If the C++ index is not found in the list of desired parameters, pass
# NULL to the C func unless the param is not optional.
if (~($$cpp_param_flags[$cpp_param_index] & FLAG_PARAM_OPTIONAL))
{
push(@result, "0");
next;
}
}
# C property value:
if ($cppParamType ne $cParamType) #If a type conversion is needed.
{
push(@result, sprintf("_CONVERT(%s,%s,%s,%s)",
$cppParamType,
$cParamType,
$cppParamName,
$wrap_line_number) );
}
else
{
push(@result, $cppParamName);
}
}
return join(", ", @result);
}
### Convert _WRAP to a corba method
# _CORBA_METHOD(retype, method_name,args, arg_names_only) - implemented in libbonobomm.
# void output_wrap_corba_method($filename, $line_num, $objCppFunc)
sub output_wrap_corba_method($$$$)
{
my ($self, $filename, $line_num, $objCppfunc) = @_;
my $str = sprintf("_CORBA_METHOD(%s,%s,\`%s\',\`%s\')dnl\n",
$$objCppfunc{rettype},
$$objCppfunc{name},
$objCppfunc->args_types_and_names(),
$objCppfunc->args_names_only()
);
$self->append($str);
}
sub output_implements_interface($$)
{
my ($self, $interface, $ifdef) = @_;
my $str = sprintf("_IMPLEMENTS_INTERFACE_CC(%s, %s)dnl\n",
$interface,
$ifdef);
$self->append($str);
}
1; # indicate proper module load.
|