ltt library extra careful warnings check
[lttv.git] / ltt / branches / poly / ltt / parser.h
CommitLineData
449cb9d7 1/*
2
3parser.c: Generate helper declarations and functions to trace events
4 from an event description file.
5
6Copyright (C) 2002, Xianxiu Yang
7Copyright (C) 2002, Michel Dagenais
8This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10the Free Software Foundation; version 2 of the License.
11
12This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/
21
6cd62ccf 22#ifndef PARSER_H
23#define PARSER_H
24
25/* Extensible array container */
26
27typedef struct _sequence {
28 int size;
29 int position;
30 void **array;
31} sequence;
32
33void sequence_init(sequence *t);
34void sequence_dispose(sequence *t);
35void sequence_push(sequence *t, void *elem);
36void *sequence_pop(sequence *t);
37
38
39/* Hash table */
40
41typedef struct _table {
42 sequence keys;
43 sequence values;
44} table;
45
46void table_init(table *t);
47void table_dispose(table *t);
48void table_insert(table *t, char *key, void *value);
49void *table_find(table *t, char *key);
50void table_insert_int(table *t, int *key, void *value);
51void *table_find_int(table *t, int *key);
52
53
54/* Token types */
55
56typedef enum _token_type {
57 ENDFILE,
963b5f2d 58 FORWARDSLASH,
59 LANGLEBRACKET,
60 RANGLEBRACKET,
6cd62ccf 61 EQUAL,
62 QUOTEDSTRING,
63 NUMBER,
64 NAME
65} token_type;
66
67
68/* State associated with a file being parsed */
69typedef struct _parse_file {
70 char *name;
71 FILE * fp;
72 int lineno;
73 char *buffer;
74 token_type type;
75 int unget;
76 void (*error) (struct _parse_file *, char *);
77} parse_file;
78
79void ungetToken(parse_file * in);
80char *getToken(parse_file *in);
963b5f2d 81char *getForwardslash(parse_file *in);
82char *getLAnglebracket(parse_file *in);
83char *getRAnglebracket(parse_file *in);
6cd62ccf 84char *getQuotedString(parse_file *in);
85char *getName(parse_file *in);
963b5f2d 86int getNumber(parse_file *in);
87char *getEqual(parse_file *in);
88char seekNextChar(parse_file *in);
6cd62ccf 89
90void skipComment(parse_file * in);
91void skipEOL(parse_file * in);
6cd62ccf 92
93/* Some constants */
94
95static const int BUFFER_SIZE = 1024;
96
97
98/* Events data types */
99
100typedef enum _data_type {
101 INT,
102 UINT,
103 FLOAT,
104 STRING,
105 ENUM,
106 ARRAY,
107 SEQUENCE,
108 STRUCT,
963b5f2d 109 UNION,
6cd62ccf 110 NONE
111} data_type;
112
113
114/* Event type descriptors */
115
116typedef struct _type_descriptor {
117 char * type_name; //used for named type
118 data_type type;
119 char *fmt;
120 int size;
121 sequence labels; // for enumeration
122 sequence fields; // for structure
123 struct _type_descriptor *nested_type; // for array and sequence
124} type_descriptor;
125
126
127/* Fields within types */
128
8d1e6362 129typedef struct _type_fields{
6cd62ccf 130 char *name;
131 char *description;
132 type_descriptor *type;
8d1e6362 133} type_fields;
6cd62ccf 134
135
136/* Events definitions */
137
8d1e6362 138typedef struct _event_t {
6cd62ccf 139 char *name;
140 char *description;
141 type_descriptor *type;
8d1e6362 142} event_t;
6cd62ccf 143
8d1e6362 144typedef struct _facility_t {
963b5f2d 145 char * name;
146 char * description;
147 sequence events;
148 sequence unnamed_types;
149 table named_types;
8d1e6362 150} facility_t;
963b5f2d 151
6cd62ccf 152int getSize(parse_file *in);
963b5f2d 153unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
6cd62ccf 154
8d1e6362 155void parseFacility(parse_file *in, facility_t * fac);
156void parseEvent(parse_file *in, event_t *ev, sequence * unnamed_types, table * named_types);
6cd62ccf 157void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
158type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
159void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
160void checkNamedTypesImplemented(table * namedTypes);
161type_descriptor * find_named_type(char *name, table * named_types);
162void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
163
164
963b5f2d 165/* get attributes */
166char * getNameAttribute(parse_file *in);
167char * getFormatAttribute(parse_file *in);
168int getSizeAttribute(parse_file *in);
169int getValueAttribute(parse_file *in);
170char * getValueStrAttribute(parse_file *in);
171
172char * getDescription(parse_file *in);
173
6cd62ccf 174
175static char *intOutputTypes[] = {
176 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
177
178static char *uintOutputTypes[] = {
179 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
180 "unsigned int", "unsigned long int" };
181
182static char *floatOutputTypes[] = {
183 "undef", "undef", "float", "double", "undef", "float", "double" };
184
185
186/* Dynamic memory allocation and freeing */
187
188void * memAlloc(int size);
189char *allocAndCopy(char * str);
190char *appendString(char *s, char *suffix);
191void freeTypes(sequence *t);
192void freeType(type_descriptor * td);
193void freeEvents(sequence *t);
194void freeNamedType(table * t);
195void error_callback(parse_file *in, char *msg);
196
197
198//checksum part
199static const unsigned int crctab32[] =
200{
201#include "crc32.tab"
202};
203
204static inline unsigned long
205partial_crc32_one(unsigned char c, unsigned long crc)
206{
207 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
208}
209
210static inline unsigned long
211partial_crc32(const char *s, unsigned long crc)
212{
213 while (*s)
214 crc = partial_crc32_one(*s++, crc);
215 return crc;
216}
217
218static inline unsigned long
219crc32(const char *s)
220{
221 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
222}
223
224
225#endif // PARSER_H
This page took 0.051931 seconds and 4 git commands to generate.