yast2-core
Bytecode.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: Bytecode.h
14 
15  Primitive bytecode I/O functions.
16  Acts as a namespace wrapper.
17 
18  Author: Klaus Kaempf <kkaempf@suse.de>
19  Maintainer: Klaus Kaempf <kkaempf@suse.de>
20 
21 /-*/
22 // -*- c++ -*-
23 
24 #ifndef Bytecode_h
25 #define Bytecode_h
26 
27 #include "ycp/YCPValue.h"
28 #include "ycp/YCode.h"
29 #include "ycp/YStatement.h"
30 #include "ycp/YBlock.h"
31 #include "ycp/Type.h"
32 
33 class Y2Namespace;
34 
35 #include <iosfwd>
36 #include <string>
37 #include <map>
38 
39 #include <fstream>
40 
42 class bytecodeistream : public std::ifstream
43 {
45  public:
46  bytecodeistream (string filename);
47  bool isVersion (int major, int minor, int revision);
48  bool isVersionAtMost (int major, int minor, int revision);
49 
50  int major () const { return m_major; }
51  int minor () const { return m_minor; }
52  int release () const { return m_release; }
53 };
54 
56 class Bytecode {
60 
64  bool with_xrefs;
65  };
67  static map<string, YBlockPtr>* m_bytecodeCache;
68 
69  public:
76  class Invalid {};
77 
78  // bool I/O
79  static std::ostream & writeBool (std::ostream & streamref, bool value);
80  static bool readBool (bytecodeistream & streamref);
81 
82  // string I/O
83  static std::ostream & writeString (std::ostream & streamref, const std::string & stringref);
84  static bool readString (bytecodeistream & streamref, std::string & stringref);
85 
86  // Ustring I/O
87  static std::ostream & writeUstring (std::ostream & streamref, const Ustring ustringref);
88  static Ustring readUstring (bytecodeistream & streamref);
89 
90  // char * I/O
91  static std::ostream & writeCharp (std::ostream & streamref, const char * charp);
92  static char * readCharp (bytecodeistream & streamref);
93 
94  // bytepointer I/O
95  static std::ostream & writeBytep (std::ostream & streamref, const unsigned char * bytep, unsigned int len);
96  static unsigned char * readBytep (bytecodeistream & streamref);
97 
98  // u_int32_t I/O
99  static std::ostream & writeInt32 (std::ostream & str, const u_int32_t value);
100  static u_int32_t readInt32 (bytecodeistream & str);
101 
102  // Type I/O
103  static std::ostream & writeType (std::ostream & str, constTypePtr type);
104  static TypePtr readType (bytecodeistream & str);
105 
106  // YCPValue I/O
107  static std::ostream & writeValue (std::ostream & str, const YCPValue value);
108  static YCPValue readValue (bytecodeistream & str);
109 
110  // ycodelist_t * I/O
111  static std::ostream & writeYCodelist (std::ostream & str, const ycodelist_t *codelist);
112  static bool readYCodelist (bytecodeistream & str, ycodelist_t **anchor);
113 
114  //-----------------------------------------------------------
115  // block nesting handling
116  //
117  static void namespaceInit ();
118  // retrieve ID (nesting level) for namespace
119  static int namespaceId (const Y2Namespace *name_space);
120  // retrieve namespace for ID
121  static const Y2Namespace *namespacePtr (int namespace_id);
122 
123  // push given namespace to id stack, return new id, -1 on error
124  static int pushNamespace (const Y2Namespace *name_space, bool with_xrefs = false);
125 
126  // pop given namespace from id stack, return namespace id, -1 on error
127  static int popNamespace (const Y2Namespace *name_space);
128 
129  // pop all from id stack until given namespace is reached and popped too
130  static void popUptoNamespace (const Y2Namespace *name_space);
131 
132  // reset current namespace stack to 'empty' for module loading
133  // returns a tare id needed later
134  static int tareStack ();
135  static void untareStack (int tare_id);
136 
137  //-----------------------------------------------------------
138  // SymbolEntry pointer (!) handling
139  // the SymbolEntries itself are 'owned' by Y2Namespace (YBlock in YCP) and referenced via pointers
140  // to SymbolEntry. These functions handle stream I/O for SymbolEntry pointers.
141  static std::ostream &writeEntry (std::ostream & str, const SymbolEntryPtr entry);
142  static SymbolEntryPtr readEntry (bytecodeistream & str);
143 
144  //-----------------------------------------------------------
145  // YCode read.
146  // Must be implemented outside of YCode since we have derived classes to allocate...
147  // see YCode for write
148  static YCodePtr readCode (bytecodeistream & str);
149 
150  // File I/O
151  // reading and writing complete files is done via separate functions
152  // which add/check a 'magic value' header denoting "YCode" and its version.
153 
154  // read YCode from file in Module path, return YBlock (NULL in case of error)
155  static YBlockPtr readModule (const string & mname);
156 
157  // read YCode from file, return YCode (YError in case of failure)
158  static YCodePtr readFile (const string & filename);
159 
160  // write YCode to file, return true on success (check errno for errors)
161  static bool writeFile (const YCodePtr code, const string & filename);
162 };
163 
164 #endif // Bytecode_h
#define str
Definition: scanner.cc:1003
static int m_namespace_nesting_array_size
Definition: Bytecode.h:58
bool isVersionAtMost(int major, int minor, int revision)
Definition: Bytecode.cc:103
bytecodeistream(string filename)
Definition: Bytecode.cc:68
bool isVersion(int major, int minor, int revision)
Definition: Bytecode.cc:96
Definition: YCode.h:58
const Y2Namespace * name_space
Definition: Bytecode.h:63
int m_major
Definition: Bytecode.h:44
static map< string, YBlockPtr > * m_bytecodeCache
Definition: Bytecode.h:67
int minor() const
Definition: Bytecode.h:51
Unique strings.
Definition: Ustring.h:124
static int m_namespace_tare_level
Definition: Bytecode.h:59
bool with_xrefs
external references... ???
Definition: Bytecode.h:64
references to namespaces
Definition: Bytecode.h:62
int release() const
Definition: Bytecode.h:52
int m_minor
Definition: Bytecode.h:44
*.ybc I/O
Definition: Bytecode.h:56
int m_release
Definition: Bytecode.h:44
int major() const
Definition: Bytecode.h:50
static int m_namespace_nesting_level
Definition: Bytecode.h:57
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
Definition: Y2Namespace.h:43
Definition: Bytecode.h:76
An istream that remembers some data about the bytecode.
Definition: Bytecode.h:42
static namespaceentry_t * m_namespace_nesting_array
Definition: Bytecode.h:66

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