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