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 / EXPR.H < prev    next >
C/C++ Source or Header  |  1994-07-24  |  9KB  |  293 lines

  1. #ifndef EXPR_H
  2. #define EXPR_H
  3.  
  4. /* $Id: expr.h,v 1.2 1993/10/15 18:48:24 libes Exp $ */
  5.  
  6. /************************************************************************
  7. ** Module:    Expression
  8. ** Description:    This module implements the Expression abstraction.
  9. **    Several types of expressions are supported: identifiers,
  10. **    literals, operations (arithmetic, logical, array indexing,
  11. **    etc.), function calls, and query expressions.  Every expression
  12. **    is marked with a type.
  13. ** Constants:
  14. **    EXPRESSION_NULL        - the null expression
  15. **    LITERAL_E        - a real literal with the value 2.7182...
  16. **    LITERAL_EMPTY_SET    - a set literal representing the empty set
  17. **    LITERAL_INFINITY    - a numeric literal representing infinity
  18. **    LITERAL_PI        - a real literal with the value 3.1415...
  19. **    LITERAL_ZERO        - an integer literal representing 0
  20. **
  21. ************************************************************************/
  22.  
  23. /*
  24.  * This software was developed by U.S. Government employees as part of
  25.  * their official duties and is not subject to copyright.
  26.  *
  27.  * $Log: expr.h,v $
  28.  * Revision 1.2  1993/10/15  18:48:24  libes
  29.  * CADDETC certified
  30.  *
  31.  * Revision 1.6  1993/02/16  03:21:31  libes
  32.  * fixed numerous confusions of type with return type
  33.  * fixed implicit loop variable type declarations
  34.  * improved errors
  35.  *
  36.  * Revision 1.5  1993/01/19  22:44:17  libes
  37.  * *** empty log message ***
  38.  *
  39.  * Revision 1.4  1992/08/27  23:39:59  libes
  40.  * *** empty log message ***
  41.  *
  42.  * Revision 1.3  1992/08/18  17:12:41  libes
  43.  * rm'd extraneous error messages
  44.  *
  45.  * Revision 1.2  1992/06/08  18:06:24  libes
  46.  * prettied up interface to print_objects_when_running
  47.  */
  48.  
  49. /*************/
  50. /* constants */
  51. /*************/
  52.  
  53. #define EXPRESSION_NULL    (Expression)0
  54.  
  55. /*****************/
  56. /* packages used */
  57. /*****************/
  58.  
  59. #include <math.h>
  60. #include "expbasic.h"    /* get basic definitions */
  61.  
  62. #ifndef MAXINT
  63. #define MAXINT (~(1 << 31))
  64. #endif
  65.  
  66. /************/
  67. /* typedefs */
  68. /************/
  69.  
  70. typedef enum {
  71.     OP_AND,            OP_ANDOR,
  72.     OP_ARRAY_ELEMENT,    OP_CONCAT,
  73.     OP_DIV,            OP_DOT,            OP_EQUAL,
  74.     OP_EXP,            OP_GREATER_EQUAL,    OP_GREATER_THAN,
  75.     OP_GROUP,
  76.     OP_IN,            OP_INST_EQUAL,        OP_INST_NOT_EQUAL,
  77.     OP_LESS_EQUAL,        OP_LESS_THAN,        OP_LIKE,
  78.     OP_MINUS,        OP_MOD,            OP_NEGATE,
  79.     OP_NOT,            OP_NOT_EQUAL,        OP_OR,
  80.     OP_PLUS,        OP_REAL_DIV,        OP_SUBCOMPONENT,
  81.     OP_TIMES,        OP_XOR,            OP_UNKNOWN,
  82.     OP_LAST    /* must be last - used only to size tables */
  83. } Op_Code;
  84.  
  85. typedef struct Qualified_Attr    Qualified_Attr;
  86. typedef struct Expression    *Expression;
  87. typedef Expression        Ary_Expression, One_Of_Expression, Identifier,
  88.                 Literal;
  89. typedef struct Query        *Query;
  90. typedef One_Of_Expression    Function_Call;
  91. typedef Ary_Expression        Ternary_Expression, Binary_Expression,
  92.                 Unary_Expression;
  93. typedef Literal            Aggregate_Literal, Integer_Literal,
  94.                 Logical_Literal, Real_Literal, String_Literal,
  95.                 Binary_Literal;
  96.  
  97. /****************/
  98. /* modules used */
  99. /****************/
  100.  
  101. #include "entity.h"
  102. #include "type.h"
  103. #include "variable.h"
  104. #include "alg.h"
  105. #include "scope.h"
  106.  
  107. /***************************/
  108. /* hidden type definitions */
  109. /***************************/
  110.  
  111. /* expression types */
  112.  
  113. struct Qualified_Attr {
  114.     struct Expression *complex;    /* complex entity instance */
  115.     Symbol *entity;
  116.     Symbol *attribute;
  117. };
  118.  
  119. struct Op_Subexpression {
  120.     Op_Code op_code;
  121.     Expression op1;
  122.     Expression op2;
  123.     Expression op3;
  124. };
  125.  
  126. struct Query {
  127.     Variable local;
  128.     Expression aggregate;    /* set from which to test */
  129.     Expression expression;    /* logical expression */
  130.     struct Scope *scope;
  131. };
  132.  
  133. struct Funcall {
  134.     struct Scope *function;    /* can also be an entity because entities */
  135.                 /* can be called as functions */
  136.     Linked_List list;
  137. };
  138.  
  139. union expr_union {
  140.     int integer;
  141.     float real;
  142. /*    char *string;        find string name in symbol in Expression */
  143.     char *attribute;    /* inverse .... for 'attr' */
  144.     char *binary;
  145.     int logical;
  146.     Boolean boolean;
  147.     struct Query *query;
  148.     struct Funcall funcall;
  149.  
  150.     /* if etype == aggregate, list of expressions */
  151.     /* if etype == funcall, 1st element of list is funcall or entity */
  152.     /*    remaining elements are parameters */
  153.     Linked_List list;    /* aggregates (bags, lists, sets, arrays) */
  154.                 /* or lists for oneof expressions */
  155.     Expression expression;    /* derived value in derive attrs, or*/
  156.                 /* initializer in local vars, or */
  157.                 /* enumeration tags */
  158.                 /* or oneof value */
  159.     struct Scope *entity;    /* used by subtype exp, group expr */
  160.                 /* and self expr, some funcall's and any */
  161.                 /* expr that results in an entity */
  162.     Variable variable;    /* attribute reference */
  163. };
  164.  
  165. struct Expression {
  166.     Symbol symbol;        /* contains things like funcall names */
  167.                 /* string names, binary values, */
  168.                 /* enumeration names */
  169.     Type type;
  170.     Type return_type;    /* type of value returned by expression */
  171.         /* The difference between 'type' and 'return_type' is */
  172.         /* illustrated by "func(a)".  Here, 'type' is Type_Function */
  173.         /* while 'return_type'  might be Type_Integer (assuming func */
  174.         /* returns an integer). */
  175.     struct Op_Subexpression e;
  176.     union expr_union u;
  177. };
  178.  
  179. /* indexed by the op enumeration values */
  180. struct EXPop_entry {
  181.     char *token;        /* literal token, e.g., "<>" */
  182.     Type (*resolve) PROTO((Expression,struct Scope *));
  183. };
  184.  
  185. /********************/
  186. /* global variables */
  187. /********************/
  188.  
  189. #ifdef EXPR_C
  190. #include "defstart.h"
  191. #else
  192. #include "decstart.h"
  193. #endif /*EXPRESSION_C*/
  194.  
  195. GLOBAL struct EXPop_entry EXPop_table[OP_LAST];
  196.  
  197. GLOBAL Expression     LITERAL_E        INITIALLY(EXPRESSION_NULL);
  198. GLOBAL Expression     LITERAL_INFINITY    INITIALLY(EXPRESSION_NULL);
  199. GLOBAL Expression     LITERAL_PI        INITIALLY(EXPRESSION_NULL);
  200. GLOBAL Expression     LITERAL_ZERO        INITIALLY(EXPRESSION_NULL);
  201. GLOBAL Expression     LITERAL_ONE;
  202.  
  203. GLOBAL Error    ERROR_bad_qualification            INITIALLY(ERROR_none);
  204. GLOBAL Error    ERROR_integer_expression_expected    INITIALLY(ERROR_none);
  205.  
  206. GLOBAL struct freelist_head EXP_fl;
  207. GLOBAL struct freelist_head OP_fl;
  208. GLOBAL struct freelist_head QUERY_fl;
  209. GLOBAL struct freelist_head QUAL_ATTR_fl;
  210.  
  211. #include "de_end.h"
  212.  
  213. /******************************/
  214. /* macro function definitions */
  215. /******************************/
  216.  
  217. #define EXP_new()    (struct Expression *)MEM_new(&EXP_fl)
  218. #define EXP_destroy(x)    MEM_destroy(&EXP_fl,(Freelist *)(Generic)x)
  219. #define OP_new()    (struct Op_Subexpression *)MEM_new(&OP_fl)
  220. #define OP_destroy(x)    MEM_destroy(&OP_fl,(Freelist *)(Generic)x)
  221. #define QUERY_new()    (struct Query *)MEM_new(&QUERY_fl)
  222. #define QUERY_destroy(x) MEM_destroy(&QUERY_fl,(Freelist *)(Generic)x)
  223. #define QUAL_ATTR_new()    (struct Qualified_Attr *)MEM_new(&QUAL_ATTR_fl)
  224. #define QUAL_ATTR_destroy(x) MEM_destroy(&QUAL_ATTR_fl,(Freelist *)(Generic)x)
  225.  
  226. #define EXPget_name(e)            ((e)->symbol.name)
  227. #define ENUMget_name(e)            ((e)->symbol.name)
  228.  
  229. #define BIN_EXPget_operator(e)        ARY_EXPget_operator(e)
  230. #define BIN_EXPget_first_operand(e)    ARY_EXPget_operand(e)
  231.  
  232. #define UN_EXPget_operator(e)        ARY_EXPget_operator(e)
  233. #define UN_EXPget_operand(e)        ARY_EXPget_operand(e)
  234.  
  235. #define FCALLput_parameters(expr,parms)    ((e)->u.funcall.list = (parms))
  236. #define FCALLget_parameters(e)        ((e)->u.funcall.list)
  237. #define FCALLput_function(expr,func)    ((e)->u.funcall.function = (func))
  238. #define FCALLget_function(e)        ((e)->u.funcall.function)
  239. /* assumes the function is not an entity-function! */
  240. #define FCALLget_algorithm(e)        ((e)->u.funcall.function->u.function->body)
  241.  
  242. #define INT_LITget_value(e)        ((e)->u.integer)
  243. #define LOG_LITget_value(e)        ((e)->u.logical)
  244. #define REAL_LITget_value(e)        ((e)->u.real)
  245. #define STR_LITget_value(e)        ((e)->symbol.name)
  246. #define STR_LITput_value(e,s)        ((e)->symbol.name = (s))
  247. #define BIN_LITget_value(e)        ((e)->u.binary)
  248. #define AGGR_LITget_value(e)        ((e)->u.list)
  249. #define EXPget_type(e)            ((e)->type)
  250. #define ARY_EXPget_operand(e)        ((e)->e.op1)
  251. #define ARY_EXPget_operator(e)        ((e)->e.op_code)
  252. #define BIN_EXPget_operand(e)        ((e)->e.op2)
  253. #define TERN_EXPget_second_operand(e)    ((e)->e.op2)
  254. #define TERN_EXPget_third_operand(e)    ((e)->e.op3)
  255. #define    QUERYget_variable(e)        ((e)->u.query->local)
  256. #define QUERYget_source(e)        ((e)->u.query->aggregate)
  257. #define QUERYget_discriminant(e)    ((e)->u.query->expression)
  258. #define ONEOFget_list(e)        ((e)->u.list)
  259.  
  260. /***********************/
  261. /* function prototypes */
  262. /***********************/
  263.  
  264. extern Expression     EXPcreate PROTO((Type));
  265. extern Expression     EXPcreate_simple PROTO((Type));
  266. extern Expression     EXPcreate_from_symbol PROTO((Type,Symbol *));
  267. extern Expression     UN_EXPcreate PROTO((Op_Code, Expression));
  268. extern Expression     BIN_EXPcreate PROTO((Op_Code, Expression, Expression));
  269. extern Expression     TERN_EXPcreate PROTO((Op_Code, Expression, Expression, Expression));
  270. extern Expression     QUERYcreate PROTO((Symbol *, Expression));
  271. extern void        EXPinitialize PROTO((void));
  272. extern Type        EXPtype PROTO((Expression,struct Scope *));
  273. extern int        EXPget_integer_value PROTO((Expression));
  274.  
  275. /********************/
  276. /* inline functions */
  277. /********************/
  278.  
  279. #if defined(EXPR_C)
  280.  
  281. static_inline
  282. int
  283. OPget_number_of_operands(Op_Code op)
  284. {
  285.     if ((op == OP_NEGATE) || (op == OP_NOT)) return 1;
  286.     else if (op == OP_SUBCOMPONENT) return 3;
  287.     else return 2;
  288. }
  289.  
  290. #endif /* supports_inline_functions || defined(EXPRESSION_C) */
  291.  
  292. #endif /*EXPRESSION_H*/
  293.