vtf-logo

StatParser.h

Go to the documentation of this file.
00001 #ifndef STAT_PARSER_H
00002 #define STAT_PARSER_H
00003 
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <math.h>
00007 #include <vector>
00008 
00016 /* constants */
00017 
00018 #ifndef TRUE
00019 #define TRUE  1
00020 #endif
00021 #ifndef FALSE
00022 #define FALSE 0
00023 #endif
00024 #ifndef RETURN_OK
00025 #define RETURN_OK 0
00026 #endif
00027 #ifndef RETURN_ERROR
00028 #define RETURN_ERROR -1
00029 #endif
00030 
00031 /* predefined variable names */
00032 
00033 #define STAT_COORD_A "a"
00034 #define STAT_COORD_B "b"
00035 #define STAT_COORD_X "x"
00036 #define STAT_COORD_Y "y"
00037 #define STAT_COORD_Z "z"
00038 #define STAT_XMIN    "xmin"
00039 #define STAT_XMAX    "xmax"
00040 #define STAT_YMIN    "ymin"
00041 #define STAT_YMAX    "ymax"
00042 #define STAT_ZMIN    "zmin"
00043 #define STAT_ZMAX    "zmax"
00044 #define STAT_NX      "nx"
00045 #define STAT_NY      "ny"
00046 #define STAT_NZ      "nz"
00047 #define STAT_NXF     "nxfine"
00048 #define STAT_NYF     "nyfine"
00049 #define STAT_NZF     "nzfine"
00050 
00051 /* predefined average operations */
00052 #define STAT_RAW      0
00053 #define STAT_AVERAGED 1
00054 
00055 #define STAT_PRIMITIVE 0
00056 #define STAT_DERIVED   1
00057 
00058 /* function prototypes */
00059 void staterror (char const *msg);
00060 void staterror (char const * msg, int l, int c);
00061 
00062 void stat_parser_set_debug(void);
00063 void stat_scanner_set_debug(void);
00064 
00065 typedef double (*func_t1) (double);
00066 typedef double (*func_t2) (double, double);
00067 
00068 typedef struct {
00069     int na; /* number of point over which dimensiona are discretized */
00070     int ave;  /* do we average after sampling */
00071   } stat_thread;
00072 
00073 typedef struct {
00074     int na, nb; 
00075     int avea, aveb;
00076   } stat_surface;
00077 
00078 typedef struct {
00079     int dir, na, nb;
00080     double amin, amax, bmin, bmax, value;
00081   } stat_plane;
00082 
00083 typedef union {
00084   stat_thread thread;
00085   stat_surface surface;
00086   stat_plane plane;
00087   double bndry[6];
00088 } stat_uop;
00089 
00090 template<class data_type>
00091 class _symrec {
00092  public:
00093   int type;            /* type of symbol */
00094   int src;             /* source of information */
00095   char * name;         /* name of symbol */
00096   union {
00097     int    iptr;       /* integer variable index */
00098     int    ivalue;     /* integer value */
00099     double dvalue;     /* real values */
00100     void*  ptr;        /* pointer to function */
00101   } vdata;
00102   int npoints;         /* number of points to evaluate */
00103   data_type* pdata;    /* array of points to evaluate */
00104   class _symrec<data_type> * prev, * next, *ref;  /* linked list and pointer to original symbol */
00105 };
00106 
00107 #define YYPARSE_TEMPLATE_DEF template<class point_type, class data_type, int dim>
00108 #define YYPARSE_PARAM_TYPE StatParser<point_type,data_type,dim>
00109 
00110 YYPARSE_TEMPLATE_DEF
00111 class StatParser {
00112 
00113  private:
00114     int _exec;
00115   
00116  public:
00117   typedef _symrec<data_type> symrec;
00118   typedef std::vector<symrec*> symvec;
00119   
00120  protected:
00121 
00122   /* all information regarding the probes is contained here */
00123   typedef struct {
00124     int type;
00125     stat_uop options;
00126     point_type * coords; /* coordinate of sample points */
00127     symvec sym_coords;  /* list of expressions to evaluate coordinates */
00128   } probe;
00129 
00130   typedef std::vector<probe*> provec;
00131 
00132   /* all groups with their list of variables and probes */
00133   typedef struct {
00134     int step;
00135     symvec  sym_table;
00136     provec  probe_table;
00137   } group;
00138   
00139   typedef std::vector<group*> grpvec;
00140 
00141   /* master symbol table */
00142   symvec sym_table;
00143   /* group table */
00144   grpvec group_table;
00145   /* temporary storage lists */
00146   symvec sym_stack;
00147 
00148   void dump_token(symrec* ptr, symrec* ptr_org);
00149   void dump_sym(symvec &list);
00150   void dump_probe(provec &list);
00151   char*  token(int tok);
00152 
00153   int delprobe(probe* ptr);
00154   int delgroup(group* ptr);
00155 
00156   int clearsym(symvec &table);  
00157   int cleargroup(grpvec &table);
00158   int clearprobe(provec &list);
00159 
00160   int evalstack(symvec& stack, point_type& xc);
00161   symrec* clonestack(symvec& stack);
00162   void unlinksym(symrec* ptr);
00163   int buildcoords(probe * ptr);
00164   int clearcoords(probe * ptr);
00165 
00166   symrec* allocsym(char const * sym_name);
00167   int freesym(symrec* ptr);
00168 
00169   int vectorize(symrec* ptr, int Npoints);
00170   int unvectorize(symrec* ptr);
00171 
00172  public:
00173   
00174   StatParser () ;
00175   ~StatParser ();
00176 
00177   /* helper functions */
00178   void   dump_all();
00179 
00180   /* master table functions */
00181   symrec * putsym(int sym_type, char const * sym_name);
00182   
00183   int parse(char const * fname);
00184 
00185   int parser_exec() { return _exec; };
00186   void parser_activate_exec() { _exec = 1; };
00187   void parser_deactivate_exec() { _exec = 0; };
00188 
00189   symrec * getsym(char const * sym_name);
00190   int addgroup(void);
00191   int group_step(int);
00192   int group_add_probe(int probe_type, stat_uop & options);
00193   int group_add_keys(void);
00194   int searchtoken(int tok);
00195   int searchtoken(char const * psz);
00196   int counttoken(int tok);
00197 
00198   /* work table functions */
00199   symrec * addsym(int sym_type, char const * sym_name = NULL);
00200 };
00201 
00202 /* pass argument from calling subroutine */
00203 #define YYPARSE_PARAM parg
00204 
00205 /* pass argument to lexer */
00206 #define YYLEX_PARAM   parg
00207 
00208 #include "StatParser_parser.c"
00209 #include "StatParser_scanner.c"
00210 #include "StatParser.ipp"
00211 
00212 #endif