00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef YCode_h
00022 #define YCode_h
00023
00024 #include <string>
00025 using std::string;
00026
00027
00028 #include <y2util/MemUsage.h>
00029 #include "ycp/YCodePtr.h"
00030
00031 #include "ycp/YCPValue.h"
00032 #include "ycp/YCPString.h"
00033 #include "ycp/Type.h"
00034 #include "ycp/SymbolEntry.h"
00035
00043 struct ycodelist {
00044 struct ycodelist *next;
00045 YCodePtr code;
00046 };
00047 typedef struct ycodelist ycodelist_t;
00048
00052 class YCode : public Rep
00053 #ifdef D_MEMUSAGE
00054 , public MemUsage
00055 #endif
00056 {
00057 REP_BODY(YCode);
00058 public:
00059 enum ykind {
00060 yxError = 0,
00061
00062 ycVoid, ycBoolean, ycInteger, ycFloat,
00063 ycString, ycByteblock, ycPath, ycSymbol,
00064 ycList,
00065 ycMap,
00066 ycTerm,
00067
00068 ycEntry,
00069
00070 ycConstant,
00071 ycLocale,
00072 ycFunction,
00073
00074
00075 yePropagate,
00076 yeUnary,
00077 yeBinary,
00078 yeTriple,
00079 yeCompare,
00080
00081
00082 yeLocale,
00083 yeList,
00084 yeMap,
00085 yeTerm,
00086 yeIs,
00087 yeBracket,
00088
00089
00090 yeBlock,
00091 yeReturn,
00092
00093
00094 yeVariable,
00095 yeBuiltin,
00096 yeFunction,
00097 yeReference,
00098
00099 yeExpression,
00100
00101
00102 ysTypedef,
00103 ysVariable,
00104 ysFunction,
00105 ysAssign,
00106 ysBracket,
00107 ysIf,
00108 ysWhile,
00109 ysDo,
00110 ysRepeat,
00111 ysExpression,
00112 ysReturn,
00113 ysBreak,
00114 ysContinue,
00115 ysTextdomain,
00116 ysInclude,
00117 ysFilename,
00118 ysImport,
00119 ysBlock,
00120 ysStatement
00121 };
00122
00123 protected:
00124 ykind m_kind;
00125 bool m_valid;
00126
00127 public:
00128
00132 YCode (ykind kind);
00133
00137 virtual ~YCode();
00138
00142 ykind kind() const;
00143
00147 bool valid() const;
00148
00152 virtual string toString() const;
00153 static string toString(ykind kind);
00154
00159 virtual std::ostream & toStream (std::ostream & str) const = 0;
00160
00164 bool isConstant () const;
00165
00169 bool isError () const;
00170
00174 bool isStatement () const;
00175
00179 bool isBlock () const;
00180
00184 bool isReferenceable () const;
00185
00193 virtual YCPValue evaluate (bool cse = false);
00194
00198 virtual constTypePtr type() const;
00199 };
00200
00201
00208 class YError : public YCode
00209 {
00210 REP_BODY(YError);
00211 int m_line;
00212 const char *m_msg;
00213 public:
00214 YError (int line=0, const char *msg=0);
00215 ~YError () {}
00216 YCPValue evaluate (bool cse = false);
00217 string toString() const;
00218 std::ostream & toStream (std::ostream & str) const;
00219 constTypePtr type() const { return Type::Error; }
00220 };
00221
00226 class YConst : public YCode
00227 {
00228 REP_BODY(YConst);
00229 YCPValue m_value;
00230 public:
00231 YConst (ykind kind, YCPValue value);
00232 YConst (ykind kind, std::istream & str);
00233 ~YConst () {};
00234 YCPValue value() const;
00235 string toString() const;
00236 std::ostream & toStream (std::ostream & str) const;
00237 YCPValue evaluate (bool cse = false);
00238 constTypePtr type() const;
00239 };
00240
00241 #include <ext/hash_map>
00242 #include <string>
00243 #include <cstddef>
00244
00251 class YELocale;
00252
00253 class YLocale : public YCode
00254 {
00255 REP_BODY(YLocale);
00256 const char *m_locale;
00257
00258 struct eqstr
00259 {
00260 bool operator()(const char* s1, const char* s2) const
00261 {
00262 return strcmp(s1, s2) == 0;
00263 }
00264 };
00265
00266 public:
00267 typedef __gnu_cxx::hash_map<const char*, bool, __gnu_cxx::hash<const char*>, eqstr> t_uniquedomains;
00268
00269 static t_uniquedomains domains;
00270 static t_uniquedomains::const_iterator setDomainStatus (const string& domain, bool status);
00271 static void ensureBindDomain (const string& domain);
00272
00273 YLocale (const char *locale, const char *textdomain);
00274 YLocale (std::istream & str);
00275 ~YLocale ();
00276 const char *value () const;
00277 const char *domain () const;
00278 string toString() const;
00279 std::ostream & toStream (std::ostream & str) const;
00280 YCPValue evaluate (bool cse = false);
00281 constTypePtr type() const { return Type::Locale; }
00282
00283 private:
00284
00285 t_uniquedomains::const_iterator m_domain;
00286
00287 };
00288
00293 class YDeclaration : public YCode
00294 {
00295 REP_BODY(YDeclaration);
00296 declaration_t *m_value;
00297 public:
00298 YDeclaration (ykind kind, declaration_t *value);
00299 YDeclaration (std::istream & str);
00300 ~YDeclaration () {};
00301 declaration_t *value() const;
00302 string toString() const;
00303 std::ostream & toStream (std::ostream & str) const;
00304 YCPValue evaluate (bool cse = false);
00305 constTypePtr type() const { return m_value->type; }
00306 };
00307
00314 class YFunction : public YCode
00315 {
00316 REP_BODY(YFunction);
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 YBlockPtr m_declaration;
00329
00330
00331 YBlockPtr m_definition;
00332
00333 bool m_is_global;
00334
00335 public:
00336 YFunction (YBlockPtr parameterblock, const SymbolEntryPtr entry = 0);
00337 YFunction (std::istream & str);
00338 ~YFunction ();
00339
00340
00341 unsigned int parameterCount () const;
00342 YBlockPtr declaration () const;
00343 SymbolEntryPtr parameter (unsigned int position) const;
00344
00345
00346 YBlockPtr definition () const;
00347 void setDefinition (YBlockPtr body);
00348
00349 void setDefinition (std::istream & str);
00350
00351 string toStringDeclaration () const;
00352 string toString () const;
00353 std::ostream & toStreamDefinition (std::ostream & str) const;
00354 std::ostream & toStream (std::ostream & str) const;
00355 virtual YCPValue evaluate (bool cse = false);
00356 constTypePtr type() const;
00357 };
00358
00359
00360 #endif // YCode_h