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
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
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
00052 #define STAT_RAW 0
00053 #define STAT_AVERAGED 1
00054
00055 #define STAT_PRIMITIVE 0
00056 #define STAT_DERIVED 1
00057
00058
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;
00070 int ave;
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;
00094 int src;
00095 char * name;
00096 union {
00097 int iptr;
00098 int ivalue;
00099 double dvalue;
00100 void* ptr;
00101 } vdata;
00102 int npoints;
00103 data_type* pdata;
00104 class _symrec<data_type> * prev, * next, *ref;
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
00123 typedef struct {
00124 int type;
00125 stat_uop options;
00126 point_type * coords;
00127 symvec sym_coords;
00128 } probe;
00129
00130 typedef std::vector<probe*> provec;
00131
00132
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
00142 symvec sym_table;
00143
00144 grpvec group_table;
00145
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
00178 void dump_all();
00179
00180
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
00199 symrec * addsym(int sym_type, char const * sym_name = NULL);
00200 };
00201
00202
00203 #define YYPARSE_PARAM parg
00204
00205
00206 #define YYLEX_PARAM parg
00207
00208 #include "StatParser_parser.c"
00209 #include "StatParser_scanner.c"
00210 #include "StatParser.ipp"
00211
00212 #endif