first version of reading api source files
[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,
37 COMA,
38 LPARENTHESIS,
39 RPARENTHESIS,
40 SEMICOLON,
41 EQUAL,
42 QUOTEDSTRING,
43 NUMBER,
44 NAME
45} token_type;
46
47
48/* State associated with a file being parsed */
49typedef struct _parse_file {
50 char *name;
51 FILE * fp;
52 int lineno;
53 char *buffer;
54 token_type type;
55 int unget;
56 void (*error) (struct _parse_file *, char *);
57} parse_file;
58
59void ungetToken(parse_file * in);
60char *getToken(parse_file *in);
61char *getComa(parse_file *in);
62char *getLParenthesis(parse_file *in);
63char *getRParenthesis(parse_file *in);
64char *getSemiColon(parse_file *in);
65char *getQuotedString(parse_file *in);
66char *getName(parse_file *in);
67int getNumber(parse_file *in);
68char * getEqual(parse_file *in);
69
70void skipComment(parse_file * in);
71void skipEOL(parse_file * in);
72int isalpha(char car);
73int isalnum(char car);
74
75/* Some constants */
76
77static const int BUFFER_SIZE = 1024;
78
79
80/* Events data types */
81
82typedef enum _data_type {
83 INT,
84 UINT,
85 FLOAT,
86 STRING,
87 ENUM,
88 ARRAY,
89 SEQUENCE,
90 STRUCT,
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;
123 int nested;
124} event;
125
126int getSize(parse_file *in);
127unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type, int * nestedStruct);
128
129void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
130void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
131type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
132void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
133void checkNamedTypesImplemented(table * namedTypes);
134type_descriptor * find_named_type(char *name, table * named_types);
135void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
136
137
138
139static char *intOutputTypes[] = {
140 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
141
142static char *uintOutputTypes[] = {
143 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
144 "unsigned int", "unsigned long int" };
145
146static char *floatOutputTypes[] = {
147 "undef", "undef", "float", "double", "undef", "float", "double" };
148
149
150/* Dynamic memory allocation and freeing */
151
152void * memAlloc(int size);
153char *allocAndCopy(char * str);
154char *appendString(char *s, char *suffix);
155void freeTypes(sequence *t);
156void freeType(type_descriptor * td);
157void freeEvents(sequence *t);
158void freeNamedType(table * t);
159void error_callback(parse_file *in, char *msg);
160
161
162//checksum part
163static const unsigned int crctab32[] =
164{
165#include "crc32.tab"
166};
167
168static inline unsigned long
169partial_crc32_one(unsigned char c, unsigned long crc)
170{
171 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
172}
173
174static inline unsigned long
175partial_crc32(const char *s, unsigned long crc)
176{
177 while (*s)
178 crc = partial_crc32_one(*s++, crc);
179 return crc;
180}
181
182static inline unsigned long
183crc32(const char *s)
184{
185 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
186}
187
188
189#endif // PARSER_H
This page took 0.028133 seconds and 4 git commands to generate.