Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Examples

Y2Namespace.h

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

Generated on Tue Mar 22 11:35:48 2005 for yast2-core by  doxygen 1.4.1