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                 Stanislav Visnovsky <visnov@suse.cz>
00018    Maintainer:  Klaus Kaempf <kkaempf@suse.de>
00019 
00020 /-*/
00021 // -*- c++ -*-
00022 
00023 #ifndef SymbolEntry_h
00024 #define SymbolEntry_h
00025 
00026 #include <y2util/Ustring.h>
00027 #include <y2util/RepDef.h>
00028 
00029 #include "ycp/YCPValue.h"
00030 #include "ycp/Type.h"
00031 
00032 #include <stack>
00033 
00034 class Y2Namespace;
00035 
00036 DEFINE_BASE_POINTER (SymbolEntry);
00037 
00041 class SymbolEntry : public Rep
00042 #ifdef D_MEMUSAGE
00043   , public MemUsage
00044 #endif
00045 {
00046     REP_BODY (SymbolEntry);
00047 
00048 public:
00049     // hash for unique strings
00050     static UstringHash* _nameHash;
00051     static Ustring emptyUstring;
00052 
00053 public:
00054     typedef enum {
00055         c_unspec = 0,           //  0 unspecified local symbol (sets m_global = false)
00056         c_global,               //  1 unspecified global symbol (translates to c_unspec, sets m_global = true)
00057         c_module,               //  2 a module identifier
00058         c_variable,             //  3 a variable
00059         c_reference,            //  4 a reference to a variable
00060         c_function,             //  5 a defined function
00061         c_builtin,              //  6 a builtin function
00062         c_typedef,              //  7 a type
00063         c_const,                //  8 a constant (a read-only c_variable)
00064         c_namespace,            //  9 a namespace identifier
00065         c_self,                 // 10 the current namespace (namespace prefix used in namespace definition)
00066         c_predefined,           // 11 a predefined namespace identifier
00067         c_filename              // 12 a filename (used in conjunction with TableEntry to store definition locations)
00068     } category_t;
00069 
00070 protected:
00071     /*
00072      * if it's global
00073      */
00074     bool m_global;
00075 
00076     /*
00077      * the namespace this entry belongs to
00078      */
00079     const Y2Namespace *m_namespace;
00080 
00081     /*
00082      * position in the namespace
00083      */
00084     unsigned int m_position;
00085 
00086     /*
00087      * the name of the entry
00088      */
00089     Ustring m_name;
00090 
00091     /*
00092      * the category of the entry
00093      */
00094     category_t m_category;
00095 
00096     /*
00097      * the type (string) of the entry
00098      */
00099     constTypePtr m_type;
00100 
00101     /*  the current (actual) value of the entry c_const  */
00102     YCPValue m_value;
00103     
00104     typedef std::stack<YCPValue> valuestack_t;
00105     valuestack_t* m_recurse_stack;
00106 
00107 public:
00108     // create symbol beloging to namespace (at position)
00109     SymbolEntry (const Y2Namespace* name_space, unsigned int position, const char *name, category_t cat, constTypePtr type);
00110 
00111     virtual ~SymbolEntry ();
00112 
00113     // symbols' link to the defining namespace
00114     const Y2Namespace *nameSpace () const;
00115     void setNamespace (const Y2Namespace *name_space);
00116 
00117     // payload access
00118 
00119     // returns true for a declared symbol which isn't defined yet.
00120     virtual bool onlyDeclared () const { return false; }
00121 
00122     // this is the position of the entry in the namespace (>= 0)
00123     //   or in the xref table (< 0), see YSImport()
00124     unsigned int position () const;
00125     void setPosition (unsigned int position);
00126 
00127     bool isGlobal () const;
00128     void setGlobal (bool global);
00129 
00130     bool isModule () const { return m_category == c_module; }
00131     bool isVariable () const { return m_category == c_variable; }
00132     bool isReference () const { return m_category == c_reference; }
00133     bool isFunction () const { return m_category == c_function; }
00134     bool isBuiltin () const { return m_category == c_builtin; }
00135     bool isNamespace () const { return m_category == c_namespace; }
00136     bool isSelf () const { return m_category == c_self; }
00137     bool isFilename () const { return m_category == c_filename; }
00138     bool isPredefined () const { return m_category == c_predefined; }
00139 
00140     bool likeNamespace () const { return isModule() || isNamespace() || isSelf(); }
00141 
00142     const char *name () const;
00143     category_t category () const;
00144     void setCategory (category_t cat);
00145     constTypePtr type () const;
00146     string catString () const;
00147     void setType (constTypePtr type);
00148     YCPValue setValue (YCPValue value);
00149     YCPValue value () const;
00150     
00151     void push ();
00152     void pop ();
00153 
00154     virtual string toString (bool with_type = true) const;
00155 };
00156 
00157 #endif // SymbolEntry_h

Generated on Fri Jun 16 18:07:45 2006 for yast2-core by  doxygen 1.4.6