00001
00002 #ifndef TYPE_H
00003 #define TYPE_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "stdtypes.h"
00020 #include "fifo_list.h"
00021 #include "typedefs.h"
00022 #include "str.h"
00023 #include "pools.h"
00024
00025 enum { bad_type,
00026 ty_time,
00027 ty_range,
00028 ty_real,
00029 ty_array,
00030 ty_record,
00031 ty_file };
00032
00033
00034
00070 class type {
00071 private:
00073 uint width;
00074
00075 public:
00076 type(void)
00077 {
00078 width = 0;
00079 }
00080
00081
00082
00083
00084 void *operator new( unsigned int num_bytes )
00085 {
00086 assert( FALSE );
00087 return NULL;
00088 }
00089
00090 void *operator new( unsigned int num_bytes, pool *mem_pool )
00091 {
00092 return mem_pool->GetMem( num_bytes );
00093 }
00094
00095
00096
00097 void operator delete( void *addr ) {}
00098
00099 const uint get_width(void)
00100 {
00101 return width;
00102 }
00103
00104 void set_width( uint w )
00105 {
00106 width = w;
00107 }
00108
00109
00110
00111
00112 virtual const uint get_ty_kind(void)
00113 {
00114 return bad_type;
00115 }
00116
00117
00118
00119
00120
00121 virtual void set_unit(uint unit )
00122 {
00123 assert( FALSE );
00124 }
00125 virtual uint get_unit(void)
00126 {
00127 assert( FALSE );
00128 return 0;
00129 }
00130
00131
00132
00133 virtual void set_lhs( int l )
00134 {
00135 assert( FALSE );
00136 }
00137 virtual const int get_lhs(void)
00138 {
00139 assert( FALSE );
00140 return 0;
00141 }
00142
00143 virtual void set_rhs( int r )
00144 {
00145 assert( FALSE );
00146 }
00147 const int get_rhs(void)
00148 {
00149 assert( FALSE );
00150 return 0;
00151 }
00152
00153 virtual void set_dir( uint dir )
00154 {
00155 assert( FALSE );
00156 }
00157 virtual const uint get_dir(void)
00158 {
00159 assert( FALSE );
00160 return 0;
00161 }
00162
00163 virtual void set_range( int l, int r, uint dir )
00164 {
00165 assert( FALSE );
00166 }
00167
00168 virtual void set_box(void)
00169 {
00170 assert( FALSE );
00171 }
00172 virtual void unset_box(void)
00173 {
00174 assert( FALSE );
00175 }
00176 virtual const Boolean is_box(void)
00177 {
00178 assert( FALSE );
00179 return FALSE;
00180 }
00181
00182
00183
00184 virtual const uchar get_num_dims(void)
00185 {
00186 assert( FALSE );
00187 return 0;
00188 }
00189 virtual void set_num_dims( uint ndim )
00190 {
00191 assert( FALSE );
00192 }
00193 virtual const uint get_array_size(void)
00194 {
00195 assert( FALSE );
00196 return 0;
00197 }
00198 virtual void set_array_size( uint s )
00199 {
00200 assert( FALSE );
00201 }
00202 virtual const pTypeRange get_array_range(void)
00203 {
00204 assert( FALSE );
00205 return NULL;
00206 }
00207 virtual void set_array_range( pTypeRange r )
00208 {
00209 assert( FALSE );
00210 }
00211 virtual const pType get_array_base_type(void)
00212 {
00213 assert( FALSE );
00214 return NULL;
00215 }
00216 virtual void set_array_base_type( pType tBase )
00217 {
00218 assert( FALSE );
00219 }
00220
00221
00222
00223 virtual void dealloc()
00224 {
00225 assert( FALSE );
00226 }
00227
00228 virtual const uint get_rec_size(void)
00229 {
00230 assert( FALSE );
00231 return 0;
00232 }
00233 virtual void put_rec_size( uint s )
00234 {
00235 assert( FALSE );
00236 }
00237
00238 virtual pSym find_elem( STRING name )
00239 {
00240 assert( FALSE );
00241 return NULL;
00242 }
00243 virtual void add_elem( pSym sym )
00244 {
00245 assert( FALSE );
00246 }
00247
00248
00249
00250 virtual const pType get_file_base_type(void)
00251 {
00252 assert( FALSE );
00253 return NULL;
00254 }
00255 virtual void set_file_base_type( pType tBase )
00256 {
00257 assert( FALSE );
00258 }
00259 };
00260
00261
00262
00263 enum { time_bad_time,
00264 time_fs,
00265 time_ps,
00266 time_ns,
00267 time_us,
00268 time_ms,
00269 time_sec,
00270 time_min,
00271 time_hr
00272 };
00273
00274
00280 class type_time : public type {
00281 private:
00282 uint time_unit;
00283
00284 public:
00285 type_time(uint unit = time_bad_time ) : type()
00286 {
00287 time_unit = unit;
00288 }
00289
00290 void set_unit(uint unit )
00291 {
00292 time_unit = unit;
00293 }
00294 uint get_unit(void)
00295 {
00296 return time_unit;
00297 }
00298
00299 const uint get_ty_kind(void)
00300 {
00301 return ty_time;
00302 }
00303 };
00304
00305
00306
00307 enum { bad_range_dir,
00308 range_to,
00309 range_downto };
00310
00320 class type_range : public type {
00321 private:
00323 int lhs;
00325 int rhs;
00326 uint direction : 2,
00327 unconstrained : 1,
00328 unused : 29;
00329
00330 public:
00331 type_range() : type()
00332 {
00333 lhs = 0;
00334 rhs = 0;
00335 direction = bad_range_dir;
00336 unconstrained = FALSE;
00337 }
00338 void set_lhs( int l )
00339 {
00340 lhs = l;
00341 }
00342 const int get_lhs(void)
00343 {
00344 return lhs;
00345 }
00346
00347 void set_rhs( int r )
00348 {
00349 rhs = r;
00350 }
00351 const int get_rhs(void)
00352 {
00353 return rhs;
00354 }
00355
00356 void set_dir( uint dir )
00357 {
00358 direction = dir;
00359 }
00360 const uint get_dir(void)
00361 {
00362 return direction;
00363 }
00364
00365 void set_range( int l, int r, uint dir )
00366 {
00367 set_lhs( l );
00368 set_rhs( r );
00369 set_dir( dir );
00370 }
00371
00372 void set_box(void)
00373 {
00374 unconstrained = TRUE;
00375 }
00376 void unset_box(void)
00377 {
00378 unconstrained = FALSE;
00379 }
00380 const Boolean is_box(void)
00381 {
00382 return unconstrained;
00383 }
00384
00385 const uint get_ty_kind(void)
00386 {
00387 return ty_range;
00388 }
00389 };
00390
00391
00392
00393
00394 class type_real : public type {
00395 public:
00396 type_real() : type() {}
00397 const uint get_ty_kind(void)
00398 {
00399 return ty_real;
00400 }
00401 };
00402
00403
00424 class type_array : public type {
00425 private:
00426 uchar num_dims;
00427 uint size;
00428 pTypeRange range;
00429 pType base_type;
00430
00431 public:
00432 type_array() : type()
00433 {
00434 num_dims = 0;
00435 size = 0;
00436 range = NULL;
00437 base_type = NULL;
00438 }
00439
00440 const uchar get_num_dims(void)
00441 {
00442 return num_dims;
00443 }
00444 void set_num_dims( uint ndim )
00445 {
00446 num_dims = (uchar)ndim;
00447 }
00448
00449 const uint get_array_size(void)
00450 {
00451 return size;
00452 }
00453 void set_array__ize( uint s )
00454 {
00455 size = s;
00456 }
00457
00458 const pTypeRange get_array_range(void)
00459 {
00460 return range;
00461 }
00462 void set_array_range( pTypeRange r )
00463 {
00464 range = r;
00465 }
00466
00467 const pType get_array_base_type(void)
00468 {
00469 return base_type;
00470 }
00471 void set_array_base_type( pType tBase )
00472 {
00473 base_type = tBase;
00474 }
00475
00476 const uint get_ty_kind(void)
00477 {
00478 return ty_array;
00479 }
00480 };
00481
00482
00483
00496 class type_record : public type {
00497
00498 private:
00499 uint size;
00500 FIFO_LIST<pSym> elem_list;
00501
00502 public:
00503 type_record() : type()
00504 {
00505 size = 0;
00506 }
00507
00508
00509 void dealloc()
00510 {
00511
00512 elem_list.dealloc();
00513 }
00514
00515 const uint get_rec_size(void)
00516 {
00517 return size;
00518 }
00519 void put_rec_size( uint s )
00520 {
00521 size = s;
00522 }
00523
00524 pSym find_elem( STRING name );
00525
00526
00527 void add_elem( pSym sym )
00528 {
00529 elem_list.add( sym );
00530 }
00531
00532 const uint get_ty_kind(void)
00533 {
00534 return ty_record;
00535 }
00536 };
00537
00538
00539
00540 class type_file : public type {
00541 private:
00542 pType base_type;
00543
00544
00545
00546 public:
00547 type_file() : type()
00548 {
00549 base_type = NULL;
00550 }
00551
00552 const pType get_file_base_type(void)
00553 {
00554 return base_type;
00555 }
00556 void set_file_base_type( pType tBase )
00557 {
00558 base_type = tBase;
00559 }
00560
00561 const uint get_ty_kind(void)
00562 {
00563 return ty_file;
00564 }
00565 };
00566
00567
00568 #endif