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 class TableEntry;
00036 class bytecodeistream;
00037 class Logger;
00038 
00039 // Only use BUILTIN_STATISTICS for testing. It will create three files
00040 // /tmp/builtin-X.txt which list all builtins registered, looked up
00041 // and used.
00042 // #define BUILTIN_STATISTICS
00043 
00044 
00045 // structure for static declarations
00046 enum DeclFlags
00047 {
00048     DECL_NIL =          0x00000001,     // function accepts nil
00049     DECL_WILD =         0x00000002,     // function expects wildcard
00050     DECL_SYMBOL =       0x00000004,     // function expects a symbol as parameter (local environment)
00051     DECL_CODE =         0x00000008,     // function expects code as parameter (local evaluation)
00052     DECL_LOOP =         0x00000010,     // function implements a loop, allows break statement
00053     DECL_TYPEDEF =      0x00000020,     // name declares a typedef
00054     DECL_CONSTANT =     0x00000040,     // name declares a constant
00055     DECL_NAMESPACE =    0x00000080,     // name declares a namespace (switches registerDeclarations !)
00056     DECL_FLEX =         0x00000100,     // function signature include 'flex' type
00057     DECL_NOEVAL =       0x00000200,     // function will evaluate its parameters on its own (boolean functions for shortcut eval)
00058     DECL_CALL_HANDLER = 0x00000400,     // ptr is a call handler (only together with DECL_NAMESPACE)
00059     DECL_DEPRECATED =   0x00000800,     // deprecated function
00060     DECL_FORMATTED =    0x00001000      // has format string with "%1" as first arg
00061 };
00062 
00063 // declaration::ptr is a function pointer of this type if the first entry of a StaticDeclaration
00064 // is declared with flags DECL_NAMESPACE | DECL_CALL_HANDLER :
00065 typedef YCPValue (*call_handler_t)(void * function, int argc, YCPValue args[] );
00066 
00071 struct declaration {
00072     const char *name;                   // name of variable/function/typedef
00073     const char *signature;              // signature of variable/function/typedef (before registration)
00074     void *ptr;                          // pointer to builtin value/function
00075     int flags;                          // parameter acceptance, @ref DeclFlags
00076     struct declaration *name_space;     // table of the namespace (internal use only)
00077     constTypePtr type;
00078     TableEntry* tentry;
00079 };
00080 typedef struct declaration declaration_t;
00081 
00082 class StaticDeclaration {
00083 private:
00084     // toplevel table for all static declaration
00085     SymbolTable *m_declTable;
00086     // list of predefined namespaces which are already active, Y2Namespace is non-const since it might get evaluated
00087     std::list<std::pair<std::string, Y2Namespace *> > m_active_predefined;
00088 public:
00089     // constructor
00090     StaticDeclaration ();
00091     ~StaticDeclaration ();
00092 
00093     SymbolTable *symbolTable() { return m_declTable; };
00094 
00095     // list of registered namespaces which were predefined
00096     const std::list<std::pair<std::string, Y2Namespace *> > & active_predefined() const { return m_active_predefined; };
00097 
00098     // register declarations
00099     void registerDeclarations (const char *filename, declaration_t *declarations);
00100 
00101     // find a declaration
00102     declaration_t *findDeclaration (const char *name) const;
00103     declaration_t *findDeclaration (const char *name, constTypePtr type, bool partial = false) const;
00104     declaration_t *findDeclaration (declaration_t *decl, constTypePtr type, bool partial = false) const;
00105 
00106     // dump all registered builtins
00107     void dumpDeclarations () const;
00108 
00109     // write declaration to stream (name and type)
00110     std::ostream & writeDeclaration (std::ostream & str, const declaration_t *decl) const;
00111 
00112     // read declaration from stream (return declaration matching name and type _exactly_)
00113     declaration_t *readDeclaration (bytecodeistream & str) const;
00114 
00115     // show a declaration
00116     // @param full if false, just show the name; if true, show name and signatur
00117     static string Decl2String (const declaration_t *declaration, bool full = false);
00118     
00119     static void errorNoMatch (Logger* problem_logger, constFunctionTypePtr orig, declaration_t* first_decl);
00120 };
00121 
00122 #endif // StaticDeclaration_h

Generated on Fri Jun 16 18:07:45 2006 for yast2-core by  doxygen 1.4.6