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/YSymbolEntry.h"
00035
00043 struct ycodelist {
00044 struct ycodelist *next;
00045 YCodePtr code;
00046 constTypePtr type;
00047 };
00048 typedef struct ycodelist ycodelist_t;
00049
00053 class YCode : public Rep
00054 #ifdef D_MEMUSAGE
00055 , public MemUsage
00056 #endif
00057 {
00058 REP_BODY(YCode);
00059 public:
00060 enum ykind {
00061 yxError = 0,
00062
00063 ycVoid, ycBoolean, ycInteger, ycFloat,
00064 ycString, ycByteblock, ycPath, ycSymbol,
00065 ycList,
00066 ycMap,
00067 ycTerm,
00068
00069 ycEntry,
00070
00071 ycConstant,
00072 ycLocale,
00073 ycFunction,
00074
00075
00076 yePropagate,
00077 yeUnary,
00078 yeBinary,
00079 yeTriple,
00080 yeCompare,
00081
00082
00083 yeLocale,
00084 yeList,
00085 yeMap,
00086 yeTerm,
00087 yeIs,
00088 yeBracket,
00089
00090
00091 yeBlock,
00092 yeReturn,
00093
00094
00095 yeVariable,
00096 yeBuiltin,
00097 yeFunction,
00098 yeReference,
00099
00100 yeFunctionPointer,
00101
00102 yeExpression,
00103
00104
00105 ysTypedef,
00106 ysVariable,
00107 ysFunction,
00108 ysAssign,
00109 ysBracket,
00110 ysIf,
00111 ysWhile,
00112 ysDo,
00113 ysRepeat,
00114 ysExpression,
00115 ysReturn,
00116 ysBreak,
00117 ysContinue,
00118 ysTextdomain,
00119 ysInclude,
00120 ysFilename,
00121 ysImport,
00122 ysBlock,
00123 ysSwitch,
00124 ysStatement
00125 };
00126
00127 public:
00128
00132 YCode ();
00133
00137 virtual ~YCode();
00138
00142 virtual ykind kind() const = 0;
00143
00147 virtual string toString() const;
00148 static string toString(ykind kind);
00149
00154 virtual std::ostream & toStream (std::ostream & str) const = 0;
00155 virtual std::ostream & toXml (std::ostream & str, int indent ) const = 0;
00156
00160 virtual bool isConstant () const;
00161
00165 bool isError () const;
00166
00170 virtual bool isStatement () const;
00171
00175 virtual bool isBlock () const;
00176
00180 virtual bool isReferenceable () const;
00181
00189 virtual YCPValue evaluate (bool cse = false);
00190
00194 virtual constTypePtr type() const;
00195 };
00196
00197
00202 class YConst : public YCode
00203 {
00204 REP_BODY(YConst);
00205 ykind m_kind;
00206 YCPValue m_value;
00207 public:
00208 YConst (ykind kind, YCPValue value);
00209 YConst (ykind kind, bytecodeistream & str);
00210 ~YConst () {};
00211 YCPValue value() const;
00212 virtual ykind kind() const;
00213 string toString() const;
00214 std::ostream & toStream (std::ostream & str) const;
00215 std::ostream & toXml (std::ostream & str, int indent ) const;
00217 virtual bool isConstant () const { return true; }
00218 YCPValue evaluate (bool cse = false);
00219 constTypePtr type() const;
00220 };
00221
00222
00223
00224
00225 #ifdef HAVE_CXX0X
00226 #include <unordered_map>
00227 #else
00228 #include <ext/hash_map>
00229 #endif
00230
00231 #include <string>
00232 #include <cstddef>
00233
00240 class YELocale;
00241
00242 class YLocale : public YCode
00243 {
00244 REP_BODY(YLocale);
00245 const char *m_locale;
00246
00247 struct eqstr
00248 {
00249 bool operator()(const char* s1, const char* s2) const
00250 {
00251 return strcmp(s1, s2) == 0;
00252 }
00253 };
00254
00255 public:
00256 #ifdef HAVE_CXX0X
00257 typedef unordered_map<const char*, bool, hash<const char*>, eqstr> t_uniquedomains;
00258 #else
00259 typedef __gnu_cxx::hash_map<const char*, bool, __gnu_cxx::hash<const char*>, eqstr> t_uniquedomains;
00260 #endif
00261
00262 static t_uniquedomains domains;
00263 static t_uniquedomains::const_iterator setDomainStatus (const string& domain, bool status);
00264 static void ensureBindDomain (const string& domain);
00265 static void bindDomainDir (const string& domain, const string& domain_path);
00266 static bool findDomain(const string& domain);
00267 YLocale (const char *locale, const char *textdomain);
00268 YLocale (bytecodeistream & str);
00269 ~YLocale ();
00270 virtual ykind kind () const { return ycLocale; }
00271 const char *value () const;
00272 const char *domain () const;
00273 string toString() const;
00274 std::ostream & toStream (std::ostream & str) const;
00275 std::ostream & toXml (std::ostream & str, int indent ) const;
00276 YCPValue evaluate (bool cse = false);
00277 constTypePtr type() const { return Type::Locale; }
00278
00279 private:
00280
00281 t_uniquedomains::const_iterator m_domain;
00282
00283 };
00284
00291 class YFunction : public YCode
00292 {
00293 REP_BODY(YFunction);
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 YBlockPtr m_declaration;
00306
00307
00308 YBlockPtr m_definition;
00309
00310 bool m_is_global;
00311
00312 public:
00313 YFunction (YBlockPtr parameterblock, const SymbolEntryPtr entry = 0);
00314 YFunction (bytecodeistream & str);
00315 ~YFunction ();
00316 virtual ykind kind () const { return ycFunction; }
00317
00318
00319 unsigned int parameterCount () const;
00320 YBlockPtr declaration () const;
00321 SymbolEntryPtr parameter (unsigned int position) const;
00322
00323
00324 YBlockPtr definition () const;
00325 void setDefinition (YBlockPtr body);
00326
00327 void setDefinition (bytecodeistream & str);
00328
00329 string toStringDeclaration () const;
00330 string toString () const;
00331 std::ostream & toStreamDefinition (std::ostream & str ) const;
00332 std::ostream & toXmlDefinition (std::ostream & str, int indent ) const;
00333 std::ostream & toStream (std::ostream & str ) const;
00334 std::ostream & toXml (std::ostream & str, int indent ) const;
00335 virtual YCPValue evaluate (bool cse = false);
00336 constTypePtr type() const;
00337 };
00338
00339
00340 #endif // YCode_h