source: git/dyn_modules/modgen/modgen.h @ 3c473c

spielwiese
Last change on this file since 3c473c was 3c473c, checked in by Kai Krüger <krueger@…>, 14 years ago
rename directory modules to dyn_modules anticipating "modules" directory for cmake. git-svn-id: file:///usr/local/Singular/svn/trunk@13033 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 *  $Id$
3 *
4 */
5
6#ifndef _MODGEN_H
7#define _MODGEN_H
8#define MOD_GEN_VERSION "0.3"
9
10#define BUFLEN 128
11#define TMPL_HEAD ""
12#define TMPL_FOOT ""
13
14#include <stdio.h>
15#include <string.h>
16
17/* Basic definitions */
18#ifndef BOOLEAN
19  typedef int BOOLEAN;
20#endif
21
22#ifndef TRUE
23#  define TRUE 1
24#endif
25
26#ifndef FALSE
27#  define FALSE 0
28#endif
29
30/*
31 * LANG_TOP     : Toplevel package only
32 * LANG_SINGULAR:
33 * LANG_C       :
34 */
35typedef enum { LANG_NONE, LANG_TOP, LANG_SINGULAR, LANG_C, LANG_MAX}
36  language_defs;
37
38/* id type */
39typedef int idtyp;
40
41
42
43class paramdef;
44class procdef;
45class moddef;
46class cfiles;
47class procflags;
48class stringdef;
49
50typedef paramdef * paramdefv;
51typedef procdef * procdefv;
52typedef cfiles * cfilesv;
53typedef moddef * moddefv;
54typedef procflags *procflagsv;
55typedef stringdef *stringdefv;
56
57class procflags {
58  public:
59  char start_of_code;
60  char declaration_done;
61  char typecheck_done;
62
63  char auto_header;
64  char do_declaration;
65  char do_typecheck;
66  char do_return;
67  char result_done;
68};
69
70class paramdef {
71 public:
72  char *name;
73  char *typname;
74  int  typ;
75  char *varname;
76};
77
78class procdef {
79 public:
80  char       * procname;
81  char       * funcname;
82  language_defs language;
83  int          lineno;
84  int          lineno_other;
85  int          is_static;
86  paramdef     return_val;
87  paramdefv    param;
88  int          paramcnt;
89  procflags    flags;
90  char       * c_code;
91  char       * help_string;
92  long         example_len;
93  char       * example_string;
94  long         sing_start;
95  long         sing_end;
96};
97
98class cfiles {
99  public:
100  cfilesv next;
101  char *filename;
102};
103
104class moddef {
105 public:
106  FILE * modfp;           /* module file */
107  FILE * modfp_h;         /* header file */
108  FILE * fmtfp;           /* temporary file */
109  FILE * fmtfp2;          /* temporary file */
110  FILE * fmtfp3;          /* temporary file */
111  FILE * binfp;           /* include singular procedures are stored
112                             in an extra file */
113  FILE * docfp;           /* help/example is stored in this file
114                             for building the reference manual */
115  char * filename;        /* inputfile to parse */
116  char * name;            /* name of the module directory*/
117  char * targetname;      /* name of dynamic module + package */
118  unsigned int major, minor, level;
119  char * version;
120  char * category;
121  char * revision;
122  char * info;
123  char * c_code;
124  procdefv procs;
125  int      proccnt;
126  cfilesv  files;
127  int      filecnt;
128};
129
130class stringdef
131{
132  public:
133  char *string;
134  int lineno;
135};
136
137typedef enum { VAR_UNKNOWN, VAR_BOOL, VAR_NUM, VAR_STRING,
138               VAR_FILE, VAR_FILES
139} var_type;
140
141typedef enum { CMD_NONE, CMD_BADSYNTAX, CMD_DECL, CMD_CHECK, CMD_RETURN,
142               CMD_SINGULAR, CMD_ERROR, CMD_NODECL
143} cmd_token;
144
145typedef enum { CMDT_SINGLE, CMDT_0, CMDT_ANY, CMDT_EQ
146} cmd_type;
147
148
149typedef enum { VAR_NONE, VAR_MODULE, VAR_HELP, VAR_INFO, VAR_VERSION,
150               VAR_TYPECHECK, VAR_RETURN, VAR_FUNCTION, VAR_CATEGORY
151} var_token;
152
153/*
154 *
155 */
156extern int modlineno;    /* lineno within module */
157extern int debug;
158extern int trace;
159extern int xyz;
160
161extern int IsCmd(char *n, int & tok);
162extern char * decl2str(int n, char *name);
163
164extern int myyyerror(char *fmt, ...);
165
166
167extern void PrintProclist(moddefv module);
168extern void generate_mod(moddefv module, int section);
169extern void mod_create_makefile(moddefv module);
170extern void Add2files(moddefv module, char *buff);
171
172extern void mod_copy_tmp(FILE *fp_out, FILE *fp_in);
173extern void mod_write_header(FILE *fp, char *module, char what);
174extern void generate_header(procdefv pi, FILE *fp);
175extern void write_header(FILE *fp, char *module, char *comment="");
176extern void make_version(char *p, moddefv module);
177extern void make_module_name(char *p, moddefv module);
178extern void write_procedure_text(moddefv module, int lineno);
179/*extern void write_procedure_header(moddefv module);*/
180
181extern int init_proc(procdefv p, char *procname, paramdefv ret, int line,
182                     language_defs language = LANG_C);
183extern void setup_proc(moddefv module, procdefv p);
184extern void proc_set_var(procdefv p, var_type type, var_token varid,
185                         char *varname, void *varvalue);
186void proc_set_default_var(var_type type, var_token varid, char *varname,
187                          void *varvalue);
188void write_finish_functions(moddefv module, procdefv proc);
189void AddParam(procdefv p, paramdefv vnew, char *name = NULL);
190
191/* from makefile.cc */
192extern void mod_create_makefile(moddefv module);
193extern void build_head_section(FILE *fp, moddefv module);
194extern void build_clean_section(FILE *fp, moddefv module);
195extern void build_install_section(FILE *fp, moddefv module);
196static char *object_name(char *p);
197extern void build_compile_section(FILE *fp, moddefv module);
198
199/* from utils.cc */
200extern int create_tmpfile(moddefv module_def, int which = 0);
201extern char *build_filename(moddefv module, char *text, int what);
202extern unsigned long crccheck(char *file);
203extern void write_crccheck(FILE *fp);
204extern void write_crctable(FILE *fp);
205
206/* from proc_setup.cc */
207extern int check_reseverd(char *name);
208
209/* from proc.cc */
210extern void write_function_header(moddefv module, procdefv proc);
211extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp);
212extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp);
213extern void write_function_declaration(moddefv module, procdefv pi, void *arg = NULL);
214extern void write_function_nodecl(moddefv module, procdefv pi, void *arg = NULL);
215extern void write_function_error(moddefv module, procdefv pi, void *arg = NULL);
216extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL);
217extern void write_function_result(moddefv module, procdefv pi, void *arg = NULL);
218extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL);
219extern void write_function_singularcmd(moddefv module, procdefv pi, void *arg = NULL);
220extern void write_function_errorhandling(moddefv module, procdefv pi);
221extern void write_help(moddefv module, procdefv pi);
222extern void write_example(moddefv module, procdefv pi);
223extern int  write_singular_procedures(moddefv module, procdefv proc);
224extern void write_singular_parameter(moddefv module,int lineno,
225                                     char *typname, char *varname);
226extern void write_singular_end(moddefv module, procdefv proc,int lineno);
227extern int write_helpfile_help(moddefv module, procdefv proc);
228
229extern void write_codeline(moddefv module, procdefv proc,
230                           char *line, int lineno = -1);
231
232/* from misc.cc */
233extern cmd_token checkcmd(
234  char *cmdname,
235  void(**write_cmd)(moddefv module, procdefv pi, void *arg),
236  cmd_type  type,
237  int args);
238extern var_token checkvar(
239  char *varname, var_type type,
240  void (**write_cmd)(moddefv module, var_token type, idtyp t,
241                     void *arg1, void *arg2));
242void write_main_variable(moddefv module, var_token type,
243                         idtyp t, void *arg1, void *arg2);
244
245#endif /* _MODGEN_H */
Note: See TracBrowser for help on using the repository browser.