00001
00002 # define TRACE
00003 # undef TRACE
00004 # define DEBUG
00005 # undef DEBUG
00006 # define TRACE2
00007 # undef TRACE2
00008 # include <stdio.h>
00009 # include "parm.h"
00010 # include "arith.h"
00011
00012 # include "stree/ststructs.mh"
00013 # ifdef DEBUG
00014 # include "stree/is_ptr.h"
00015 # endif
00016
00017 # include "sigs.h"
00018
00019 # include "stree/Array.h"
00020
00021
00022 # include "pass1/stt/sttdefs.h"
00023
00024 extern FILE * unparse_file;
00025
00026 extern boolean Gflag;
00027
00028 # define UNDEFNAME ((sttrelptr) 0)
00029
00030 extern int yynerrs;
00031
00032 # define ERR_NODE_DEFINED
00033 extern NODE * err_node;
00034
00035 extern char * err_msg;
00036
00037 extern NODE * curr_tsig;
00038
00039
00040 NODE * declerr;
00041
00042 NODE * substerr;
00043
00044
00045
00046
00047
00048
00049 extern NODE * failed_asig;
00050 extern NODE * failed_psig;
00051 extern NODE * failed_comp;
00052
00053 extern struct cn * dontsubst;
00054
00055
00056
00057 extern int comp_index;
00058
00059 # ifdef VAX
00060 int nargs();
00061 # endif
00062
00063 boolean may_fail;
00064
00065
00066 NODE * findidsig(p)
00067 register NODE * p;
00068 {
00069 NODE * q;
00070
00071 if(p -> id_str_table_index == -1) {
00072
00073 chgsig(p, curr_tsig);
00074 p -> sig_done = SIG_UNKNOWN;
00075
00076 return(SUCCESS);
00077 }
00078 # ifdef TRACE
00079 printf("Finding signature of %s, may_fail = %d\n",
00080 getname(p -> id_str_table_index), may_fail);
00081 # endif
00082
00083
00084 if (failed_asig != NIL) {
00085 vfree(unlock(failed_asig));
00086 }
00087 failed_asig = NIL;
00088 if ((q = finddecl(p)) != SUCCESS) {
00089 p -> sig_done = SIG_UNKNOWN;
00090 # ifdef TRACE
00091 printf("Can't find declaration for\n");
00092 unparse_file = stdout;
00093 unparse(p);
00094 printf("\n");
00095 # endif
00096 return(q);
00097 }
00098
00099 if (p -> sig_done == SIG_DONE) {
00100 return(SUCCESS);
00101 }
00102 if (!(p -> id_def_found)) {
00103 if(may_fail) {
00104
00105
00106 p -> sig_done = SIG_UNKNOWN;
00107 # ifdef TRACE
00108 printf("Didn't find:\n");
00109 unparse_file = stdout;
00110 unparse(p);
00111 printf("\n");
00112 # endif
00113 return(p);
00114 } else {
00115 errmsg1(
00116 p,
00117 "No declaration with appropriate signature for %s",
00118 getname(p -> id_str_table_index)
00119 );
00120 if (p -> id_appl != NIL) {
00121 unparse_file = stderr;
00122 maplist(s, p -> id_appl -> ap_args, {
00123 fprintf(stderr, "\tArgument: ");
00124 unparse(s);
00125 fprintf(stderr, "\n\tArgument signature: ");
00126 unparse(s -> signature);
00127 fprintf(stderr, "\n");
00128 });
00129 }
00130 if (failed_asig != NIL) {
00131 fprintf(stderr, "\tAttempted to match:\n\t");
00132 unparse_file = stderr;
00133 unparse(failed_asig);
00134 fprintf(stderr, "\n\tagainst:\n\t");
00135 unparse(failed_psig);
00136 fprintf(stderr, "\n");
00137 if (failed_comp != NIL) {
00138 if(failed_comp -> kind == TSCOMPONENT) {
00139 fprintf(stderr,
00140 "\t\tOffending parameter component:\n\t\t");
00141 unparse(failed_comp -> tsc_id);
00142 fprintf(stderr, ":");
00143 unparse(failed_comp -> tsc_signature);
00144 fprintf(stderr, "\n");
00145 } else {
00146 fprintf(stderr, "\t\tMissing constant\n");
00147 }
00148 }
00149 }
00150 if (p -> signature != NIL) {
00151 unparse_file = stderr;
00152 fprintf(stderr, "\tSpecified signature: ");
00153 unparse(p -> signature);
00154 fprintf(stderr, "\n");
00155 }
00156 p -> signature = ERR_SIG;
00157 p -> sig_done = SIG_DONE;
00158 return(SUCCESS);
00159
00160 }
00161 }
00162 if (p -> sel_type != NIL) {
00163 NODE * tsig;
00164 boolean sel_index_correct = TRUE;
00165
00166
00167 if( (q = findsig(p -> sel_type,FALSE)) != SUCCESS ) {
00168 NODE * curr_type = p -> sel_type;
00169 NODE * curr_decl;
00170
00171 # ifdef TRACE
00172 printf("Didn't find sel type signature for %X\n", p);
00173 # endif
00174 sel_index_correct = FALSE;
00175 if (!trivial(p -> sel_type)) {
00176 dontsubst = cn_cons(p -> sel_type, dontsubst);
00177 }
00178
00179
00180
00181
00182
00183
00184
00185 for(;;) {
00186 # ifdef TRACE
00187 printf("node = %X, curr_type = %X\n",p, curr_type);
00188 unparse_file = stdout;
00189 unparse(curr_type);
00190 printf("\n");
00191 # endif
00192 switch(curr_type -> kind) {
00193 case LETTERID:
00194 case OPRID:
00195 if (curr_type -> id_str_table_index == -1) {
00196 tsig = curr_tsig;
00197 goto found_tsig;
00198 }
00199
00200 if (finddecl(curr_type) != SUCCESS
00201 || !(curr_type -> id_def_found)) {
00202 p -> sig_done = SIG_UNKNOWN;
00203 return(q);
00204 }
00205 if (curr_type -> sel_type != NIL) {
00206 if((q = findsig(curr_type, FALSE)) != SUCCESS) {
00207 p -> sig_done = SIG_UNKNOWN;
00208 return(q);
00209 }
00210 tsig = curr_type -> signature;
00211 goto found_tsig;
00212 }
00213 curr_decl = curr_type -> id_last_definition;
00214 switch (curr_decl -> kind) {
00215 case DECLARATION:
00216 if (curr_decl -> decl_signature != NIL) {
00217 tsig = curr_decl -> decl_signature;
00218 goto found_tsig;
00219 }
00220 curr_type = curr_decl -> decl_denotation;
00221 break;
00222 case PARAMETER:
00223 tsig = curr_decl -> par_signature;
00224 goto found_tsig;
00225 case TYPESIGNATURE:
00226 tsig = curr_decl;
00227 goto found_tsig;
00228 default:
00229 curr_type = curr_decl;
00230 }
00231 break;
00232 case MODPRIMARY:
00233 {
00234 NODE * tm = curr_type -> mp_type_modifier;
00235 switch (tm -> kind) {
00236 case EXPORTLIST:
00237 case HIDELIST:
00238 curr_type = curr_type -> mp_primary;
00239 break;
00240 case WITHLIST:
00241 begin_maplist(s, tm -> wl_component_list) {
00242 if (s -> decl_id -> id_str_table_index
00243 == p -> id_str_table_index) {
00244 NODE * prim = curr_type -> mp_primary;
00245 NODE * r = findsig(prim, FALSE);
00246
00247 # ifdef TRACE
00248 printf("Found with list component\n");
00249 # endif
00250 if (r != SUCCESS ||
00251 prim -> signature == ERR_SIG ||
00252 prim -> signature -> kind !=
00253 TYPESIGNATURE ||
00254 hascomp(prim -> signature,
00255 p -> id_str_table_index)) {
00256
00257
00258 # ifdef TRACE
00259 printf("Also primary component\n");
00260 # endif
00261 p -> sig_done = SIG_UNKNOWN;
00262 return(q);
00263 } else {
00264
00265 NODE * t = declsig(s);
00266 NODE * subst_sig;
00267
00268 # ifdef TRACE
00269 printf("Occurs only in with list\n");
00270 # endif
00271 if (declerr != SUCCESS) {
00272 p -> sig_done = SIG_UNKNOWN;
00273 return(q);
00274 } else {
00275 substerr = NIL;
00276 subst_sig = tsubst(t, curr_type, p -> sel_type, FALSE);
00277 if (substerr != NIL) {
00278 # ifdef TRACE
00279 printf("substitution error\n");
00280 # endif
00281 p -> sig_done = SIG_UNKNOWN;
00282 return(q);
00283 }
00284 if (!def_match(subst_sig, NIL, p -> id_appl, p, FALSE)) {
00285 continue;
00286 }
00287 initsig(p, subst_sig);
00288 p -> sig_done = SIG_UNKNOWN;
00289
00290
00291
00292 # ifdef TRACE
00293 printf("success\n");
00294 # endif
00295 return(SUCCESS);
00296 }
00297 }
00298 }
00299 } end_maplist;
00300
00301 # ifdef TRACE
00302 printf("Not in with list\n");
00303 # endif
00304 curr_type = curr_type -> mp_primary;
00305 break;
00306 }
00307 }
00308 break;
00309 default:
00310 if((q = findsig(curr_type, FALSE)) != SUCCESS) {
00311 p -> sig_done = SIG_UNKNOWN;
00312 return(q);
00313 }
00314 tsig = curr_type -> signature;
00315 goto found_tsig;
00316 }
00317 }
00318 } else {
00319 tsig = p -> sel_type -> signature;
00320 }
00321 found_tsig:
00322 if (tsig != ERR_SIG && tsig -> kind != TYPESIGNATURE) {
00323 tsig = sig_structure(tsig);
00324 if (tsig -> kind != TYPESIGNATURE) {
00325 errmsg1(
00326 p,
00327 "Identifier %s selected from non-type",
00328 getname(p -> id_str_table_index)
00329 );
00330 p -> sig_done = SIG_DONE;
00331 chgsig(p, ERR_SIG);
00332 return(SUCCESS);
00333 }
00334 }
00335 substerr = SUCCESS;
00336 if( (q = getcomp(tsig,
00337 p,
00338 p -> sel_type,
00339 p -> signature, NIL,
00340 p -> id_appl, TRUE)) == NIL
00341 && (q = getcomp(tsig,
00342 p,
00343 p -> sel_type,
00344 p -> signature, NIL,
00345 p -> id_appl, FALSE)) == NIL ) {
00346
00347 errmsg1(
00348 p,
00349 "No appropriate type component %s",
00350 getname(p -> id_str_table_index)
00351 );
00352 if (p -> id_appl != NIL) {
00353 unparse_file = stderr;
00354 maplist(s, p -> id_appl -> ap_args, {
00355 fprintf(stderr, "\tArgument: ");
00356 unparse(s);
00357 fprintf(stderr, "\n\tArgument signature: ");
00358 unparse(s -> signature);
00359 fprintf(stderr, "\n");
00360 });
00361 }
00362 if (p -> signature != NIL) {
00363 unparse_file = stderr;
00364 fprintf(stderr, "\tSpecified signature: ");
00365 unparse(p -> signature);
00366 fprintf(stderr, "\n");
00367 }
00368 if ((q = getcomp(tsig,
00369 p,
00370 p -> sel_type,
00371 NIL, NIL,
00372 NIL, TRUE)) != NIL
00373 && is_unique(tsig, p -> id_str_table_index) ) {
00374 fprintf(stderr, "\tActual component signature: ");
00375 unparse_file = stderr;
00376 unparse(q);
00377 fprintf(stderr, "\n");
00378 if (q -> kind == FUNCSIGNATURE
00379 && ! is_empty(q -> fsig_param_list)
00380 && p -> id_appl != NIL
00381 && ! is_empty (p -> id_appl -> ap_args)) {
00382 if (amatch( first(p -> id_appl -> ap_args) -> signature,
00383 first(q -> fsig_param_list) -> par_signature)) {
00384 fprintf(stderr, "\tFirst argument signature matches\n");
00385 } else {
00386 extern NODE * diff_p, * diff_q;
00387 if (diff_p != NIL) {
00388 fprintf(stderr, "\tFirst arg match failed at ");
00389 unparse(diff_p);
00390 fprintf(stderr, " and ");
00391 unparse(diff_q);
00392 fprintf(stderr, "\n");
00393 } else {
00394 fprintf(stderr, "\tMatch of first argument failed\n");
00395 }
00396 }
00397 }
00398 } else {
00399 fprintf(stderr, "\tActual type signature: ");
00400 unparse_file = stderr;
00401 unparse(tsig);
00402 fprintf(stderr, "\n");
00403 }
00404 p -> sig_done = SIG_DONE;
00405 chgsig(p, ERR_SIG);
00406 return(SUCCESS);
00407
00408 }
00409 if (sel_index_correct) {
00410 # ifdef TRACE
00411 printf("Setting selection index for %X(%s) to %d\n",
00412 p, getname(p -> id_str_table_index),comp_index);
00413 # endif
00414 p -> sel_index = comp_index;
00415 }
00416 if (substerr == SUCCESS) {
00417 chgsig(p, q);
00418 p -> sig_done = sel_index_correct? SIG_DONE
00419 : SIG_UNKNOWN;
00420 } else {
00421 # ifdef TRACE
00422 printf("bad substitution\n");
00423 printf("Returning substerr: 0x%X\n");
00424 # endif
00425 p -> sig_done = SIG_UNKNOWN;
00426 }
00427 return(substerr);
00428 }
00429
00430 q = declsig(p -> id_last_definition);
00431 if (declerr == SUCCESS) {
00432 chgsig(p, q);
00433 p -> sig_done = SIG_DONE;
00434 } else {
00435 p -> sig_done = SIG_UNKNOWN;
00436 }
00437 # ifdef TRACE
00438 if (declerr != SUCCESS) {
00439 printf("Returning declerr: 0x%X\n", declerr);
00440 }
00441 # endif
00442 return(declerr);
00443 }