Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Examples

YExpression.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:        YExpression.h
00014 
00015    Author:      Klaus Kaempf <kkaempf@suse.de>
00016    Maintainer:  Klaus Kaempf <kkaempf@suse.de>
00017 
00018    This file defines the various 'expressions' in YCode
00019 
00020 /-*/
00021 // -*- c++ -*-
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 //---------------------------------------------------------
00034 
00035 DEFINE_DERIVED_POINTER(YEVariable, YCode);
00036 DEFINE_DERIVED_POINTER(YEReference, YCode);
00037 DEFINE_DERIVED_POINTER(YETerm, YCode);
00038 DEFINE_DERIVED_POINTER(YECompare, YCode);
00039 DEFINE_DERIVED_POINTER(YELocale, YCode);
00040 DEFINE_DERIVED_POINTER(YEList, YCode);
00041 DEFINE_DERIVED_POINTER(YEMap, YCode);
00042 DEFINE_DERIVED_POINTER(YEPropagate, YCode);
00043 DEFINE_DERIVED_POINTER(YEUnary, YCode);
00044 DEFINE_DERIVED_POINTER(YEBinary, YCode);
00045 DEFINE_DERIVED_POINTER(YETriple, YCode);
00046 DEFINE_DERIVED_POINTER(YEIs, YCode);
00047 DEFINE_DERIVED_POINTER(YEReturn, YCode);
00048 DEFINE_DERIVED_POINTER(YEBracket, YCode);
00049 DEFINE_DERIVED_POINTER(YEBuiltin, YCode);
00050 DEFINE_DERIVED_POINTER(YEFunction, YCode);
00051 
00052 //---------------------------------------------------------
00053 // variable ref (-> Block + position)
00054 
00055 class YEVariable : public YCode
00056 {
00057     REP_BODY(YEVariable);
00058     SymbolEntryPtr m_entry;
00059 public:
00060     YEVariable (SymbolEntryPtr entry);
00061     YEVariable (std::istream & str);
00062     ~YEVariable () {};
00063     const char *name () const;
00064     SymbolEntryPtr entry () const;
00065     string toString () const;
00066     YCPValue evaluate (bool cse = false);
00067     std::ostream & toStream (std::ostream & str) const;
00068     constTypePtr type() const { return m_entry->type(); }
00069 };
00070 
00071 //---------------------------------------------------------
00072 // reference (-> Block + position)
00073 
00074 class YEReference : public YCode
00075 {
00076     REP_BODY(YEReference);
00077     SymbolEntryPtr m_entry;
00078 public:
00079     YEReference (SymbolEntryPtr entry);
00080     YEReference (std::istream & str);
00081     ~YEReference () {};
00082     const char *name () const;
00083     SymbolEntryPtr entry () const;
00084     string toString () const;
00085     YCPValue evaluate (bool cse = false);
00086     std::ostream & toStream (std::ostream & str) const;
00087     constTypePtr type() const;
00088 };
00089 
00090 //---------------------------------------------------------
00091 // Term (-> name, args)
00092 
00093 class YETerm : public YCode
00094 {
00095     REP_BODY(YETerm);
00096     const char *m_name;
00097     ycodelist_t *m_parameters;
00098 public:
00099     YETerm (const char *name);
00100     YETerm (std::istream & str);
00101     ~YETerm ();
00102     // dummy is here just to make it similar to YEBuiltin and YEFunction
00103     constTypePtr attachParameter (YCodePtr code, constTypePtr dummy = Type::Unspec);
00104     string toString () const;
00105     const char *name () const;
00106     YCPValue evaluate (bool cse = false);
00107     std::ostream & toStream (std::ostream & str) const;
00108     constTypePtr type() const { return Type::Term; }
00109 };
00110 
00111 
00112 //---------------------------------------------------------
00113 // Compare (-> arg1, arg2, type)
00114 
00115 class YECompare : public YCode
00116 {
00117     REP_BODY(YECompare);
00118 public:
00119     enum cmp_op { C_NOT = 1, C_EQ = 2, C_LT = 4,        // base operations
00120                   C_NEQ = C_NOT|C_EQ,
00121                   C_LE =  C_EQ|C_LT,
00122                   C_GE =  C_NOT|C_LT,
00123                   C_GT =  C_NOT|C_EQ|C_LT
00124     };
00125     typedef cmp_op c_op;            
00126 private:
00127     YCodePtr m_left;
00128     c_op m_op;
00129     YCodePtr m_right;
00130 public:
00131     YECompare (YCodePtr left, c_op op, YCodePtr right);
00132     YECompare (std::istream & str);
00133     ~YECompare ();
00134     string toString () const;
00135     YCPValue evaluate (bool cse = false);
00136     std::ostream & toStream (std::ostream & str) const;
00137     constTypePtr type() const { return Type::Boolean; }
00138 };
00139 
00140 
00141 //---------------------------------------------------------
00142 // locale expression (-> singular, plural, count)
00143 
00144 class YELocale : public YCode
00145 {
00146     REP_BODY(YELocale);
00147     const char *m_singular;
00148     const char *m_plural;
00149     YCodePtr m_count;
00150     YLocale::t_uniquedomains::const_iterator m_domain;
00151 public:
00152     YELocale (const char *singular, const char *plural, YCodePtr count, const char *textdomain);
00153     YELocale (std::istream & str);
00154     ~YELocale ();
00155     string toString () const;
00156     YCPValue evaluate (bool cse = false);
00157     std::ostream & toStream (std::ostream & str) const;
00158     constTypePtr type() const { return Type::Locale; }
00159 };
00160 
00161 
00162 //---------------------------------------------------------
00163 // list expression (-> value, next list value)
00164 
00165 class YEList : public YCode
00166 {
00167     REP_BODY(YEList);
00168     ycodelist_t *m_first;
00169 public:
00170     YEList (YCodePtr code);
00171     YEList (std::istream & str);
00172     ~YEList ();
00173     void attach (YCodePtr element);
00174 //    YCodePtr code () const;
00175     string toString () const;
00176     YCPValue evaluate (bool cse = false);
00177     std::ostream & toStream (std::ostream & str) const;
00178     constTypePtr type() const { return Type::List; }
00179     int count () const;
00180     YCodePtr value (int index) const;
00181 };
00182 
00183 
00184 //---------------------------------------------------------
00185 // map expression (-> key, value, next key/value pair)
00186 
00187 class YEMap : public YCode
00188 {
00189     REP_BODY(YEMap);
00190     typedef struct mapval { YCodePtr key; YCodePtr value; struct mapval *next; } mapval_t;
00191     mapval_t *m_first;
00192 public:
00193     YEMap (YCodePtr key, YCodePtr value);
00194     YEMap (std::istream & str);
00195     ~YEMap ();
00196     void attach (YCodePtr key, YCodePtr value);
00197 //    YCodePtr key () const;
00198 //    YCodePtr value () const;
00199     string toString () const;
00200     YCPValue evaluate (bool cse = false);
00201     std::ostream & toStream (std::ostream & str) const;
00202     constTypePtr type() const { return Type::Map; }
00203 };
00204 
00205 
00206 //---------------------------------------------------------
00207 // propagation expression (-> value, from type, to type)
00208 
00209 class YEPropagate : public YCode
00210 {
00211     REP_BODY(YEPropagate);
00212     constTypePtr m_from;
00213     constTypePtr m_to;
00214     YCodePtr m_value;
00215 public:
00216     YEPropagate (YCodePtr value, constTypePtr from, constTypePtr to);
00217     YEPropagate (std::istream & str);
00218     ~YEPropagate ();
00219     string toString () const;
00220     bool canPropagate(const YCPValue& value, constTypePtr to_type) const;
00221     YCPValue evaluate (bool cse = false);
00222     std::ostream & toStream (std::ostream & str) const;
00223     constTypePtr type() const { return m_to; }
00224 };
00225 
00226 
00227 //---------------------------------------------------------
00228 // unary expression (-> declaration_t, arg)
00229 
00230 class YEUnary : public YCode
00231 {
00232     REP_BODY(YEUnary);
00233     declaration_t *m_decl;
00234     YCodePtr m_arg;             // argument
00235 public:
00236     YEUnary (declaration_t *decl, YCodePtr arg);                // expression
00237     YEUnary (std::istream & str);
00238     ~YEUnary ();
00239     declaration_t *decl () const;
00240 //    YCodePtr arg () const;
00241     string toString () const;
00242     YCPValue evaluate (bool cse = false);
00243     std::ostream & toStream (std::ostream & str) const;
00244     constTypePtr type() const { return m_decl->type; }
00245 };
00246 
00247 
00248 //---------------------------------------------------------
00249 // binary expression (-> declaration_t, arg1, arg2)
00250 
00251 class YEBinary : public YCode
00252 {
00253     REP_BODY(YEBinary);
00254     declaration_t *m_decl;
00255     YCodePtr m_arg1;            // argument1
00256     YCodePtr m_arg2;            // argument2
00257 public:
00258     YEBinary (declaration_t *decl, YCodePtr arg1, YCodePtr arg2);
00259     YEBinary (std::istream & str);
00260     ~YEBinary ();
00261     declaration_t *decl ();
00262 //    YCodePtr arg1 () const;
00263 //    YCodePtr arg2 () const;
00264     string toString () const;
00265     YCPValue evaluate (bool cse = false);
00266     std::ostream & toStream (std::ostream & str) const;
00267     constTypePtr type() const { return m_decl->type; }
00268 };
00269 
00270 
00271 //---------------------------------------------------------
00272 // Triple (? :) expression (-> bool expr, true value, false value)
00273 
00274 class YETriple : public YCode
00275 {
00276     REP_BODY(YETriple);
00277     YCodePtr m_expr;            // bool expr
00278     YCodePtr m_true;            // true value
00279     YCodePtr m_false;           // false value
00280 public:
00281     YETriple (YCodePtr a_expr, YCodePtr a_true, YCodePtr a_false);
00282     YETriple (std::istream & str);
00283     ~YETriple ();
00284 //    YCodePtr expr () const;
00285 //    YCodePtr iftrue () const;
00286 //    YCodePtr iffalse () const;
00287     string toString () const;
00288     YCPValue evaluate (bool cse = false);
00289     std::ostream & toStream (std::ostream & str) const;
00290     constTypePtr type() const { return m_true->type ()->commontype (m_false->type ()); }
00291 };
00292 
00293 
00294 //---------------------------------------------------------
00295 // is (-> expression, type)
00296 
00297 class YEIs : public YCode
00298 {
00299     REP_BODY(YEIs);
00300     YCodePtr m_expr;
00301     constTypePtr m_type;
00302 public:
00303     YEIs (YCodePtr expr, constTypePtr type);
00304     YEIs (std::istream & str);
00305     ~YEIs ();
00306     string toString () const;
00307     YCPValue evaluate (bool cse = false);
00308     std::ostream & toStream (std::ostream & str) const;
00309     constTypePtr type() const { return Type::Boolean; }
00310 };
00311 
00312 
00313 //---------------------------------------------------------
00314 // return (-> expression)
00315 
00316 class YEReturn : public YCode
00317 {
00318     REP_BODY(YEReturn);
00319     YCodePtr m_expr;
00320 public:
00321     YEReturn (YCodePtr expr);
00322     YEReturn (std::istream & str);
00323     ~YEReturn ();
00324     string toString () const;
00325     YCPValue evaluate (bool cse = false);
00326     std::ostream & toStream (std::ostream & str) const;
00327     constTypePtr type() const { return m_expr->type(); }
00328 };
00329 
00330 
00331 //---------------------------------------------------------
00332 // bracket (-> expression)
00333 
00334 class YEBracket : public YCode
00335 {
00336     REP_BODY(YEBracket);
00337     YCodePtr m_var;             // (list, map) variable
00338     YCodePtr m_arg;             // bracket arguments
00339     YCodePtr m_def;             // default expression
00340     constTypePtr m_resultType;  // result type according to the parser
00341 public:
00342     YEBracket (YCodePtr var, YCodePtr arg, YCodePtr def, constTypePtr resultType);
00343     YEBracket (std::istream & str);
00344     ~YEBracket ();
00345     string toString () const;
00346     YCPValue evaluate (bool cse = false);
00347     std::ostream & toStream (std::ostream & str) const;
00348     constTypePtr type() const { return m_resultType; }
00349     YCodePtr def () const { return m_def; }
00350 };
00351 
00352 
00353 //---------------------------------------------------------
00354 // Builtin ref (-> declaration_t, type, Args)
00355 
00356 class YEBuiltin : public YCode
00357 {
00358     REP_BODY(YEBuiltin);
00359     declaration_t *m_decl;
00360     constFunctionTypePtr m_type;
00361 
00362     // symbol parameters (NULL, if no symbolic parameters)
00363     YBlockPtr m_parameterblock;
00364 
00365     ycodelist_t *m_parameters;
00366 public:
00367     YEBuiltin (declaration_t *decl, YBlockPtr parameterblock = 0, constTypePtr type = 0);
00368     YEBuiltin (std::istream & str);
00369     ~YEBuiltin ();
00370     declaration_t *decl () const;
00379     constTypePtr finalize ();
00380     // check if m_parameterblock is really needed, drop if not
00381     void closeParameters ();
00382     constTypePtr returnType () const;
00383     // see YEFunction::attachParameter
00384     constTypePtr attachParameter (YCodePtr code, constTypePtr type = Type::Unspec);
00385     // attach symbolic variable parameter to function, return created TableEntry
00386     constTypePtr attachSymVariable (const char *name, constTypePtr type, unsigned int line, TableEntry *&tentry);
00387     string toString () const;
00388     YCPValue evaluate (bool cse = false);
00389     std::ostream & toStream (std::ostream & str) const;
00390     constTypePtr type () const;
00391     YBlockPtr parameterBlock () const;
00392 };
00393 
00394 //---------------------------------------------------------
00395 // Function ref (-> SymbolEntry ( param, param, ...) )
00396 
00397 class YEFunction : public YCode, public Y2Function
00398 {
00399     REP_BODY(YEFunction);
00400     const SymbolEntryPtr m_entry;
00401     ycodelist_t *m_parameters;
00402 public:
00403     YEFunction (const SymbolEntryPtr entry);
00404     YEFunction (std::istream & str);
00405     ~YEFunction ();
00406     const SymbolEntryPtr entry () const;
00416     constTypePtr attachParameter (YCodePtr code, constTypePtr type);
00424     constTypePtr finalize ();
00425     string toString () const;
00426     virtual YCPValue evaluate (bool cse = false);
00427     std::ostream & toStream (std::ostream & str) const;
00428     constTypePtr type() const;
00429     string qualifiedName () const;
00430 
00431     // implementation of the Y2Function interface:
00432 
00433     virtual bool attachParameter (const YCPValue& arg, const int pos);
00434     virtual constTypePtr wantedParameterType () const;
00435     virtual bool appendParameter (const YCPValue& arg);
00436     virtual bool finishParameters ();
00437     virtual YCPValue evaluateCall () { return evaluate (); }
00438 };
00439 
00440 #endif   // YExpression_h

Generated on Fri Nov 9 18:15:23 2007 for yast2-core by doxygen 1.3.6