Changeset 5f0f19 in git


Ignore:
Timestamp:
Mar 29, 2000, 11:31:43 AM (24 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '648d28f488f6ff08f5607ff229b9ad9e4a5b93c2')
Children:
d161932a93ab558891ddb9f8752886545a9637bd
Parents:
280508457fc99b25c2f1e5f97221b04f934229b9
Message:
	* creat_top.cc misc.cc proc.cc utils.cc grammar.y modgen.h:
	* scanner.l stype.h:
	  - rewrite of linenumbering in module.cc
	  - some changes to %return in procdeclaration


git-svn-id: file:///usr/local/Singular/svn/trunk@4225 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/modgen
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • modules/modgen/creat_top.cc

    r280508 r5f0f19  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: creat_top.cc,v 1.7 2000-03-28 07:13:18 krueger Exp $ */
     4/* $Id: creat_top.cc,v 1.8 2000-03-29 09:31:41 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    1010
    1111#include "modgen.h"
     12extern int yylineno;
    1213
    1314void enter_id(FILE *fp, char *name, char *value);
     
    2324  fseek(fp_in, 0L, 0);
    2425  do {
    25     nread = fread (buf, sizeof (char), sizeof(buf)-1, fp_in);
    26     fwrite(buf, sizeof(char), nread, fp_out);
     26    memset(buf, 0, sizeof(buf));
     27    fgets(buf, sizeof(buf), fp_in);
     28    modlineno++;
     29    //nread = fread (buf, sizeof (char), sizeof(buf)-1, fp_in);
     30    if(strncmp(buf, "#line @d ", 8)==0) {
     31      buf[6]='%';
     32      fprintf(fp_out, buf, modlineno);
     33    }
     34    else
     35      fwrite(buf, sizeof(char), strlen(buf)/*nread*/, fp_out);
    2736  } while(!feof(fp_in));
    2837  fputs("\n", fp_out);
     
    4756  fprintf(fp, "  return(h);\n");
    4857  fprintf(fp, "}\n");
     58  modlineno+=16;
    4959}
    5060
     
    8191  fprintf(fp, "  return(h);\n");
    8292  fprintf(fp, "}\n");
     93  modlineno+=30;
    8394}
    8495
    8596/*========================================================================*/
    8697void write_mod_init(
     98  moddefv module,
    8799  FILE *fp
    88100  )
    89101{
    90102  fprintf(fp, "\n\n");
     103  fprintf(fp, "#line @d \"%s.cc\"\n", module->name);
    91104  fprintf(fp, "extern \"C\"\n");
    92105  fprintf(fp, "int mod_init(int(*iiAddCproc)())\n{\n");
     
    94107  fprintf(fp, "  idhdl helphdl = enter_id(\"Help\", NULL, PACKAGE_CMD);\n");
    95108  fprintf(fp, "  idhdl examplehdl = enter_id(\"Example\", NULL, PACKAGE_CMD);\n\n");
     109  fprintf(fp, "  \n");
     110  fprintf(fp, "   if( helphdl == NULL)\n");
     111  fprintf(fp, "     Warn(\"Cannot create help-package\\n\");\n");
     112  fprintf(fp, "   else fill_help_package(helphdl);\n");
     113  fprintf(fp, "  \n");
     114  fprintf(fp, "   if( examplehdl == NULL)\n");
     115  fprintf(fp, "     Warn(\"Cannot create example-package\\n\");\n");
     116  fprintf(fp, "   else fill_example_package(examplehdl);\n");
    96117}
    97118
  • modules/modgen/grammar.y

    r280508 r5f0f19  
    11/*
    2  * $Id: grammar.y,v 1.8 2000-03-22 10:23:56 krueger Exp $
     2 * $Id: grammar.y,v 1.9 2000-03-29 09:31:42 krueger Exp $
    33 */
    44
     
    2424extern int init_modgen(moddef *module_def, char *filename);
    2525extern int write_intro(moddefv module);
    26 extern void write_mod_init(FILE *fp);
     26extern void write_mod_init(moddefv module, FILE *fp);
    2727extern void enter_id(FILE *fp, char *name, char *value,
    2828                     int lineno, char *file);
     
    4141
    4242%token MCOLONCOLON
     43%token MEQUAL
    4344
    4445/* special symbols */
     
    6465%token VARNAMETOK
    6566/*%token MSTRINGTOK */
    66 %token <name> MSTRINGTOK
     67%token <sv>  MSTRINGTOK
    6768%token <name> NAME
    6869%token <name> FILENAME
     
    7172%token <name> CODEPART
    7273%token <name> PROCCMD
     74%token <name> ANYTOK
    7375%token  <tp> VARTYPETOK
    7476%token <i>    NUMTOK
     
    103105                                          yylineno, module_def.filename);
    104106          free($1);
    105           write_mod_init(module_def.fmtfp);
     107          write_mod_init(&module_def, module_def.fmtfp);
    106108        }
    107109
     
    127129                if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) {
    128130                  if(write_cmd!=0)
    129                     write_cmd(&module_def, vt, STRING_CMD, $1, $3);
     131                    write_cmd(&module_def, vt, STRING_CMD, $1, $3.string);
    130132                }
    131133                else {
     
    136138              case 2: /* pass 2: procedure declaration */
    137139                if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) {
    138                   proc_set_var(&procedure_decl, VAR_STRING, vt, $1, $3);
     140                  proc_set_var(&procedure_decl, VAR_STRING, vt, $1, $3.string);
    139141                }
    140142                else {
     
    147149          }
    148150          free($1);
    149           free($3);
     151          free($3.string);
    150152        }
    151153        | NAME '=' FILENAME
     
    339341procdeclhelp: MSTRINGTOK
    340342        {
    341           procedure_decl.help_string = $1;
     343          procedure_decl.help_string = $1.string;
     344          procedure_decl.lineno_other = $1.lineno;
    342345          printf("\t\thelp at %d\n", yylineno);
    343346          write_help(&module_def, &procedure_decl);
     
    478481          }
    479482          free($2);
     483        }
     484        | '%' NAME MEQUAL ANYTOK
     485        {
     486          cmd_token vt;
     487          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
     488         
     489          switch(vt=checkcmd($2, &write_cmd, CMDT_EQ, 0)) {
     490              case CMD_NONE:
     491                myyyerror("Line %d: Unknown command '%s' in section %d\n",
     492                          yylineno, $2, sectnum);
     493                break;
     494              case CMD_BADSYNTAX:
     495                myyyerror("Line %d: bad syntax of command '%s' in section %d\n",
     496                          yylineno, $2, sectnum);
     497                break;
     498              default:
     499                write_cmd(&module_def, &procedure_decl, $4);
     500          }
     501          free($2);
    480502        };
    481503
  • modules/modgen/misc.cc

    r280508 r5f0f19  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.7 2000-03-22 10:23:57 krueger Exp $ */
     4/* $Id: misc.cc,v 1.8 2000-03-29 09:31:41 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    210210  { "declaration",  write_function_declaration, CMD_DECL,   CMDT_SINGLE, 0 },
    211211  { "typecheck",    write_function_typecheck,   CMD_CHECK,  CMDT_SINGLE, 0 },
     212  { "return",       write_function_result,      CMD_RETURN, CMDT_EQ,     0 },
    212213  { "return",       write_function_return,      CMD_RETURN, CMDT_SINGLE, 1 },
    213214  { "return",       write_function_return,      CMD_RETURN, CMDT_0,     1 },
     
    479480
    480481  write_header(fp, module);
     482  fprintf(fp, "#line %d \"%s.cc\"\n", modlineno++, module);
    481483  fprintf(fp, "#include <stdlib.h>\n");
    482484  fprintf(fp, "#include <stdio.h>\n");
     
    488490  if(what != 'h') {
    489491    fprintf(fp, "#include \"%s.h\"\n", module);
     492    modlineno+=8;
     493   
     494    fprintf(fp, "#line %d \"%s.cc\"\n", modlineno++, module);
    490495    write_enter_id(fp);
    491     fprintf(fp, "\n");
     496    fprintf(fp, "\n");    modlineno+=1;
     497    fprintf(fp, "#line %d \"%s.cc\"\n", modlineno++, module);
    492498    write_add_singular_proc(fp);
    493499    fprintf(fp, "\n");
     500   
     501    fprintf(fp, "void fill_help_package(idhdl pl);\n");
     502    fprintf(fp, "void fill_example_package(idhdl pl);\n");
     503    modlineno+=3;
    494504  }
    495505  fprintf(fp, "\n");
     506 
    496507}
    497508
     
    506517  fprintf(fp, "%s\n", comment);
    507518  fprintf(fp, "%s\n", comment);
    508  
     519  if(strlen(comment)==1)modlineno+=10;
    509520}
    510521
  • modules/modgen/modgen.h

    r280508 r5f0f19  
    11/*
    2  *  $Id: modgen.h,v 1.8 2000-03-22 10:23:57 krueger Exp $
     2 *  $Id: modgen.h,v 1.9 2000-03-29 09:31:43 krueger Exp $
    33 *
    44 */
     
    2222class cfiles;
    2323class procflags;
     24class stringdef;
    2425
    2526typedef paramdef * paramdefv;
     
    2829typedef moddef * moddefv;
    2930typedef procflags *procflagsv;
     31typedef stringdef *stringdefv;
    3032
    3133class procflags {
     
    3638  char do_typecheck;
    3739  char do_return;
     40  char result_done;
    3841};
    3942
     
    9598};
    9699
     100class stringdef
     101{
     102  public:
     103  char *string;
     104  int lineno;
     105};
     106
    97107typedef enum { VAR_UNKNOWN, VAR_BOOL, VAR_NUM, VAR_STRING,
    98108               VAR_FILE, VAR_FILES
     
    103113} cmd_token;
    104114
    105 typedef enum { CMDT_SINGLE, CMDT_0, CMDT_ANY
     115typedef enum { CMDT_SINGLE, CMDT_0, CMDT_ANY, CMDT_EQ
    106116} cmd_type;
    107117
     
    114124 *
    115125 */
    116 
     126extern int modlineno;    /* lineno within module */
    117127
    118128extern int IsCmd(char *n, int & tok);
     
    164174extern void write_function_declaration(moddefv module, procdefv pi, void *arg = NULL);
    165175extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL);
     176extern void write_function_result(moddefv module, procdefv pi, void *arg = NULL);
    166177extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL);
    167178extern void write_function_singularcmd(moddefv module, procdefv pi, void *arg = NULL);
  • modules/modgen/proc.cc

    r280508 r5f0f19  
    11/*
    2  * $Id: proc.cc,v 1.9 2000-03-28 07:15:13 krueger Exp $
     2 * $Id: proc.cc,v 1.10 2000-03-29 09:31:42 krueger Exp $
    33 */
    44
     
    4141  if(trace) printf("\tcreating '%s'...", proc->procname); fflush(stdout);
    4242  fprintf(module->modfp, "#line %d \"%s\"\n", proc->lineno, module->filename);
     43  modlineno+=1;
    4344
    4445  switch(proc->language) {
     
    5657                proc->is_static ? "TRUE" : "FALSE",
    5758                proc->procname);
     59        modlineno+=1;
    5860       
     61#if 0
    5962        if(proc->help_string!=NULL) {
    6063          printf("WRITE HELP\n");
    61 //          fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
    62 //          fprintf(module->modfp, " IDID(helphdl));\n");
    63           fprintf(module->fmtfp2, "  enter_id(\"%s\",", proc->procname);
     64          fprintf(module->fmtfp2, "  1-enter_id(\"%s\",", proc->procname);
    6465          fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n", proc->help_string);
    65 //          fprintf(module->modfp, "  namespaceroot->push();\n");
    6666        }
    6767        if(proc->example_string!=NULL) {
    6868          printf("WRITE EXAMPLE\n");
    69           fprintf(module->fmtfp3, "  enter_id(\"%s\",", proc->procname);
     69          fprintf(module->fmtfp3, "  1-enter_id(\"%s\",", proc->procname);
    7070          fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n",
    7171                  proc->example_string);
    7272        }
     73#endif
    7374        fprintf(module->modfp, "\n");
     75        modlineno+=1;
    7476
    7577        write_procedure_header(module, proc, module->fmtfp);
     
    8486                proc->sing_start, proc->sing_end,
    8587                proc->is_static ? "TRUE" : "FALSE");
     88        modlineno+=1;
    8689        break;
    8790  }
     
    129132  if(pi->paramcnt>0) {
    130133    fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
     134    fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
    131135    fprintf(module->fmtfp, "  leftv v = h, v_save;\n");
    132136    fprintf(module->fmtfp, "  int tok = NONE, index = 0;\n");
     
    149153{
    150154  fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
     155  fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
    151156  write_procedure_typecheck(module, pi, module->fmtfp);
    152157  fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
    153158  pi->flags.typecheck_done = 1;
     159}
     160
     161void write_function_result(
     162  moddefv module,
     163  procdefv pi,
     164  void *arg
     165  )
     166{
     167  fprintf(module->fmtfp, "  res->data =%s\n", arg);
     168  pi->flags.result_done = 1;
     169  write_procedure_return(module, pi, module->fmtfp);
    154170}
    155171
     
    199215 
    200216  printf("\nWriting return-block\n");
     217  fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
    201218  fprintf(module->fmtfp, "/* code for running singular commands */\n");
    202219  fprintf(module->fmtfp, "/*\n");
     
    280297  fprintf(module->modfp, "  return 0;\n}\n\n");
    281298  fflush(module->modfp);
    282 
    283   fprintf(module->modfp, "#if 0 /* Help section */\n");
     299  modlineno+=3;
     300 
     301  fprintf(module->modfp, "#line %d \"%s.cc\"\n", modlineno++, module->name);
     302  fprintf(module->modfp, "/* Help section */\n");
     303  fprintf(module->modfp, "void fill_help_package(idhdl pl) {\n");
     304  fprintf(module->modfp, "  namespaceroot->push(IDPACKAGE(pl), IDID(pl));\n");
     305  modlineno+=3;
    284306  mod_copy_tmp(module->modfp, module->fmtfp2);
    285   fprintf(module->modfp, "#endif /* End of Help section */\n\n");
    286   fprintf(module->modfp, "#if 0 /* Example section */\n");
     307  fprintf(module->modfp, "#line %d \"%s.cc\"\n", modlineno++, module->name);
     308  fprintf(module->modfp, "  namespaceroot->pop();\n");
     309  fprintf(module->modfp, "}  /* End of Help section */\n\n");
     310  modlineno+=3;
     311
     312  fprintf(module->modfp, "/* Example section */\n");
     313  fprintf(module->modfp, "void fill_example_package(idhdl pl) {\n");
     314  fprintf(module->modfp, "  namespaceroot->push(IDPACKAGE(pl), IDID(pl));\n");
     315  modlineno+=3;
    287316  mod_copy_tmp(module->modfp, module->fmtfp3);
    288   fprintf(module->modfp, "#endif /* End of Example section */\n\n");
     317  fprintf(module->modfp, "#line %d \"%s.cc\"\n", modlineno++, module->name);
     318  fprintf(module->modfp, "  namespaceroot->pop();\n");
     319  fprintf(module->modfp, "} /* End of Example section */\n\n");
     320  modlineno+=2;
     321
    289322  mod_copy_tmp(module->modfp, module->fmtfp);
     323  fprintf(module->modfp, "#line %d \"%s.cc\"\n", modlineno++, module->name);
    290324  printf("  done.\n");fflush(stdout);
    291325  fclose(module->fmtfp);
     
    337371  printf("### RETURN: '%s' '%s' '%d'\n", pi->return_val.name,
    338372         pi->return_val.typname, pi->return_val.typ);
     373  fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
    339374  if(pi->funcname == NULL) {
     375    if(!pi->flags.result_done) fprintf(fmtfp, "  res->data = NULL;\n");
    340376    fprintf(fmtfp, "  res->rtyp = %s;\n", pi->return_val.typname);
    341     fprintf(fmtfp, "  res->data = NULL;\n");
    342377    //fprintf(fmtfp, "  res->rtyp = NONE;\n");
    343378    //fprintf(fmtfp, "  res->data = NULL;\n");
     
    355390
    356391        case NONE:
     392          if(!pi->flags.result_done) fprintf(fmtfp, "  res->data = NULL;\n");
    357393          fprintf(fmtfp, "  res->rtyp = %s;\n", pi->return_val.typname);
    358           fprintf(fmtfp, "  res->data = NULL;\n");
    359394          fprintf(fmtfp, "  return(%s(", pi->funcname);
    360395          for (i=0;i<pi->paramcnt; i++) {
     
    440475    fprintf(module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
    441476            module->filename);
    442 //     fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
    443 //     fprintf(module->modfp, " IDID(helphdl));\n");
    444477    fprintf(module->fmtfp2, "  enter_id(\"%s\",", pi->procname);
    445478    fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n\n", pi->help_string);
    446 //     fprintf(module->modfp, "  namespaceroot->push();\n");
    447479  }
    448480}
     
    463495    fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n\n", pi->example_string);
    464496  }
    465  
    466 #if 0
    467     fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(examplehdl) ,");
    468     fprintf(module->modfp, " IDID(examplehdl));\n");
    469     fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
    470     fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);
    471     fprintf(module->modfp, "  namespaceroot->push();\n");
    472 #endif
    473497}
    474498
     
    530554
    531555      case LANG_C:
    532         if(lineno>=0)
     556        if(lineno>=0) {
    533557          fprintf(module->fmtfp, "#line %d \"%s\"\n",
    534                                           lineno, module->filename);
     558                  lineno, module->filename);
     559          fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
     560        }
    535561        fprintf(module->fmtfp, "%s", line); break;
    536562  }
  • modules/modgen/scanner.l

    r280508 r5f0f19  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 /* $Id: scanner.l,v 1.8 2000-03-22 10:23:58 krueger Exp $ */
     5/* $Id: scanner.l,v 1.9 2000-03-29 09:31:43 krueger Exp $ */
    66#include <stdio.h>
    77#include <string.h>
     
    126126%x PROCDECL
    127127%x EXAMPLE
     128%x ANYLINE
    128129
    129130%x pdef
     
    167168        ","     { return ','; }
    168169
    169         "\""    { do_return++; push_state(YYSTATE, STRING, "string"); }
     170        "\""    { do_return++;
     171                  lvalp->sv.lineno = yylineno;
     172                  push_state(YYSTATE, STRING, "string");
     173                }
    170174        ^"%%".* {
    171175                  sectnum = 2;
     
    214218                    pop_state();
    215219                    if(do_return) {
    216                       s = t = lvalp->name = dupyytext();
     220                      s = t = lvalp->sv.string = dupyytext();
    217221                      while (*yytext)
    218222                      {
     
    324328         "/*"       push_state(YYSTATE, COMMENT, "COMMENT");yymore();
    325329         "//".*{NL}  ++yylineno; ACTION_ECHO;
    326          "\""    { do_return++; push_state(YYSTATE, STRING, "string"); /*yymore();*/}
     330         "\""    { do_return++;
     331                   lvalp->sv.lineno = yylineno;
     332                   push_state(YYSTATE, STRING, "string");
     333                 }
    327334         {BOOL}  { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i);
    328335                   else {
     
    367374         "/*"      push_state(YYSTATE, COMMENT, "COMMENT"); yymore();
    368375         "//".*{NL} { yylineno++; lvalp->name = yytext; return CODEPART; }
    369          "\""    { push_state(YYSTATE, STRING, "string"); yymore();}
     376         "\""    {
     377                   lvalp->sv.lineno = yylineno;
     378                   push_state(YYSTATE, STRING, "string"); yymore();}
    370379         "{"     { brace1++; yymore();}
    371380         "}"     { brace1--;
     
    408417       {NL}   { yylineno++; }
    409418       "::"   { return MCOLONCOLON; }
     419       "="    { switch_state(YYSTATE, ANYLINE, "ANYLINE"); return MEQUAL; }
    410420       .      { printf("PCB: '%s'\n", yytext); }
    411421       }
     422
     423<ANYLINE>{
     424       {col}  { lvalp->name = yytext;
     425                pop_state();
     426                return ANYTOK; }
     427       {NL}   { yylineno++; }
     428       .       { yymore(); }
     429}
    412430
    413431%%
  • modules/modgen/stype.h

    r280508 r5f0f19  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: stype.h,v 1.3 2000-01-17 08:32:27 krueger Exp $ */
     6/* $Id: stype.h,v 1.4 2000-03-29 09:31:43 krueger Exp $ */
    77/*
    88* ABSTRACT: flex/bison interface
     
    1616  char    * name;
    1717  moddefv    lv;
     18  stringdef sv;
    1819  paramdef  tp;
    1920} MYYSTYPE;
  • modules/modgen/utils.cc

    r280508 r5f0f19  
    11/*
    2  * $Id: utils.cc,v 1.5 2000-02-18 13:33:49 krueger Exp $
     2 * $Id: utils.cc,v 1.6 2000-03-29 09:31:42 krueger Exp $
    33 */
    44
     
    88#include <stdarg.h>
    99#include <ctype.h>
     10
     11int modlineno;    /* lineno within module */
     12
    1013#include "modgen.h"
    1114
     
    2023  char tmpfile[64];
    2124  char *p, *q;
     25 
     26  modlineno = 0;
    2227 
    2328  if(module_def == NULL) return -1;
Note: See TracChangeset for help on using the changeset viewer.