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/SymbolEntryPtr.h" 00029 00030 class SymbolTable; 00031 class Point; 00032 class Y2Function; 00033 class StaticDeclaration; 00034 00039 class Y2Namespace { 00040 protected: 00041 typedef vector<SymbolEntryPtr> symbols_t; 00042 00043 SymbolTable* m_table; 00044 unsigned int m_symbolcount; 00045 symbols_t m_symbols; 00046 00047 // add symbol to namespace, it now belongs here 00048 // returns the index into m_symbols 00049 // 00050 // this is used for blocks with a local environment but no table 00051 unsigned int addSymbol (SymbolEntryPtr sentry); 00052 00053 // add symbol _and_ enter into table for lookup 00054 // 00055 // this is used for namespaces with a global environment and a table 00056 void enterSymbol (SymbolEntryPtr sentry, Point *point = 0); 00057 00058 // lookup symbol by name in m_symbols 00059 SymbolEntryPtr lookupSymbol (const char *name) const; 00060 00061 // find symbol by pointer 00062 // return index if found, -1 if not found 00063 // int findSymbol (const SymbolEntryPtr sentry) const; 00064 00065 // release symbol from m_symbols 00066 // it's no longer owned by this block but by a ysFunction() 00067 void releaseSymbol (unsigned int position); 00068 // void releaseSymbol (SymbolEntryPtr sentry); 00069 00070 bool m_initialized; 00071 00072 public: 00073 00074 Y2Namespace (); 00075 00076 virtual ~Y2Namespace(); 00077 00078 // end of symbols, finish and clean up m_symbols 00079 void finish (); 00080 00082 virtual const string name () const; 00084 virtual const string filename () const = 0; 00085 00087 // e.g. needed for function declarations which keep their symbolic 00088 // parameters in a Y2Namespace 00089 virtual unsigned int symbolCount () const; 00090 00092 // bytecode uses unsigneds 00093 virtual SymbolEntryPtr symbolEntry (unsigned int position) const; 00094 00096 virtual string toString () const; 00097 00098 // just m_symbols, for debugging and YBlock::toString 00099 string symbolsToString () const; 00100 00102 // constructor is handled separately 00103 virtual YCPValue evaluate (bool cse = false) = 0; 00104 00106 virtual SymbolTable* table () const; 00107 00108 // this will ensure existence of the table. 00109 // after calling this function @ref table will always return a valid pointer 00110 void createTable (); 00111 00120 virtual Y2Function* createFunctionCall (const string name) = 0; 00121 00122 // push all local variables to stack, uses SymbolEntry::push() 00123 void pushToStack (); 00124 00125 // pop all local variables from stack, uses SymbolEntry::pop() 00126 void popFromStack (); 00127 00128 // ensure that the namespace is initialized 00129 virtual void initialize (); 00130 00131 }; 00132 00133 00134 #endif // Y2Namespace_h