summaryrefslogtreecommitdiff
path: root/src/struct.h
blob: 7ff8256b78a787e2054cf2e33650b67f77f40896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef _COLM_STRUCT_H
#define _COLM_STRUCT_H

#if defined(__cplusplus)
extern "C" {
#endif


typedef struct _StreamImpl StreamImpl;

typedef void (*colm_destructor_t)( struct colm_program *prg,
		Tree **sp, struct colm_struct *s );

struct colm_struct
{
	short id;
	struct colm_struct *prev, *next;
};

/* Must overlay colm_struct. */
struct colm_inbuilt
{
	short id;
	struct colm_struct *prev, *next;
	colm_destructor_t destructor;
};

/* Must overlay colm_inbuilt. */
typedef struct colm_parser
{
	short id;
	struct colm_struct *prev, *next;
	colm_destructor_t destructor;

	void *buffer[10];

	struct _PdaRun *pdaRun;
	struct colm_stream *input;
	Tree *result;
} Parser;


/* Must overlay colm_inbuilt. */
typedef struct colm_stream
{
	short id;
	struct colm_struct *prev, *next;
	colm_destructor_t destructor;

	void *buffer[8];

	StreamImpl *impl;
} Stream;

#define COLM_LIST_EL_SIZE 2
typedef struct colm_list_el
{
	struct colm_list_el *list_next;
	struct colm_list_el *list_prev;
} ListEl;

/* Must overlay colm_inbuilt. */
typedef struct colm_list
{
	short id;
	struct colm_struct *prev, *next;
	colm_destructor_t destructor;

	void *buffer[8];

	ListEl *head, *tail;
	long listLen;
	GenericInfo *genericInfo;
} List;

typedef struct colm_map_el
{
	Tree *key;

	struct colm_map_el *left, *right, *parent;
	long height;

	struct colm_map_el *next, *prev;
} MapEl;

#define COLM_MAP_EL_SIZE ( sizeof(colm_map_el) / sizeof(void*) )

typedef struct colm_map
{
	short id;
	struct colm_struct *prev, *next;
	colm_destructor_t destructor;

	void *buffer[8];

	struct colm_map_el *head, *tail, *root;
	long treeSize;
	GenericInfo *genericInfo;
} Map;

struct colm_struct *colm_struct_new_size( struct colm_program *prg, int size );
struct colm_struct *colm_struct_new( struct colm_program *prg, int id );
void colm_struct_add( struct colm_program *prg, struct colm_struct *item );
void colm_struct_delete( struct colm_program *prg, struct colm_tree **sp,
		struct colm_struct *el );

struct colm_struct *colm_struct_inbuilt( struct colm_program *prg, int size,
		colm_destructor_t destructor );

#define colm_struct_get_field( obj, type, field ) \
	(type)(((void**)(((struct colm_struct*)obj)+1))[field])

#define colm_struct_set_field( obj, type, field, val ) \
	((type*)(((struct colm_struct*)obj)+1))[field] = val

#define colm_struct_get_addr( obj, type, field ) \
	(type)(&(((void **)(((struct colm_struct*)obj)+1))[field]))

#define colm_struct_container( el, field ) \
	((void*)el) - (field * sizeof(void*)) - sizeof(struct colm_struct)

#define colm_generic_el_container( prg, el, genId ) \
	colm_struct_container( el, prg->rtd->genericInfo[genId].elOffset )

#define colm_struct_to_list_el( prg, obj, genId ) \
	colm_struct_get_addr( obj, ListEl*, prg->rtd->genericInfo[genId].elOffset )

#define colm_struct_to_map_el( prg, obj, genId ) \
	colm_struct_get_addr( obj, MapEl*, prg->rtd->genericInfo[genId].elOffset )

Parser *colm_parser_new( struct colm_program *prg, GenericInfo *gi );
Stream *colm_stream_new( struct colm_program *prg );
Stream *colm_stream_new_struct( struct colm_program *prg );

List *colm_list_new( struct colm_program *prg );
struct colm_struct *colm_list_get( struct colm_program *prg, List *list,
		Word genId, Word field );
struct colm_struct *colm_list_el_get( struct colm_program *prg,
		ListEl *listEl, Word genId, Word field );
ListEl *colm_list_detach_head( List *list );
long colm_list_length( List *list );

Map *colm_map_new( struct colm_program *prg );
struct colm_struct *colm_map_el_get( struct colm_program *prg,
		MapEl *mapEl, Word genId, Word field );

#define STRUCT_INBUILT_ID -1

#if defined(__cplusplus)
}
#endif

#endif