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 / STMT.H < prev    next >
C/C++ Source or Header  |  1994-07-24  |  8KB  |  256 lines

  1. #ifndef STMT_H
  2. #define STMT_H
  3.  
  4. /* $Id: stmt.h,v 1.2 1993/10/15 18:48:24 libes Exp $ */
  5.  
  6. /************************************************************************
  7. ** Module:    Statement
  8. ** Description:    This module implements the Statement abstraction.  A
  9. **    statement is, in effect, a typeless Expression.  Due to the
  10. **    existence of complex language constructs, however, it often is
  11. **    not practical to implement the abstraction thus.  For this reason,
  12. **    there is a separate module for statements.  This abstraction
  13. **    supports various looping constructs, if/then/else, switch
  14. **    statements, and procedure calls.
  15. ** Constants:
  16. **    STATEMENT_NULL    - the null statement
  17. **
  18. ************************************************************************/
  19.  
  20. /*
  21.  * This software was developed by U.S. Government employees as part of
  22.  * their official duties and is not subject to copyright.
  23.  *
  24.  * $Log: stmt.h,v $
  25.  * Revision 1.2  1993/10/15  18:48:24  libes
  26.  * CADDETC certified
  27.  *
  28.  * Revision 1.5  1993/02/16  03:27:02  libes
  29.  * removed artifical begin/end nesting for improved reconstruction (printing)
  30.  * of original Express file
  31.  *
  32.  * Revision 1.4  1992/08/18  17:12:41  libes
  33.  * rm'd extraneous error messages
  34.  *
  35.  * Revision 1.3  1992/06/08  18:06:24  libes
  36.  * prettied up interface to print_objects_when_running
  37.  */
  38.  
  39. /*************/
  40. /* constants */
  41. /*************/
  42.  
  43. #define STATEMENT_NULL        (Statement)0
  44. #define STATEMENT_LIST_NULL    (Linked_List)0
  45.  
  46. /*****************/
  47. /* packages used */
  48. /*****************/
  49.  
  50. #include "expbasic.h"    /* get basic definitions */
  51. #include "scope.h"
  52.  
  53. /************/
  54. /* typedefs */
  55. /************/
  56.  
  57. typedef struct Statement    *Statement,
  58.                 *Alias,
  59.                 *Assignment,
  60.                 *Case_Statement,
  61.                 *Compound_Statement,
  62.                 *Conditional,
  63.                 *Loop,
  64.                 *Procedure_Call,
  65.                 *Return_Statement;
  66.  
  67. typedef struct Scope *Increment;
  68.  
  69. /****************/
  70. /* modules used */
  71. /****************/
  72.  
  73. #include "expr.h"
  74. #include "alg.h"
  75.  
  76. /***************************/
  77. /* hidden type definitions */
  78. /***************************/
  79.  
  80. #define STMT_ASSIGN    0x1
  81. #define STMT_CASE    0x2
  82. #define STMT_COMPOUND    0x4
  83. #define STMT_COND    0x8
  84. #define STMT_LOOP    0x10
  85. #define STMT_PCALL    0x20
  86. #define STMT_RETURN    0x40
  87. #define STMT_ALIAS    0x80
  88. #define STMT_SKIP    0x100
  89. #define STMT_ESCAPE    0x200
  90.  
  91. /* these should probably all be expression types */
  92.  
  93. struct Statement {
  94.     Symbol symbol;    /* can hold pcall or alias name */
  95.             /* but otherwise is not used for anything */
  96.     int type;    /* one of STMT_XXX above */
  97.     /* hey, is there nothing in common beside symbol and private data?? */
  98.     union u_statement {
  99.         struct Alias        *alias;
  100.         struct Assignment    *assign;
  101.         struct Case_Statement    *Case;
  102.         struct Compound_Statement *compound;
  103.         struct Conditional    *cond;
  104.         struct Loop        *loop;
  105.         struct Procedure_Call    *proc;
  106.         struct Return_Statement    *ret;
  107.         /* skip & escape have no data */
  108.     } u;
  109. };
  110.  
  111. struct Alias {
  112.     struct Scope *scope;
  113.     struct Variable *variable;
  114.     Linked_List statements;        /* list of statements */
  115. };
  116.  
  117. struct Assignment {
  118.     Expression lhs;
  119.     Expression rhs;
  120. };
  121.  
  122. struct Case_Statement {
  123.     Expression selector;
  124.     Linked_List cases;
  125. };
  126.  
  127. struct Compound_Statement {
  128.     Linked_List    statements;
  129. };
  130.  
  131. struct Conditional {
  132.     Expression test;
  133.     Linked_List code;        /* list of statements */
  134.     Linked_List otherwise;        /* list of statements */
  135. };
  136.  
  137. struct Loop {
  138.     struct Scope *scope;        /* scope for increment control */
  139.     Expression while_expr;
  140.     Expression until_expr;
  141.     Linked_List statements;        /* list of statements */
  142. };
  143.  
  144. /* this is an element in the optional Loop scope */
  145. struct Increment {
  146.     Expression init;
  147.     Expression end;
  148.     Expression increment;
  149. };
  150.  
  151. struct Procedure_Call {
  152.     struct Scope *procedure;
  153.     Linked_List    parameters;    /* list of expressions */
  154. };
  155.  
  156. struct Return_Statement {
  157.     Expression value;
  158. };
  159.  
  160.  
  161.  
  162. /********************/
  163. /* global variables */
  164. /********************/
  165.  
  166. #ifdef STMT_C
  167. #include "defstart.h"
  168. #else
  169. #include "decstart.h"
  170. #endif /*STATEMENT_C*/
  171.  
  172. GLOBAL struct freelist_head STMT_fl;
  173.  
  174. GLOBAL struct freelist_head ALIAS_fl;
  175. GLOBAL struct freelist_head ASSIGN_fl;
  176. GLOBAL struct freelist_head CASE_fl;
  177. GLOBAL struct freelist_head COMP_STMT_fl;
  178. GLOBAL struct freelist_head COND_fl;
  179. GLOBAL struct freelist_head LOOP_fl;
  180. GLOBAL struct freelist_head PCALL_fl;
  181. GLOBAL struct freelist_head RET_fl;
  182. GLOBAL struct freelist_head INCR_fl;
  183.  
  184. GLOBAL Statement    STATEMENT_ESCAPE    INITIALLY(STATEMENT_NULL);
  185. GLOBAL Statement    STATEMENT_SKIP        INITIALLY(STATEMENT_NULL);
  186.  
  187. #include "de_end.h"
  188.  
  189. /******************************/
  190. /* macro function definitions */
  191. /******************************/
  192.  
  193. #define STMT_new()    (struct Statement *)MEM_new(&STMT_fl)
  194. #define STMT_destroy(x)    MEM_destroy(&STMT_fl,(Freelist *)(Generic)x)
  195.  
  196. #define ALIAS_new()        (struct Alias *)MEM_new(&ALIAS_fl)
  197. #define ALIAS_destroy(x)        MEM_destroy(&ALIAS_fl,(Freelist *)(Generic)x)
  198. #define ASSIGN_new()        (struct Assignment *)MEM_new(&ASSIGN_fl)
  199. #define ASSIGN_destroy(x)        MEM_destroy(&ASSIGN_fl,(Freelist *)(Generic)x)
  200. #define CASE_new()        (struct Case_Statement *)MEM_new(&CASE_fl)
  201. #define CASE_destroy(x)        MEM_destroy(&CASE_fl,(Freelist *)(Generic)x)
  202. #define COMP_STMT_new()        (struct Compound_Statement *)MEM_new(&COMP_STMT_fl)
  203. #define COMP_STMT_destroy(x)        MEM_destroy(&COMP_STMT_fl,(Freelist *)(Generic)x)
  204. #define COND_new()        (struct Conditional *)MEM_new(&COND_fl)
  205. #define COND_destroy(x)        MEM_destroy(&COND_fl,(Freelist *)(Generic)x)
  206. #define LOOP_new()        (struct Loop *)MEM_new(&LOOP_fl)
  207. #define LOOP_destroy(x)        MEM_destroy(&LOOP_fl,(Freelist *)(Generic)x)
  208. #define PCALL_new()        (struct Procedure_Call *)MEM_new(&PCALL_fl)
  209. #define PCALL_destroy(x)    MEM_destroy(&PCALL_fl,(Freelist *)(Generic)x)
  210. #define RET_new()        (struct Return_Statement *)MEM_new(&RET_fl)
  211. #define RET_destroy(x)        MEM_destroy(&RET_fl,(Freelist *)(Generic)x)
  212.  
  213. #define INCR_new()        (struct Increment *)MEM_new(&INCR_fl)
  214. #define INCR_destroy(x)        MEM_destroy(&INCR_fl,(Freelist *)(char *)x)
  215.  
  216. #define    ASSIGNget_lhs(s)    ((s)->u.assign->lhs)
  217. #define    ASSIGNget_rhs(s)    ((s)->u.assign->rhs)
  218. #define    CASEget_selector(s)    ((s)->u.Case->selector)
  219. #define    CASEget_items(s)    ((s)->u.Case->cases)
  220. #define    COMP_STMTget_items(s)    ((s)->u.compound->statements)
  221. #define    CONDget_condition(s)    ((s)->u.cond->test)
  222. #define    CONDget_then_clause(s)    ((s)->u.cond->code)
  223. #define    CONDget_else_clause(s)    ((s)->u.cond->otherwise)
  224. #define    LOOPget_while(s)    ((s)->u.loop->while)
  225. #define    LOOPget_until(s)    ((s)->u.loop->until)
  226. #define    LOOPget_body(s)        ((s)->u.loop->statement)
  227. #define    PCALLget_procedure(s)    ((s)->u.proc->procedure)
  228. #define    PCALLget_parameters(s)    ((s)->u.proc->parameters)
  229. #define    RETget_expression(s)    ((s)->u.ret->value)
  230.  
  231. /***********************/
  232. /* function prototypes */
  233. /***********************/
  234.  
  235. extern Statement    STMTcreate PROTO((int));
  236. extern Statement    ALIAScreate PROTO((struct Scope *,Variable,Linked_List));
  237. extern Statement    CASEcreate PROTO((Expression , Linked_List));
  238. extern Statement    ASSIGNcreate PROTO((Expression , Expression ));
  239. extern Statement    COMP_STMTcreate PROTO((Linked_List));
  240. extern Statement    CONDcreate PROTO((Expression,Linked_List,Linked_List));
  241. extern Statement    LOOPcreate PROTO((struct Scope *,Expression,Expression,Linked_List));
  242. extern Statement    PCALLcreate PROTO((Linked_List));
  243. extern Statement    RETcreate PROTO((Expression ));
  244. extern void        STMTinitialize PROTO((void));
  245. extern struct Scope *INCR_CTLcreate PROTO((Symbol *, Expression start,
  246.            Expression end, Expression increment));
  247.  
  248. /********************/
  249. /* inline functions */
  250. /********************/
  251.  
  252. #if supports_inline_functions || defined(STMT_C)
  253. #endif /* supports_inline_functions || defined(STATEMENT_C) */
  254.  
  255. #endif /*STATEMENT_H*/
  256.