00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SymbolEntry_h
00023 #define SymbolEntry_h
00024
00025 #include <y2util/Ustring.h>
00026 #include <y2util/RepDef.h>
00027
00028 #include "ycp/YCPValue.h"
00029 #include "ycp/Type.h"
00030 #include "ycp/StaticDeclaration.h"
00031 #include "ycp/YCode.h"
00032
00033 #include <stack>
00034
00035 class YBlock;
00036 class Y2Namespace;
00037 class TableEntry;
00038
00042 class SymbolEntry : public Rep
00043 #ifdef D_MEMUSAGE
00044 , public MemUsage
00045 #endif
00046 {
00047 REP_BODY (SymbolEntry);
00048
00049 public:
00050
00051 static UstringHash _nameHash;
00052 static Ustring emptyUstring;
00053
00054 public:
00055 typedef enum {
00056 c_unspec = 0,
00057 c_global,
00058 c_module,
00059 c_variable,
00060 c_reference,
00061 c_function,
00062 c_builtin,
00063 c_typedef,
00064 c_const,
00065 c_namespace,
00066 c_self,
00067 c_predefined,
00068 c_filename
00069 } category_t;
00070
00071 private:
00072
00073
00074
00075 bool m_global;
00076
00077
00078
00079
00080 const Y2Namespace *m_namespace;
00081
00082
00083
00084
00085 unsigned int m_position;
00086
00087
00088
00089
00090 Ustring m_name;
00091
00092
00093
00094
00095 category_t m_category;
00096
00097
00098
00099
00100 constTypePtr m_type;
00101
00114 union payload {
00115 Y2Namespace *m_namespace;
00116 declaration_t *m_decl;
00117 SymbolTable *m_table;
00118 } m_payload;
00119
00120
00121
00122
00123
00124
00125
00126
00127 YCodePtr m_code;
00128
00129
00130 YCPValue m_value;
00131
00132 stack<YCPValue> m_recurse_stack;
00133
00134 public:
00135
00136
00137 SymbolEntry (const Y2Namespace* name_space, unsigned int position, const char *name, category_t cat, constTypePtr type, YCodePtr payload = 0);
00138
00139
00140 SymbolEntry (const char *name, constTypePtr type, declaration_t *payload, const Y2Namespace *name_space = 0);
00141
00142
00143 SymbolEntry (const char *name, constTypePtr type, SymbolTable *payload);
00144
00145
00146 SymbolEntry (const char *filename);
00147
00148 SymbolEntry (std::istream & str, const Y2Namespace *name_space = 0);
00149
00150 virtual ~SymbolEntry ();
00151
00152
00153 const Y2Namespace *nameSpace () const;
00154 void setNamespace (const Y2Namespace *name_space);
00155
00156
00157
00158
00159 bool onlyDeclared () const;
00160
00161
00162 void setCode (YCodePtr code);
00163 YCodePtr code () const;
00164
00165
00166 void setDeclaration (declaration_t *decl);
00167 declaration_t *declaration () const;
00168
00169
00170 void setTable (SymbolTable *table);
00171 SymbolTable *table() const;
00172
00173
00174 Y2Namespace *payloadNamespace () const;
00175 void setPayloadNamespace (Y2Namespace *name_space);
00176
00177
00178
00179 unsigned int position () const;
00180 void setPosition (unsigned int position);
00181
00182 bool isGlobal () const;
00183
00184 bool isModule () const { return m_category == c_module; }
00185 bool isVariable () const { return m_category == c_variable; }
00186 bool isReference () const { return m_category == c_reference; }
00187 bool isFunction () const { return m_category == c_function; }
00188 bool isBuiltin () const { return m_category == c_builtin; }
00189 bool isNamespace () const { return m_category == c_namespace; }
00190 bool isSelf () const { return m_category == c_self; }
00191 bool isFilename () const { return m_category == c_filename; }
00192 bool isPredefined () const { return m_category == c_predefined; }
00193
00194 bool likeNamespace () const { return isModule() || isNamespace() || isSelf(); }
00195
00196 const char *name () const;
00197 category_t category () const;
00198 void setCategory (category_t cat);
00199 constTypePtr type () const;
00200 string catString () const;
00201 void setType (constTypePtr type);
00202 YCPValue setValue (YCPValue value);
00203 YCPValue value () const;
00204
00205 void push ();
00206 void pop ();
00207
00208 string toString (bool with_type = true) const;
00209 std::ostream & toStream (std::ostream & str) const;
00210 };
00211
00212
00213 #endif // SymbolEntry_h