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;
00076 virtual bool isStatement () const { return true; }
00077 int line () const { return m_line; };
00078 virtual YCPValue evaluate (bool cse = false);
00079 constTypePtr type () const { return Type::Void; };
00080 };
00081
00082
00083
00088 class YSBreak : public YStatement
00089 {
00090 REP_BODY(YSBreak);
00091 public:
00092 YSBreak (int line = 0);
00093 YSBreak (bytecodeistream & str);
00094 virtual ykind kind () const { return ysBreak; }
00095 string toString () const;
00096 std::ostream & toStream (std::ostream & str) const;
00097 YCPValue evaluate (bool cse = false);
00098 };
00099
00100
00101
00106 class YSContinue : public YStatement
00107 {
00108 REP_BODY(YSContinue);
00109 public:
00110 YSContinue (int line = 0);
00111 YSContinue (bytecodeistream & str);
00112 virtual ykind kind () const { return ysContinue; }
00113 string toString () const;
00114 std::ostream & toStream (std::ostream & str) const;
00115 YCPValue evaluate (bool cse = false);
00116 };
00117
00118
00119
00124 class YSExpression : public YStatement
00125 {
00126 REP_BODY(YSExpression);
00127 YCodePtr m_expr;
00128 public:
00129 YSExpression (YCodePtr expr, int line = 0);
00130 YSExpression (bytecodeistream & str);
00131 ~YSExpression ();
00132 virtual ykind kind () const { return ysExpression; }
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 YSBlock : public YStatement
00146 {
00147 REP_BODY(YSBlock);
00148 YBlockPtr m_block;
00149 public:
00150 YSBlock (YBlockPtr block, int line = 0);
00151 YSBlock (bytecodeistream & str);
00152 ~YSBlock ();
00153 virtual ykind kind () const { return ysBlock; }
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 YSReturn : public YStatement
00167 {
00168 REP_BODY(YSReturn);
00169 YCodePtr m_value;
00170 public:
00171 YSReturn (YCodePtr value, int line = 0);
00172 YSReturn (bytecodeistream & str);
00173 ~YSReturn ();
00174 virtual ykind kind () const { return ysReturn; }
00175 void propagate (constTypePtr from, constTypePtr to);
00176 YCodePtr value () const;
00177 void clearValue ();
00178 string toString () const;
00179 std::ostream & toStream (std::ostream & str) const;
00180 YCPValue evaluate (bool cse = false);
00181 constTypePtr type () const { return Type::Void; };
00182 };
00183
00184
00185
00190 class YSTypedef : public YStatement
00191 {
00192 REP_BODY(YSTypedef);
00193 Ustring m_name;
00194 constTypePtr m_type;
00195 public:
00196 YSTypedef (const string &name, constTypePtr type, int line = 0);
00197 YSTypedef (bytecodeistream & str);
00198 ~YSTypedef () {};
00199 virtual ykind kind () const { return ysTypedef; }
00200 string toString() const;
00201 std::ostream & toStream (std::ostream & str) const;
00202 YCPValue evaluate (bool cse = false);
00203 constTypePtr type () const { return Type::Void; };
00204 };
00205
00206
00207
00212 class YSFunction : public YStatement
00213 {
00214 REP_BODY(YSFunction);
00215
00216 YSymbolEntryPtr m_entry;
00217
00218 public:
00219 YSFunction (YSymbolEntryPtr entry, int line = 0);
00220 YSFunction (bytecodeistream & str);
00221 ~YSFunction ();
00222 virtual ykind kind () const { return ysFunction; }
00223
00224
00225 SymbolEntryPtr entry () const;
00226
00227
00228 YFunctionPtr function () const;
00229
00230 string toString () const;
00231 std::ostream & toStream (std::ostream & str) const;
00232 YCPValue evaluate (bool cse = false);
00233 constTypePtr type () const { return Type::Void; };
00234 };
00235
00236
00237
00243 class YSAssign : public YStatement
00244 {
00245 REP_BODY(YSAssign);
00246 protected:
00247 SymbolEntryPtr m_entry;
00248 YCodePtr m_code;
00249 public:
00250 YSAssign (SymbolEntryPtr entry, YCodePtr code, int line = 0);
00251 YSAssign (bytecodeistream & str);
00252 ~YSAssign ();
00253 virtual ykind kind () const { return ysAssign; }
00254 string toString () const;
00255 std::ostream & toStream (std::ostream & str) const;
00256 YCPValue evaluate (bool cse = false);
00257 };
00258
00259
00260
00266 class YSVariable : public YSAssign
00267 {
00268 REP_BODY(YSVariable);
00269 public:
00270 YSVariable (SymbolEntryPtr entry, YCodePtr code, int line = 0);
00271 YSVariable (bytecodeistream & str);
00272 ~YSVariable ();
00273 virtual ykind kind () const { return ysVariable; }
00274 string toString () const;
00275 };
00276
00277
00278
00284 class YSBracket : public YStatement
00285 {
00286 REP_BODY(YSBracket);
00287 SymbolEntryPtr m_entry;
00288 YCodePtr m_arg;
00289 YCodePtr m_code;
00290 public:
00291 YSBracket (SymbolEntryPtr entry, YCodePtr arg, YCodePtr code, int line = 0);
00292 YSBracket (bytecodeistream & str);
00293 ~YSBracket ();
00294 virtual ykind kind () const { return ysBracket; }
00295 string toString () const;
00296 std::ostream & toStream (std::ostream & str) const;
00297
00298
00299 YCPValue commit (YCPValue current, int idx, YCPList arg, YCPValue value);
00300 YCPValue evaluate (bool cse = false);
00301 constTypePtr type () const { return Type::Void; };
00302 };
00303
00304
00305
00310 class YSIf : public YStatement
00311 {
00312 REP_BODY(YSIf);
00313 YCodePtr m_condition;
00314 YCodePtr m_true;
00315 YCodePtr m_false;
00316 public:
00317 YSIf (YCodePtr a_expr, YCodePtr a_true, YCodePtr a_false, int line = 0);
00318 YSIf (bytecodeistream & str);
00319 ~YSIf ();
00320 virtual ykind kind () const { return ysIf; }
00321 string toString () const;
00322 std::ostream & toStream (std::ostream & str) const;
00323 YCPValue evaluate (bool cse = false);
00324 constTypePtr type () const { return Type::Void; };
00325 };
00326
00327
00328
00333 class YSWhile : public YStatement
00334 {
00335 REP_BODY(YSWhile);
00336 YCodePtr m_condition;
00337 YCodePtr m_loop;
00338
00339 public:
00340 YSWhile (YCodePtr expr, YCodePtr loop, int line = 0);
00341 YSWhile (bytecodeistream & str);
00342 ~YSWhile ();
00343 virtual ykind kind () const { return ysWhile; }
00344 string toString () const;
00345 std::ostream & toStream (std::ostream & str) const;
00346 YCPValue evaluate (bool cse = false);
00347 constTypePtr type () const { return Type::Void; };
00348 };
00349
00350
00351
00356 class YSRepeat : public YStatement
00357 {
00358 REP_BODY(YSRepeat);
00359 YCodePtr m_loop;
00360 YCodePtr m_condition;
00361
00362 public:
00363 YSRepeat (YCodePtr loop, YCodePtr expr, int line = 0);
00364 YSRepeat (bytecodeistream & str);
00365 ~YSRepeat ();
00366 virtual ykind kind () const { return ysRepeat; }
00367 string toString () const;
00368 std::ostream & toStream (std::ostream & str) const;
00369 YCPValue evaluate (bool cse = false);
00370 constTypePtr type () const { return Type::Void; };
00371 };
00372
00373
00374
00379 class YSDo : public YStatement
00380 {
00381 REP_BODY(YSDo);
00382 YCodePtr m_loop;
00383 YCodePtr m_condition;
00384
00385 public:
00386 YSDo (YCodePtr loop, YCodePtr expr, int line = 0);
00387 YSDo (bytecodeistream & str);
00388 ~YSDo ();
00389 virtual ykind kind () const { return ysDo; }
00390 string toString () const;
00391 std::ostream & toStream (std::ostream & str) const;
00392 YCPValue evaluate (bool cse = false);
00393 constTypePtr type () const { return Type::Void; };
00394 };
00395
00396
00397
00402 class YSTextdomain : public YStatement
00403 {
00404 REP_BODY(YSTextdomain);
00405 Ustring m_domain;
00406 public:
00407 YSTextdomain (const string &textdomain, int line = 0);
00408 YSTextdomain (bytecodeistream & str);
00409 ~YSTextdomain ();
00410 virtual ykind kind () const { return ysTextdomain; }
00411 string toString () const;
00412 std::ostream & toStream (std::ostream & str) const;
00413 YCPValue evaluate (bool cse = false);
00414 constTypePtr type () const { return Type::Void; };
00415 const char *domain () const { return m_domain->c_str(); };
00416 private:
00417 void bind ();
00418 };
00419
00420
00421
00426 class YSInclude : public YStatement
00427 {
00428 REP_BODY(YSInclude);
00429 Ustring m_filename;
00430 bool m_skipped;
00431 public:
00432 YSInclude (const string &filename, int line = 0, bool skipped = false);
00433 YSInclude (bytecodeistream & str);
00434 ~YSInclude ();
00435 virtual ykind kind () const { return ysInclude; }
00436 string toString () const;
00437 std::ostream & toStream (std::ostream & str) const;
00438 YCPValue evaluate (bool cse = false);
00439 constTypePtr type () const { return Type::Void; };
00440 string filename () const { return m_filename; };
00441 };
00442
00443
00444
00449 class YSImport : public YStatement, public Import
00450 {
00451 REP_BODY(YSImport);
00452 public:
00453 YSImport (const string &name, int line = 0);
00454 YSImport (const string &name, Y2Namespace *name_space);
00455 YSImport (bytecodeistream & str);
00456 ~YSImport ();
00457 virtual ykind kind () const { return ysImport; }
00458 string name () const;
00459 string toString () const;
00460 std::ostream & toStream (std::ostream & str) const;
00461 YCPValue evaluate (bool cse = false);
00462 constTypePtr type () const { return Type::Void; };
00463 };
00464
00465
00466
00471 class YSFilename : public YStatement
00472 {
00473 REP_BODY(YSFilename);
00474 Ustring m_filename;
00475 public:
00476 YSFilename (const string &filename, int line = 0);
00477 YSFilename (bytecodeistream & str);
00478 ~YSFilename ();
00479 virtual ykind kind () const { return ysFilename; }
00480 string toString () const;
00481 std::ostream & toStream (std::ostream & str) const;
00482 YCPValue evaluate (bool cse = false);
00483 constTypePtr type () const { return Type::Void; };
00484 };
00485
00486
00491 class YSSwitch : public YStatement
00492 {
00493 REP_BODY(YSSwitch);
00494 YCodePtr m_condition;
00495 YBlockPtr m_block;
00496
00497
00498 int m_defaultcase;
00499
00500
00501 map<YCPValue, int, ycpless> m_cases;
00502
00503 public:
00504 YSSwitch (YCodePtr condition);
00505 YSSwitch (bytecodeistream & str);
00506 ~YSSwitch ();
00507 virtual ykind kind () const { return ysSwitch; }
00508 string name () const;
00509 string toString () const;
00510 std::ostream & toStream (std::ostream & str) const;
00511 YCPValue evaluate (bool cse = false);
00512 constTypePtr type () const { return Type::Void; };
00513 constTypePtr conditionType () const { return m_condition->type (); };
00514 bool setCase (YCPValue value);
00515 bool setDefaultCase ();
00516 void setBlock (YBlockPtr block);
00517 };
00518
00519
00520 #endif // YStatement_h