new version of the reading API
[lttv.git] / ltt / branches / poly / ltt / parser.h
CommitLineData
6cd62ccf 1#ifndef PARSER_H
2#define PARSER_H
3
4/* Extensible array container */
5
6typedef struct _sequence {
7 int size;
8 int position;
9 void **array;
10} sequence;
11
12void sequence_init(sequence *t);
13void sequence_dispose(sequence *t);
14void sequence_push(sequence *t, void *elem);
15void *sequence_pop(sequence *t);
16
17
18/* Hash table */
19
20typedef struct _table {
21 sequence keys;
22 sequence values;
23} table;
24
25void table_init(table *t);
26void table_dispose(table *t);
27void table_insert(table *t, char *key, void *value);
28void *table_find(table *t, char *key);
29void table_insert_int(table *t, int *key, void *value);
30void *table_find_int(table *t, int *key);
31
32
33/* Token types */
34
35typedef enum _token_type {
36 ENDFILE,
963b5f2d 37 FORWARDSLASH,
38 LANGLEBRACKET,
39 RANGLEBRACKET,
6cd62ccf 40 EQUAL,
41 QUOTEDSTRING,
42 NUMBER,
43 NAME
44} token_type;
45
46
47/* State associated with a file being parsed */
48typedef struct _parse_file {
49 char *name;
50 FILE * fp;
51 int lineno;
52 char *buffer;
53 token_type type;
54 int unget;
55 void (*error) (struct _parse_file *, char *);
56} parse_file;
57
58void ungetToken(parse_file * in);
59char *getToken(parse_file *in);
963b5f2d 60char *getForwardslash(parse_file *in);
61char *getLAnglebracket(parse_file *in);
62char *getRAnglebracket(parse_file *in);
6cd62ccf 63char *getQuotedString(parse_file *in);
64char *getName(parse_file *in);
963b5f2d 65int getNumber(parse_file *in);
66char *getEqual(parse_file *in);
67char seekNextChar(parse_file *in);
6cd62ccf 68
69void skipComment(parse_file * in);
70void skipEOL(parse_file * in);
71int isalpha(char car);
72int isalnum(char car);
73
74/* Some constants */
75
76static const int BUFFER_SIZE = 1024;
77
78
79/* Events data types */
80
81typedef enum _data_type {
82 INT,
83 UINT,
84 FLOAT,
85 STRING,
86 ENUM,
87 ARRAY,
88 SEQUENCE,
89 STRUCT,
963b5f2d 90 UNION,
6cd62ccf 91 NONE
92} data_type;
93
94
95/* Event type descriptors */
96
97typedef struct _type_descriptor {
98 char * type_name; //used for named type
99 data_type type;
100 char *fmt;
101 int size;
102 sequence labels; // for enumeration
103 sequence fields; // for structure
104 struct _type_descriptor *nested_type; // for array and sequence
105} type_descriptor;
106
107
108/* Fields within types */
109
110typedef struct _field{
111 char *name;
112 char *description;
113 type_descriptor *type;
114} field;
115
116
117/* Events definitions */
118
119typedef struct _event {
120 char *name;
121 char *description;
122 type_descriptor *type;
6cd62ccf 123} event;
124
963b5f2d 125typedef struct _facility {
126 char * name;
127 char * description;
128 sequence events;
129 sequence unnamed_types;
130 table named_types;
131} facility;
132
6cd62ccf 133int getSize(parse_file *in);
963b5f2d 134unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
6cd62ccf 135
963b5f2d 136void parseFacility(parse_file *in, facility * fac);
6cd62ccf 137void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
138void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
139type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
140void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
141void checkNamedTypesImplemented(table * namedTypes);
142type_descriptor * find_named_type(char *name, table * named_types);
143void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
144
145
963b5f2d 146/* get attributes */
147char * getNameAttribute(parse_file *in);
148char * getFormatAttribute(parse_file *in);
149int getSizeAttribute(parse_file *in);
150int getValueAttribute(parse_file *in);
151char * getValueStrAttribute(parse_file *in);
152
153char * getDescription(parse_file *in);
154
6cd62ccf 155
156static char *intOutputTypes[] = {
157 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
158
159static char *uintOutputTypes[] = {
160 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
161 "unsigned int", "unsigned long int" };
162
163static char *floatOutputTypes[] = {
164 "undef", "undef", "float", "double", "undef", "float", "double" };
165
166
167/* Dynamic memory allocation and freeing */
168
169void * memAlloc(int size);
170char *allocAndCopy(char * str);
171char *appendString(char *s, char *suffix);
172void freeTypes(sequence *t);
173void freeType(type_descriptor * td);
174void freeEvents(sequence *t);
175void freeNamedType(table * t);
176void error_callback(parse_file *in, char *msg);
177
178
179//checksum part
180static const unsigned int crctab32[] =
181{
182#include "crc32.tab"
183};
184
185static inline unsigned long
186partial_crc32_one(unsigned char c, unsigned long crc)
187{
188 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
189}
190
191static inline unsigned long
192partial_crc32(const char *s, unsigned long crc)
193{
194 while (*s)
195 crc = partial_crc32_one(*s++, crc);
196 return crc;
197}
198
199static inline unsigned long
200crc32(const char *s)
201{
202 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
203}
204
205
206#endif // PARSER_H
This page took 0.032221 seconds and 4 git commands to generate.