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
00039 #include <string>
00040 using std::string;
00041
00042
00043 #include <y2util/MemUsage.h>
00044 #include "ycp/YCodePtr.h"
00045
00046 #include "ycp/YCPValue.h"
00047 #include "ycp/YCPString.h"
00048 #include "ycp/Type.h"
00049 #include "ycp/YSymbolEntry.h"
00050
00058 struct ycodelist {
00059 struct ycodelist *next;
00060 YCodePtr code;
00061 constTypePtr type;
00062 };
00063 typedef struct ycodelist ycodelist_t;
00064
00075 class YCode : public Rep
00076 #ifdef D_MEMUSAGE
00077 , public MemUsage
00078 #endif
00079 {
00080 REP_BODY(YCode);
00081 public:
00082 enum ykind {
00083 yxError = 0,
00084
00085 ycVoid, ycBoolean, ycInteger, ycFloat,
00086 ycString, ycByteblock, ycPath, ycSymbol,
00087 ycList,
00088 ycMap,
00089 ycTerm,
00090
00091 ycEntry,
00092
00093 ycConstant,
00094 ycLocale,
00095 ycFunction,
00096
00097
00098 yePropagate,
00099 yeUnary,
00100 yeBinary,
00101 yeTriple,
00102 yeCompare,
00103
00104
00105 yeLocale,
00106 yeList,
00107 yeMap,
00108 yeTerm,
00109 yeIs,
00110 yeBracket,
00111
00112
00113 yeBlock,
00114 yeReturn,
00115
00116
00117 yeVariable,
00118 yeBuiltin,
00119 yeFunction,
00120 yeReference,
00121
00122 yeFunctionPointer,
00123
00124 yeExpression,
00125
00126
00127 ysTypedef,
00128 ysVariable,
00129 ysFunction,
00130 ysAssign,
00131 ysBracket,
00132 ysIf,
00133 ysWhile,
00134 ysDo,
00135 ysRepeat,
00136 ysExpression,
00137 ysReturn,
00138 ysBreak,
00139 ysContinue,
00140 ysTextdomain,
00141 ysInclude,
00142 ysFilename,
00143 ysImport,
00144 ysBlock,
00145 ysSwitch,
00146 ysStatement
00147 };
00148
00149 public:
00150
00154 YCode ();
00155
00159 virtual ~YCode();
00160
00166 virtual ykind kind() const = 0;
00167
00173 virtual string toString() const;
00174
00181 static string toString(ykind kind);
00182
00189 virtual std::ostream & toStream (std::ostream & str) const = 0;
00190
00198 virtual std::ostream & toXml (std::ostream & str, int indent ) const = 0;
00199
00205 virtual bool isConstant () const;
00206
00212 bool isError () const;
00213
00219 virtual bool isStatement () const;
00220
00226 virtual bool isBlock () const;
00227
00233 virtual bool isReferenceable () const;
00234
00242 virtual YCPValue evaluate (bool cse = false);
00243
00249 virtual constTypePtr type() const;
00250 };
00251
00252
00258 class YConst : public YCode
00259 {
00260 REP_BODY(YConst);
00261 ykind m_kind;
00262 YCPValue m_value;
00263 public:
00264 YConst (ykind kind, YCPValue value);
00265 YConst (ykind kind, bytecodeistream & str);
00266 ~YConst () {};
00267 YCPValue value() const;
00268 virtual ykind kind() const;
00269 string toString() const;
00270 std::ostream & toStream (std::ostream & str) const;
00271 std::ostream & toXml (std::ostream & str, int indent ) const;
00273 virtual bool isConstant () const { return true; }
00274 YCPValue evaluate (bool cse = false);
00275 constTypePtr type() const;
00276 };
00277
00278
00279
00280
00281 #ifdef HAVE_CXX0X
00282 #include <unordered_map>
00283 #else
00284 #include <ext/hash_map>
00285 #endif
00286
00287 #include <string>
00288 #include <cstddef>
00289
00296 class YELocale;
00297
00298 class YLocale : public YCode
00299 {
00300 REP_BODY(YLocale);
00301 const char *m_locale;
00302
00303 struct eqstr
00304 {
00305 bool operator()(const char* s1, const char* s2) const
00306 {
00307 return strcmp(s1, s2) == 0;
00308 }
00309 };
00310
00311 public:
00312 #ifdef HAVE_CXX0X
00313 typedef unordered_map<const char*, bool, hash<const char*>, eqstr> t_uniquedomains;
00314 #else
00315 typedef __gnu_cxx::hash_map<const char*, bool, __gnu_cxx::hash<const char*>, eqstr> t_uniquedomains;
00316 #endif
00317
00318 static t_uniquedomains domains;
00319 static t_uniquedomains::const_iterator setDomainStatus (const string& domain, bool status);
00320 static void ensureBindDomain (const string& domain);
00321 static void bindDomainDir (const string& domain, const string& domain_path);
00322 static bool findDomain(const string& domain);
00323 YLocale (const char *locale, const char *textdomain);
00324 YLocale (bytecodeistream & str);
00325 ~YLocale ();
00326 virtual ykind kind () const { return ycLocale; }
00327 const char *value () const;
00328 const char *domain () const;
00329 string toString() const;
00330 std::ostream & toStream (std::ostream & str) const;
00331 std::ostream & toXml (std::ostream & str, int indent ) const;
00332 YCPValue evaluate (bool cse = false);
00333 constTypePtr type() const { return Type::Locale; }
00334
00335 private:
00336
00337 t_uniquedomains::const_iterator m_domain;
00338
00339 };
00340
00347 class YFunction : public YCode
00348 {
00349 REP_BODY(YFunction);
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 YBlockPtr m_declaration;
00362
00363
00364 YBlockPtr m_definition;
00365
00366 bool m_is_global;
00367
00368 public:
00369 YFunction (YBlockPtr parameterblock, const SymbolEntryPtr entry = 0);
00370 YFunction (bytecodeistream & str);
00371 ~YFunction ();
00372 virtual ykind kind () const { return ycFunction; }
00373
00374
00375 unsigned int parameterCount () const;
00376 YBlockPtr declaration () const;
00377 SymbolEntryPtr parameter (unsigned int position) const;
00378
00379
00380 YBlockPtr definition () const;
00381 void setDefinition (YBlockPtr body);
00382
00383 void setDefinition (bytecodeistream & str);
00384
00385 string toStringDeclaration () const;
00386 string toString () const;
00387 std::ostream & toStreamDefinition (std::ostream & str ) const;
00388 std::ostream & toXmlDefinition (std::ostream & str, int indent ) const;
00389 std::ostream & toStream (std::ostream & str ) const;
00390 std::ostream & toXml (std::ostream & str, int indent ) const;
00391 virtual YCPValue evaluate (bool cse = false);
00392 constTypePtr type() const;
00393 };
00394
00395
00396 #endif // YCode_h