00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef YStatement_h
00023 #define YStatement_h
00024
00025 #include <string>
00026 using std::string;
00027
00028 #include "ycp/YCode.h"
00029 #include "ycp/SymbolTable.h"
00030 #include "ycp/YSymbolEntry.h"
00031 #include "ycp/Import.h"
00032 #include "ycp/ycpless.h"
00033
00034 class YBlock;
00035
00036
00037
00038 DEFINE_DERIVED_POINTER(YStatement, YCode);
00039 DEFINE_DERIVED_POINTER(YSExpression, YCode);
00040 DEFINE_DERIVED_POINTER(YSBlock, YCode);
00041 DEFINE_DERIVED_POINTER(YSReturn, YCode);
00042 DEFINE_DERIVED_POINTER(YSTypedef, YCode);
00043 DEFINE_DERIVED_POINTER(YSFunction, YCode);
00044 DEFINE_DERIVED_POINTER(YSAssign, YCode);
00045 DEFINE_DERIVED_POINTER(YSBracket, YCode);
00046 DEFINE_DERIVED_POINTER(YSIf, YCode);
00047 DEFINE_DERIVED_POINTER(YSWhile, YCode);
00048 DEFINE_DERIVED_POINTER(YSRepeat, YCode);
00049 DEFINE_DERIVED_POINTER(YSDo, YCode);
00050 DEFINE_DERIVED_POINTER(YSTextdomain, YCode);
00051 DEFINE_DERIVED_POINTER(YSInclude, YCode);
00052 DEFINE_DERIVED_POINTER(YSImport, YCode);
00053 DEFINE_DERIVED_POINTER(YSFilename, YCode);
00054 DEFINE_DERIVED_POINTER(YSSwitch, YCode);
00055
00056
00061 class YStatement : public YCode
00062 {
00063 REP_BODY(YStatement);
00064 int m_line;
00065 public:
00066 YStatement (ykind kind, int line = 0);
00067 YStatement (ykind kind, bytecodeistream & str);
00068 ~YStatement () {};
00069 virtual string toString () const;
00070 std::ostream & toStream (std::ostream & str) const;
00071 int line () const { return m_line; };
00072 virtual YCPValue evaluate (bool cse = false);
00073 constTypePtr type () const { return Type::Void; };
00074 };
00075
00076
00077
00082 class YSExpression : public YStatement
00083 {
00084 REP_BODY(YSExpression);
00085 YCodePtr m_expr;
00086 public:
00087 YSExpression (YCodePtr expr, int line = 0);
00088 YSExpression (bytecodeistream & str);
00089 ~YSExpression ();
00090 string toString () const;
00091 std::ostream & toStream (std::ostream & str) const;
00092 YCPValue evaluate (bool cse = false);
00093 constTypePtr type () const { return Type::Void; };
00094 };
00095
00096
00097
00102 class YSBlock : public YStatement
00103 {
00104 REP_BODY(YSBlock);
00105 YBlockPtr m_block;
00106 public:
00107 YSBlock (YBlockPtr block, int line = 0);
00108 YSBlock (bytecodeistream & str);
00109 ~YSBlock ();
00110 string toString () const;
00111 std::ostream & toStream (std::ostream & str) const;
00112 YCPValue evaluate (bool cse = false);
00113 constTypePtr type () const { return Type::Void; };
00114 };
00115
00116
00117
00122 class YSReturn : public YStatement
00123 {
00124 REP_BODY(YSReturn);
00125 YCodePtr m_value;
00126 public:
00127 YSReturn (YCodePtr value, int line = 0);
00128 YSReturn (bytecodeistream & str);
00129 ~YSReturn ();
00130 void propagate (constTypePtr from, constTypePtr to);
00131 YCodePtr value () const;
00132 void clearValue ();
00133 string toString () const;
00134 std::ostream & toStream (std::ostream & str) const;
00135 YCPValue evaluate (bool cse = false);
00136 constTypePtr type () const { return Type::Void; };
00137 };
00138
00139
00140
00145 class YSTypedef : public YStatement
00146 {
00147 REP_BODY(YSTypedef);
00148 Ustring m_name;
00149 constTypePtr m_type;
00150 public:
00151 YSTypedef (const string &name, constTypePtr type, int line = 0);
00152 YSTypedef (bytecodeistream & str);
00153 ~YSTypedef () {};
00154 string toString() const;
00155 std::ostream & toStream (std::ostream & str) const;
00156 YCPValue evaluate (bool cse = false);
00157 constTypePtr type () const { return Type::Void; };
00158 };
00159
00160
00161
00166 class YSFunction : public YStatement
00167 {
00168 REP_BODY(YSFunction);
00169
00170 YSymbolEntryPtr m_entry;
00171
00172 public:
00173 YSFunction (YSymbolEntryPtr entry, int line = 0);
00174 YSFunction (bytecodeistream & str);
00175 ~YSFunction ();
00176
00177
00178 SymbolEntryPtr entry () const;
00179
00180
00181 YFunctionPtr function () const;
00182
00183 string toString () const;
00184 std::ostream & toStream (std::ostream & str) const;
00185 YCPValue evaluate (bool cse = false);
00186 constTypePtr type () const { return Type::Void; };
00187 };
00188
00189
00190
00196 class YSAssign : public YStatement
00197 {
00198 REP_BODY(YSAssign);
00199 SymbolEntryPtr m_entry;
00200 YCodePtr m_code;
00201 public:
00202 YSAssign (bool definition, SymbolEntryPtr entry, YCodePtr code, int line = 0);
00203 YSAssign (bool definition, bytecodeistream & str);
00204 ~YSAssign ();
00205 string toString () const;
00206 std::ostream & toStream (std::ostream & str) const;
00207 YCPValue evaluate (bool cse = false);
00208 constTypePtr type () const { return Type::Void; };
00209 };
00210
00211
00212
00218 class YSBracket : public YStatement
00219 {
00220 REP_BODY(YSBracket);
00221 SymbolEntryPtr m_entry;
00222 YCodePtr m_arg;
00223 YCodePtr m_code;
00224 public:
00225 YSBracket (SymbolEntryPtr entry, YCodePtr arg, YCodePtr code, int line = 0);
00226 YSBracket (bytecodeistream & str);
00227 ~YSBracket ();
00228 string toString () const;
00229 std::ostream & toStream (std::ostream & str) const;
00230
00231
00232 YCPValue commit (YCPValue current, int idx, YCPList arg, YCPValue value);
00233 YCPValue evaluate (bool cse = false);
00234 constTypePtr type () const { return Type::Void; };
00235 };
00236
00237
00238
00243 class YSIf : public YStatement
00244 {
00245 REP_BODY(YSIf);
00246 YCodePtr m_condition;
00247 YCodePtr m_true;
00248 YCodePtr m_false;
00249 public:
00250 YSIf (YCodePtr a_expr, YCodePtr a_true, YCodePtr a_false, int line = 0);
00251 YSIf (bytecodeistream & str);
00252 ~YSIf ();
00253 string toString () const;
00254 std::ostream & toStream (std::ostream & str) const;
00255 YCPValue evaluate (bool cse = false);
00256 constTypePtr type () const { return Type::Void; };
00257 };
00258
00259
00260
00265 class YSWhile : public YStatement
00266 {
00267 REP_BODY(YSWhile);
00268 YCodePtr m_condition;
00269 YCodePtr m_loop;
00270
00271 public:
00272 YSWhile (YCodePtr expr, YCodePtr loop, int line = 0);
00273 YSWhile (bytecodeistream & str);
00274 ~YSWhile ();
00275 string toString () const;
00276 std::ostream & toStream (std::ostream & str) const;
00277 YCPValue evaluate (bool cse = false);
00278 constTypePtr type () const { return Type::Void; };
00279 };
00280
00281
00282
00287 class YSRepeat : public YStatement
00288 {
00289 REP_BODY(YSRepeat);
00290 YCodePtr m_loop;
00291 YCodePtr m_condition;
00292
00293 public:
00294 YSRepeat (YCodePtr loop, YCodePtr expr, int line = 0);
00295 YSRepeat (bytecodeistream & str);
00296 ~YSRepeat ();
00297 string toString () const;
00298 std::ostream & toStream (std::ostream & str) const;
00299 YCPValue evaluate (bool cse = false);
00300 constTypePtr type () const { return Type::Void; };
00301 };
00302
00303
00304
00309 class YSDo : public YStatement
00310 {
00311 REP_BODY(YSDo);
00312 YCodePtr m_loop;
00313 YCodePtr m_condition;
00314
00315 public:
00316 YSDo (YCodePtr loop, YCodePtr expr, int line = 0);
00317 YSDo (bytecodeistream & str);
00318 ~YSDo ();
00319 string toString () const;
00320 std::ostream & toStream (std::ostream & str) const;
00321 YCPValue evaluate (bool cse = false);
00322 constTypePtr type () const { return Type::Void; };
00323 };
00324
00325
00326
00331 class YSTextdomain : public YStatement
00332 {
00333 REP_BODY(YSTextdomain);
00334 Ustring m_domain;
00335 public:
00336 YSTextdomain (const string &textdomain, int line = 0);
00337 YSTextdomain (bytecodeistream & str);
00338 ~YSTextdomain ();
00339 string toString () const;
00340 std::ostream & toStream (std::ostream & str) const;
00341 YCPValue evaluate (bool cse = false);
00342 constTypePtr type () const { return Type::Void; };
00343 const char *domain () const { return m_domain->c_str(); };
00344 private:
00345 void bind ();
00346 };
00347
00348
00349
00354 class YSInclude : public YStatement
00355 {
00356 REP_BODY(YSInclude);
00357 Ustring m_filename;
00358 bool m_skipped;
00359 public:
00360 YSInclude (const string &filename, int line = 0, bool skipped = false);
00361 YSInclude (bytecodeistream & str);
00362 ~YSInclude ();
00363 string toString () const;
00364 std::ostream & toStream (std::ostream & str) const;
00365 YCPValue evaluate (bool cse = false);
00366 constTypePtr type () const { return Type::Void; };
00367 string filename () const { return m_filename; };
00368 };
00369
00370
00371
00376 class YSImport : public YStatement, public Import
00377 {
00378 REP_BODY(YSImport);
00379 public:
00380 YSImport (const string &name, int line = 0);
00381 YSImport (const string &name, Y2Namespace *name_space);
00382 YSImport (bytecodeistream & str);
00383 ~YSImport ();
00384 string name () const;
00385 string toString () const;
00386 std::ostream & toStream (std::ostream & str) const;
00387 YCPValue evaluate (bool cse = false);
00388 constTypePtr type () const { return Type::Void; };
00389 };
00390
00391
00392
00397 class YSFilename : public YStatement
00398 {
00399 REP_BODY(YSFilename);
00400 Ustring m_filename;
00401 public:
00402 YSFilename (const string &filename, int line = 0);
00403 YSFilename (bytecodeistream & str);
00404 ~YSFilename ();
00405 string toString () const;
00406 std::ostream & toStream (std::ostream & str) const;
00407 YCPValue evaluate (bool cse = false);
00408 constTypePtr type () const { return Type::Void; };
00409 };
00410
00411
00416 class YSSwitch : public YStatement
00417 {
00418 REP_BODY(YSSwitch);
00419 YCodePtr m_condition;
00420 YBlockPtr m_block;
00421
00422
00423 int m_defaultcase;
00424
00425
00426 map<YCPValue, int, ycpless> m_cases;
00427
00428 public:
00429 YSSwitch (YCodePtr condition);
00430 YSSwitch (bytecodeistream & str);
00431 ~YSSwitch ();
00432 string name () const;
00433 string toString () const;
00434 std::ostream & toStream (std::ostream & str) const;
00435 YCPValue evaluate (bool cse = false);
00436 constTypePtr type () const { return Type::Void; };
00437 constTypePtr conditionType () const { return m_condition->type (); };
00438 bool setCase (YCPValue value);
00439 bool setDefaultCase ();
00440 void setBlock (YBlockPtr block);
00441 };
00442
00443
00444 #endif // YStatement_h