00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef YExpression_h
00024 #define YExpression_h
00025
00026 #include <iosfwd>
00027 #include <string>
00028 using std::string;
00029
00030 #include "ycp/YCode.h"
00031 #include "y2/Y2Function.h"
00032
00033 class Logger;
00034
00035
00036
00037 DEFINE_DERIVED_POINTER(YEVariable, YCode);
00038 DEFINE_DERIVED_POINTER(YEReference, YCode);
00039 DEFINE_DERIVED_POINTER(YETerm, YCode);
00040 DEFINE_DERIVED_POINTER(YECompare, YCode);
00041 DEFINE_DERIVED_POINTER(YELocale, YCode);
00042 DEFINE_DERIVED_POINTER(YEList, YCode);
00043 DEFINE_DERIVED_POINTER(YEMap, YCode);
00044 DEFINE_DERIVED_POINTER(YEPropagate, YCode);
00045 DEFINE_DERIVED_POINTER(YEUnary, YCode);
00046 DEFINE_DERIVED_POINTER(YEBinary, YCode);
00047 DEFINE_DERIVED_POINTER(YETriple, YCode);
00048 DEFINE_DERIVED_POINTER(YEIs, YCode);
00049 DEFINE_DERIVED_POINTER(YEReturn, YCode);
00050 DEFINE_DERIVED_POINTER(YEBracket, YCode);
00051 DEFINE_DERIVED_POINTER(YEBuiltin, YCode);
00052 DEFINE_DERIVED_POINTER(YECall, YCode);
00053 DEFINE_DERIVED_POINTER(YEFunction, YECall);
00054 DEFINE_DERIVED_POINTER(YEFunctionPointer, YECall);
00055
00056
00057
00058
00059 class YEVariable : public YCode
00060 {
00061 REP_BODY(YEVariable);
00062 SymbolEntryPtr m_entry;
00063 public:
00064 YEVariable (SymbolEntryPtr entry);
00065 YEVariable (bytecodeistream & str);
00066 ~YEVariable () {};
00067 const char *name () const;
00068 SymbolEntryPtr entry () const;
00069 string toString () const;
00070 YCPValue evaluate (bool cse = false);
00071 std::ostream & toStream (std::ostream & str) const;
00072 constTypePtr type() const { return m_entry->type(); }
00073 };
00074
00075
00076
00077
00078 class YEReference : public YCode
00079 {
00080 REP_BODY(YEReference);
00081 SymbolEntryPtr m_entry;
00082 public:
00083 YEReference (SymbolEntryPtr entry);
00084 YEReference (bytecodeistream & str);
00085 ~YEReference () {};
00086 const char *name () const;
00087 SymbolEntryPtr entry () const;
00088 string toString () const;
00089 YCPValue evaluate (bool cse = false);
00090 std::ostream & toStream (std::ostream & str) const;
00091 constTypePtr type() const;
00092 };
00093
00094
00095
00096
00097 class YETerm : public YCode
00098 {
00099 REP_BODY(YETerm);
00100 const char *m_name;
00101 ycodelist_t *m_parameters;
00102 public:
00103 YETerm (const char *name);
00104 YETerm (bytecodeistream & str);
00105 ~YETerm ();
00106
00107 constTypePtr attachParameter (YCodePtr code, constTypePtr dummy = Type::Unspec);
00108 string toString () const;
00109 const char *name () const;
00110 YCPValue evaluate (bool cse = false);
00111 std::ostream & toStream (std::ostream & str) const;
00112 constTypePtr type() const { return Type::Term; }
00113 };
00114
00115
00116
00117
00118
00119 class YECompare : public YCode
00120 {
00121 REP_BODY(YECompare);
00122 public:
00123 enum cmp_op { C_NOT = 1, C_EQ = 2, C_LT = 4,
00124 C_NEQ = C_NOT|C_EQ,
00125 C_LE = C_EQ|C_LT,
00126 C_GE = C_NOT|C_LT,
00127 C_GT = C_NOT|C_EQ|C_LT
00128 };
00129 typedef cmp_op c_op;
00130 private:
00131 YCodePtr m_left;
00132 c_op m_op;
00133 YCodePtr m_right;
00134 public:
00135 YECompare (YCodePtr left, c_op op, YCodePtr right);
00136 YECompare (bytecodeistream & str);
00137 ~YECompare ();
00138 string toString () const;
00139 YCPValue evaluate (bool cse = false);
00140 std::ostream & toStream (std::ostream & str) const;
00141 constTypePtr type() const { return Type::Boolean; }
00142 };
00143
00144
00145
00146
00147
00148 class YELocale : public YCode
00149 {
00150 REP_BODY(YELocale);
00151 const char *m_singular;
00152 const char *m_plural;
00153 YCodePtr m_count;
00154 YLocale::t_uniquedomains::const_iterator m_domain;
00155 public:
00156 YELocale (const char *singular, const char *plural, YCodePtr count, const char *textdomain);
00157 YELocale (bytecodeistream & str);
00158 ~YELocale ();
00159 string toString () const;
00160 YCPValue evaluate (bool cse = false);
00161 std::ostream & toStream (std::ostream & str) const;
00162 constTypePtr type() const { return Type::Locale; }
00163 };
00164
00165
00166
00167
00168
00169 class YEList : public YCode
00170 {
00171 REP_BODY(YEList);
00172 ycodelist_t *m_first;
00173 public:
00174 YEList (YCodePtr code);
00175 YEList (bytecodeistream & str);
00176 ~YEList ();
00177 void attach (YCodePtr element);
00178
00179 string toString () const;
00180 YCPValue evaluate (bool cse = false);
00181 std::ostream & toStream (std::ostream & str) const;
00182 constTypePtr type() const;
00183 int count () const;
00184 YCodePtr value (int index) const;
00185 };
00186
00187
00188
00189
00190
00191 class YEMap : public YCode
00192 {
00193 REP_BODY(YEMap);
00194 typedef struct mapval { YCodePtr key; YCodePtr value; struct mapval *next; } mapval_t;
00195 mapval_t *m_first;
00196 public:
00197 YEMap (YCodePtr key, YCodePtr value);
00198 YEMap (bytecodeistream & str);
00199 ~YEMap ();
00200 void attach (YCodePtr key, YCodePtr value);
00201
00202
00203 string toString () const;
00204 YCPValue evaluate (bool cse = false);
00205 std::ostream & toStream (std::ostream & str) const;
00206 constTypePtr type() const;
00207 };
00208
00209
00210
00211
00212
00213 class YEPropagate : public YCode
00214 {
00215 REP_BODY(YEPropagate);
00216 constTypePtr m_from;
00217 constTypePtr m_to;
00218 YCodePtr m_value;
00219 public:
00220 YEPropagate (YCodePtr value, constTypePtr from, constTypePtr to);
00221 YEPropagate (bytecodeistream & str);
00222 ~YEPropagate ();
00223 string toString () const;
00224 bool canPropagate(const YCPValue& value, constTypePtr to_type) const;
00225 YCPValue evaluate (bool cse = false);
00226 std::ostream & toStream (std::ostream & str) const;
00227 constTypePtr type() const { return m_to; }
00228 };
00229
00230
00231
00232
00233
00234 class YEUnary : public YCode
00235 {
00236 REP_BODY(YEUnary);
00237 declaration_t *m_decl;
00238 YCodePtr m_arg;
00239 public:
00240 YEUnary (declaration_t *decl, YCodePtr arg);
00241 YEUnary (bytecodeistream & str);
00242 ~YEUnary ();
00243 declaration_t *decl () const;
00244
00245 string toString () const;
00246 YCPValue evaluate (bool cse = false);
00247 std::ostream & toStream (std::ostream & str) const;
00248 constTypePtr type() const { return ((constFunctionTypePtr)m_decl->type)->returnType (); }
00249 };
00250
00251
00252
00253
00254
00255 class YEBinary : public YCode
00256 {
00257 REP_BODY(YEBinary);
00258 declaration_t *m_decl;
00259 YCodePtr m_arg1;
00260 YCodePtr m_arg2;
00261 public:
00262 YEBinary (declaration_t *decl, YCodePtr arg1, YCodePtr arg2);
00263 YEBinary (bytecodeistream & str);
00264 ~YEBinary ();
00265 declaration_t *decl ();
00266
00267
00268 string toString () const;
00269 YCPValue evaluate (bool cse = false);
00270 std::ostream & toStream (std::ostream & str) const;
00271 constTypePtr type() const;
00272 };
00273
00274
00275
00276
00277
00278 class YETriple : public YCode
00279 {
00280 REP_BODY(YETriple);
00281 YCodePtr m_expr;
00282 YCodePtr m_true;
00283 YCodePtr m_false;
00284 public:
00285 YETriple (YCodePtr a_expr, YCodePtr a_true, YCodePtr a_false);
00286 YETriple (bytecodeistream & str);
00287 ~YETriple ();
00288
00289
00290
00291 string toString () const;
00292 YCPValue evaluate (bool cse = false);
00293 std::ostream & toStream (std::ostream & str) const;
00294 constTypePtr type() const { return m_true->type ()->commontype (m_false->type ()); }
00295 };
00296
00297
00298
00299
00300
00301 class YEIs : public YCode
00302 {
00303 REP_BODY(YEIs);
00304 YCodePtr m_expr;
00305 constTypePtr m_type;
00306 public:
00307 YEIs (YCodePtr expr, constTypePtr type);
00308 YEIs (bytecodeistream & str);
00309 ~YEIs ();
00310 string toString () const;
00311 YCPValue evaluate (bool cse = false);
00312 std::ostream & toStream (std::ostream & str) const;
00313 constTypePtr type() const { return Type::Boolean; }
00314 };
00315
00316
00317
00318
00319
00320 class YEReturn : public YCode
00321 {
00322 REP_BODY(YEReturn);
00323 YCodePtr m_expr;
00324 public:
00325 YEReturn (YCodePtr expr);
00326 YEReturn (bytecodeistream & str);
00327 ~YEReturn ();
00328 string toString () const;
00329 YCPValue evaluate (bool cse = false);
00330 std::ostream & toStream (std::ostream & str) const;
00331 constTypePtr type() const { return m_expr->type(); }
00332 };
00333
00334
00335
00336
00337
00338 class YEBracket : public YCode
00339 {
00340 REP_BODY(YEBracket);
00341 YCodePtr m_var;
00342 YCodePtr m_arg;
00343 YCodePtr m_def;
00344 constTypePtr m_resultType;
00345 public:
00346 YEBracket (YCodePtr var, YCodePtr arg, YCodePtr def, constTypePtr resultType);
00347 YEBracket (bytecodeistream & str);
00348 ~YEBracket ();
00349 string toString () const;
00350 YCPValue evaluate (bool cse = false);
00351 std::ostream & toStream (std::ostream & str) const;
00352 constTypePtr type() const { return m_resultType; }
00353 YCodePtr def () const { return m_def; }
00354 };
00355
00356
00357
00358
00359
00360 class YEBuiltin : public YCode
00361 {
00362 REP_BODY(YEBuiltin);
00363 declaration_t *m_decl;
00364 constFunctionTypePtr m_type;
00365
00366
00367 YBlockPtr m_parameterblock;
00368
00369 ycodelist_t *m_parameters;
00370 public:
00371 YEBuiltin (declaration_t *decl, YBlockPtr parameterblock = 0, constTypePtr type = 0);
00372 YEBuiltin (bytecodeistream & str);
00373 ~YEBuiltin ();
00374 declaration_t *decl () const;
00383 constTypePtr finalize (Logger* problem_logger);
00384
00385 void closeParameters ();
00386
00387 constTypePtr attachParameter (YCodePtr code, constTypePtr type = Type::Unspec);
00388
00389 constTypePtr attachSymVariable (const char *name, constTypePtr type, unsigned int line, TableEntry *&tentry);
00390 string toString () const;
00391 YCPValue evaluate (bool cse = false);
00392 std::ostream & toStream (std::ostream & str) const;
00393 constTypePtr type () const;
00394 constTypePtr completeType () const;
00395 YBlockPtr parameterBlock () const;
00396 };
00397
00398
00399
00400
00401 class YECall : public YCode
00402 {
00403 REP_BODY(YECall);
00404 protected:
00405 TableEntry* m_entry;
00406 SymbolEntryPtr m_sentry;
00407 YCodePtr *m_parameters;
00408 constTypePtr *m_parameter_types;
00409 Y2Function* m_functioncall;
00410
00411 uint m_next_param_id;
00412 public:
00413 YECall (TableEntry* entry);
00414 YECall (bytecodeistream & str);
00415 ~YECall ();
00416 const SymbolEntryPtr entry () const;
00426 constTypePtr attachParameter (YCodePtr code, constTypePtr type);
00434 virtual constTypePtr finalize ();
00435 string toString () const;
00436 std::ostream & toStream (std::ostream & str) const;
00437 constTypePtr type() const;
00438 string qualifiedName () const;
00439
00440 static YECallPtr readCall (bytecodeistream & str);
00441 };
00442
00443
00444
00445
00446 class YEFunction : public YECall
00447 {
00448 REP_BODY(YEFunction);
00449 public:
00450 YEFunction (TableEntry* entry);
00451 YEFunction (bytecodeistream & str);
00452 virtual YCPValue evaluate (bool cse = false);
00453 virtual constTypePtr finalize ();
00454 };
00455
00456
00457
00458
00459 class YEFunctionPointer : public YECall
00460 {
00461 REP_BODY(YEFunctionPointer);
00462 public:
00463 YEFunctionPointer (TableEntry* entry);
00464 YEFunctionPointer (bytecodeistream & str);
00465 virtual YCPValue evaluate (bool cse = false);
00466 };
00467
00468
00469
00470
00471 class Y2YCPFunction : public Y2Function
00472 {
00473 YSymbolEntryPtr m_sentry;
00474 YCPValue* m_parameters;
00475 public:
00476 Y2YCPFunction (YSymbolEntryPtr entry);
00477 ~Y2YCPFunction ();
00478
00479 string qualifiedName () const;
00480 string name () const;
00481
00482
00483
00484 virtual bool attachParameter (const YCPValue& arg, const int pos);
00485 virtual constTypePtr wantedParameterType () const;
00486 virtual bool appendParameter (const YCPValue& arg);
00487 virtual bool finishParameters ();
00488 virtual YCPValue evaluateCall ();
00489 virtual bool reset ();
00490 };
00491
00492 #endif // YExpression_h