home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / tree-misc.h < prev    next >
C/C++ Source or Header  |  1995-02-21  |  7KB  |  362 lines

  1. // tree-misc.h                                      -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #if !defined (octave_tree_misc_h)
  25. #define octave_tree_misc_h 1
  26.  
  27. class ostream;
  28. class Octave_object;
  29. class tree_constant;
  30. class tree_command;
  31. class tree_expression;
  32. class tree_simple_assignment_expression;
  33. class tree_identifier;
  34. class symbol_record;
  35. class symbol_table;
  36.  
  37. class tree_statement;
  38. class tree_statement_list;
  39. class tree_argument_list;
  40. class tree_parameter_list;
  41. class tree_return_list;
  42. class tree_va_return_list;
  43. class tree_global;
  44. class tree_global_init_list;
  45.  
  46. #include <SLList.h>
  47.  
  48. #include "tree-base.h"
  49. #include "tree-expr.h"
  50. #include "tree-const.h"
  51. #include "tree-cmd.h"
  52.  
  53. // A list of expressions and commands to be executed.
  54.  
  55. class
  56. tree_statement : public tree_print_code
  57. {
  58. friend class tree_statement_list;
  59.  
  60. public:
  61.   tree_statement (void)
  62.     {
  63.       command = 0;
  64.       expression = 0;
  65.       print_flag = 1;
  66.     }
  67.  
  68.   tree_statement (tree_command *c)
  69.     {
  70.       command = c;
  71.       expression = 0;
  72.       print_flag = 1;
  73.     }
  74.  
  75.   tree_statement (tree_expression *e)
  76.     {
  77.       command = 0;
  78.       expression = e;
  79.       print_flag = 1;
  80.     }
  81.  
  82.   ~tree_statement (void);
  83.  
  84.   void set_print_flag (int print)
  85.     { print_flag = print; }
  86.  
  87.   void print_code (ostream& os);
  88.  
  89. private:
  90.   tree_command *command;    // Command to execute.
  91.   tree_expression *expression;    // Command to execute.
  92.   int print_flag;        // Print result of eval for this command?
  93. };
  94.  
  95. class
  96. tree_statement_list : public SLList<tree_statement *>, public tree_print_code
  97. {
  98. public:
  99.   tree_statement_list (void) : SLList<tree_statement *> () { }
  100.   tree_statement_list (tree_statement *s) : SLList<tree_statement *> ()
  101.     { append (s); }
  102.  
  103.   ~tree_statement_list (void)
  104.     {
  105.       while (! empty ())
  106.     {
  107.       tree_statement *t = remove_front ();
  108.       delete t;
  109.     }
  110.     }
  111.  
  112.   tree_constant eval (int print);
  113.  
  114.   Octave_object eval (int print, int nargout);
  115.  
  116.   void print_code (ostream& os);
  117. };
  118.  
  119. // Argument lists.  Used to hold the list of expressions that are the
  120. // arguments in a function call or index expression.
  121.  
  122. class
  123. tree_argument_list : public SLList<tree_expression *>, public tree_print_code
  124. {
  125. public:
  126.   tree_argument_list (void) : SLList<tree_expression *> () { }
  127.   tree_argument_list (tree_expression *t) : SLList<tree_expression *> ()
  128.     { append (t); }
  129.  
  130.   ~tree_argument_list (void)
  131.     {
  132.       while (! empty ())
  133.     {
  134.       tree_expression *t = remove_front ();
  135.       delete t;
  136.     }
  137.     }
  138.  
  139.   Octave_object convert_to_const_vector (void);
  140.  
  141.   void print_code (ostream& os);
  142. };
  143.  
  144. // Parameter lists.  Used to hold the list of input and output
  145. // parameters in a function definition.  Elements are identifiers
  146. // only.
  147.  
  148. class
  149. tree_parameter_list : public SLList<tree_identifier *>, public tree_print_code
  150. {
  151. public:
  152.   tree_parameter_list (void) : SLList<tree_identifier *> ()
  153.     { marked_for_varargs = 0; }
  154.  
  155.   tree_parameter_list (tree_identifier *t) : SLList<tree_identifier *> ()
  156.     {
  157.       marked_for_varargs = 0;
  158.       append (t);
  159.     }
  160.  
  161.   ~tree_parameter_list (void)
  162.     {
  163.       while (! empty ())
  164.     {
  165.       tree_identifier *t = remove_front ();
  166.       delete t;
  167.     }
  168.     }
  169.  
  170. //  char *name (void) const;
  171.  
  172.   void mark_as_formal_parameters (void);
  173.  
  174.   void mark_varargs (void)
  175.     { marked_for_varargs = 1; }
  176.  
  177.   int takes_varargs (void) const
  178.     { return marked_for_varargs; }
  179.  
  180.   void mark_varargs_only (void)
  181.     { marked_for_varargs = -1; }
  182.  
  183.   int varargs_only (void)
  184.     { return (marked_for_varargs < 0); }
  185.  
  186.   void initialize_undefined_elements (tree_constant& val);
  187.  
  188.   void define_from_arg_vector (const Octave_object& args);
  189.  
  190.   int is_defined (void);
  191.  
  192.   Octave_object convert_to_const_vector (tree_va_return_list *vr_list);
  193.  
  194.   void print_code (ostream& os);
  195.  
  196. private:
  197.   int marked_for_varargs;
  198. };
  199.  
  200. // Return lists.  Used to hold the right hand sides of multiple
  201. // assignment expressions.
  202.  
  203. class
  204. tree_return_list : public SLList<tree_index_expression *>,
  205.   public tree_print_code 
  206. {
  207. public:
  208.   tree_return_list (void) : SLList<tree_index_expression *> () { }
  209.   tree_return_list (tree_index_expression *t)
  210.     : SLList<tree_index_expression *> ()
  211.       { append (t); }
  212.  
  213.   ~tree_return_list (void)
  214.     {
  215.       while (! empty ())
  216.     {
  217.       tree_index_expression *t = remove_front ();
  218.       delete t;
  219.     }
  220.     }
  221.  
  222.   void print_code (ostream& os);
  223. };
  224.  
  225. class
  226. tree_va_return_list : public SLList<tree_constant>
  227. {
  228. public:
  229.   tree_va_return_list (void) : SLList<tree_constant> () { }
  230. };
  231.  
  232. // List of expressions that make up a global statement.
  233.  
  234. class
  235. tree_global : public tree_print_code
  236. {
  237. public:
  238.   tree_global (void)
  239.     {
  240.       ident = 0;
  241.       assign_expr = 0;
  242.     }
  243.  
  244.   tree_global (tree_identifier *id)
  245.     {
  246.       ident = id;
  247.       assign_expr = 0;
  248.     }
  249.  
  250.   tree_global (tree_simple_assignment_expression *ass)
  251.     {
  252.       ident = 0;
  253.       assign_expr = ass;
  254.     }
  255.  
  256.   ~tree_global (void)
  257.     {
  258.       delete ident;
  259.       delete assign_expr;
  260.     }
  261.  
  262.   void eval (void);
  263.  
  264.   void print_code (ostream& os);
  265.  
  266. private:
  267.   tree_identifier *ident;
  268.   tree_simple_assignment_expression *assign_expr;
  269. };
  270.  
  271. class
  272. tree_global_init_list : public SLList<tree_global *>, public tree_print_code
  273. {
  274. public:
  275.   tree_global_init_list (void) : SLList<tree_global *> () { }
  276.   tree_global_init_list (tree_global *t) : SLList<tree_global *> ()
  277.     { append (t); }
  278.  
  279.   ~tree_global_init_list (void)
  280.     {
  281.       while (! empty ())
  282.     {
  283.       tree_global *t = remove_front ();
  284.       delete t;
  285.     }
  286.     }
  287.  
  288.   void eval (void);
  289.  
  290.   void print_code (ostream& os);
  291. };
  292.  
  293. class
  294. tree_if_clause : public tree_print_code
  295. {
  296. public:
  297.   tree_if_clause (void)
  298.     {
  299.       expr = 0;
  300.       list = 0;
  301.     }
  302.  
  303.   tree_if_clause (tree_statement_list *l)
  304.     {
  305.       expr = 0;
  306.       list = l;
  307.     }
  308.  
  309.   tree_if_clause (tree_expression *e, tree_statement_list *l)
  310.     {
  311.       expr = e;
  312.       list = l;
  313.     }
  314.  
  315.   ~tree_if_clause (void)
  316.     {
  317.       delete expr;
  318.       delete list;
  319.     }
  320.  
  321.   int is_else_clause (void);
  322.  
  323.   int eval (void);
  324.  
  325.   void print_code (ostream& os);
  326.  
  327. private:
  328.   tree_expression *expr;
  329.   tree_statement_list *list;
  330. };
  331.  
  332. class
  333. tree_if_command_list : public SLList<tree_if_clause *>, public tree_print_code
  334. {
  335. public:
  336.   tree_if_command_list (void) : SLList<tree_if_clause *> () { }
  337.   tree_if_command_list (tree_if_clause *t) : SLList<tree_if_clause *> ()
  338.     { append (t); }
  339.  
  340.   ~tree_if_command_list (void)
  341.     {
  342.       while (! empty ())
  343.     {
  344.       tree_if_clause *t = remove_front ();
  345.       delete t;
  346.     }
  347.     }
  348.  
  349.   void eval (void);
  350.  
  351.   void print_code (ostream& os);
  352. };
  353.  
  354. #endif
  355.  
  356. /*
  357. ;;; Local Variables: ***
  358. ;;; mode: C++ ***
  359. ;;; page-delimiter: "^/\\*" ***
  360. ;;; End: ***
  361. */
  362.