C:/Users/Dennis/src/lang/russell.orig/src/pass3/expand_str.c

Go to the documentation of this file.
00001 # include "parm.h"
00002 
00003 # include "stree/ststructs.mh"
00004 
00005 extern NODE * sig_const;
00006 extern int indx_empty;
00007 extern int indx_sconc;
00008 extern int indx_pconc;
00009 
00010 /*
00011  * expand_str(pointer_to_string_node)
00012  *
00013  *  Returns a tree containing the expanded version of the string.
00014  * It is assumed that the selection type is explicitly present in
00015  * the argument node.  It is also assumed that the selection type
00016  * has the necessary components, and that the characters in the string
00017  * have constant signature.
00018  */
00019 
00020 NODE *
00021 expand_str(string)
00022 NODE * string;
00023 {
00024     char * next_char;     /* next character to be added to expansion    */
00025     NODE * expansion;     /* current partial expansion                  */
00026     NODE * id_node;       /* identifier node currently being generated  */
00027     NODE * conc_op;       /* concatenation operator node                */
00028     char * const_template = "'X'";
00029 
00030 #   ifdef DEBUG
00031         if (string -> sel_type == NIL) {
00032             dbgmsg("expand_str: missing selection type\n");
00033             abort();
00034         }
00035 #   endif
00036     next_char = string -> str_string;
00037     /* Build first node of expansion */
00038         switch (string -> kind) {
00039             case QSTR:
00040                 id_node = mknode(LETTERID, indx_empty);
00041                 initfld(&(id_node -> sel_type), string -> sel_type);
00042                 id_node -> id_def_found = TRUE;
00043                 break;
00044             case UQSTR:
00045 #               ifdef DEBUG
00046                     if (*next_char == '\0') {
00047                         dbgmsg("expand_str: empty unquoted string\n");
00048                     }
00049 #               endif
00050                 const_template[1] = * next_char++;
00051                 id_node = mknode(LETTERID, stt_enter(const_template,4));
00052                 initfld(&(id_node -> sel_type), string -> sel_type);
00053                 id_node -> id_def_found = TRUE;
00054                 break;
00055 #           ifdef DEBUG
00056                 default:
00057                     dbgmsg("expand_str: bad string node\n");
00058 #           endif
00059         }
00060     expansion = mknode(APPLICATION, id_node, emptylist());
00061 
00062     if (*next_char) {
00063         /* build conc_op */
00064             switch(string -> kind) {
00065                 case QSTR:
00066                     conc_op = mknode(LETTERID, indx_sconc);
00067                     break;
00068                 case UQSTR:
00069                     conc_op = mknode(LETTERID, indx_pconc);
00070                     break;
00071             }
00072             initfld(&(conc_op -> sel_type), string -> sel_type);
00073             conc_op -> id_def_found = TRUE;
00074     }
00075 
00076     /* add remaining characters */
00077         while (*next_char) {
00078             const_template[1] = * next_char++;
00079             id_node = mknode(LETTERID, stt_enter(const_template,4));
00080             initfld(&(id_node -> sel_type), string -> sel_type);
00081             id_node -> id_def_found = TRUE;
00082             expansion = mknode( APPLICATION,
00083                                 conc_op,
00084                                 mklist( expansion,
00085                                         mknode( APPLICATION,
00086                                                 id_node,
00087                                                 emptylist()
00088                                         ),
00089                                         -1
00090                                 )
00091                         );
00092         }
00093     return(expansion);
00094 }

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