1 | // $Source$ |
---|
2 | // $Revision: 288 $ |
---|
3 | // $Date: 2002-12-19 12:11:29 +0000 (Thu, 19 Dec 2002) $ |
---|
4 | |
---|
5 | #ifndef __rf_term_hh__ |
---|
6 | #define __rf_term_hh__ |
---|
7 | |
---|
8 | #include "pxx_memory_chunk.hh" |
---|
9 | #include "rf_common.hh" |
---|
10 | |
---|
11 | namespace rfrt |
---|
12 | { |
---|
13 | |
---|
14 | #define M_Chunk pxx::Memory_Chunk |
---|
15 | |
---|
16 | #if UINTPTR_MAX == UINT32_MAX |
---|
17 | #define ORDER_SHIFT 3 |
---|
18 | #define REF_BIT (uintptr_t(0x04)) |
---|
19 | #define PTR_MASK (~(uintptr_t(0x07))) |
---|
20 | #define ORDER1_MASK (uintptr_t(0x03)) |
---|
21 | #define ORDER2_MASK (uintptr_t(0x07)) |
---|
22 | #elif UINTPTR_MAX == UINT64_MAX |
---|
23 | #define ORDER_SHIFT 4 |
---|
24 | #define REF_BIT (uintptr_t(0x08)) |
---|
25 | #define PTR_MASK (~(uintptr_t(0x0F))) |
---|
26 | #define ORDER1_MASK (uintptr_t(0x03)) |
---|
27 | #define ORDER2_MASK (uintptr_t(0x0F)) |
---|
28 | #else |
---|
29 | #error "Unsupported pointer size" |
---|
30 | #endif |
---|
31 | //#define COMPOUND_BIT (uintptr_t(0x8000)) |
---|
32 | //#define CHAR_SHIFT ((sizeof(uintptr_t) - sizeof (uint16_t)) * 8) |
---|
33 | #define ORDER1(x) ((uintptr_t)((x) >> ORDER_SHIFT)) |
---|
34 | #define ORDER2(x) ((uintptr_t)((x) & ORDER2_MASK)) |
---|
35 | #define ORDER(x,y) (((x) << ORDER_SHIFT) | (y)) |
---|
36 | |
---|
37 | enum SymbolType { |
---|
38 | SYM_EMPTY = 0, |
---|
39 | SYM_BORDER, |
---|
40 | SYM_CHAR |
---|
41 | }; |
---|
42 | |
---|
43 | class Term |
---|
44 | { |
---|
45 | |
---|
46 | friend class Expr ; |
---|
47 | friend inline Expr operator + (Term const&, Expr const&) ; |
---|
48 | friend inline Expr operator + (Term const&, Term const&) ; |
---|
49 | friend inline bool operator == (Term const&, Term const&) ; |
---|
50 | friend inline bool flat_eq ( |
---|
51 | const Expr &_e1, uintptr_t _pos1, |
---|
52 | const Expr &_e2, uintptr_t _pos2, uintptr_t _len ); |
---|
53 | |
---|
54 | private: |
---|
55 | |
---|
56 | uintptr_t data1 ; |
---|
57 | uintptr_t data2 ; |
---|
58 | |
---|
59 | inline Term (uint16_t const _c) : |
---|
60 | data1 (SYM_CHAR), |
---|
61 | data2 (_c) |
---|
62 | {} |
---|
63 | |
---|
64 | /* |
---|
65 | inline Term (Term* _first, Term* _last, unsigned _order, uintptr_t _ref_fl) : |
---|
66 | data1 ((uintptr_t)_first | ORDER1(_order)), |
---|
67 | data2 ((uintptr_t)_last | ORDER2(_order)) |
---|
68 | { |
---|
69 | data1 |= _ref_fl; |
---|
70 | } |
---|
71 | */ |
---|
72 | |
---|
73 | // |
---|
74 | // is needed for () operation |
---|
75 | inline Term (Expr const& _expr); |
---|
76 | |
---|
77 | public: |
---|
78 | |
---|
79 | inline ~Term () |
---|
80 | {} |
---|
81 | |
---|
82 | inline bool is_ref () const |
---|
83 | { |
---|
84 | return data1 > 0xFFFF; |
---|
85 | } |
---|
86 | |
---|
87 | inline bool is_sym () const |
---|
88 | { |
---|
89 | return data1 <= 0xFFFF; |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | inline bool is_compound () const |
---|
94 | { |
---|
95 | return (data1 & COMPOUND_BIT) != 0; |
---|
96 | } |
---|
97 | */ |
---|
98 | |
---|
99 | inline bool is_char () const |
---|
100 | { |
---|
101 | return (data1 & SYM_CHAR) != 0; |
---|
102 | } |
---|
103 | |
---|
104 | inline int get_char () const |
---|
105 | { |
---|
106 | return (int)(data2); |
---|
107 | } |
---|
108 | |
---|
109 | inline bool is_border () const |
---|
110 | { |
---|
111 | return ((data1 & SYM_BORDER) != 0); |
---|
112 | } |
---|
113 | |
---|
114 | inline unsigned get_order () const |
---|
115 | { |
---|
116 | return ORDER(data1 & ORDER1_MASK, data2 & ORDER2_MASK); |
---|
117 | } |
---|
118 | |
---|
119 | inline Term* get_first () const |
---|
120 | { |
---|
121 | return (Term*)(data1 & PTR_MASK); |
---|
122 | } |
---|
123 | |
---|
124 | inline Term* get_last () const |
---|
125 | { |
---|
126 | return (Term*)(data2 & PTR_MASK); |
---|
127 | } |
---|
128 | |
---|
129 | inline SymbolType get_type () const |
---|
130 | { |
---|
131 | return (SymbolType)(data1 & 0x7FFF); |
---|
132 | } |
---|
133 | |
---|
134 | // |
---|
135 | // return pointer to our memory chunk |
---|
136 | inline M_Chunk *get_mem_chunk() const |
---|
137 | { |
---|
138 | return static_cast<M_Chunk*>( |
---|
139 | allocator.get_block_start( get_first(), get_order() ) |
---|
140 | ); |
---|
141 | } |
---|
142 | |
---|
143 | }; |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | #endif // __rf_term_hh__ |
---|