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
00039 DEFINE_DERIVED_POINTER(YStatement, YCode);
00040 DEFINE_DERIVED_POINTER(YSBreak, YCode);
00041 DEFINE_DERIVED_POINTER(YSContinue, YCode);
00042 DEFINE_DERIVED_POINTER(YSExpression, YCode);
00043 DEFINE_DERIVED_POINTER(YSBlock, YCode);
00044 DEFINE_DERIVED_POINTER(YSReturn, YCode);
00045 DEFINE_DERIVED_POINTER(YSTypedef, YCode);
00046 DEFINE_DERIVED_POINTER(YSFunction, YCode);
00047 DEFINE_DERIVED_POINTER(YSAssign, YCode);
00048 DEFINE_DERIVED_POINTER(YSVariable, YCode);
00049 DEFINE_DERIVED_POINTER(YSBracket, YCode);
00050 DEFINE_DERIVED_POINTER(YSIf, YCode);
00051 DEFINE_DERIVED_POINTER(YSWhile, YCode);
00052 DEFINE_DERIVED_POINTER(YSRepeat, YCode);
00053 DEFINE_DERIVED_POINTER(YSDo, YCode);
00054 DEFINE_DERIVED_POINTER(YSTextdomain, YCode);
00055 DEFINE_DERIVED_POINTER(YSInclude, YCode);
00056 DEFINE_DERIVED_POINTER(YSImport, YCode);
00057 DEFINE_DERIVED_POINTER(YSFilename, YCode);
00058 DEFINE_DERIVED_POINTER(YSSwitch, YCode);
00059
00060
00065 class YStatement : public YCode
00066 {
00067 REP_BODY(YStatement);
00068 int m_line;
00069 public:
00070 YStatement (int line = 0);
00071 YStatement (bytecodeistream & str);
00072 ~YStatement () {};
00073 virtual string toString () const;
00074 std::ostream & toStream (std::ostream & str) const;
00075 std::ostream & toXml (std::ostream & str, int indent ) const;
00077 virtual bool isStatement () const { return true; }
00078 int line () const { return m_line; };
00079 virtual YCPValue evaluate (bool cse = false);
00080 constTypePtr type () const { return Type::Void; };
00081 };
00082
00083
00084
00089 class YSBreak : public YStatement
00090 {
00091 REP_BODY(YSBreak);
00092 public:
00093 YSBreak (int line = 0);
00094 YSBreak (bytecodeistream & str);
00095 virtual ykind kind () const { return ysBreak; }
00096 string toString () const;
00097 std::ostream & toStream (std::ostream & str) const;
00098 std::ostream & toXml (std::ostream & str, int indent ) const;
00099 YCPValue evaluate (bool cse = false);
00100 };
00101
00102
00103
00108 class YSContinue : public YStatement
00109 {
00110 REP_BODY(YSContinue);
00111 public:
00112 YSContinue (int line = 0);
00113 YSContinue (bytecodeistream & str);
00114 virtual ykind kind () const { return ysContinue; }
00115 string toString () const;
00116 std::ostream & toStream (std::ostream & str) const;
00117 std::ostream & toXml (std::ostream & str, int indent ) const;
00118 YCPValue evaluate (bool cse = false);
00119 };
00120
00121
00122
00127 class YSExpression : public YStatement
00128 {
00129 REP_BODY(YSExpression);
00130 YCodePtr m_expr;
00131 public:
00132 YSExpression (YCodePtr expr, int line = 0);
00133 YSExpression (bytecodeistream & str);
00134 ~YSExpression ();
00135 virtual ykind kind () const { return ysExpression; }
00136 string toString () const;
00137 std::ostream & toStream (std::ostream & str) const;
00138 std::ostream & toXml (std::ostream & str, int indent ) const;
00139 YCPValue evaluate (bool cse = false);
00140 constTypePtr type () const { return Type::Void; };
00141 };
00142
00143
00144
00149 class YSBlock : public YStatement
00150 {
00151 REP_BODY(YSBlock);
00152 YBlockPtr m_block;
00153 public:
00154 YSBlock (YBlockPtr block, int line = 0);
00155 YSBlock (bytecodeistream & str);
00156 ~YSBlock ();
00157 virtual ykind kind () const { return ysBlock; }
00158 string toString () const;
00159 std::ostream & toStream (std::ostream & str) const;
00160 std::ostream & toXml (std::ostream & str, int indent ) const;
00161 YCPValue evaluate (bool cse = false);
00162 constTypePtr type () const { return Type::Void; };
00163 };
00164
00165
00166
00171 class YSReturn : public YStatement
00172 {
00173 REP_BODY(YSReturn);
00174 YCodePtr m_value;
00175 public:
00176 YSReturn (YCodePtr value, int line = 0);
00177 YSReturn (bytecodeistream & str);
00178 ~YSReturn ();
00179 virtual ykind kind () const { return ysReturn; }
00180 void propagate (constTypePtr from, constTypePtr to);
00181 YCodePtr value () const;
00182 void clearValue ();
00183 string toString () const;
00184 std::ostream & toStream (std::ostream & str) const;
00185 std::ostream & toXml (std::ostream & str, int indent ) const;
00186 YCPValue evaluate (bool cse = false);
00187 constTypePtr type () const { return Type::Void; };
00188 };
00189
00190
00191
00196 class YSTypedef : public YStatement
00197 {
00198 REP_BODY(YSTypedef);
00199 Ustring m_name;
00200 constTypePtr m_type;
00201 public:
00202 YSTypedef (const string &name, constTypePtr type, int line = 0);
00203 YSTypedef (bytecodeistream & str);
00204 ~YSTypedef () {};
00205 virtual ykind kind () const { return ysTypedef; }
00206 string toString() const;
00207 std::ostream & toStream (std::ostream & str) const;
00208 std::ostream & toXml (std::ostream & str, int indent ) const;
00209 YCPValue evaluate (bool cse = false);
00210 constTypePtr type () const { return Type::Void; };
00211 };
00212
00213
00214
00219 class YSFunction : public YStatement
00220 {
00221 REP_BODY(YSFunction);
00222
00223 YSymbolEntryPtr m_entry;
00224
00225 public:
00226 YSFunction (YSymbolEntryPtr entry, int line = 0);
00227 YSFunction (bytecodeistream & str);
00228 ~YSFunction ();
00229 virtual ykind kind () const { return ysFunction; }
00230
00231
00232 SymbolEntryPtr entry () const;
00233
00234
00235 YFunctionPtr function () const;
00236
00237 string toString () const;
00238 std::ostream & toStream (std::ostream & str) const;
00239 std::ostream & toXml (std::ostream & str, int indent ) const;
00240 YCPValue evaluate (bool cse = false);
00241 constTypePtr type () const { return Type::Void; };
00242 };
00243
00244
00245
00251 class YSAssign : public YStatement
00252 {
00253 REP_BODY(YSAssign);
00254 protected:
00255 SymbolEntryPtr m_entry;
00256 YCodePtr m_code;
00257 public:
00258 YSAssign (SymbolEntryPtr entry, YCodePtr code, int line = 0);
00259 YSAssign (bytecodeistream & str);
00260 ~YSAssign ();
00261 virtual ykind kind () const { return ysAssign; }
00262 string toString () const;
00263 std::ostream & toStream (std::ostream & str) const;
00264 std::ostream & toXml (std::ostream & str, int indent ) const;
00265 YCPValue evaluate (bool cse = false);
00266 };
00267
00268
00269
00275 class YSVariable : public YSAssign
00276 {
00277 REP_BODY(YSVariable);
00278 public:
00279 YSVariable (SymbolEntryPtr entry, YCodePtr code, int line = 0);
00280 YSVariable (bytecodeistream & str);
00281 ~YSVariable ();
00282 virtual ykind kind () const { return ysVariable; }
00283 string toString () const;
00284 };
00285
00286
00287
00293 class YSBracket : public YStatement
00294 {
00295 REP_BODY(YSBracket);
00296 SymbolEntryPtr m_entry;
00297 YCodePtr m_arg;
00298 YCodePtr m_code;
00299 public:
00300 YSBracket (SymbolEntryPtr entry, YCodePtr arg, YCodePtr code, int line = 0);
00301 YSBracket (bytecodeistream & str);
00302 ~YSBracket ();
00303 virtual ykind kind () const { return ysBracket; }
00304 string toString () const;
00305 std::ostream & toStream (std::ostream & str) const;
00306 std::ostream & toXml (std::ostream & str, int indent ) const;
00307
00308
00309 YCPValue commit (YCPValue current, int idx, YCPList arg, YCPValue value);
00310 YCPValue evaluate (bool cse = false);
00311 constTypePtr type () const { return Type::Void; };
00312 };
00313
00314
00315
00320 class YSIf : public YStatement
00321 {
00322 REP_BODY(YSIf);
00323 YCodePtr m_condition;
00324 YCodePtr m_true;
00325 YCodePtr m_false;
00326 public:
00327 YSIf (YCodePtr a_expr, YCodePtr a_true, YCodePtr a_false, int line = 0);
00328 YSIf (bytecodeistream & str);
00329 ~YSIf ();
00330 virtual ykind kind () const { return ysIf; }
00331 string toString () const;
00332 std::ostream & toStream (std::ostream & str) const;
00333 std::ostream & toXml (std::ostream & str, int indent ) const;
00334 YCPValue evaluate (bool cse = false);
00335 constTypePtr type () const { return Type::Void; };
00336 };
00337
00338
00339
00344 class YSWhile : public YStatement
00345 {
00346 REP_BODY(YSWhile);
00347 YCodePtr m_condition;
00348 YCodePtr m_loop;
00349
00350 public:
00351 YSWhile (YCodePtr expr, YCodePtr loop, int line = 0);
00352 YSWhile (bytecodeistream & str);
00353 ~YSWhile ();
00354 virtual ykind kind () const { return ysWhile; }
00355 string toString () const;
00356 std::ostream & toStream (std::ostream & str) const;
00357 std::ostream & toXml (std::ostream & str, int indent ) const;
00358 YCPValue evaluate (bool cse = false);
00359 constTypePtr type () const { return Type::Void; };
00360 };
00361
00362
00363
00368 class YSRepeat : public YStatement
00369 {
00370 REP_BODY(YSRepeat);
00371 YCodePtr m_loop;
00372 YCodePtr m_condition;
00373
00374 public:
00375 YSRepeat (YCodePtr loop, YCodePtr expr, int line = 0);
00376 YSRepeat (bytecodeistream & str);
00377 ~YSRepeat ();
00378 virtual ykind kind () const { return ysRepeat; }
00379 string toString () const;
00380 std::ostream & toStream (std::ostream & str) const;
00381 std::ostream & toXml (std::ostream & str, int indent ) const;
00382 YCPValue evaluate (bool cse = false);
00383 constTypePtr type () const { return Type::Void; };
00384 };
00385
00386
00387
00392 class YSDo : public YStatement
00393 {
00394 REP_BODY(YSDo);
00395 YCodePtr m_loop;
00396 YCodePtr m_condition;
00397
00398 public:
00399 YSDo (YCodePtr loop, YCodePtr expr, int line = 0);
00400 YSDo (bytecodeistream & str);
00401 ~YSDo ();
00402 virtual ykind kind () const { return ysDo; }
00403 string toString () const;
00404 std::ostream & toStream (std::ostream & str) const;
00405 std::ostream & toXml (std::ostream & str, int indent ) const;
00406 YCPValue evaluate (bool cse = false);
00407 constTypePtr type () const { return Type::Void; };
00408 };
00409
00410
00411
00416 class YSTextdomain : public YStatement
00417 {
00418 REP_BODY(YSTextdomain);
00419 Ustring m_domain;
00420 public:
00421 YSTextdomain (const string &textdomain, int line = 0);
00422 YSTextdomain (bytecodeistream & str);
00423 ~YSTextdomain ();
00424 virtual ykind kind () const { return ysTextdomain; }
00425 string toString () const;
00426 std::ostream & toStream (std::ostream & str) const;
00427 std::ostream & toXml (std::ostream & str, int indent ) const;
00428 YCPValue evaluate (bool cse = false);
00429 constTypePtr type () const { return Type::Void; };
00430 const char *domain () const { return m_domain->c_str(); };
00431 private:
00432 void bind ();
00433 };
00434
00435
00436
00441 class YSInclude : public YStatement
00442 {
00443 REP_BODY(YSInclude);
00444 Ustring m_filename;
00445 bool m_skipped;
00446 public:
00447 YSInclude (const string &filename, int line = 0, bool skipped = false);
00448 YSInclude (bytecodeistream & str);
00449 ~YSInclude ();
00450 virtual ykind kind () const { return ysInclude; }
00451 string toString () const;
00452 std::ostream & toStream (std::ostream & str) const;
00453 std::ostream & toXml (std::ostream & str, int indent ) const;
00454 YCPValue evaluate (bool cse = false);
00455 constTypePtr type () const { return Type::Void; };
00456 string filename () const { return m_filename; };
00457 };
00458
00459
00460
00465 class YSImport : public YStatement, public Import
00466 {
00467 REP_BODY(YSImport);
00468 public:
00469 YSImport (const string &name, int line = 0);
00470 YSImport (const string &name, Y2Namespace *name_space);
00471 YSImport (bytecodeistream & str);
00472 ~YSImport ();
00473 virtual ykind kind () const { return ysImport; }
00474 string name () const;
00475 string toString () const;
00476 std::ostream & toStream (std::ostream & str) const;
00477 std::ostream & toXml (std::ostream & str, int indent ) const;
00478 YCPValue evaluate (bool cse = false);
00479 constTypePtr type () const { return Type::Void; };
00480 };
00481
00482
00483
00488 class YSFilename : public YStatement
00489 {
00490 REP_BODY(YSFilename);
00491 Ustring m_filename;
00492 public:
00493 YSFilename (const string &filename, int line = 0);
00494 YSFilename (bytecodeistream & str);
00495 ~YSFilename ();
00496 virtual ykind kind () const { return ysFilename; }
00497 string toString () const;
00498 std::ostream & toStream (std::ostream & str) const;
00499 std::ostream & toXml (std::ostream & str, int indent ) const;
00500 YCPValue evaluate (bool cse = false);
00501 constTypePtr type () const { return Type::Void; };
00502 };
00503
00504
00509 class YSSwitch : public YStatement
00510 {
00511 REP_BODY(YSSwitch);
00512 YCodePtr m_condition;
00513 YBlockPtr m_block;
00514
00515
00516 int m_defaultcase;
00517
00518
00519 map<YCPValue, int, ycp_less> m_cases;
00520
00521 public:
00522 YSSwitch (YCodePtr condition);
00523 YSSwitch (bytecodeistream & str);
00524 ~YSSwitch ();
00525 virtual ykind kind () const { return ysSwitch; }
00526 string name () const;
00527 string toString () const;
00528 std::ostream & toStream (std::ostream & str) const;
00529 std::ostream & toXml (std::ostream & str, int indent ) const;
00530 YCPValue evaluate (bool cse = false);
00531 constTypePtr type () const { return Type::Void; };
00532 constTypePtr conditionType () const { return m_condition->type (); };
00533 bool setCase (YCPValue value);
00534 bool setDefaultCase ();
00535 void setBlock (YBlockPtr block);
00536 };
00537
00538
00539 #endif // YStatement_h