yast2-core
StaticDeclaration.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12 
13  File: StaticDeclaration.h
14 
15  Author: Klaus Kaempf <kkaempf@suse.de>
16  Maintainer: Klaus Kaempf <kkaempf@suse.de>
17 
18 /-*/
19 // -*- c++ -*-
20 
21 #ifndef StaticDeclaration_h
22 #define StaticDeclaration_h
23 
24 #include <string>
25 #include <list>
26 using namespace std;
27 
28 #include "ycp/YCPValue.h"
29 #include "ycp/YCPList.h"
30 #include "ycp/Type.h"
31 #include "y2/Y2Namespace.h"
32 
33 class SymbolEntry;
34 class SymbolTable;
35 class TableEntry;
36 class bytecodeistream;
37 class Logger;
38 
39 // Only use BUILTIN_STATISTICS for testing. It will create three files
40 // /tmp/builtin-X.txt which list all builtins registered, looked up
41 // and used.
42 // #define BUILTIN_STATISTICS
43 
44 
45 // structure for static declarations
47 {
48  DECL_NIL = 0x00000001, // function accepts nil
49  DECL_WILD = 0x00000002, // function expects wildcard
50  DECL_SYMBOL = 0x00000004, // function expects a symbol as parameter (local environment)
51  DECL_CODE = 0x00000008, // function expects code as parameter (local evaluation)
52  DECL_LOOP = 0x00000010, // function implements a loop, allows break statement
53  DECL_TYPEDEF = 0x00000020, // name declares a typedef
54  DECL_CONSTANT = 0x00000040, // name declares a constant
55  DECL_NAMESPACE = 0x00000080, // name declares a namespace (switches registerDeclarations !)
56  DECL_FLEX = 0x00000100, // function signature include 'flex' type
57  DECL_NOEVAL = 0x00000200, // function will evaluate its parameters on its own (boolean functions for shortcut eval)
58  DECL_CALL_HANDLER = 0x00000400, // ptr is a call handler (only together with DECL_NAMESPACE)
59  DECL_DEPRECATED = 0x00000800, // deprecated function
60  DECL_FORMATTED = 0x00001000 // has format string with "%1" as first arg
61 };
62 
63 // declaration::ptr is a function pointer of this type if the first entry of a StaticDeclaration
64 // is declared with flags DECL_NAMESPACE | DECL_CALL_HANDLER :
65 typedef YCPValue (*call_handler_t)(void * function, int argc, YCPValue args[] );
66 
71 struct declaration {
72  const char *name; // name of variable/function/typedef
73  const char *signature; // signature of variable/function/typedef (before registration)
74  void *ptr; // pointer to builtin value/function
75  int flags; // parameter acceptance, @ref DeclFlags
76  struct declaration *name_space; // table of the namespace (internal use only)
77  constTypePtr type;
79 };
80 typedef struct declaration declaration_t;
81 
83 private:
84  // toplevel table for all static declaration
86  // list of predefined namespaces which are already active, Y2Namespace is non-const since it might get evaluated
87  std::list<std::pair<std::string, Y2Namespace *> > m_active_predefined;
88 public:
89  // constructor
92 
93  SymbolTable *symbolTable() { return m_declTable; };
94 
95  // list of registered namespaces which were predefined
96  const std::list<std::pair<std::string, Y2Namespace *> > & active_predefined() const { return m_active_predefined; };
97 
98  // register declarations
99  void registerDeclarations (const char *filename, declaration_t *declarations);
100 
101  // find a declaration
102  declaration_t *findDeclaration (const char *name) const;
103  declaration_t *findDeclaration (const char *name, constTypePtr type, bool partial = false) const;
104  declaration_t *findDeclaration (declaration_t *decl, constTypePtr type, bool partial = false) const;
105 
106  // dump all registered builtins
107  void dumpDeclarations () const;
108 
109  // write declaration to stream (name and type)
110  std::ostream & writeDeclaration (std::ostream & str, const declaration_t *decl) const;
111  std::ostream & writeXmlDeclaration (std::ostream & str, const declaration_t *decl) const;
112 
113  // read declaration from stream (return declaration matching name and type _exactly_)
114  declaration_t *readDeclaration (bytecodeistream & str) const;
115 
116  // show a declaration
117  // @param full if false, just show the name; if true, show name and signatur
118  static string Decl2String (const declaration_t *declaration, bool full = false);
119 
120  static void errorNoMatch (Logger* problem_logger, constFunctionTypePtr orig, declaration_t* first_decl);
121 };
122 
123 #endif // StaticDeclaration_h
c++ interface for logging
Definition: libycp/src/include/ycp/y2log.h:73
Definition: StaticDeclaration.h:51
Definition: SymbolEntry.h:41
struct declaration * name_space
Definition: StaticDeclaration.h:76
#define str
Definition: scanner.cc:997
YCPValue(* call_handler_t)(void *function, int argc, YCPValue args[])
Definition: StaticDeclaration.h:65
constTypePtr type
Definition: StaticDeclaration.h:77
Definition: SymbolTable.h:100
STL namespace.
void * ptr
Definition: StaticDeclaration.h:74
Definition: StaticDeclaration.h:49
Definition: StaticDeclaration.h:48
Definition: StaticDeclaration.h:60
Definition: StaticDeclaration.h:55
Definition: StaticDeclaration.h:54
Definition: StaticDeclaration.h:57
Definition: StaticDeclaration.h:59
Definition: StaticDeclaration.h:50
Definition: StaticDeclaration.h:58
TableEntry * tentry
Definition: StaticDeclaration.h:78
SymbolTable * m_declTable
Definition: StaticDeclaration.h:85
Definition: StaticDeclaration.h:71
int flags
Definition: StaticDeclaration.h:75
Definition: StaticDeclaration.h:52
const char * name
Definition: StaticDeclaration.h:72
std::list< std::pair< std::string, Y2Namespace * > > m_active_predefined
Definition: StaticDeclaration.h:87
Wrapper for YCPValueRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPValueRep with the arrow operator. See YCPValueRep.
Definition: YCPValue.h:275
DeclFlags
Definition: StaticDeclaration.h:46
An istream that remembers some data about the bytecode.
Definition: Bytecode.h:42
const char * signature
Definition: StaticDeclaration.h:73
Definition: StaticDeclaration.h:82
Definition: StaticDeclaration.h:53
Definition: StaticDeclaration.h:56
Definition: SymbolTable.h:42
SymbolTable * symbolTable()
Definition: StaticDeclaration.h:93
const std::list< std::pair< std::string, Y2Namespace * > > & active_predefined() const
Definition: StaticDeclaration.h:96

Generated on a sunny day for yast2-core by doxygen 1.8.8