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

StaticDeclaration.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:        StaticDeclaration.h
00014 
00015    Author:      Klaus Kaempf <kkaempf@suse.de>
00016    Maintainer:  Klaus Kaempf <kkaempf@suse.de>
00017 
00018 /-*/
00019 // -*- c++ -*-
00020 
00021 #ifndef StaticDeclaration_h
00022 #define StaticDeclaration_h
00023 
00024 #include <string>
00025 #include <list>
00026 using namespace std;
00027 
00028 #include "ycp/YCPValue.h"
00029 #include "ycp/YCPList.h"
00030 #include "ycp/Type.h"
00031 #include "y2/Y2Namespace.h"
00032 
00033 class SymbolEntry;
00034 class SymbolTable;
00035 
00036 // Only use BUILTIN_STATISTICS for testing. It will create three files
00037 // /tmp/builtin-X.txt which list all builtins registered, looked up
00038 // and used.
00039 // #define BUILTIN_STATISTICS
00040 
00041 
00042 // structure for static declarations
00043 enum DeclFlags
00044 {
00045     DECL_NIL =          0x00000001,     // function accepts nil
00046     DECL_WILD =         0x00000002,     // function expects wildcard
00047     DECL_SYMBOL =       0x00000004,     // function expects a symbol as parameter (local environment)
00048     DECL_CODE =         0x00000008,     // function expects code as parameter (local evaluation)
00049     DECL_LOOP =         0x00000010,     // function implements a loop, allows break statement
00050     DECL_TYPEDEF =      0x00000020,     // name declares a typedef
00051     DECL_CONSTANT =     0x00000040,     // name declares a constant
00052     DECL_NAMESPACE =    0x00000080,     // name declares a namespace (switches registerDeclarations !)
00053     DECL_FLEX =         0x00000100,     // function signature include 'flex' type
00054     DECL_NOEVAL =       0x00000200,     // function will evaluate its parameters on its own (boolean functions for shortcut eval)
00055     DECL_CALL_HANDLER = 0x00000400,     // ptr is a call handler (only together with DECL_NAMESPACE)
00056     DECL_DEPRECATED =   0x00000800      // deprecated function
00057 };
00058 
00059 // declaration::ptr is a function pointer of this type if the first entry of a StaticDeclaration
00060 // is declared with flags DECL_NAMESPACE | DECL_CALL_HANDLER :
00061 typedef YCPValue (*call_handler_t)(void * function, int argc, YCPValue args[] );
00062 
00067 struct declaration {
00068     const char *name;                   // name of variable/function/typedef
00069     const char *signature;              // signature of variable/function/typedef (before registration)
00070     void *ptr;                          // pointer to builtin value/function
00071     int flags;                          // parameter acceptance, @ref DeclFlags
00072     struct declaration *next;           // link to next overloaded declaration (internal use only)
00073     struct declaration *name_space;     // table of the namespace (internal use only)
00074     constTypePtr type;
00075 };
00076 typedef struct declaration declaration_t;
00077 
00078 class StaticDeclaration {
00079 private:
00080     // toplevel table for all static declaration
00081     SymbolTable *m_declTable;
00082     // list of predefined namespaces which are already active, Y2Namespace is non-const since it might get evaluated
00083     std::list<std::pair<std::string, Y2Namespace *> > m_active_predefined;
00084 public:
00085     // constructor
00086     StaticDeclaration ();
00087     ~StaticDeclaration ();
00088 
00089     SymbolTable *symbolTable() { return m_declTable; };
00090 
00091     // list of registered namespaces which were predefined
00092     const std::list<std::pair<std::string, Y2Namespace *> > & active_predefined() const { return m_active_predefined; };
00093 
00094     // register declarations
00095     void registerDeclarations (const char *filename, declaration_t *declarations);
00096 
00097     // find a declaration
00098     declaration_t *findDeclaration (const char *name) const;
00099     declaration_t *findDeclaration (const char *name, constTypePtr type, bool partial = false) const;
00100     declaration_t *findDeclaration (declaration_t *decl, constTypePtr type, bool partial = false) const;
00101 
00102     // dump all registered builtins
00103     void dumpDeclarations () const;
00104 
00105     // write declaration to stream (name and type)
00106     std::ostream & writeDeclaration (std::ostream & str, const declaration_t *decl) const;
00107 
00108     // read declaration from stream (return declaration matching name and type _exactly_)
00109     declaration_t *readDeclaration (std::istream & str) const;
00110 
00111     // show a declaration
00112     // @param full if false, just show the name; if true, show name and signatur
00113     static string Decl2String (const declaration_t *declaration, bool full = false);
00114 };
00115 
00116 #endif // StaticDeclaration_h

Generated on Fri Nov 9 18:15:22 2007 for yast2-core by doxygen 1.3.6