home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / FED_PLUS.EXE / TYPE.H < prev    next >
C/C++ Source or Header  |  1994-07-23  |  12KB  |  369 lines

  1. #ifndef TYPE_H
  2. #define TYPE_H
  3.  
  4. /* $Id: type.h,v 1.11 1994/05/11 19:51:05 libes Exp $ */
  5.  
  6. /************************************************************************
  7. ** Module:    Type
  8. ** Description:    This module implements the type abstraction.  It is
  9. **    rather unpleasant, since this abstraction is quite well suited
  10. **    to an object-oriented environment with inheritance.
  11. **
  12. ************************************************************************/
  13.  
  14. /*
  15.  * This software was developed by U.S. Government employees as part of
  16.  * their official duties and is not subject to copyright.
  17.  *
  18.  * $Log: type.h,v $
  19.  * Revision 1.11  1994/05/11  19:51:05  libes
  20.  * numerous fixes
  21.  *
  22.  * Revision 1.10  1993/10/15  18:48:24  libes
  23.  * CADDETC certified
  24.  *
  25.  * Revision 1.8  1993/03/19  20:43:45  libes
  26.  * add is_enum macro
  27.  *
  28.  * Revision 1.7  1993/01/21  19:48:25  libes
  29.  * fix bug in TYPEget_base_type
  30.  *
  31.  * Revision 1.6  1993/01/19  22:16:09  libes
  32.  * *** empty log message ***
  33.  *
  34.  * Revision 1.5  1992/09/16  18:23:45  libes
  35.  * added some functions for easier access to base types
  36.  *
  37.  * Revision 1.4  1992/08/18  17:12:41  libes
  38.  * rm'd extraneous error messages
  39.  *
  40.  * Revision 1.3  1992/06/08  18:06:24  libes
  41.  * prettied up interface to print_objects_when_running
  42.  */
  43.  
  44. /*************/
  45. /* constants */
  46. /*************/
  47.  
  48. #define TYPE_NULL        (Type)0
  49.     /* since we can't evaluate true size of many aggregates, prepare */
  50.     /* to grow them by chunks of this size */
  51. #define AGGR_CHUNK_SIZE    30
  52.  
  53. /* these are all orthogonal types */
  54. enum type_enum {
  55.     unknown_ = 0,    /* 0 catches uninit. errors */
  56.     special_,    /* placeholder, given meaning by it's owner, */
  57.             /* such as Type_Dont_Care, Type_Bad, Type_User_Def */
  58.     runtime_,    /* cannot be further determined until runtime */
  59.     integer_,
  60.     real_,
  61.     string_,
  62.     binary_,
  63.     boolean_,
  64.     logical_,
  65.  
  66.     /* formals-only */
  67.     number_,
  68.     generic_,
  69.  
  70.     /* aggregates */
  71.     aggregate_,    /* as a formal */
  72.     array_,
  73.     bag_,
  74.     set_,
  75.     list_,
  76.     last_aggregate_,/* not real, just for easier computation */
  77.  
  78.     oneof_,
  79.  
  80.             /* while they are really used for different */
  81.             /* purposes, it might be worth considering */
  82.             /* collapsing entity_ and entity_list_ */
  83.     entity_,    /* single entity */
  84.     entity_list_,    /* linked list of entities */
  85.     enumeration_,
  86.     select_,
  87.     reference_,    /* something only defined by a base type, i.e., a */
  88.             /* type reference */
  89.     query_,
  90.     op_,        /* something with an operand */
  91.     inverse_,    /* is? an inverse */
  92.  
  93.     identifier_,    /* simple identifier in an expression */
  94.     attribute_,    /* attribute reference (i.e., expr->u.variable) */
  95.     derived_,/*?*/
  96.     funcall_,    /* a function call and actual parameters */
  97.  
  98.     self_
  99.        };
  100.  
  101. /*****************/
  102. /* packages used */
  103. /*****************/
  104.  
  105. #include "expbasic.h"    /* get basic definitions */
  106. #include "symbol.h"
  107. #include "object.h"
  108. #include "scope.h"
  109.  
  110. /************/
  111. /* typedefs */
  112. /************/
  113.  
  114. /*typedef struct Scope    *Type;*/
  115. typedef struct TypeHead    *TypeHead;
  116. typedef struct TypeBody    *TypeBody;
  117. typedef enum type_enum    TypeType;
  118.  
  119. /* following are all for backwards compatibility - not otherwise necessary */
  120. typedef Type        Aggregate_Type, Composed_Type, Sized_Type, Type_Reference;
  121. typedef Aggregate_Type    Array_Type, List_Type, Bag_Type;
  122. typedef Bag_Type    Set_Type;
  123. typedef Composed_Type    Entity_Type, Enumeration_Type, Select_Type;
  124. typedef Sized_Type    Integer_Type, Real_Type, String_Type, Binary_Type;
  125.  
  126. /* provide a replacement for Class */
  127. typedef enum type_enum    Class_Of_Type;
  128. typedef enum type_enum    Class;
  129. #define OBJget_class(typ)    ((typ)->u.type->body->type)
  130. #define CLASSinherits_from    TYPEinherits_from
  131.  
  132. /* backwards compatibility */
  133. #define Class_Integer_Type    integer_
  134. #define Class_Number_Type    number_
  135. #define Class_Real_Type        real_
  136. #define Class_Entity_Type    entity_
  137. #define Class_Entity_List_Type    entity_list_
  138. #define    Class_Enumeration_Type    enumeration_
  139. #define Class_Boolean_Type    boolean_
  140. #define Class_Logical_Type    logical_
  141. #define Class_Binary_Type    binary_
  142. #define Class_String_Type    string_
  143. #define Class_Array_Type    array_
  144. #define Class_List_Type        list_
  145. #define Class_Set_Type        set_
  146. #define Class_Bag_Type        bag_
  147. #define Class_Generic_Type    generic_
  148. #define Class_Select_Type    select_
  149. #define Class_Reference_Type    reference_
  150. #define Class_Aggregate_Type    aggregate_
  151.  
  152. /****************/
  153. /* modules used */
  154. /****************/
  155.  
  156. #include "dict.h"
  157. #include "entity.h"
  158. #include "expr.h"
  159. #include "scope.h"
  160.  
  161. /***************************/
  162. /* hidden type definitions */
  163. /***************************/
  164.  
  165. struct TypeHead {
  166.     Type head;            /* if we are a defined type */
  167.                     /* this is who we point to */
  168.     struct TypeBody    *body;        /* true type, ignoring defined types */
  169. #if 0
  170.     /* if we are concerned about memory (over time) uncomment this and */
  171.     /* other references to refcount in parser and TYPEresolve.  It is */
  172.     /* explained in TYPEresolve. */
  173.     int refcount;
  174. #endif
  175. };
  176.  
  177. struct TypeBody {
  178. #if 1
  179.     struct TypeHead *head;        /* for debugging only */
  180. #endif
  181.     enum type_enum type;        /* bits describing this type, int, real, etc */
  182.     struct {
  183.         unsigned unique        :1;
  184.         unsigned optional    :1;
  185.         unsigned fixed        :1;
  186.         unsigned shared        :1;    /* type is shared */
  187.         unsigned repeat        :1;    /* expression is a repeat count*/
  188.         unsigned encoded    :1;    /* encoded string */
  189.     } flags;
  190.     Type base;    /* underlying base type if any */
  191.                 /* can also contain true type if this type */
  192.                 /* is a type reference */
  193.     Type tag;        /* optional tag */
  194. /* a lot of the stuff below can be unionized */
  195.     Expression precision;
  196.     Linked_List list;    /* used by select_types */
  197.                 /* and composed types, such as for a */
  198.                 /* list of entities in an instance */
  199. /*    Dictionary enumeration;    *//* only used by enumerations */
  200.     Expression upper;
  201.     Expression lower;
  202.     struct Scope *entity;        /* only used by entity types */
  203. };
  204.  
  205. /********************/
  206. /* global variables */
  207. /********************/
  208.  
  209. #ifdef TYPE_C
  210. #include "defstart.h"
  211. #else
  212. #include "decstart.h"
  213. #endif    /*  TYPE_C  */
  214.  
  215. /* Very commonly-used read-only types */
  216. /* non-constant versions probably aren't necessary? */
  217. GLOBAL Type Type_Bad;
  218. GLOBAL Type Type_Unknown;
  219. GLOBAL Type Type_Dont_Care;
  220. GLOBAL Type Type_Runtime;    /* indicates that this object can't be */
  221.                 /* calculated now but must be deferred */
  222.                 /* til (the mythical) runtime */
  223. GLOBAL Type Type_Binary;
  224. GLOBAL Type Type_Boolean;
  225. GLOBAL Type Type_Enumeration;
  226. GLOBAL Type Type_Expression;
  227. GLOBAL Type Type_Aggregate;
  228. GLOBAL Type Type_Integer;
  229. GLOBAL Type Type_Integer;
  230. GLOBAL Type Type_Number;
  231. GLOBAL Type Type_Real;
  232. GLOBAL Type Type_String;
  233. GLOBAL Type Type_String_Encoded;
  234. GLOBAL Type Type_Logical;
  235. GLOBAL Type Type_Set;
  236. GLOBAL Type Type_Attribute;
  237. GLOBAL Type Type_Entity;
  238. GLOBAL Type Type_Funcall;
  239. GLOBAL Type Type_Generic;
  240. GLOBAL Type Type_Identifier;
  241. GLOBAL Type Type_Oneof;
  242. GLOBAL Type Type_Query;
  243. GLOBAL Type Type_Self;
  244. GLOBAL Type Type_Set_Of_String;
  245. GLOBAL Type Type_Set_Of_Generic;
  246. GLOBAL Type Type_Aggregate;
  247.  
  248. GLOBAL struct freelist_head TYPEHEAD_fl;
  249. GLOBAL struct freelist_head TYPEBODY_fl;
  250.  
  251. GLOBAL Error ERROR_corrupted_type    INITIALLY(ERROR_none);
  252.  
  253. #include "de_end.h"
  254.  
  255. /******************************/
  256. /* macro function definitions */
  257. /******************************/
  258.  
  259. #define TYPEHEAD_new()        (struct TypeHead *)MEM_new(&TYPEHEAD_fl)
  260. #define TYPEHEAD_destroy(x)    MEM_destroy(&TYPEHEAD_fl,(Freelist *)(Generic)x)
  261. #define TYPEBODY_new()        (struct TypeBody *)MEM_new(&TYPEBODY_fl)
  262. #define TYPEBODY_destroy(x)    MEM_destroy(&TYPEBODY_fl,(Freelist *)(Generic)x)
  263.  
  264. #define TYPEis(t)        ((t)->u.type->body->type)
  265. #define TYPEis_identifier(t)    ((t)->u.type->body->type == identifier_)
  266. #define TYPEis_logical(t)    ((t)->u.type->body->type == logical_)
  267. #define TYPEis_boolean(t)    ((t)->u.type->body->type == boolean_)
  268. #define TYPEis_string(t)    ((t)->u.type->body->type == string_)
  269. #define TYPEis_expression(t)    ((t)->u.type->body->type == op_)
  270. #define TYPEis_oneof(t)        ((t)->u.type->body->type == oneof_)
  271. #define TYPEis_entity(t)    ((t)->u.type->body->type == entity_)
  272. #define TYPEis_enumeration(t)    ((t)->u.type->body->type == enumeration_)
  273. /*#define TYPEis_aggregate(t)    ((t)->u.type->body->type >= aggregate_ && (t)->u.type->body->type < last_aggregate_)*/
  274. #define TYPEis_aggregate(t)    ((t)->u.type->body->base)
  275. #define TYPEis_aggregate_raw(t)    ((t)->u.type->body->type == aggregate_)
  276. #define TYPEis_array(t)        ((t)->u.type->body->type == array_)
  277. #define TYPEis_select(t)    ((t)->u.type->body->type == select_)
  278. #define TYPEis_reference(t)    ((t)->u.type->body->type == reference_)
  279. #define TYPEis_unknown(t)    ((t)->u.type->body->type == unknown_)
  280. #define TYPEis_runtime(t)    ((t)->u.type->body->type == runtime_)
  281. #define TYPEis_shared(t)    ((t)->u.type->body->flags.shared)
  282. #define TYPEis_optional(t)    ((t)->u.type->body->flags.optional)
  283. #define TYPEis_encoded(t)    ((t)->u.type->body->flags.encoded)
  284.  
  285. #define TYPEget_symbol(t)    (&(t)->symbol)
  286.  
  287. #define TYPEget_head(t)        ((t)->u.type->head)
  288. #define TYPEput_head(t,h)    ((t)->u.type->head = (h))
  289.  
  290. #define TYPEget_body(t)        ((t)->u.type->body)
  291. #define TYPEput_body(t,h)    ((t)->u.type->body = (h))
  292.  
  293. #define TYPEget_type(t)        ((t)->u.type->body->type)
  294. #define TYPEget_base_type(t)    ((t)->u.type->body->base)
  295.  
  296. #define TYPEput_name(type,n)    ((type)->symbol.name = (n))
  297. #define TYPEget_name(type)    ((type)->symbol.name)
  298.  
  299. #define TYPEget_where(t)    ((t)->where)
  300. #define TYPEput_where(t,w)    (((t)->where) = w)
  301.  
  302. #define ENT_TYPEget_entity(t)        ((t)->u.type->body->entity)
  303. #define ENT_TYPEput_entity(t,ent)    ((t)->u.type->body->entity = ent)
  304.  
  305. #define COMP_TYPEget_items(t)        ((t)->u.type->body->list)
  306. #define COMP_TYPEput_items(t,lis)    ((t)->u.type->body->list = (lis))
  307. #define COMP_TYPEadd_items(t,lis)    LISTadd_all((t)->u.type->body->list, (lis));
  308.  
  309. /*#define ENUM_TYPEput_items(type,list)    COMP_TYPEput_items(type, list)*/
  310. #define ENUM_TYPEget_items(t)        ((t)->symbol_table)
  311. #define TYPEget_optional(t)        ((t)->u.type->body->flags.optional)
  312. #define TYPEget_unique(t)        ((t)->u.type->body->flags.unique)
  313.  
  314. #define SEL_TYPEput_items(type,list)    COMP_TYPEput_items(type, list)
  315. #define SEL_TYPEget_items(type)        COMP_TYPEget_items(type)
  316.  
  317. #define AGGR_TYPEget_upper_limit(t)    ((t)->u.type->body->upper?(t)->u.type->body->upper:LITERAL_INFINITY)
  318. #define AGGR_TYPEget_lower_limit(t)    ((t)->u.type->body->lower?(t)->u.type->body->lower:LITERAL_ZERO)
  319.  
  320. #define TYPEget_enum_tags(t)        ((t)->symbol_table)
  321.  
  322. /* for backwards compatibility */
  323. #define AGGR_TYPEget_base_type        TYPEget_base_type
  324.  
  325. #define TYPEget_clientData(t)        ((t)->clientData)
  326. #define TYPEput_clientData(t,d)        ((t)->clientData = (d))
  327.  
  328. /***********************/
  329. /* function prototypes */
  330. /***********************/
  331.  
  332. extern Type    TYPEcreate_partial PROTO((struct Symbol *,Scope));
  333.  
  334. extern Type    TYPEcreate PROTO((enum type_enum));
  335. extern Type    TYPEcreate_from_body_anonymously PROTO((TypeBody));
  336. extern Type    TYPEcreate_name PROTO((struct Symbol *));
  337. extern Type    TYPEcreate_nostab PROTO((struct Symbol *,Scope,char));
  338. /*extern Type    TYPEcreate_typedef PROTO((Type, TypeBody,
  339.                         Scope,struct Symbol *));*/
  340. extern TypeBody    TYPEBODYcreate PROTO((enum type_enum));
  341. /*extern Type    TYPEcopy_shallow PROTO((Type));*/
  342. extern void    TYPEinitialize PROTO((void));
  343.  
  344. #if 0
  345. extern Dictionary TYPEget_enum_tags PROTO((Type));
  346. #endif
  347. extern Boolean TYPEinherits_from PROTO((Type,enum type_enum));
  348. extern Type    TYPEget_nonaggregate_base_type PROTO((Type));
  349.  
  350. extern Type TYPEcreate_user_defined_type PROTO((Type,Scope,struct Symbol *));
  351. extern Type TYPEcreate_user_defined_tag PROTO((Type,Scope,struct Symbol *));
  352.  
  353. #if 0
  354. extern int        TYPEget_size PROTO((Type));
  355. extern Boolean        TYPEcompatible PROTO((Type, Type));
  356. extern Expression     SZD_TYPEget_precision PROTO((Sized_Type));
  357. extern Boolean        SZD_TYPEget_varying PROTO((Sized_Type));
  358. extern Expression     TYPE_REFget_full_name PROTO((Type_Reference *));
  359. #endif /*0*/
  360.  
  361. /********************/
  362. /* inline functions */
  363. /********************/
  364.  
  365. #if supports_inline_functions || defined(TYPE_C)
  366. #endif /* supports_inline_functions || defined(TYPE_C) */
  367.  
  368. #endif    /*  TYPE_H  */
  369.