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 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
|
/* $Id: makedcls.c,v 1.15 2003/03/17 23:15:49 moniot Exp $
Routines for declaration file output
*/
/*
Copyright (c) 2001 by Robert K. Moniot.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Acknowledgement: the above permission notice is what is known
as the "MIT License."
*/
/* Originally written by Nelson H.F. Beebe before source text was
saved in the symbol table. Rewritten by R. Moniot to make use
of said text. */
/*
Shared functions defined:
make_declarations produces the declarations file
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "ftnchek.h"
#include "symtab.h"
#include "plsymtab.h"
extern int free_form; /* for choosing 'C' or '!' as comment char */
/* Declarations of local functions */
PROTO(PRIVATE char * base_filename,( char *curr_filename ));
PROTO(PRIVATE void append_char_to_fragment,( int c ));
PROTO(PRIVATE void append_string_to_fragment,( char *s ));
PROTO(PRIVATE void append_expr_text_to_fragment,( char *s ));
PROTO(PRIVATE void maybe_print_module_header,( void ));
PROTO(PRIVATE void new_fragment,( void ));
PROTO(PRIVATE void print_blanks,( int nblanks ));
PROTO(PRIVATE void print_common_decls,( Lsymtab *sym_entry ));
PROTO(PRIVATE void print_empty_comment_line,( void ));
PROTO(PRIVATE void print_equivalence_decls,( Lsymtab *sym_entry ));
PROTO(PRIVATE int count_undeclared_variables,( Lsymtab *sym_entry ));
PROTO(PRIVATE void print_list_decls,( Lsymtab *sym_list[], int n, char
*header, char *list_type_name ));
PROTO(PRIVATE int print_list_name,( char *list_type_name, char *name ));
PROTO(PRIVATE void print_declaration_class,( Lsymtab *sym_list[], int n,
const char *header ));
PROTO(PRIVATE void print_one_list_decls,( Lsymtab *sym_entry, char
*list_type_name, char **pheader, int
*pnd ));
PROTO(PRIVATE void print_parameter_statement,( Lsymtab *symt ));
PROTO(PRIVATE void print_selected_declarations,( Lsymtab *sym_list[], int n,
int the_type, const char
*the_type_name, const char * (*pheader) ));
PROTO(PRIVATE int print_typename,( int the_type, const char *the_type_name, int
the_size, Lsymtab *symt ));
PROTO(PRIVATE int make_sym_list,( Lsymtab *sym_list[], int (*selector)(Lsymtab
*sym_entry) ));
PROTO(PRIVATE int select_arguments,( Lsymtab *sym_entry ));
PROTO(PRIVATE void strip_blanks,(char *s));
#if 0 /* not currently used */
PROTO(PRIVATE int select_commons,( Lsymtab *sym_entry ));
#endif
PROTO(PRIVATE int select_externals_by_name,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_externals_by_type,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_intrinsics_by_name,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_intrinsics_by_type,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_locals,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_common_blocks,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_namelists,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_parameters,( Lsymtab *sym_entry ));
PROTO(PRIVATE int select_statement_functions,( Lsymtab *sym_entry ));
PROTO(PRIVATE int sf3_internal_name,( Lsymtab *sym_entry ));
PROTO(PRIVATE char * get_dimension_list,( Lsymtab *symt ));
PROTO(PRIVATE char * get_parameter_value,( Lsymtab *symt ));
PROTO(PRIVATE char * get_size_expression,( Lsymtab *symt ));
#if 0 /* This is how Beebe wrote it */
#define ACTUAL_SIZE(p) (((p)->size == 0) ? \
std_size[the_type] : (p)->size)
#else
/* This is what it has to be if IMPLICIT types supported */
#define ACTUAL_SIZE(p) (get_size((p),sym_type))
#endif
#define DECLARE_ONLY_UNDECLARED() (dcl_only_undeclared)
#define DECLARE_COMPACT() (dcl_compact)
#define NO_CONTINUATION_LINES() (!(dcl_use_continuations))
#define EXCL_SF3_DECLARATIONS() (dcl_excl_sftran3_internal_vars)
#define ASTERISK_COMMENT_CHAR() (dcl_asterisk_comment_character)
#define FREE_FORM() (dcl_free_form||free_form)
#define KEYWORDS_LOWERCASE() (dcl_keywords_lowercase)
#define LOWERCASE_COMMENT_CHARACTER() (dcl_lowercase_comment_character)
#define VARIABLES_AND_CONSTANTS_LOWERCASE() (dcl_vars_and_consts_lowercase)
#define ARRAY_VARS_DIMENSIONED() (!(dcl_no_array_dimensions))
#define COLUMN_WIDTH 13
#ifndef PFORT_FIRST_VARIABLE_COLUMN
#define PFORT_FIRST_VARIABLE_COLUMN 26 /* to match Extended PFORT Verifier */
#endif
PRIVATE int first_variable_column;
#define NEXT_COLUMN(column) (first_variable_column + \
(((column) - first_variable_column + \
COLUMN_WIDTH - 1) / COLUMN_WIDTH)*COLUMN_WIDTH)
#define isaletter(C) isalpha((int)(C))
/* define isidletter to allow underscore and/or dollar sign */
#define isidletter(C) (isalpha((int)(C)) || (C) == '_' || (C) == '$')
#define makelower(C) (isupper((int)(C)) ? tolower((int)(C)) : (int)(C))
#define makeupper(C) (islower((int)(C)) ? toupper((int)(C)) : (int)(C))
PRIVATE char *begin_module;
#define MAX_STMT (72 + 19*72 + 1) /* longest Fortran stmt */
PRIVATE char stmt_fragment[MAX_STMT];
PRIVATE char comment_char = 'C'; /* default value */
PRIVATE int std_size[] = /* NB: depends on type_XXX order in symtab.h */
{
0, /* unknown */
4, /* INTEGER*4 */
4, /* REAL*4 */
8, /* DOUBLE PRECISION == REAL*8 */
8, /* COMPLEX*8 */
16, /* DOUBLE COMPLEX == COMPLEX*16 */
4, /* LOGICAL*4 */
1 /* CHARACTER*1 == CHARACTER */
};
PRIVATE int
pos_fragment = 0; /* cursor in stmt_fragment buffer */
PRIVATE int
dcl_indent; /* amount to indent declarations */
PRIVATE char *
#if HAVE_STDC
base_filename(char *curr_filename)
#else /* K&R style */
base_filename(curr_filename)
char *curr_filename;
#endif /* HAVE_STDC */
{
char *path_end=(char *)NULL;
#ifdef UNIX
path_end = strrchr(curr_filename,'/');
#endif
#ifdef VMS
path_end = strrchr(curr_filename,']');
if( path_end == (char *)NULL )
path_end = strrchr(curr_filename,':'); /* for symbolic names */
#endif
#ifdef MSDOS /* look for either \ or / at end. */
path_end = strrchr(curr_filename,'\\');
if( path_end == (char *)NULL )
path_end = strrchr(curr_filename,'/');
#endif
if( path_end == (char *)NULL )
path_end = curr_filename;
else
++path_end;
return (path_end);
}
PRIVATE void
#if HAVE_STDC
append_char_to_fragment(int c)
#else /* K&R style */
append_char_to_fragment(c)
int c;
#endif /* HAVE_STDC */
{
if (pos_fragment < (MAX_STMT - 1))
stmt_fragment[pos_fragment++] = c;
}
PRIVATE void
#if HAVE_STDC
append_string_to_fragment(char *s)
#else /* K&R style */
append_string_to_fragment(s)
char *s;
#endif /* HAVE_STDC */
{
while (*s)
append_char_to_fragment(*s++);
}
/* Appends source text of an expression, up- or
down-casing the letters according to pref. */
PRIVATE void
#if HAVE_STDC
append_expr_text_to_fragment(char *s)
#else /* K&R style */
append_expr_text_to_fragment(s)
char *s;
#endif /* HAVE_STDC */
{
int quote_char, inside_quote;
inside_quote = FALSE;
for (; *s; ++s) {
if(! inside_quote) {
if(*s == '\'' || *s == '"') { /* Start of a quote */
inside_quote = TRUE;
quote_char = *s;
}
append_char_to_fragment(VARIABLES_AND_CONSTANTS_LOWERCASE()
? makelower(*s) : makeupper(*s));
}
else { /* inside quote */
if(*s == quote_char) { /* End of quote (quoted quote_char is handled
as if consecutive strings) */
inside_quote=FALSE;
}
append_char_to_fragment(*s);
}
}
}
PRIVATE char *
#if HAVE_STDC
get_dimension_list(Lsymtab *symt)
#else /* K&R style */
get_dimension_list(symt)
Lsymtab *symt;
#endif /* HAVE_STDC */
{
int n, dims;
/* Get list of array dimensions from symbol table */
new_fragment();
append_char_to_fragment('(');
dims = array_dims(symt->info.array_dim);
for (n = 0; n < dims; ++n)
{
if (n > 0)
append_char_to_fragment(',');
append_expr_text_to_fragment(symt->src.textvec[n]);
}
append_char_to_fragment(')');
append_char_to_fragment('\0');
return (&stmt_fragment[0]);
}
PRIVATE char *
#if HAVE_STDC
get_parameter_value(Lsymtab *symt)
#else /* K&R style */
get_parameter_value(symt)
Lsymtab *symt;
#endif /* HAVE_STDC */
{
/* Construct parameter list "(NAME = value)" */
new_fragment();
append_char_to_fragment('(');
append_expr_text_to_fragment(symt->name);
append_string_to_fragment(" = ");
append_expr_text_to_fragment(symt->info.param->src_text);
append_char_to_fragment(')');
append_char_to_fragment('\0');
return (&stmt_fragment[0]);
}
PRIVATE char *
#if HAVE_STDC
get_size_expression(Lsymtab *symt)
#else /* K&R style */
get_size_expression(symt)
Lsymtab *symt;
#endif /* HAVE_STDC */
{
/* Get a CHARACTER size expression from the symbol table */
new_fragment();
append_char_to_fragment('*');
append_expr_text_to_fragment(get_size_text(symt,0));
append_char_to_fragment('\0');
return (&stmt_fragment[0]);
}
void
#if HAVE_STDC
make_declarations(Lsymtab **sym_list, char *mod_name)
#else /* K&R style */
make_declarations(sym_list,mod_name)
Lsymtab *sym_list[];
char *mod_name;
#endif /* HAVE_STDC */
{
const char *header;
char begin[72+1+72+1+2+1];
char *base_curr_filename; /* basename of current input file */
int len_base_curr_filename;
if ( ! ANY_DCL_DECLARATIONS() )
return;
base_curr_filename = base_filename(current_filename);
len_base_curr_filename = strlen(base_curr_filename);
/* Establish indentation and comment character
for free form or fixed form.
*/
dcl_indent = 6;
first_variable_column = PFORT_FIRST_VARIABLE_COLUMN;
if (FREE_FORM()) {
dcl_indent = DCL_FREEFORM_INDENT;
first_variable_column = PFORT_FIRST_VARIABLE_COLUMN-(6-dcl_indent);
comment_char = '!';
}
else if (LOWERCASE_COMMENT_CHARACTER())
comment_char = 'c';
else if (ASTERISK_COMMENT_CHAR())
comment_char = '*';
else
comment_char = 'C';
/* In the event there are no declarations to be output, we want
the declaration file to be empty, because that reduces the
number of files that the user has to deal with. In fact, if it
IS empty, it will be deleted on close. Instead of printing the
module header comment here, we point a global pointer at it,
and then in the print_xxx() functions, print the header before
the first declaration that is output.
We also need to take care not be overwrite the begin[] array,
which could happen if the module name or file name are
exceptionally long. We therefore take at most 20 characters
from the start of the module name, and at most 25 (so the
total length of 72 is not surpassed) from the END of the base
of the filename, discarding the directory path prefix. */
(void)sprintf(begin,
"%c====>Begin Module %-20.20s File %-25.25s\n%c---->Makedcls Options: %-48s\n%c\n",
comment_char,
mod_name,
(len_base_curr_filename > 25) ?
(base_curr_filename + len_base_curr_filename - 25) :
base_curr_filename,
comment_char,
EXCL_SF3_DECLARATIONS()?
(DECLARE_ONLY_UNDECLARED() ?
"Undeclared variables except SFTRAN3 internals" :
"All variables except SFTRAN3 internals") :
(DECLARE_ONLY_UNDECLARED() ?
"Undeclared variables" :
"All variables"),
comment_char);
begin_module = &begin[0];
print_selected_declarations(sym_list,
make_sym_list(sym_list,
select_intrinsics_by_name),
type_ERROR, "INTRINSIC",
(header = "Intrinsic functions", &header));
print_declaration_class(sym_list,
make_sym_list(sym_list,select_intrinsics_by_type),
"Built-in functions");
print_selected_declarations(sym_list,
make_sym_list(sym_list,
select_externals_by_name),
type_ERROR, "EXTERNAL",
(header = "External functions", &header));
print_declaration_class(sym_list,
make_sym_list(sym_list,select_externals_by_type),
(char*)NULL);
print_declaration_class(sym_list,
make_sym_list(sym_list,select_statement_functions),
"Statement functions");
print_declaration_class(sym_list,
make_sym_list(sym_list,select_parameters),
"Parameter variables");
print_declaration_class(sym_list,
make_sym_list(sym_list,select_arguments),
"Argument variables");
print_declaration_class(sym_list,
make_sym_list(sym_list,select_locals),
"Local variables");
print_list_decls(sym_list,
make_sym_list(sym_list,select_namelists),
"Namelists","NAMELIST");
/* Common block declarations must be last,
for dcl2inc to work correctly.
*/
print_list_decls(sym_list,
make_sym_list(sym_list,select_common_blocks),
"Common blocks","COMMON");
if (begin_module == (char*)NULL) /* then need a trailer comment */
(void)fprintf(dcl_fd,
"%c====>End Module %-20.20s File %-25.25s\n",
comment_char,
mod_name,
(len_base_curr_filename > 25) ?
(base_curr_filename + len_base_curr_filename - 25) :
base_curr_filename);
}
PRIVATE void
maybe_print_module_header(VOID)
{
if (begin_module != (char*)NULL)
{ /* print module header comment only once */
(void)fputs(begin_module, dcl_fd);
begin_module = (char*)NULL;
}
}
PRIVATE void
new_fragment(VOID)
{
pos_fragment = 0;
}
PRIVATE void
#if HAVE_STDC
print_blanks(int nblanks)
#else /* K&R style */
print_blanks(nblanks)
int nblanks;
#endif /* HAVE_STDC */
{
for ( ; nblanks > 0; --nblanks)
(void)putc(' ',dcl_fd);
}
/* Routine to print namelist and
common declarations. */
PRIVATE void
#if HAVE_STDC
print_common_decls(Lsymtab *sym_entry)
/* COMMON block symbol table entry */
#else /* K&R style */
print_common_decls(sym_entry)
Lsymtab *sym_entry; /* COMMON block symbol table entry */
#endif /* HAVE_STDC */
{
int h;
int n;
Token *t;
#ifdef DYNAMIC_TABLES /* tables will be mallocked at runtime */
static Lsymtab **sym_list=(Lsymtab **)NULL;
if(sym_list == (Lsymtab **)NULL) { /* Initialize if not done before */
if( (sym_list=(Lsymtab **)calloc(LOCSYMTABSZ,sizeof(Lsymtab *)))
== (Lsymtab **)NULL) {
oops_message(OOPS_FATAL,NO_LINE_NUM,NO_COL_NUM,
"Cannot malloc space for local symbol list");
}
}
#else
Lsymtab *sym_list[LOCSYMTABSZ]; /* temp. list of symtab entries to print */
#endif
for (n = 0, t = sym_entry->src.toklist->tokenlist;
t != NULL;
t = t->next_token)
{
h = t->value.integer;
sym_list[n++] = hashtab[h].loc_symtab;
}
if (n > 0)
{
sort_lsymbols(sym_list,n);
print_declaration_class(sym_list, n, "Common variables");
}
}
PRIVATE void
print_empty_comment_line(VOID)
{
(void)putc(comment_char,dcl_fd);
(void)putc('\n',dcl_fd);
}
PRIVATE void
#if HAVE_STDC
print_equivalence_decls(Lsymtab *sym_entry)
/* COMMON block symbol table entry */
#else /* K&R style */
print_equivalence_decls(sym_entry)
Lsymtab *sym_entry; /* COMMON block symbol table entry */
#endif /* HAVE_STDC */
{
int h;
int n;
Lsymtab *s;
Token *t;
#ifdef DYNAMIC_TABLES /* tables will be mallocked at runtime */
static Lsymtab **sym_list=(Lsymtab **)NULL;
if(sym_list == (Lsymtab **)NULL) { /* Initialize if not done before */
if( (sym_list=(Lsymtab **)calloc(LOCSYMTABSZ,sizeof(Lsymtab *)))
== (Lsymtab **)NULL) {
oops_message(OOPS_FATAL,NO_LINE_NUM,NO_COL_NUM,
"Cannot malloc space for local symbol list");
}
}
#else
Lsymtab *sym_list[LOCSYMTABSZ]; /* temp. list of symtab entries to print */
#endif
for (n = 0, t = sym_entry->src.toklist->tokenlist;
t != NULL;
t = t->next_token)
{
h = t->value.integer;
for (s = hashtab[h].loc_symtab, s = s->equiv_link;
(s != NULL) && (s != hashtab[h].loc_symtab);
s = s->equiv_link)
sym_list[n++] = s;
}
if (n > 0)
{
sort_lsymbols(sym_list,n);
print_declaration_class(sym_list, n,
"Equivalenced common variables");
}
}
PRIVATE int
#if HAVE_STDC
count_undeclared_variables(Lsymtab *sym_entry)
#else /* K&R style */
count_undeclared_variables(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
int count, h;
Token *t;
Lsymtab *symt;
for (count = 0, t = sym_entry->src.toklist->tokenlist;
t != NULL;
t = t->next_token)
{ /* Loop over members */
h = t->value.integer;
symt = hashtab[h].loc_symtab;
if (datatype_of(symt->type) == type_UNDECL)
count++;
}
return (count);
}
PRIVATE void
#if HAVE_STDC
print_list_decls(Lsymtab **sym_list, int n, char *header, char *list_type_name)
#else /* K&R style */
print_list_decls(sym_list, n, header, list_type_name)
Lsymtab *sym_list[];
int n;
char *header;
char *list_type_name;
#endif /* HAVE_STDC */
{
int i, nd;
if (DECLARE_ONLY_UNDECLARED() &&
(strcmp(list_type_name,"NAMELIST") == 0)) /* These lists are always declared */
return;
nd = 0;
for (i=0; i<n; i++)
{ /* Loop over COMMON or NAMELIST lists */
if (sym_list[i]->src.toklist != NULL)
{
if (strcmp(list_type_name,"COMMON") == 0)
{ /* then COMMON list */
if (!DECLARE_ONLY_UNDECLARED() ||
(DECLARE_ONLY_UNDECLARED() &&
(count_undeclared_variables(sym_list[i]) > 0)))
{
print_common_decls(sym_list[i]);
if (!DECLARE_ONLY_UNDECLARED())
print_one_list_decls(sym_list[i], list_type_name,
&header, &nd);
print_equivalence_decls(sym_list[i]);
}
}
else /* must be NAMELIST list */
print_one_list_decls(sym_list[i], list_type_name, &header, &nd);
}
}
if ((nd > 0) && (strcmp(list_type_name,"COMMON") != 0))
print_empty_comment_line();
}
/* routine to print COMMON or NAMELIST
name between slashes. */
PRIVATE int
#if HAVE_STDC
print_list_name(char *list_type_name, char *name)
#else /* K&R style */
print_list_name(list_type_name,name)
char *list_type_name;
char *name;
#endif /* HAVE_STDC */
{
int column, len;
char *p;
maybe_print_module_header();
/* Compact mode: COMMON /blknam/
Padded mode: COMMON / blknam /
*/
print_blanks(dcl_indent);
column = dcl_indent;
for (p = list_type_name; *p; ++p, ++column)
(void)putc(KEYWORDS_LOWERCASE() ? makelower(*p) : makeupper(*p),
dcl_fd);
print_blanks(1);
column++;
(void)putc('/',dcl_fd);
column++;
if (!DECLARE_COMPACT())
{
print_blanks(1);
column++;
}
len = 0;
if (strcmp(name,blank_com_name) != 0) {
for (p=name; *p; ++p, ++len)
(void)putc(VARIABLES_AND_CONSTANTS_LOWERCASE() ?
makelower(*p) : makeupper(*p),dcl_fd);
}
column += len;
if (!DECLARE_COMPACT())
{
if (len <= 6) /* Max standard length */
{
print_blanks(7-len); /* Print padding */
column += 7-len;
}
}
(void)putc('/',dcl_fd);
column++;
if (DECLARE_COMPACT())
{
print_blanks(1);
column++;
}
else if (column < first_variable_column)
{
print_blanks(first_variable_column-column);
column = first_variable_column;
}
else if (column == first_variable_column)
{
print_blanks(1);
column++;
print_blanks(NEXT_COLUMN(column)-column);
column = NEXT_COLUMN(column);
}
else
{
print_blanks(NEXT_COLUMN(column)-column);
column = NEXT_COLUMN(column);
}
return column;
}
PRIVATE void
#if HAVE_STDC
print_declaration_class(Lsymtab **sym_list, int n, const char *header)
#else /* K&R style */
print_declaration_class(sym_list, n, header)
Lsymtab *sym_list[];
int n;
char *header;
#endif /* HAVE_STDC */
{
unsigned t;
static int types_table[] = /* table defining output declaration order */
{ /* (alphabetical by type name) */
type_STRING,
type_COMPLEX,
type_DCOMPLEX,
type_DP,
type_INTEGER,
type_LOGICAL,
type_REAL,
};
if (n > 0)
{
for (t = 0; t < sizeof(types_table)/sizeof(types_table[0]); ++t)
print_selected_declarations(sym_list, n, types_table[t],
(char*)NULL, &header);
}
}
PRIVATE void
#if HAVE_STDC
print_one_list_decls(Lsymtab *sym_entry, char *list_type_name, char **pheader, int *pnd)
#else /* K&R style */
print_one_list_decls(sym_entry, list_type_name, pheader, pnd)
Lsymtab *sym_entry;
char *list_type_name;
char **pheader;
int *pnd;
#endif /* HAVE_STDC */
{
int column, need, next_column, nv;
int ncontin;
int h;
Token *t;
Lsymtab *symt;
char *p;
column = 0;
ncontin = 0; /* count of continuation lines */
nv = 0; /* count of variables in statement */
for(t = sym_entry->src.toklist->tokenlist;
t != NULL;
t = t->next_token)
{ /* Loop over members */
h = t->value.integer;
symt = hashtab[h].loc_symtab;
if (column == 0) /* at beginning of line, so */
{ /* we need a type name */
maybe_print_module_header();
if ((*pheader != (char*)NULL) &&
(strcmp(list_type_name,"COMMON") != 0))
{ /* print header only once */
(void)fprintf(dcl_fd,"%c %s\n", comment_char,*pheader);
print_empty_comment_line();
*pheader = (char*)NULL; /* so we don't print it again */
}
column = print_list_name(list_type_name,sym_entry->name);
nv = 0; /* no variables yet in statement */
ncontin = 0;
++(*pnd); /* count declarations produced */
}
if (DECLARE_COMPACT())
next_column = (nv==0?column:column + 2);
else
next_column = NEXT_COLUMN(nv==0?column:column + 2);
need = (int)strlen(symt->name);
if ((next_column + need) > 72) /* then must start new line */
{
if (nv>0 && (strcmp(list_type_name,"COMMON") == 0) &&
(NO_CONTINUATION_LINES() || ncontin == (FREE_FORM()?39:19)))
{
(void)putc('\n',dcl_fd);
column = print_list_name(list_type_name,sym_entry->name);
nv = 0; /* no variables yet in statement */
ncontin = 0;
}
else
{
if( FREE_FORM() ) { /* do a free-form continuation */
print_blanks(next_column-column);
(void)fputs("&\n",dcl_fd);
print_blanks(dcl_indent);
column = dcl_indent;
}
else { /* do a fixed-form continuation */
(void)putc('\n',dcl_fd);
print_blanks(5);
(void)putc('x',dcl_fd);
column = 6;
}
if (DECLARE_COMPACT())
next_column = (nv==0?column:column + 2);
else
next_column = NEXT_COLUMN(nv==0?column:column + 2);
++ncontin;
}
}
if (nv > 0) /* multiple variables */
{
(void)fputs(", ",dcl_fd);
print_blanks(next_column - column - 2);
column = next_column;
}
for (p = symt->name; *p; ++p)
(void)putc(VARIABLES_AND_CONSTANTS_LOWERCASE() ?
makelower(*p) : makeupper(*p),dcl_fd);
column += need;
nv++; /* count variables */
}
if ((nv > 0) && (strcmp(list_type_name,"COMMON") == 0))
{
if (column > 0)
(void)putc('\n',dcl_fd);
print_empty_comment_line();
column = 0;
}
if (column > 0)
(void)putc('\n',dcl_fd);
}
PRIVATE void
#if HAVE_STDC
print_parameter_statement(Lsymtab *symt)
#else /* K&R style */
print_parameter_statement(symt)
Lsymtab *symt;
#endif /* HAVE_STDC */
{
int column;
int need;
int i;
column = print_typename(type_ERROR,"PARAMETER",0,symt);
need = strlen(get_parameter_value(symt));
if ((column + need) > 72) /* then too long to fit on current line */
{
if( FREE_FORM() ) {
(void)fputs(" &\n",dcl_fd);
print_blanks(dcl_indent);
column = dcl_indent;
}
else {
(void)fputs("\n x",dcl_fd);
column = 6;
}
if ((column + need) > 72)
{ /* long parameter setting requires line break */
for (i = 0; stmt_fragment[i]; ++i)
{
if (column == 72)
{
if( FREE_FORM() ) {
(void)fputs("&\n",dcl_fd);
print_blanks(dcl_indent);
(void)putc('&',dcl_fd);
column = dcl_indent+1;
}
else {
(void)fputs("\n x",dcl_fd);
column = 6;
}
}
(void)putc((int)stmt_fragment[i],dcl_fd);
column++;
}
}
else
(void)fputs(stmt_fragment,dcl_fd);
}
else /* fits on current line */
(void)fputs(stmt_fragment,dcl_fd);
(void)putc('\n',dcl_fd);
}
PRIVATE void
#if HAVE_STDC
print_selected_declarations(Lsymtab **sym_list, int n, int the_type,
const char *the_type_name,
const char * (*pheader)) /* **pheader is const, *pheader is not */
#else /* K&R style */
print_selected_declarations(sym_list, n, the_type, the_type_name, pheader)
Lsymtab *sym_list[];
int n;
int the_type;
char *the_type_name;
char **pheader;
#endif /* HAVE_STDC */
{
int column, i, last_size, need, next_column, nt, nv, ncontin,
raw_type, sym_type, sym_size;
char *p;
column = 0;
last_size = 0;
nt = 0; /* count of type declaration stmts */
nv = 0; /* count of variables in statement */
for (i = 0; i < n; ++i)
{ /* loop over variables */
raw_type = datatype_of(sym_list[i]->type);
if (DECLARE_ONLY_UNDECLARED())
{
if (raw_type != type_UNDECL)
continue; /* want declarations only for undeclared vars */
if (sym_list[i]->external) /* and not for explicit EXTERNAL */
continue;
if (sym_list[i]->intrinsic) /* and not for explicit INTRINSIC */
continue;
}
sym_type = (raw_type == type_UNDECL) ?
get_type(sym_list[i]) : datatype_of(sym_list[i]->type);
if ((the_type != type_ERROR) && (sym_type != the_type))
continue;
sym_size = ACTUAL_SIZE(sym_list[i]);
if ((nv > 0) && (sym_size != last_size))
{ /* have new length modifier, so must start new declaration */
(void)putc('\n',dcl_fd);
nt++; /* count type declaration statements */
column = 0;
ncontin = 0;
nv = 0;
}
if (column == 0) /* at beginning of line, so */
{ /* we need a type name */
maybe_print_module_header();
if (*pheader != (char*)NULL)
{ /* print header only once */
(void)fprintf(dcl_fd,"%c %s\n",comment_char,*pheader);
print_empty_comment_line();
*pheader = (char*)NULL; /* so we don't print it again */
}
column = print_typename(the_type,the_type_name, sym_size,
sym_list[i]);
last_size = sym_size;
nv = 0; /* no variables yet in statement */
ncontin = 0;
}
if (DECLARE_COMPACT())
next_column = (nv==0?column:column + 2);
else
next_column = NEXT_COLUMN(nv==0?column:column + 2);
need = (int)strlen(sym_list[i]->name);
if (sym_list[i]->array_var /* leave space for "(...)" */
&& ARRAY_VARS_DIMENSIONED())
need += strlen(get_dimension_list(sym_list[i]));
if ((next_column + need) > 72) /* then must start new declaration */
{
nt++; /* count type declaration statements */
if (nv>0 && (NO_CONTINUATION_LINES() || ncontin == 19))
{
(void)putc('\n',dcl_fd);
column = print_typename(the_type,the_type_name, sym_size,
sym_list[i]);
ncontin = 0;
nv = 0; /* no variables yet in statement */
}
else
{
if( FREE_FORM() ) { /* do a free-form continuation */
print_blanks(next_column-column);
(void)fputs("&\n",dcl_fd);
print_blanks(dcl_indent);
column = dcl_indent;
}
else { /* do a fixed-form continuation */
(void)putc('\n',dcl_fd);
print_blanks(5);
(void)putc('x',dcl_fd);
column = 6;
}
if (DECLARE_COMPACT())
next_column = (nv==0?column:column + 2);
else
next_column = NEXT_COLUMN(nv==0?column:column + 2);
++ncontin;
}
last_size = sym_size;
}
if (nv > 0) /* multiple variables */
{
(void)fputs(", ",dcl_fd);
print_blanks(next_column - column - 2);
column = next_column;
}
for (p = sym_list[i]->name; *p; ++p)
(void)putc(VARIABLES_AND_CONSTANTS_LOWERCASE() ?
makelower(*p) : makeupper(*p),dcl_fd);
if (sym_list[i]->array_var
&& ARRAY_VARS_DIMENSIONED())
(void)fputs(stmt_fragment,dcl_fd);
column += need;
nv++; /* count variables */
if (sym_list[i]->parameter)
{
(void)putc('\n',dcl_fd);
print_parameter_statement(sym_list[i]);
column = 0;
nt++;
nv = 0;
}
}
if (column > 0)
{
(void)putc('\n',dcl_fd);
nt++; /* count type declaration statements */
}
if (nt > 0)
print_empty_comment_line();
}
PRIVATE int
#if HAVE_STDC
print_typename(int the_type, const char *the_type_name, int the_size, Lsymtab *symt)
/* type_ERROR if typename non-NULL */
/* non-NULL overrides type_table[] use */
#else /* K&R style */
print_typename(the_type,the_type_name,the_size,symt)
int the_type; /* type_ERROR if the_type_name non-NULL */
char *the_type_name; /* non-NULL overrides type_table[] use */
int the_size;
Lsymtab *symt;
#endif /* HAVE_STDC */
{ /* return value is last column printed */
int column;
char digits[sizeof("*18446744073709551616")]; /* big enough for 2^64 */
const char *p;
char *size_expression;
maybe_print_module_header();
print_blanks(dcl_indent);
column = dcl_indent;
for (p = (the_type_name == (char*)NULL) ? type_table[the_type] : the_type_name;
*p; ++p, ++column)
(void)putc(KEYWORDS_LOWERCASE() ? makelower(*p) : makeupper(*p),
dcl_fd);
if (symt != NULL) {
if (((symt->size_is_adjustable && (the_type == type_STRING))) ||
(the_size == size_ADJUSTABLE)) /* happens only for CHARACTER*(*) */
{
/* size_is_adjustable overrides the_size because def_parameter() */
/* in symtab.c replaced size_ADJUSTABLE with actual size. */
(void)fputs("*(*)",dcl_fd);
column += 4;
}
else if (symt->size_is_expression && (the_type == type_STRING))
{
size_expression = get_size_expression(symt);
(void)fputs(size_expression,dcl_fd);
column += strlen(size_expression);
}
else if ((the_size > 0) &&
(the_type != type_ERROR) &&
(the_size != std_size[the_type]))
{ /* supply length modifier for non-standard type sizes */
(void)sprintf(digits,"*%d",the_size);
(void)fputs(digits,dcl_fd);
column += strlen(digits);
}
}
if (DECLARE_COMPACT())
{
print_blanks(1);
column++;
}
else if (column < first_variable_column)
{
print_blanks(first_variable_column-column);
column = first_variable_column;
}
else if (column == first_variable_column)
{
print_blanks(1);
column++;
print_blanks(NEXT_COLUMN(column)-column);
column = NEXT_COLUMN(column);
}
else
{
print_blanks(NEXT_COLUMN(column)-column);
column = NEXT_COLUMN(column);
}
return (column);
}
PRIVATE int
#if HAVE_STDC
select_arguments(Lsymtab *sym_entry)
#else /* K&R style */
select_arguments(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is a module argument) */
if (sym_entry->declared_external ||
sym_entry->invoked_as_func)
return (0);
else if (sym_entry->argument)
return (1);
else
return (0);
}
#if 0 /* this function not currently used */
PRIVATE int
#if HAVE_STDC
select_commons(Lsymtab *sym_entry)
#else /* K&R style */
select_commons(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is in a COMMON block) */
if (sym_entry->common_var)
return (1);
else
return (0);
}
#endif /*0*/
PRIVATE int
#if HAVE_STDC
select_externals_by_name(Lsymtab *sym_entry)
#else /* K&R style */
select_externals_by_name(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is external and must appear in EXTERNAL declaration) */
if (sym_entry->declared_intrinsic) /* must appear first, because symbols */
return (0); /* can be both declared_intrinsic and declared_external*/
/* ??? is this a bug in ftnchek 2.7 ??? */
else if (storage_class_of(sym_entry->type) == class_STMT_FUNCTION)
return (0);
else if (sym_entry->declared_external)
return (1);
else if (sym_entry->declared_intrinsic || sym_entry->intrinsic)
return (0);
else if (sym_entry->invoked_as_func)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
select_externals_by_type(Lsymtab *sym_entry)
#else /* K&R style */
select_externals_by_type(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is external and must appear in a type declaration) */
if (storage_class_of(sym_entry->type) == class_STMT_FUNCTION)
return (0);
else if (sym_entry->declared_external)
return (1);
else if (sym_entry->declared_intrinsic)
return (0);
else if (sym_entry->intrinsic)
{
if (datatype_of(sym_entry->type) == type_UNDECL)
{ /* user provided no type declaration */
if ((sym_entry->info.intrins_info)->result_type == type_GENERIC)
return (0); /* generics CANNOT have explicit type */
else
return (1); /* not generic, so has explicit type */
}
else /* user supplied an explicit type */
return (1);
}
else if (sym_entry->invoked_as_func)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
select_intrinsics_by_name(Lsymtab *sym_entry)
#else /* K&R style */
select_intrinsics_by_name(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is intrinsic and must appear in INTRINSIC declaration) */
if (sym_entry->declared_intrinsic)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
select_intrinsics_by_type(Lsymtab *sym_entry)
#else /* K&R style */
select_intrinsics_by_type(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is intrinsic and must appear in a type declaration) */
if (sym_entry->intrinsic &&
((sym_entry->info.intrins_info)->result_type == type_GENERIC))
return (0);
else
return (select_intrinsics_by_name(sym_entry));
}
PRIVATE int
#if HAVE_STDC
select_locals(Lsymtab *sym_entry)
#else /* K&R style */
select_locals(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is a local variable) */
if (EXCL_SF3_DECLARATIONS() && sf3_internal_name(sym_entry))
return (0);
else if (sym_entry->argument ||
sym_entry->common_var ||
sym_entry->declared_external ||
sym_entry->declared_intrinsic ||
sym_entry->entry_point ||
sym_entry->external ||
sym_entry->intrinsic ||
sym_entry->invoked_as_func ||
sym_entry->parameter)
return (0);
else
return (1);
}
PRIVATE int
#if HAVE_STDC
select_common_blocks(Lsymtab *sym_entry)
#else /* K&R style */
select_common_blocks(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is a COMMON block name) */
if (storage_class_of(sym_entry->type) == class_COMMON_BLOCK)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
select_namelists(Lsymtab *sym_entry)
#else /* K&R style */
select_namelists(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is a NAMELIST name) */
if (storage_class_of(sym_entry->type) == class_NAMELIST)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
select_parameters(Lsymtab *sym_entry)
#else /* K&R style */
select_parameters(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
/* return (symbol is a PARAMETER name) */
if (sym_entry->parameter)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
select_statement_functions(Lsymtab *sym_entry)
#else /* K&R style */
select_statement_functions(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{
if (storage_class_of(sym_entry->type) == class_STMT_FUNCTION)
return (1);
else
return (0);
}
PRIVATE int
#if HAVE_STDC
sf3_internal_name(Lsymtab *sym_entry)
#else /* K&R style */
sf3_internal_name(sym_entry)
Lsymtab *sym_entry;
#endif /* HAVE_STDC */
{ /* Return (symbol is an SFTRAN3 internal name). */
char *p = sym_entry->name;
/* The SFTRAN3 preprocessor uses internal names of the form NPRddd,
NXdddd, N2dddd, and N3dddd, where d is a decimal digit. */
if ((p[0] != 'N') || (strlen(p) != 6))
return (0);
switch (p[1])
{
case 'P':
if ((p[2] == 'R') && isdigit(p[3]) && isdigit(p[4]) && isdigit(p[5]))
return (1);
else
return (0);
case 'X': /* fall through */
case '2': /* fall through */
case '3':
if (isdigit(p[2]) && isdigit(p[3]) && isdigit(p[4]) && isdigit(p[5]))
return (1);
else
return (0);
default:
return (0);
}
}
PRIVATE int
#if HAVE_STDC
make_sym_list(Lsymtab **sym_list, int (*selector) (Lsymtab *))
#else /* K&R style */
make_sym_list(sym_list,selector)
Lsymtab *sym_list[];
PROTO(int (*selector),( Lsymtab *sym_entry ));
#endif /* HAVE_STDC */
{
int i;
int n;
for (i = 0, n = 0; i < loc_symtab_top; ++i)
{
if (selector(&loc_symtab[i]))
sym_list[n++] = &loc_symtab[i];
}
if (n > 0)
{
if (selector == select_parameters) {
/* Free form is not blank-insensitive, so go
thru parameter declarations and remove any
blanks from within numbers.
*/
if( FREE_FORM() ) {
for(i=0; i < n; i++) {
if( is_numeric_type(get_type(sym_list[i])) ) {
strip_blanks(sym_list[i]->info.param->src_text);
}
}
}
/* original PARAMETER statement order must be preserved so that
the expressions do not refer to as-yet-undefined parameter names */
sort_parameters(sym_list,n);
}
else
sort_lsymbols(sym_list,n);
}
return (n);
}
/* Routine to remove whitespace from a string */
PRIVATE void
strip_blanks(char *s)
{
char *t;
for( t=s; *s != '\0'; s++ ) {
if( !isspace(*s) )
*t++ = *s;
}
*t = '\0';
}
|