yast2-core
YStatement.h
Go to the documentation of this file.
1 /*---------------------------------------------------------*- c++ -*---\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12 
13  File: YStatement.h
14 
15  Author: Klaus Kaempf <kkaempf@suse.de>
16  Stanislav Visnovsky <visnov@suse.cz>
17  Maintainer: Stanislav Visnovsky <visnov@suse.cz>
18 
19 /-*/
20 // -*- c++ -*-
21 
22 #ifndef YStatement_h
23 #define YStatement_h
24 
25 #include <string>
26 using std::string;
27 
28 #include "ycp/YCode.h"
29 #include "ycp/SymbolTable.h"
30 #include "ycp/YSymbolEntry.h"
31 #include "ycp/Import.h"
32 #include "ycp/ycpless.h"
33 
34 class YBlock; // forward declaration for YDo, YRepeat
35 
36 //-------------------------------------------------------------------
37 
38 // FIXME bad inheritance
59 
60 //-------------------------------------------------------------------
65 class YStatement : public YCode
66 {
68  int m_line; // line number
69 public:
70  YStatement (int line = 0);
72  ~YStatement () {};
73  virtual string toString () const;
74  std::ostream & toStream (std::ostream & str) const;
75  std::ostream & toXml (std::ostream & str, int indent ) const;
77  virtual bool isStatement () const { return true; }
78  int line () const { return m_line; };
79  virtual YCPValue evaluate (bool cse = false);
80  constTypePtr type () const { return Type::Void; };
81 };
82 
83 
84 //-------------------------------------------------------------------
89 class YSBreak : public YStatement
90 {
92 public:
93  YSBreak (int line = 0); // statement
95  virtual ykind kind () const { return ysBreak; }
96  string toString () const;
97  std::ostream & toStream (std::ostream & str) const;
98  std::ostream & toXml (std::ostream & str, int indent ) const;
99  YCPValue evaluate (bool cse = false);
100 };
101 
102 
103 //-------------------------------------------------------------------
108 class YSContinue : public YStatement
109 {
111 public:
112  YSContinue (int line = 0); // statement
114  virtual ykind kind () const { return ysContinue; }
115  string toString () const;
116  std::ostream & toStream (std::ostream & str) const;
117  std::ostream & toXml (std::ostream & str, int indent ) const;
118  YCPValue evaluate (bool cse = false);
119 };
120 
121 
122 //-------------------------------------------------------------------
127 class YSExpression : public YStatement
128 {
130  YCodePtr m_expr;
131 public:
132  YSExpression (YCodePtr expr, int line = 0); // statement
134  ~YSExpression ();
135  virtual ykind kind () const { return ysExpression; }
136  string toString () const;
137  std::ostream & toStream (std::ostream & str) const;
138  std::ostream & toXml (std::ostream & str, int indent ) const;
139  YCPValue evaluate (bool cse = false);
140  constTypePtr type () const { return Type::Void; };
141 };
142 
143 
144 //-------------------------------------------------------------------
149 class YSBlock : public YStatement
150 {
151  REP_BODY(YSBlock);
152  YBlockPtr m_block;
153 public:
154  YSBlock (YBlockPtr block, int line = 0);
156  ~YSBlock ();
157  virtual ykind kind () const { return ysBlock; }
158  string toString () const;
159  std::ostream & toStream (std::ostream & str) const;
160  std::ostream & toXml (std::ostream & str, int indent ) const;
161  YCPValue evaluate (bool cse = false);
162  constTypePtr type () const { return Type::Void; };
163 };
164 
165 
166 //-------------------------------------------------------------------
171 class YSReturn : public YStatement
172 {
174  YCodePtr m_value;
175 public:
176  YSReturn (YCodePtr value, int line = 0);
178  ~YSReturn ();
179  virtual ykind kind () const { return ysReturn; }
180  void propagate (constTypePtr from, constTypePtr to);
181  YCodePtr value () const; // needed in YBlock::justReturn
182  void clearValue (); // needed if justReturn triggers
183  string toString () const;
184  std::ostream & toStream (std::ostream & str) const;
185  std::ostream & toXml (std::ostream & str, int indent ) const;
186  YCPValue evaluate (bool cse = false);
187  constTypePtr type () const { return Type::Void; };
188 };
189 
190 
191 //-------------------------------------------------------------------
196 class YSTypedef : public YStatement
197 {
199  Ustring m_name; // name
200  constTypePtr m_type; // type
201 public:
202  YSTypedef (const string &name, constTypePtr type, int line = 0); // Typedef
204  ~YSTypedef () {};
205  virtual ykind kind () const { return ysTypedef; }
206  string toString() const;
207  std::ostream & toStream (std::ostream & str) const;
208  std::ostream & toXml (std::ostream & str, int indent ) const;
209  YCPValue evaluate (bool cse = false);
210  constTypePtr type () const { return Type::Void; };
211 };
212 
213 
214 //-------------------------------------------------------------------
219 class YSFunction : public YStatement
220 {
222  // the functions' symbol, it's code is this YSFunction !
223  YSymbolEntryPtr m_entry;
224 
225 public:
226  YSFunction (YSymbolEntryPtr entry, int line = 0);
228  ~YSFunction ();
229  virtual ykind kind () const { return ysFunction; }
230 
231  // symbol entry of function itself
232  SymbolEntryPtr entry () const;
233 
234  // access to function definition
235  YFunctionPtr function () const;
236 
237  string toString () const;
238  std::ostream & toStream (std::ostream & str) const;
239  std::ostream & toXml (std::ostream & str, int indent ) const;
240  YCPValue evaluate (bool cse = false);
241  constTypePtr type () const { return Type::Void; };
242 };
243 
244 
245 //-------------------------------------------------------------------
251 class YSAssign : public YStatement
252 {
254 protected:
255  SymbolEntryPtr m_entry;
256  YCodePtr m_code;
257 public:
258  YSAssign (SymbolEntryPtr entry, YCodePtr code, int line = 0);
260  ~YSAssign ();
261  virtual ykind kind () const { return ysAssign; }
262  string toString () const;
263  std::ostream & toStream (std::ostream & str) const;
264  std::ostream & toXml (std::ostream & str, int indent ) const;
265  YCPValue evaluate (bool cse = false);
266 };
267 
268 
269 //-------------------------------------------------------------------
275 class YSVariable : public YSAssign
276 {
278 public:
279  YSVariable (SymbolEntryPtr entry, YCodePtr code, int line = 0);
281  ~YSVariable ();
282  virtual ykind kind () const { return ysVariable; }
283  string toString () const;
284 };
285 
286 
287 //-------------------------------------------------------------------
293 class YSBracket : public YStatement
294 {
296  SymbolEntryPtr m_entry;
297  YCodePtr m_arg;
298  YCodePtr m_code;
299 public:
300  YSBracket (SymbolEntryPtr entry, YCodePtr arg, YCodePtr code, int line = 0);
302  ~YSBracket ();
303  virtual ykind kind () const { return ysBracket; }
304  string toString () const;
305  std::ostream & toStream (std::ostream & str) const;
306  std::ostream & toXml (std::ostream & str, int indent ) const;
307  // recursively extract list arg at idx, get value from current at idx
308  // and replace with value. re-generating the list/map/term during unwind
309  YCPValue commit (YCPValue current, int idx, YCPList arg, YCPValue value);
310  YCPValue evaluate (bool cse = false);
311  constTypePtr type () const { return Type::Void; };
312 };
313 
314 
315 //-------------------------------------------------------------------
320 class YSIf : public YStatement
321 {
322  REP_BODY(YSIf);
323  YCodePtr m_condition; // bool expr
324  YCodePtr m_true; // true statement/block
325  YCodePtr m_false; // false statement/block
326 public:
327  YSIf (YCodePtr a_expr, YCodePtr a_true, YCodePtr a_false, int line = 0);
329  ~YSIf ();
330  virtual ykind kind () const { return ysIf; }
331  string toString () const;
332  std::ostream & toStream (std::ostream & str) const;
333  std::ostream & toXml (std::ostream & str, int indent ) const;
334  YCPValue evaluate (bool cse = false);
335  constTypePtr type () const { return Type::Void; };
336 };
337 
338 
339 //-------------------------------------------------------------------
344 class YSWhile : public YStatement
345 {
346  REP_BODY(YSWhile);
347  YCodePtr m_condition; // bool expr
348  YCodePtr m_loop; // loop statement
349 
350 public:
351  YSWhile (YCodePtr expr, YCodePtr loop, int line = 0);
353  ~YSWhile ();
354  virtual ykind kind () const { return ysWhile; }
355  string toString () const;
356  std::ostream & toStream (std::ostream & str) const;
357  std::ostream & toXml (std::ostream & str, int indent ) const;
358  YCPValue evaluate (bool cse = false);
359  constTypePtr type () const { return Type::Void; };
360 };
361 
362 
363 //-------------------------------------------------------------------
368 class YSRepeat : public YStatement
369 {
371  YCodePtr m_loop; // loop statement
372  YCodePtr m_condition; // bool expr
373 
374 public:
375  YSRepeat (YCodePtr loop, YCodePtr expr, int line = 0);
377  ~YSRepeat ();
378  virtual ykind kind () const { return ysRepeat; }
379  string toString () const;
380  std::ostream & toStream (std::ostream & str) const;
381  std::ostream & toXml (std::ostream & str, int indent ) const;
382  YCPValue evaluate (bool cse = false);
383  constTypePtr type () const { return Type::Void; };
384 };
385 
386 
387 //-------------------------------------------------------------------
392 class YSDo : public YStatement
393 {
394  REP_BODY(YSDo);
395  YCodePtr m_loop; // loop statement
396  YCodePtr m_condition; // bool expr
397 
398 public:
399  YSDo (YCodePtr loop, YCodePtr expr, int line = 0);
401  ~YSDo ();
402  virtual ykind kind () const { return ysDo; }
403  string toString () const;
404  std::ostream & toStream (std::ostream & str) const;
405  std::ostream & toXml (std::ostream & str, int indent ) const;
406  YCPValue evaluate (bool cse = false);
407  constTypePtr type () const { return Type::Void; };
408 };
409 
410 
411 //-------------------------------------------------------------------
416 class YSTextdomain : public YStatement
417 {
420 public:
421  YSTextdomain (const string &textdomain, int line = 0);
423  ~YSTextdomain ();
424  virtual ykind kind () const { return ysTextdomain; }
425  string toString () const;
426  std::ostream & toStream (std::ostream & str) const;
427  std::ostream & toXml (std::ostream & str, int indent ) const;
428  YCPValue evaluate (bool cse = false);
429  constTypePtr type () const { return Type::Void; };
430  const char *domain () const { return m_domain->c_str(); };
431 private:
432  void bind ();
433 };
434 
435 
436 //-------------------------------------------------------------------
441 class YSInclude : public YStatement
442 {
445  bool m_skipped;
446 public:
447  YSInclude (const string &filename, int line = 0, bool skipped = false);
449  ~YSInclude ();
450  virtual ykind kind () const { return ysInclude; }
451  string toString () const;
452  std::ostream & toStream (std::ostream & str) const;
453  std::ostream & toXml (std::ostream & str, int indent ) const;
454  YCPValue evaluate (bool cse = false);
455  constTypePtr type () const { return Type::Void; };
456  string filename () const { return m_filename; };
457 };
458 
459 
460 //-------------------------------------------------------------------
465 class YSImport : public YStatement, public Import
466 {
468 public:
469  YSImport (const string &name, int line = 0);
470  YSImport (const string &name, Y2Namespace *name_space);
472  ~YSImport ();
473  virtual ykind kind () const { return ysImport; }
474  string name () const;
475  string toString () const;
476  std::ostream & toStream (std::ostream & str) const;
477  std::ostream & toXml (std::ostream & str, int indent ) const;
478  YCPValue evaluate (bool cse = false);
479  constTypePtr type () const { return Type::Void; };
480 };
481 
482 
483 //-------------------------------------------------------------------
488 class YSFilename : public YStatement
489 {
492 public:
493  YSFilename (const string &filename, int line = 0);
495  ~YSFilename ();
496  virtual ykind kind () const { return ysFilename; }
497  string toString () const;
498  std::ostream & toStream (std::ostream & str) const;
499  std::ostream & toXml (std::ostream & str, int indent ) const;
500  YCPValue evaluate (bool cse = false);
501  constTypePtr type () const { return Type::Void; };
502 };
503 
504 //-------------------------------------------------------------------
509 class YSSwitch : public YStatement
510 {
512  YCodePtr m_condition;
513  YBlockPtr m_block;
514 
515  // index of the default case statement in the block
517 
518  // indices of the case statements in the block
519  map<YCPValue, int, ycp_less> m_cases;
520 
521 public:
522  YSSwitch (YCodePtr condition);
524  ~YSSwitch ();
525  virtual ykind kind () const { return ysSwitch; }
526  string name () const;
527  string toString () const;
528  std::ostream & toStream (std::ostream & str) const;
529  std::ostream & toXml (std::ostream & str, int indent ) const;
530  YCPValue evaluate (bool cse = false);
531  constTypePtr type () const { return Type::Void; };
532  constTypePtr conditionType () const { return m_condition->type (); };
533  bool setCase (YCPValue value);
534  bool setDefaultCase ();
535  void setBlock (YBlockPtr block);
536 };
537 
538 
539 #endif // YStatement_h

Generated on a sunny day for yast2-core by doxygen 1.8.2