C:/Users/Dennis/src/lang/russell.orig/src/pass4/coerce.c

Go to the documentation of this file.
00001 # include "parm.h"
00002 
00003 # include "stree/ststructs.mh"
00004 
00005 # include "sigs.h"
00006 
00007 extern int indx_ValueOf;
00008 
00009 /*
00010  *  Return an expression which corresponds to p coerced to a value 
00011  * signature (if remotely possible).  If this is clearly impossible
00012  * just return p.  It is assumed that p's signature is known.
00013  *  Note that the only correctness claim for this procedure is
00014  * that if the coercion is possible it is done correctly.  No
00015  * attempt is made to determine whether the resulting expression
00016  * will be signature correct.  This is left up to checksigs.
00017  * The resulting expression may no longer have known signature.
00018  *  The expression tree p may be destructively updated in order
00019  * to propagate coercions into LET blocks.  This is necessary
00020  * in that it reduces the likelihood of bogus import rule violations.
00021  * It also enhances the effectiveness of allocate.c in allocating
00022  * variables to registers.
00023  *  We claim that there exists a subtle argument that shows that the
00024  * destructive update cannot update signatures, and is thus safe.
00025  */
00026 NODE * coerce(p)
00027 NODE * p;
00028 {
00029     register NODE * nappl;  /* New application node */
00030 
00031     if(p -> signature == ERR_SIG) return(p);
00032 
00033     if (p -> kind == BLOCKDENOTATION) {
00034         (void) replace_last(p -> bld_den_seq, coerce(last(p -> bld_den_seq)));
00035         chgfld(&(p -> signature), NIL);
00036         p -> sig_done = SIG_UNKNOWN;
00037         return(p);
00038     } else if (p -> kind == USELIST) {
00039         (void) replace_last(p -> usl_den_seq, coerce(last(p -> usl_den_seq)));
00040         chgfld(&(p -> signature), NIL);
00041         p -> sig_done = SIG_UNKNOWN;
00042         return(p);
00043     }
00044 
00045     switch(p -> signature -> kind) {
00046         case VALSIGNATURE:
00047             return(p);
00048             break;
00049 
00050         case VARSIGNATURE:
00051             {
00052                 NODE * nop; /* new operator node */
00053 
00054                 nop = mknode(LETTERID, indx_ValueOf);
00055                 initfld(&(nop -> sel_type), p -> signature -> var_denotation);
00056                 nop -> id_def_found = TRUE;
00057                 nappl = mknode(APPLICATION, nop, mklist(p, -1));
00058                 nappl -> vlineno = nop -> vlineno = p -> vlineno;
00059                 nappl -> pre_num = nop -> pre_num = p -> pre_num;
00060                 nappl -> post_num = nop -> post_num = p -> post_num;
00061                 return(nappl);
00062             }
00063             break;
00064 
00065         case FUNCSIGNATURE:
00066             if(length(p->signature->fsig_param_list) == 0) {
00067                 nappl = mknode(APPLICATION, p, emptylist());
00068                 nappl -> vlineno = p -> vlineno;
00069                 nappl -> pre_num = p -> pre_num;
00070                 nappl -> post_num = p -> post_num;
00071                 return(nappl);
00072             } else {
00073                 /* clearly hopeless */
00074                 return(p);
00075             }
00076             break;
00077 
00078         default:
00079             /* again hopeless */
00080             return(p);
00081     }
00082 }

Generated on Fri Jan 25 10:39:46 2008 for russell by  doxygen 1.5.4