Pol  Revision:4b29d2b
symcont.h
Go to the documentation of this file.
1 
7 #ifndef __SYMCONT_H
8 #define __SYMCONT_H
9 
10 #include <cstdio>
11 
12 #include "../clib/compilerspecifics.h"
13 #include "../clib/rawtypes.h"
14 
15 #ifndef __TOKENS_H
16 #include "tokens.h"
17 #endif
18 
19 namespace Pol
20 {
21 namespace Bscript
22 {
23 #ifdef _MSC_VER
24 #pragma pack( push, 1 )
25 #endif
26 
27 // bitfields
29 {
30 public:
31  unsigned char type;
32  unsigned char id;
33  unsigned short offset;
34  unsigned char module;
35 
36  explicit StoredToken( unsigned char aModule = 0, int aID = CTRL_STATEMENTBEGIN,
37  BTokenType aType = TYP_CONTROL,
38  unsigned aOffset = 0 //,
39  // unsigned aNargs = 0
40  );
42 #ifdef _MSC_VER
43 #pragma pack( pop )
44 #endif
45 
47 {
48 protected:
49  char* s;
50  unsigned usedLen;
51  unsigned allocLen;
52  unsigned growBy;
53 
54 public:
55  explicit SymbolContainer( int growBy = 512 );
56  virtual ~SymbolContainer();
57  virtual void pack( void ) {}
58  void erase();
59 
60  virtual void resize( unsigned lengthToAdd );
61  bool findexisting( const void* data, int datalen, unsigned& position );
62  void append( const char* string, unsigned& position );
63  void append( int lvalue, unsigned& position );
64  void append( double dvalue, unsigned& position );
65  void append( void* data, unsigned datalen, unsigned& position );
66 
67  unsigned length( void ) const { return usedLen; }
68  void setlength( unsigned newLen ) { usedLen = newLen; }
69  const char* array( void ) const { return s; }
70  virtual void* detach( void )
71  {
72  char* t = s;
73  s = NULL;
74  usedLen = allocLen = 0;
75  return t;
76  }
77  virtual void write( FILE* fp );
78  virtual void write( char* fname );
79  unsigned int get_write_length() const;
80  virtual void read( FILE* fp );
81  virtual void read( char* fname );
82 };
83 
84 /* talk to these in statement numbers */
86 {
87 public:
89  explicit StoredTokenContainer( int growBy = 512 ) : SymbolContainer( growBy ), ST( NULL ) {}
90  virtual void pack( void ) POL_OVERRIDE;
91  virtual void* detach( void ) POL_OVERRIDE;
92  virtual void resize( unsigned lengthToAdd ) POL_OVERRIDE;
93  void setcount( unsigned newCount ) { usedLen = newCount * sizeof( StoredToken ); }
94  unsigned count( void ) const { return usedLen / sizeof( StoredToken ); }
95  void append_tok( const StoredToken& token, unsigned* position = NULL );
96  void atPut1( const StoredToken& token, unsigned position );
97  void atGet1( unsigned position, StoredToken& token ) const;
98  unsigned next( void ) { return length() / sizeof( StoredToken ); }
99  virtual void read( FILE* fp ) POL_OVERRIDE;
100 };
101 }
102 }
103 #endif
#define POL_OVERRIDE
unsigned char type
Definition: symcont.h:31
unsigned short offset
Definition: symcont.h:33
virtual void pack(void)
Definition: symcont.h:57
virtual void * detach(void)
Definition: symcont.h:70
unsigned count(void) const
Definition: symcont.h:94
unsigned length(void) const
Definition: symcont.h:67
std::unordered_map< u64, ScriptDiffData > data
Definition: osmod.cpp:966
unsigned char id
Definition: symcont.h:32
const char * array(void) const
Definition: symcont.h:69
void setcount(unsigned newCount)
Definition: symcont.h:93
void setlength(unsigned newLen)
Definition: symcont.h:68
class Pol::Bscript::StoredToken POSTSTRUCT_PACK
Definition: berror.cpp:12
StoredToken(unsigned char aModule=0, int aID=CTRL_STATEMENTBEGIN, BTokenType aType=TYP_CONTROL, unsigned aOffset=0 )
Definition: symcont.cpp:222
unsigned char module
Definition: symcont.h:34
StoredTokenContainer(int growBy=512)
Definition: symcont.h:89