ucstmt.h

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000 The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef INCL_UCSTMT
00026 #define INCL_UCSTMT
00027 
00028 #include <vector>
00029 #include "ucloc.h"
00030 #include "uclabel.h"
00031 
00032 class Uc_expression;
00033 class Uc_call_expression;
00034 class Uc_array_expression;
00035 class Uc_function;
00036 class Uc_var_symbol;
00037 
00038 #ifndef ALPHA_LINUX_CXX
00039 #  include <iosfwd>
00040 #endif
00041 
00042 /*
00043  *  A statement:
00044  */
00045 class Uc_statement : public Uc_location
00046   {
00047 public:
00048   Uc_statement() : Uc_location()
00049     {  }
00050   virtual ~Uc_statement() {  }
00051           // Generate code.
00052   virtual void gen(std::vector<char>& out, Uc_function *fun) = 0;
00053   };
00054 
00055 /*
00056  *  A group of statements.
00057  */
00058 class Uc_block_statement : public Uc_statement
00059   {
00060     std::vector<Uc_statement *> statements;
00061 public:
00062   Uc_block_statement()
00063     {  }
00064   ~Uc_block_statement();
00065   void add(Uc_statement *stmt)
00066     { statements.push_back(stmt); }
00067           // Generate code.
00068   virtual void gen(std::vector<char>& out, Uc_function *fun);
00069   };
00070 
00071 /*
00072  *  An assignment statement:
00073  */
00074 class Uc_assignment_statement : public Uc_statement
00075   {
00076   Uc_expression *target, *value;
00077 public:
00078   Uc_assignment_statement(Uc_expression *t, Uc_expression *v)
00079     : target(t), value(v)
00080     {  }
00081   ~Uc_assignment_statement();
00082           // Generate code.
00083   virtual void gen(std::vector<char>& out, Uc_function *fun);
00084   };
00085 
00086 /*
00087  *  An IF statement:
00088  */
00089 class Uc_if_statement : public Uc_statement
00090   {
00091   Uc_expression *expr;    // What to test.
00092           // What to execute:
00093   Uc_statement *if_stmt, *else_stmt;
00094 public:
00095   Uc_if_statement(Uc_expression *e, Uc_statement *t, Uc_statement *f)
00096     : expr(e), if_stmt(t), else_stmt(f)
00097     {  }
00098   ~Uc_if_statement();
00099           // Generate code.
00100   virtual void gen(std::vector<char>& out, Uc_function *fun);
00101   };
00102 
00103 /*
00104  *  An WHILE statement:
00105  */
00106 class Uc_while_statement : public Uc_statement
00107   {
00108   Uc_expression *expr;    // What to test.
00109   Uc_statement *stmt;   // What to execute.
00110 public:
00111   Uc_while_statement(Uc_expression *e, Uc_statement *s)
00112     : expr(e), stmt(s)
00113     {  }
00114   ~Uc_while_statement();
00115           // Generate code.
00116   virtual void gen(std::vector<char>& out, Uc_function *fun);
00117   };
00118 
00119 /*
00120  *  An array loop statement:
00121  */
00122 class Uc_arrayloop_statement : public Uc_statement
00123   {
00124   Uc_var_symbol *var;   // Loop variable.
00125   Uc_var_symbol *array;   // Array to loop over.
00126   Uc_var_symbol *index;   // Counter.
00127   Uc_var_symbol *array_size;  // Symbol holding array size.
00128   Uc_statement *stmt;   // What to execute.
00129 public:
00130   Uc_arrayloop_statement(Uc_var_symbol *v, Uc_var_symbol *a)
00131     : var(v), array(a), index(0), array_size(0), stmt(0)
00132     {  }
00133   ~Uc_arrayloop_statement();
00134   void set_statement(Uc_statement *s)
00135     { stmt = s; }
00136   void set_index(Uc_var_symbol *i)
00137     { index = i; }
00138   void set_array_size(Uc_var_symbol *as)
00139     { array_size = as; }
00140   void finish(Uc_function *fun);  // Create tmps. if necessary.
00141           // Generate code.
00142   virtual void gen(std::vector<char>& out, Uc_function *fun);
00143   };
00144 
00145 /*
00146  *  An RETURN statement:
00147  */
00148 class Uc_return_statement : public Uc_statement
00149   {
00150   Uc_expression *expr;    // What to return.  May be 0.
00151 public:
00152   Uc_return_statement(Uc_expression *e = 0) : expr(e)
00153     {  }
00154   ~Uc_return_statement();
00155           // Generate code.
00156   virtual void gen(std::vector<char>& out, Uc_function *fun);
00157   };
00158 
00159 /*
00160  *  BREAK statement:
00161  */
00162 class Uc_break_statement : public Uc_statement
00163   {
00164 public:
00165   Uc_break_statement() {  }
00166           // Generate code.
00167   virtual void gen(std::vector<char>& out, Uc_function *fun);
00168   };
00169 
00170 /*
00171  *  a LABEL statement:
00172  */
00173 class Uc_label_statement : public Uc_statement
00174 {
00175   Uc_label *label;
00176  public:
00177   Uc_label_statement(Uc_label *l) : label(l)
00178     { }
00179   virtual void gen(std::vector<char>& out, Uc_function *fun);
00180 };
00181 
00182 /*
00183  *  a GOTO statement:
00184  */
00185 class Uc_goto_statement : public Uc_statement
00186 {
00187   char *label;
00188  public:
00189   Uc_goto_statement(char *l) : label(l)
00190     { }
00191   virtual void gen(std::vector<char>& out, Uc_function *fun);
00192 };
00193 
00194 
00195 
00196 /*
00197  *  A CONVERSE statement is a loop that prompts for a user response at
00198  *  the top, or exits the loop if there are no possible answers.
00199  */
00200 class Uc_converse_statement : public Uc_statement
00201   {
00202   Uc_statement *stmt;   // What to execute.
00203 public:
00204   Uc_converse_statement(Uc_statement *s)
00205     : stmt(s)
00206     {  }
00207   ~Uc_converse_statement();
00208           // Generate code.
00209   virtual void gen(std::vector<char>& out, Uc_function *fun);
00210   };
00211 
00212 /*
00213  *  Conversation CASE statement:
00214  */
00215 class Uc_converse_case_statement : public Uc_statement
00216   {
00217   int string_offset;    // Offset of string to compare.
00218   bool remove;      // True to remove answer.
00219   Uc_statement *statements; // Execute these.
00220 public:
00221   Uc_converse_case_statement(int soff, bool rem, Uc_statement *stmts)
00222     : string_offset(soff), remove(rem), statements(stmts)
00223     {  }
00224   ~Uc_converse_case_statement()
00225     { delete statements; }
00226           // Generate code.
00227   virtual void gen(std::vector<char>& out, Uc_function *fun);
00228   };
00229 
00230 /*
00231  *  A CONVERSE2 statement provides a less wordy way to implement a
00232  *  conversation.  It provides for CASE entries for the comparisons, and
00233  *  also generates push/pop-answers so these can be nested.
00234  */
00235 class Uc_converse2_statement : public Uc_statement
00236   {
00237   static int nest;    // Keeps track of nesting.
00238   Uc_expression *answers;   // Answers to add.
00239   Uc_statement *cases;    // What to execute.
00240 public:
00241   Uc_converse2_statement(Uc_expression *a, Uc_statement *cs)
00242     : answers(a), cases(cs)
00243     {  }
00244   ~Uc_converse2_statement();
00245           // Generate code.
00246   virtual void gen(std::vector<char>& out, Uc_function *fun);
00247   };
00248 
00249 /*
00250  *  Add string to current message (for conversations).
00251  */
00252 class Uc_message_statement : public Uc_statement
00253   {
00254   Uc_array_expression *msgs;
00255 public:
00256   Uc_message_statement(Uc_array_expression *m) : msgs(m) {  }
00257           // Generate code.
00258   virtual void gen(std::vector<char>& out, Uc_function *fun);
00259   };
00260 
00261 /*
00262  *  Print message on screen (in conversation).
00263  */
00264 class Uc_say_statement : public Uc_message_statement
00265   {
00266 public:
00267   Uc_say_statement(Uc_array_expression *m) : Uc_message_statement(m) 
00268     {  }
00269           // Generate code.
00270   virtual void gen(std::vector<char>& out, Uc_function *fun);
00271   };
00272 
00273 /*
00274  *  Call a function/intrinsic.
00275  */
00276 class Uc_call_statement : public Uc_statement
00277   {
00278   Uc_call_expression *function_call;
00279 public:
00280   Uc_call_statement(Uc_call_expression *f);
00281   ~Uc_call_statement();
00282           // Generate code.
00283   virtual void gen(std::vector<char>& out, Uc_function *fun);
00284   };
00285 
00286 #endif

Generated on Mon Jul 9 14:42:51 2007 for ExultEngine by  doxygen 1.5.1