yast2-core
SymbolEntry.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \-----------------------------------------------------------------------/
12 
13  File: SymbolEntry.h
14  symbol entry class
15 
16  Author: Klaus Kaempf <kkaempf@suse.de>
17  Stanislav Visnovsky <visnov@suse.cz>
18  Maintainer: Klaus Kaempf <kkaempf@suse.de>
19 
20 /-*/
21 // -*- c++ -*-
22 
23 #ifndef SymbolEntry_h
24 #define SymbolEntry_h
25 
26 #include <y2util/Ustring.h>
27 #include <y2util/RepDef.h>
28 
29 #include "ycp/YCPValue.h"
30 #include "ycp/Type.h"
31 
32 #include <stack>
33 
34 class Y2Namespace;
35 
37 
41 class SymbolEntry : public Rep
42 #ifdef D_MEMUSAGE
43  , public MemUsage
44 #endif
45 {
47 
48 public:
49  // hash for unique strings
52 
53 public:
54  typedef enum {
55  c_unspec = 0, // 0 unspecified local symbol (sets m_global = false)
56  c_global, // 1 unspecified global symbol (translates to c_unspec, sets m_global = true)
57  c_module, // 2 a module identifier
58  c_variable, // 3 a variable
59  c_reference, // 4 a reference to a variable
60  c_function, // 5 a defined function
61  c_builtin, // 6 a builtin function
62  c_typedef, // 7 a type
63  c_const, // 8 a constant (a read-only c_variable)
64  c_namespace, // 9 a namespace identifier
65  c_self, // 10 the current namespace (namespace prefix used in namespace definition)
66  c_predefined, // 11 a predefined namespace identifier
67  c_filename // 12 a filename (used in conjunction with TableEntry to store definition locations)
68  } category_t;
69 
70 protected:
71  /*
72  * if it's global
73  */
74  bool m_global;
75 
76  /*
77  * the namespace this entry belongs to
78  */
80 
81  /*
82  * position in the namespace
83  */
84  unsigned int m_position;
85 
86  /*
87  * the name of the entry
88  */
90 
91  /*
92  * the category of the entry
93  */
95 
96  /*
97  * the type (string) of the entry
98  */
99  constTypePtr m_type;
100 
101  /* the current (actual) value of the entry c_const */
103 
104  typedef std::stack<YCPValue> valuestack_t;
106 
107 public:
108  // create symbol beloging to namespace (at position)
109  SymbolEntry (const Y2Namespace* name_space, unsigned int position, const char *name, category_t cat, constTypePtr type);
110 
111  virtual ~SymbolEntry ();
112 
113  // symbols' link to the defining namespace
114  const Y2Namespace *nameSpace () const;
115  void setNamespace (const Y2Namespace *name_space);
116 
117  // payload access
118 
119  // returns true for a declared symbol which isn't defined yet.
120  virtual bool onlyDeclared () const { return false; }
121 
122  // this is the position of the entry in the namespace (>= 0)
123  // or in the xref table (< 0), see YSImport()
124  unsigned int position () const;
125  void setPosition (unsigned int position);
126 
127  bool isGlobal () const;
128  void setGlobal (bool global);
129 
130  bool isModule () const { return m_category == c_module; }
131  bool isVariable () const { return m_category == c_variable; }
132  bool isReference () const { return m_category == c_reference; }
133  bool isFunction () const { return m_category == c_function; }
134  bool isBuiltin () const { return m_category == c_builtin; }
135  bool isNamespace () const { return m_category == c_namespace; }
136  bool isSelf () const { return m_category == c_self; }
137  bool isFilename () const { return m_category == c_filename; }
138  bool isPredefined () const { return m_category == c_predefined; }
139 
140  bool likeNamespace () const { return isModule() || isNamespace() || isSelf(); }
141 
142  const char *name () const;
143  category_t category () const;
144  void setCategory (category_t cat);
145  constTypePtr type () const;
146  string catString () const;
147  void setType (constTypePtr type);
148  virtual YCPValue setValue (YCPValue value);
149  virtual YCPValue value () const;
150 
151  void push ();
152  void pop ();
153 
154  virtual string toString (bool with_type = true) const;
155 };
156 
157 #endif // SymbolEntry_h
virtual ~SymbolEntry()
Definition: SymbolEntry.cc:64
Definition: SymbolEntry.h:41
bool isGlobal() const
Definition: SymbolEntry.cc:83
constTypePtr type() const
Definition: SymbolEntry.cc:192
static Ustring emptyUstring
Definition: SymbolEntry.h:51
Definition: SymbolEntry.h:66
unsigned int position() const
Definition: SymbolEntry.cc:90
A Hash of unique strings.
Definition: Ustring.h:38
virtual string toString(bool with_type=true) const
Definition: SymbolEntry.cc:263
Definition: SymbolEntry.h:61
bool isFunction() const
Definition: SymbolEntry.h:133
void setPosition(unsigned int position)
Definition: SymbolEntry.cc:97
bool isReference() const
Definition: SymbolEntry.h:132
const Y2Namespace * m_namespace
Definition: SymbolEntry.h:79
virtual YCPValue value() const
Definition: SymbolEntry.cc:137
void setType(constTypePtr type)
Definition: SymbolEntry.cc:199
category_t
Definition: SymbolEntry.h:54
Definition: SymbolEntry.h:56
constTypePtr m_type
Definition: SymbolEntry.h:99
void setNamespace(const Y2Namespace *name_space)
Definition: SymbolEntry.cc:76
Ustring m_name
Definition: SymbolEntry.h:89
std::stack< YCPValue > valuestack_t
Definition: SymbolEntry.h:104
REP_BODY(SymbolEntry)
void pop()
Definition: SymbolEntry.cc:160
bool isPredefined() const
Definition: SymbolEntry.h:138
bool isFilename() const
Definition: SymbolEntry.h:137
Definition: SymbolEntry.h:60
bool isSelf() const
Definition: SymbolEntry.h:136
bool isVariable() const
Definition: SymbolEntry.h:131
Definition: SymbolEntry.h:55
Definition: SymbolEntry.h:62
bool isBuiltin() const
Definition: SymbolEntry.h:134
Definition: SymbolEntry.h:63
bool likeNamespace() const
Definition: SymbolEntry.h:140
void push()
Definition: SymbolEntry.cc:150
virtual YCPValue setValue(YCPValue value)
Definition: SymbolEntry.cc:105
Unique strings.
Definition: Ustring.h:124
Definition: SymbolEntry.h:57
virtual bool onlyDeclared() const
Definition: SymbolEntry.h:120
category_t category() const
Definition: SymbolEntry.cc:177
category_t m_category
Definition: SymbolEntry.h:94
bool isModule() const
Definition: SymbolEntry.h:130
const Y2Namespace * nameSpace() const
Definition: SymbolEntry.cc:69
Definition: SymbolEntry.h:65
unsigned int m_position
Definition: SymbolEntry.h:84
SymbolEntry(const Y2Namespace *name_space, unsigned int position, const char *name, category_t cat, constTypePtr type)
Definition: SymbolEntry.cc:52
Definition: SymbolEntry.h:64
bool isNamespace() const
Definition: SymbolEntry.h:135
Wrapper for YCPValueRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPValueRep with the arrow operator. See YCPValueRep.
Definition: YCPValue.h:275
Definition: SymbolEntry.h:67
Definition: Y2Namespace.h:43
void setCategory(category_t cat)
Definition: SymbolEntry.cc:184
YCPValue m_value
Definition: SymbolEntry.h:102
const char * name() const
Definition: SymbolEntry.cc:170
Base class for reference counted objects.
Definition: Rep.h:46
string catString() const
Definition: SymbolEntry.cc:214
Definition: SymbolEntry.h:58
static UstringHash * _nameHash
Definition: SymbolEntry.h:50
void setGlobal(bool global)
Definition: SymbolEntry.cc:207
DEFINE_BASE_POINTER(SymbolEntry)
bool m_global
Definition: SymbolEntry.h:74
Definition: SymbolEntry.h:59
Definition: MemUsage.h:37
valuestack_t * m_recurse_stack
Definition: SymbolEntry.h:105

Generated on a sunny day for yast2-core by doxygen 1.8.6