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

Bytecode.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:       Bytecode.h
00014 
00015    Primitive bytecode I/O functions.
00016    Acts as a namespace wrapper.
00017 
00018    Author:     Klaus Kaempf <kkaempf@suse.de>
00019    Maintainer: Klaus Kaempf <kkaempf@suse.de>
00020 
00021 /-*/
00022 // -*- c++ -*-
00023 
00024 #ifndef Bytecode_h
00025 #define Bytecode_h
00026 
00027 #include "ycp/YCPValue.h"
00028 #include "ycp/YCode.h"
00029 #include "ycp/YStatement.h"
00030 #include "ycp/YBlock.h"
00031 #include "ycp/Type.h"
00032 
00033 class Y2Namespace;
00034 
00035 #include <iosfwd>
00036 #include <string>
00037 #include <map>
00038 
00039 class Bytecode {
00040     static int m_namespace_nesting_level;
00041     static int m_namespace_nesting_array_size;
00042     static int m_namespace_tare_level;
00043     typedef struct { const Y2Namespace *name_space; bool with_xrefs; } namespaceentry_t;
00044     static namespaceentry_t *m_namespace_nesting_array;
00045     static map<string, YBlockPtr> m_bytecodeCache;
00046 
00047     public:
00048         // bool I/O
00049         static std::ostream & writeBool (std::ostream & streamref, bool value);
00050         static bool readBool (std::istream & streamref);
00051 
00052         // string I/O
00053         static std::ostream & writeString (std::ostream & streamref, const std::string & stringref);
00054         static bool readString (std::istream & streamref, std::string & stringref);
00055 
00056         // Ustring I/O
00057         static std::ostream & writeUstring (std::ostream & streamref, const Ustring ustringref);
00058         static Ustring readUstring (std::istream & streamref);
00059 
00060         // char * I/O
00061         static std::ostream & writeCharp (std::ostream & streamref, const char * charp);
00062         static char * readCharp (std::istream & streamref);
00063 
00064         // bytepointer I/O
00065         static std::ostream & writeBytep (std::ostream & streamref, const unsigned char * bytep, unsigned int len);
00066         static unsigned char * readBytep (std::istream & streamref);
00067 
00068         // u_int32_t I/O
00069         static std::ostream & writeInt32 (std::ostream & str, const u_int32_t value);
00070         static u_int32_t readInt32 (std::istream & str);
00071 
00072         // Type I/O
00073         static std::ostream & writeType (std::ostream & str, constTypePtr type);
00074         static TypePtr readType (std::istream & str);
00075 
00076         // YCPValue I/O
00077         static std::ostream & writeValue (std::ostream & str, const YCPValue value);
00078         static YCPValue readValue (std::istream & str);
00079 
00080         // ycodelist_t * I/O
00081         static std::ostream & writeYCodelist (std::ostream & str, const ycodelist_t *codelist);
00082         static bool readYCodelist (std::istream & str, ycodelist_t **anchor);
00083 
00084         //-----------------------------------------------------------
00085         // block nesting handling
00086         //
00087         static void namespaceInit ();
00088         // retrieve ID (nesting level) for namespace
00089         static int namespaceId (const Y2Namespace *name_space);
00090         // retrieve namespace for ID
00091         static const Y2Namespace *namespacePtr (int namespace_id);
00092 
00093         // push given namespace to id stack, return new id, -1 on error
00094         static int pushNamespace (const Y2Namespace *name_space, bool with_xrefs = false);
00095 
00096         // pop given namespace from id stack, return namespace id, -1 on error
00097         static int popNamespace (const Y2Namespace *name_space);
00098 
00099         // pop all from id stack until given namespace is reached and popped too
00100         static void popUptoNamespace (const Y2Namespace *name_space);
00101 
00102         // reset current namespace stack to 'empty' for module loading
00103         //   returns a tare id needed later
00104         static int tareStack ();
00105         static void untareStack (int tare_id);
00106 
00107         //-----------------------------------------------------------
00108         // SymbolEntry pointer (!) handling
00109         //   the SymbolEntries itself are 'owned' by Y2Namespace (YBlock in YCP) and referenced via pointers
00110         //   to SymbolEntry. These functions handle stream I/O for SymbolEntry pointers.
00111         static std::ostream &writeEntry (std::ostream & str, const SymbolEntryPtr entry);
00112         static SymbolEntryPtr readEntry (std::istream & str);
00113 
00114         //-----------------------------------------------------------
00115         // YCode read.
00116         // Must be implemented outside of YCode since we have derived classes to allocate...
00117         // see YCode for write
00118         static YCodePtr readCode (std::istream & str);
00119 
00120         // File I/O
00121         // reading and writing complete files is done via separate functions
00122         // which add/check a 'magic value' header denoting "YCode" and its version.
00123 
00124         // read YCode from file in Module path, return YBlock (NULL in case of error)
00125         static YBlockPtr readModule (const string & mname);
00126 
00127         // read YCode from file, return YCode (YError in case of failure)
00128         static YCodePtr readFile (const string & filename);
00129 
00130         // write YCode to file, return true on success (check errno for errors)
00131         static bool writeFile (const YCodePtr code, const string & filename);
00132 };
00133 
00134 #endif // Bytecode_h

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