(cos_Qcomposition): New variable.
[chise/concord.git] / cos-i.h
1 /* Internal definitions of CONCORD Object System
2
3    Copyright (C) 2013 MORIOKA Tomohiko
4    This file is part of the CONCORD Library.
5
6    The CONCORD Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The CONCORD Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the CONCORD Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 #ifndef _COS_I_H
22 #define _COS_I_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 #if 0
28 }
29 #endif
30
31 #include "sysdep.h"
32 #include "concord.h"
33 #include "cos.h"
34
35 #ifndef SIZEOF_COS_INT
36 # define SIZEOF_COS_INT SIZEOF_VOID_P
37 #endif
38
39 #ifndef SIZEOF_INT
40 # define SIZEOF_INT (sizeof (int))
41 #endif
42
43 #ifndef SIZEOF_LONG
44 # define SIZEOF_LONG (sizeof (long))
45 #endif
46
47 #ifndef SIZEOF_LONG_LONG
48 # define SIZEOF_LONG_LONG (sizeof (long long))
49 #endif
50
51 #ifndef COS_INT
52 # if SIZEOF_COS_INT == SIZEOF_LONG
53 #  define COS_INT long
54 # elif SIZEOF_COS_INT == SIZEOF_INT
55 #  define COS_INT int
56 # elif SIZEOF_COS_INT == SIZEOF_LONG_LONG
57 #  define COS_INT long long
58 # else
59 #  error Unable to determine suitable type for COS_INT
60 # endif
61 #endif
62
63 #ifndef COS_UINT
64 # define COS_UINT unsigned COS_INT
65 #endif
66
67 #define BITS_PER_COS_INT (SIZEOF_COS_INT * BITS_PER_CHAR)
68
69
70 enum COS_Type {
71   COS_Type_Entity,
72   COS_Type_Int_Even,
73   COS_Type_Char,
74   COS_Type_Int_Odd
75 };
76
77 #define COS_POINTER_TYPE_P(type) ((type) == COS_Type_Entity)
78
79 #define COS_TYPE_BITS  2
80 #define COS_INT_TYPE_BITS  1
81
82 #define COS_INT_VAL_BITS (BITS_PER_COS_INT - COS_INT_TYPE_BITS)
83 #define COS_VAL_BITS (BITS_PER_COS_INT - COS_TYPE_BITS)
84 #define COS_INT_MAX ((COS_INT) ((1UL << (COS_INT_VAL_BITS - 1)) -1UL))
85 #define COS_INT_MIN (-(COS_INT_MAX) - 1)
86
87
88 typedef struct COS_Object_Header
89 {
90   unsigned char prefix;
91   unsigned char type;
92   COS_INT       reference_count;
93 } COS_Object_Header;
94
95 #define COS_OBJECT_PREFIX_OBJECT          0
96
97 enum COS_Object_Type {
98   COS_Object_Type_NULL,
99   COS_Object_Type_C_String,
100   COS_Object_Type_int,
101   COS_Object_Type_char,
102   COS_Object_Type_String,
103   COS_Object_Type_Symbol,
104   COS_Object_Type_Cons,
105   COS_Object_Type_Container,
106   COS_Object_Type_Sexp,
107   COS_Object_Type_Binary,
108   COS_Object_Type_DS,
109   COS_Object_Type_Genre,
110   COS_Object_Type_Feature,
111   COS_Object_Type_Feature_INDEX,
112   COS_Object_Type_DB_Object
113 };
114
115 #define COS_FAT_OBJECT_TYPE_MIN COS_Object_Type_String
116 #define COS_OBJECT_TYPE_MAX COS_Object_Type_DB_Object
117
118 extern int (*COS_Object_retain_function_table[]) (COS_Object);
119 extern int (*COS_Object_release_function_table[]) (COS_Object);
120
121 struct COS_Object_ent
122 {
123   COS_Object_Header header;
124 };
125
126 COS_Object cos_allocate_object_0 (enum COS_Object_Type type,
127                                   size_t size);
128
129 #define COS_ALLOCATE_OBJECT(type) \
130   ((COS_##type)cos_allocate_object_0(COS_Object_Type_##type, \
131                                      sizeof(COS_##type##_ent)))
132
133 #define COS_OBJECT_INT_P(obj) \
134   ((COS_UINT)(obj) & 1)
135
136 #define COS_OBJECT_CHAR_P(obj) \
137   ((COS_UINT)(obj) & 2)
138
139 #define COS_OBJECT_C_STRING_P(obj) \
140   ((obj != NULL) \
141    && (((unsigned char *)obj)[0] != COS_OBJECT_PREFIX_OBJECT))
142
143 #define COS_OBJECT_P(obj) \
144   ((obj != NULL) \
145    && (!COS_OBJECT_INT_P (obj)) \
146    && (!COS_OBJECT_CHAR_P (obj)) \
147    && (((unsigned char *)obj)[0] == COS_OBJECT_PREFIX_OBJECT))
148
149 #define COS_OBJECT_TYPE_P(obj, TYPE) \
150   (COS_OBJECT_P (obj) \
151    && (((COS_Object)obj)->header.type == COS_Object_Type_##TYPE))
152
153 #define COS_OBJECT_STRING_P(obj) \
154   COS_OBJECT_TYPE_P (obj, String)
155
156 #define COS_OBJECT_SYMBOL_P(obj) \
157   COS_OBJECT_TYPE_P (obj, Symbol)
158
159 #define COS_OBJECT_CONS_P(obj) \
160   COS_OBJECT_TYPE_P (obj, Cons)
161
162 #define COS_OBJECT_DS_P(obj) \
163   COS_OBJECT_TYPE_P (obj, DS)
164
165 #define COS_OBJECT_GENRE_P(obj) \
166   COS_OBJECT_TYPE_P (obj, Genre)
167
168 #define COS_OBJECT_FEATURE_P(obj) \
169   COS_OBJECT_TYPE_P (obj, Feature)
170
171 #define COS_OBJECT_FEATURE_INDEX_P(obj) \
172   COS_OBJECT_TYPE_P (obj, Feature_INDEX)
173
174
175 struct COS_String_ent
176 {
177   COS_Object_Header header;
178
179   size_t size;
180   unsigned char* data;
181 };
182
183 int cos_retain_string (COS_Object obj);
184 int cos_release_string (COS_Object obj);
185
186
187 struct COS_Symbol_ent
188 {
189   COS_Object_Header header;
190
191   COS_String name;
192   COS_object value;
193 };
194
195 COS_Symbol cos_make_symbol (COS_String string);
196
197 int cos_retain_symbol (COS_Object obj);
198 int cos_release_symbol (COS_Object obj);
199
200
201 typedef struct COS_Symbol_Table_ent COS_Symbol_Table_ent;
202 typedef COS_Symbol_Table_ent* COS_Symbol_Table;
203
204 struct COS_Symbol_Table_ent
205 {
206   size_t size;
207   COS_Symbol* data;
208 };
209
210 COS_Symbol_Table cos_make_symbol_table (void);
211
212 int cos_symbol_table_grow (COS_Symbol_Table table);
213
214 void cos_destroy_symbol_table (COS_Symbol_Table table);
215
216 int cos_symbol_table_set (COS_Symbol_Table table, COS_Symbol symbol);
217
218 COS_Symbol
219 cos_symbol_table_intern (COS_Symbol_Table table, COS_object name);
220
221
222 struct COS_Cons_ent
223 {
224   COS_Object_Header header;
225
226   COS_object car;
227   COS_object cdr;
228 };
229
230 #define COS_CAR(obj) \
231   (((COS_Cons)(obj))->car)
232 #define COS_CDR(obj) \
233   (((COS_Cons)(obj))->cdr)
234
235 int cos_retain_cons (COS_Object obj);
236 int cos_release_cons (COS_Object obj);
237
238
239 struct COS_Container_ent
240 {
241   COS_Object_Header header;
242
243   COS_Object type;
244   size_t size;
245   size_t len;
246   size_t offset;
247   COS_Object* data;
248 };
249
250 int cos_retain_container (COS_Object obj);
251 int cos_release_container (COS_Object obj);
252
253
254 struct COS_Sexp_ent
255 {
256   COS_Object_Header header;
257
258   size_t len;
259   char* data;
260 };
261
262 int cos_retain_sexp (COS_Object obj);
263 int cos_release_sexp (COS_Object obj);
264
265
266 struct COS_Binary_ent
267 {
268   COS_Object_Header header;
269
270   size_t len;
271   unsigned char* data;
272 };
273
274 int cos_retain_binary (COS_Object obj);
275 int cos_release_binary (COS_Object obj);
276
277
278 int cos_retain_ds (COS_Object obj);
279 int cos_release_ds (COS_Object obj);
280
281
282 int cos_retain_genre (COS_Object obj);
283 int cos_release_genre (COS_Object obj);
284
285 int concord_close_genre (COS_Genre genre);
286
287
288 int cos_retain_feature (COS_Object obj);
289 int cos_release_feature (COS_Object obj);
290
291 int concord_close_feature (COS_Feature feature);
292
293
294 int cos_retain_index (COS_Object obj);
295 int cos_release_index (COS_Object obj);
296
297 int concord_close_index (COS_Feature_INDEX table);
298
299
300 struct COS_DB_Object_ent
301 {
302   COS_Object_Header header;
303
304   COS_Feature feature;
305   COS_Object id;
306 };
307
308 int cos_retain_db_object (COS_Object obj);
309 int cos_release_db_object (COS_Object obj);
310
311 #if 0
312 {
313 #endif
314 #ifdef __cplusplus
315 }
316 #endif
317
318 #endif /* !_COS_I_H */