Pol  Revision:4b29d2b
token.h
Go to the documentation of this file.
1 
7 #ifndef __TOKEN_H
8 #define __TOKEN_H
9 
10 #ifndef __TOKENS_H
11 #include "tokens.h"
12 #endif
13 #ifndef __MODULES_H
14 #include "modules.h"
15 #endif
16 
17 #include <iosfwd>
18 #include <set>
19 
20 #include <format/format.h>
21 #include "options.h"
22 
23 namespace Pol
24 {
25 namespace Bscript
26 {
27 typedef struct
28 {
29  unsigned sourceFile;
30  unsigned offset;
31  unsigned strOffset;
32 } DebugToken;
33 
34 class UserFunction;
35 
36 class Token
37 {
38 public:
41  double dval;
42  union {
45  };
48  union {
49  int lval;
50  const unsigned char* dataptr;
51  };
53  bool deprecated;
54  bool ownsStr;
55  unsigned char module;
56 
57  static unsigned int instances();
58  static void show_instances();
59 
60 protected:
61  const char* token;
62 #if STORE_INSTANCELIST
63  typedef set<Token*> Instances;
64  static Instances _instancelist;
65 #endif
66  static unsigned int _instances;
67  void register_instance();
68  void unregister_instance();
69 
70 public:
71  const char* tokval() const { return token; }
72  Token();
73  Token( const Token& tok );
74  Token& operator=( const Token& tok );
75 
76  Token( ModuleID module, BTokenId id, BTokenType type );
77  Token( BTokenId id, BTokenType type );
78  Token( ModuleID module, BTokenId id, BTokenType type, UserFunction* userfunc );
79  void nulStr();
80  void setStr( const char* s );
81  void copyStr( const char* s );
82  void copyStr( const char* s, int len );
83 
84  ~Token();
85 
86  void printOn( std::ostream& outputStream ) const;
87 };
88 
89 std::ostream& operator<<( std::ostream&, const Token& );
90 fmt::Writer& operator<<( fmt::Writer&, const Token& );
91 }
92 }
93 #endif
Token & operator=(const Token &tok)
Definition: token.cpp:112
BTokenType type
Definition: token.h:40
std::ostream & operator<<(std::ostream &os, const CompilerContext &ctx)
Definition: compctx.h:54
unsigned sourceFile
Definition: token.h:29
const char * tokval() const
Definition: token.h:71
BTokenId id
Definition: token.h:39
void copyStr(const char *s)
Definition: token.cpp:214
static unsigned int instances()
Definition: token.cpp:22
const unsigned char * dataptr
Definition: token.h:50
static void show_instances()
Definition: token.cpp:26
void unregister_instance()
Definition: token.cpp:46
unsigned strOffset
Definition: token.h:31
void register_instance()
Definition: token.cpp:38
unsigned char module
Definition: token.h:55
UserFunction * userfunc
Definition: token.h:52
void setStr(const char *s)
Definition: token.cpp:204
const char * token
Definition: token.h:61
void printOn(std::ostream &outputStream) const
Definition: tkn_strm.cpp:20
Definition: berror.cpp:12
static unsigned int _instances
Definition: token.h:66