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
constTypePtr type() const
Definition: YStatement.h:359
Definition: YStatement.h:344
SymbolEntryPtr m_entry
Definition: YStatement.h:296
SymbolEntryPtr m_entry
Definition: YStatement.h:255
constTypePtr type() const
Definition: YStatement.h:429
YCode for precompiled ycp code.
Definition: YCode.h:75
YCodePtr m_false
Definition: YStatement.h:325
constTypePtr type() const
Definition: YStatement.h:140
constTypePtr type() const
Definition: YStatement.h:407
Definition: YCode.h:135
Definition: YCode.h:151
Ustring m_domain
Definition: YStatement.h:419
YSymbolEntryPtr m_entry
Definition: YStatement.h:223
#define str
Definition: scanner.cc:1003
virtual ykind kind() const
Definition: YStatement.h:473
Definition: YStatement.h:196
Ustring m_name
Definition: YStatement.h:199
virtual ykind kind() const
Definition: YStatement.h:114
Definition: YCode.h:142
Definition: YStatement.h:171
Definition: YBlock.h:49
virtual ykind kind() const
Definition: YStatement.h:282
constTypePtr m_type
Definition: YStatement.h:200
ykind
Definition: YCode.h:90
YCodePtr m_loop
Definition: YStatement.h:348
DEFINE_DERIVED_POINTER(YStatement, YCode)
YBlockPtr m_block
Definition: YStatement.h:513
constTypePtr type() const
Definition: YStatement.h:531
Definition: YStatement.h:441
virtual ykind kind() const
Definition: YStatement.h:525
Definition: YStatement.h:149
int line() const
Definition: YStatement.h:78
~YSTypedef()
Definition: YStatement.h:204
virtual ykind kind() const
Definition: YStatement.h:229
Definition: YStatement.h:127
Definition: YCode.h:136
Definition: YStatement.h:65
YStatement(int line=0)
Definition: YStatement.cc:73
Definition: YCode.h:140
YCodePtr m_code
Definition: YStatement.h:298
Definition: YStatement.h:488
YCodePtr m_condition
Definition: YStatement.h:372
constTypePtr type() const
Definition: YStatement.h:210
Definition: YStatement.h:392
Definition: YStatement.h:368
virtual YCPValue evaluate(bool cse=false)
Definition: YStatement.cc:98
virtual string toString() const
Definition: YStatement.cc:91
constTypePtr type() const
Definition: YStatement.h:80
YBlockPtr m_block
Definition: YStatement.h:152
YCodePtr m_condition
Definition: YStatement.h:396
Definition: YCode.h:139
enters the component to the broker s list in the given order Y2Component int int current_level same as but for external components which may reside in different directories The level identifies the directory prefix from the list defined in pathsearch cc bool false for clients bool true for clients Catalog of component take it if we can stat it and it is not take it if we can t stat it and its line matches in current level only name
Definition: componentcreator.txt:34
virtual ykind kind() const
Definition: YStatement.h:261
Definition: YStatement.h:89
int m_defaultcase
Definition: YStatement.h:516
Ustring m_filename
Definition: YStatement.h:444
virtual ykind kind() const
Definition: YStatement.h:354
Definition: YStatement.h:320
Definition: YCode.h:149
virtual ykind kind() const
Definition: YStatement.h:450
instantiate to import a module
Definition: Import.h:36
Definition: YCode.h:145
Definition: YStatement.h:275
constTypePtr type() const
Definition: YStatement.h:501
Definition: YCode.h:150
Definition: YCode.h:147
virtual ykind kind() const
Definition: YStatement.h:179
int m_line
Definition: YStatement.h:68
constTypePtr type() const
Definition: YStatement.h:311
constTypePtr type() const
Definition: YStatement.h:241
YCodePtr m_condition
Definition: YStatement.h:347
constTypePtr type() const
Definition: YStatement.h:335
Definition: YCode.h:153
constTypePtr type() const
Definition: YStatement.h:187
Unique strings.
Definition: Ustring.h:124
bool m_skipped
Definition: YStatement.h:445
constTypePtr type() const
Definition: YStatement.h:455
virtual bool isStatement() const
Definition: YStatement.h:77
virtual ykind kind() const
Definition: YStatement.h:378
constTypePtr type() const
Definition: YStatement.h:383
YCodePtr m_value
Definition: YStatement.h:174
YCodePtr m_code
Definition: YStatement.h:256
string filename() const
Definition: YStatement.h:456
Wrapper for YCPListRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPListRep with the arrow operator. See YCPListRep.
Definition: YCPList.h:236
Definition: YCode.h:143
YCodePtr m_true
Definition: YStatement.h:324
YCodePtr m_condition
Definition: YStatement.h:323
virtual ykind kind() const
Definition: YStatement.h:205
constTypePtr type() const
Definition: YStatement.h:479
Definition: YCode.h:138
virtual ykind kind() const
Definition: YStatement.h:424
Definition: YStatement.h:108
Definition: YCode.h:146
YCodePtr m_expr
Definition: YStatement.h:130
YCodePtr m_condition
Definition: YStatement.h:512
Definition: YCode.h:137
virtual ykind kind() const
Definition: YStatement.h:95
Definition: YStatement.h:293
Definition: YCode.h:148
Definition: YCode.h:144
map< YCPValue, int, ycp_less > m_cases
Definition: YStatement.h:519
virtual ykind kind() const
Definition: YStatement.h:402
const char * domain() const
Definition: YStatement.h:430
Wrapper for YCPValueRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPValueRep with the arrow operator. See YCPValueRep.
Definition: YCPValue.h:275
virtual ykind kind() const
Definition: YStatement.h:330
Definition: YStatement.h:416
virtual ykind kind() const
Definition: YStatement.h:135
std::ostream & toStream(std::ostream &str) const
Definition: YStatement.cc:108
Definition: Y2Namespace.h:43
YCodePtr m_arg
Definition: YStatement.h:297
std::ostream & toXml(std::ostream &str, int indent) const
Definition: YStatement.cc:118
~YStatement()
Definition: YStatement.h:72
An istream that remembers some data about the bytecode.
Definition: Bytecode.h:42
static const constTypePtr Void
Definition: Type.h:122
Definition: YStatement.h:251
Definition: YCode.h:152
REP_BODY(YStatement)
constTypePtr type() const
Definition: YStatement.h:162
YCodePtr m_loop
Definition: YStatement.h:371
Definition: YStatement.h:219
virtual ykind kind() const
Definition: YStatement.h:157
YCodePtr m_loop
Definition: YStatement.h:395
Definition: YStatement.h:509
virtual ykind kind() const
Definition: YStatement.h:303
Definition: YCode.h:141
Definition: YStatement.h:465
constTypePtr conditionType() const
Definition: YStatement.h:532
Ustring m_filename
Definition: YStatement.h:491
virtual ykind kind() const
Definition: YStatement.h:496

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