yast2-core
Y2Namespace.h
Go to the documentation of this file.
1 /*------------------------------------------------------------*- c++ -*-\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \-----------------------------------------------------------------------/
12 
13  File: Y2Namespace.h
14  a generic interface for accessing a namespace from YCP interpreter
15 
16  Author: Stanislav Visnovsky <visnov@suse.cz>
17  Maintainer: Stanislav Visnovsky <visnov@suse.cz>
18 
19 /-*/
20 
21 #ifndef Y2Namespace_h
22 #define Y2Namespace_h
23 
24 #include <string>
25 using std::string;
26 
27 #include "ycp/YCPValue.h"
28 #include "ycp/Type.h"
29 
30 #include "SymbolEntry.h"
31 
32 class SymbolTable;
33 class Point;
34 class Y2Function;
35 class StaticDeclaration;
36 class SymbolTable;
37 class Debugger;
38 
43 class Y2Namespace {
44 protected:
45  typedef vector<SymbolEntryPtr> symbols_t;
46 
48  unsigned int m_symbolcount;
50 
51  friend class SymbolTable;
52  friend class Debugger;
53 
54  // add symbol to namespace, it now belongs here
55  // returns the index into m_symbols
56  //
57  // this is used for blocks with a local environment but no table
58  unsigned int addSymbol (SymbolEntryPtr sentry);
59 
60  // add symbol _and_ enter into table for lookup
61  //
62  // this is used for namespaces with a global environment and a table
63  void enterSymbol (SymbolEntryPtr sentry, Point *point = 0);
64 
65  // lookup symbol by name in m_symbols
66  SymbolEntryPtr lookupSymbol (const char *name) const;
67 
68  // find symbol by pointer
69  // return index if found, -1 if not found
70 // int findSymbol (const SymbolEntryPtr sentry) const;
71 
72  // release symbol from m_symbols
73  // it's no longer owned by this block but by a ysFunction()
74  void releaseSymbol (unsigned int position);
75 // void releaseSymbol (SymbolEntryPtr sentry);
76 
78 
79 public:
80 
81  Y2Namespace ();
82 
83  virtual ~Y2Namespace();
84 
85  // end of symbols, finish and clean up m_symbols
86  void finish ();
87 
89  virtual const string name () const;
91  virtual const string filename () const = 0;
92 
94  // e.g. needed for function declarations which keep their symbolic
95  // parameters in a Y2Namespace
96  virtual unsigned int symbolCount () const;
97 
99  // bytecode uses unsigneds
100  virtual SymbolEntryPtr symbolEntry (unsigned int position) const;
101 
103  virtual string toString () const;
104 
105  // just m_symbols, for debugging and YBlock::toString
106  string symbolsToString () const;
107 
109  // constructor is handled separately
110  virtual YCPValue evaluate (bool cse = false) = 0;
111 
113  virtual SymbolTable* table () const;
114 
115  // this will ensure existence of the table.
116  // after calling this function @ref table will always return a valid pointer
117  void createTable ();
118 
128  virtual Y2Function* createFunctionCall (const string name, constFunctionTypePtr type) = 0;
129 
130  // push all local variables to stack, uses SymbolEntry::push()
131  void pushToStack ();
132 
133  // pop all local variables from stack, uses SymbolEntry::pop()
134  void popFromStack ();
135 
136  // ensure that the namespace is initialized
137  virtual void initialize ();
138 
139 };
140 
141 
142 #endif // Y2Namespace_h
virtual const string name() const
what namespace do we implement
Definition: Y2Namespace.cc:63
virtual SymbolEntryPtr symbolEntry(unsigned int position) const
access to definitions of this namespace
Definition: Y2Namespace.cc:119
vector< SymbolEntryPtr > symbols_t
Definition: Y2Namespace.h:45
void finish()
Definition: Y2Namespace.cc:206
virtual unsigned int symbolCount() const
gives the number of symbol declarations
Definition: Y2Namespace.cc:70
virtual string toString() const
unparse. useful for debugging
Definition: Y2Namespace.cc:77
Definition: SymbolTable.h:100
string symbolsToString() const
Definition: Y2Namespace.cc:92
void createTable()
Definition: Y2Namespace.cc:287
void popFromStack()
Definition: Y2Namespace.cc:268
virtual SymbolTable * table() const
get our whole symbol table?
Definition: Y2Namespace.cc:281
Definition: Point.h:59
SymbolTable * m_table
Definition: Y2Namespace.h:47
virtual ~Y2Namespace()
Definition: Y2Namespace.cc:44
void pushToStack()
Definition: Y2Namespace.cc:255
virtual const string filename() const =0
used for error reporting
Debugger singleton to keep debugging-related status.
Definition: Debugger.h:34
virtual YCPValue evaluate(bool cse=false)=0
called when evaluating the import statement
unsigned int m_symbolcount
Definition: Y2Namespace.h:48
void enterSymbol(SymbolEntryPtr sentry, Point *point=0)
Definition: Y2Namespace.cc:166
symbols_t m_symbols
Definition: Y2Namespace.h:49
virtual Y2Function * createFunctionCall(const string name, constFunctionTypePtr type)=0
bool m_initialized
Definition: Y2Namespace.h:77
virtual void initialize()
Definition: Y2Namespace.cc:296
Y2Namespace()
Definition: Y2Namespace.cc:37
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: Y2Namespace.h:43
void releaseSymbol(unsigned int position)
Definition: Y2Namespace.cc:181
unsigned int addSymbol(SymbolEntryPtr sentry)
Definition: Y2Namespace.cc:134
Definition: StaticDeclaration.h:82
Definition: Y2Function.h:71
SymbolEntryPtr lookupSymbol(const char *name) const
Definition: Y2Namespace.cc:146

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