|
yast2-core
|
00001 /*------------------------------------------------------------*- c++ -*-\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \-----------------------------------------------------------------------/ 00012 00013 File: Y2Namespace.h 00014 a generic interface for accessing a namespace from YCP interpreter 00015 00016 Author: Stanislav Visnovsky <visnov@suse.cz> 00017 Maintainer: Stanislav Visnovsky <visnov@suse.cz> 00018 00019 /-*/ 00020 00021 #ifndef Y2Namespace_h 00022 #define Y2Namespace_h 00023 00024 #include <string> 00025 using std::string; 00026 00027 #include "ycp/YCPValue.h" 00028 #include "ycp/Type.h" 00029 00030 #include "SymbolEntry.h" 00031 00032 class SymbolTable; 00033 class Point; 00034 class Y2Function; 00035 class StaticDeclaration; 00036 class SymbolTable; 00037 class Debugger; 00038 00043 class Y2Namespace { 00044 protected: 00045 typedef vector<SymbolEntryPtr> symbols_t; 00046 00047 SymbolTable* m_table; 00048 unsigned int m_symbolcount; 00049 symbols_t m_symbols; 00050 00051 friend class SymbolTable; 00052 friend class Debugger; 00053 00054 // add symbol to namespace, it now belongs here 00055 // returns the index into m_symbols 00056 // 00057 // this is used for blocks with a local environment but no table 00058 unsigned int addSymbol (SymbolEntryPtr sentry); 00059 00060 // add symbol _and_ enter into table for lookup 00061 // 00062 // this is used for namespaces with a global environment and a table 00063 void enterSymbol (SymbolEntryPtr sentry, Point *point = 0); 00064 00065 // lookup symbol by name in m_symbols 00066 SymbolEntryPtr lookupSymbol (const char *name) const; 00067 00068 // find symbol by pointer 00069 // return index if found, -1 if not found 00070 // int findSymbol (const SymbolEntryPtr sentry) const; 00071 00072 // release symbol from m_symbols 00073 // it's no longer owned by this block but by a ysFunction() 00074 void releaseSymbol (unsigned int position); 00075 // void releaseSymbol (SymbolEntryPtr sentry); 00076 00077 bool m_initialized; 00078 00079 public: 00080 00081 Y2Namespace (); 00082 00083 virtual ~Y2Namespace(); 00084 00085 // end of symbols, finish and clean up m_symbols 00086 void finish (); 00087 00089 virtual const string name () const; 00091 virtual const string filename () const = 0; 00092 00094 // e.g. needed for function declarations which keep their symbolic 00095 // parameters in a Y2Namespace 00096 virtual unsigned int symbolCount () const; 00097 00099 // bytecode uses unsigneds 00100 virtual SymbolEntryPtr symbolEntry (unsigned int position) const; 00101 00103 virtual string toString () const; 00104 00105 // just m_symbols, for debugging and YBlock::toString 00106 string symbolsToString () const; 00107 00109 // constructor is handled separately 00110 virtual YCPValue evaluate (bool cse = false) = 0; 00111 00113 virtual SymbolTable* table () const; 00114 00115 // this will ensure existence of the table. 00116 // after calling this function @ref table will always return a valid pointer 00117 void createTable (); 00118 00128 virtual Y2Function* createFunctionCall (const string name, constFunctionTypePtr type) = 0; 00129 00130 // push all local variables to stack, uses SymbolEntry::push() 00131 void pushToStack (); 00132 00133 // pop all local variables from stack, uses SymbolEntry::pop() 00134 void popFromStack (); 00135 00136 // ensure that the namespace is initialized 00137 virtual void initialize (); 00138 00139 }; 00140 00141 00142 #endif // Y2Namespace_h
1.7.5.1