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

SymbolEntry.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:        SymbolEntry.h
00014                 symbol entry class
00015 
00016    Author:      Klaus Kaempf <kkaempf@suse.de>
00017    Maintainer:  Klaus Kaempf <kkaempf@suse.de>
00018 
00019 /-*/
00020 // -*- c++ -*-
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     // hash for unique strings
00051     static UstringHash _nameHash;
00052     static Ustring emptyUstring;
00053 
00054 public:
00055     typedef enum {
00056         c_unspec = 0,           //  0 unspecified local symbol (sets m_global = false)
00057         c_global,               //  1 unspecified global symbol (translates to c_unspec, sets m_global = true)
00058         c_module,               //  2 a module identifier
00059         c_variable,             //  3 a variable
00060         c_reference,            //  4 a reference to a variable
00061         c_function,             //  5 a defined function
00062         c_builtin,              //  6 a builtin function
00063         c_typedef,              //  7 a type
00064         c_const,                //  8 a constant (a read-only c_variable)
00065         c_namespace,            //  9 a namespace identifier
00066         c_self,                 // 10 the current namespace (namespace prefix used in namespace definition)
00067         c_predefined,           // 11 a predefined namespace identifier
00068         c_filename              // 12 a filename (used in conjunction with TableEntry to store definition locations)
00069     } category_t;
00070 
00071 private:
00072     /*
00073      * if it's global
00074      */
00075     bool m_global;
00076 
00077     /*
00078      * the namespace this entry belongs to
00079      */
00080     const Y2Namespace *m_namespace;
00081 
00082     /*
00083      * position in the namespace
00084      */
00085     unsigned int m_position;
00086 
00087     /*
00088      * the name of the entry
00089      */
00090     Ustring m_name;
00091 
00092     /*
00093      * the category of the entry
00094      */
00095     category_t m_category;
00096 
00097     /*
00098      * the type (string) of the entry
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      * Valid for
00122      *  c_variable:     YCode* (any value)
00123      *  c_reference:    YCode* (YEReference*)
00124      *  c_function:     YCode* (YFunction* to be precise)
00125      */
00126 
00127     YCodePtr m_code;
00128 
00129     /*  the current (actual) value of the entry c_const  */
00130     YCPValue m_value;
00131     
00132     stack<YCPValue> m_recurse_stack;
00133 
00134 public:
00135 
00136     // create symbol beloging to namespace (at position)
00137     SymbolEntry (const Y2Namespace* name_space, unsigned int position, const char *name, category_t cat, constTypePtr type, YCodePtr payload = 0);
00138 
00139     // create builtin symbol (category == c_builtin), name_space != 0 for symbols inside namespace
00140     SymbolEntry (const char *name, constTypePtr type, declaration_t *payload, const Y2Namespace *name_space = 0);
00141 
00142     // create namespace symbol (category == c_namespace)
00143     SymbolEntry (const char *name, constTypePtr type, SymbolTable *payload);
00144 
00145     // create declaration point symbol (category == c_filename)
00146     SymbolEntry (const char *filename);
00147 
00148     SymbolEntry (std::istream & str, const Y2Namespace *name_space = 0);
00149 
00150     virtual ~SymbolEntry ();
00151 
00152     // symbols' link to the defining namespace
00153     const Y2Namespace *nameSpace () const;
00154     void setNamespace (const Y2Namespace *name_space);
00155 
00156     // payload access
00157 
00158     // returns true for a declared symbol which isn't defined yet.
00159     bool onlyDeclared () const;
00160 
00161     // payload access for variables and functions
00162     void setCode (YCodePtr code);
00163     YCodePtr code () const;
00164     
00165     // payload access for builtins
00166     void setDeclaration (declaration_t *decl);
00167     declaration_t *declaration () const;
00168 
00169     // payload access for namespace symbols
00170     void setTable (SymbolTable *table);
00171     SymbolTable *table() const;
00172 
00173     // symbols' link to the defining namespace
00174     Y2Namespace *payloadNamespace () const;
00175     void setPayloadNamespace (Y2Namespace *name_space);
00176 
00177     // this is the position of the entry in the namespace (>= 0)
00178     //   or in the xref table (< 0), see YSImport()
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

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