parser.c: Generate helper declarations and functions to trace events
from an event description file.
-Copyright (C) 2002, Xianxiu Yang
-Copyright (C) 2002, Michel Dagenais
-This program is free software; you can redistribute it and/or modify
+ Copyright (C) 2005, Mathieu Desnoyers
+ Copyright (C) 2002, Xianxiu Yang
+ Copyright (C) 2002, Michel Dagenais
+ This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; version 2 of the License.
+ the Free Software Foundation; version 2 of the License.
-This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
if(strcmp("field",token))in->error(in,"expecting a field");
f = (field_t *)memAlloc(sizeof(field_t));
sequence_push(&(ev->fields),f);
- parseFields(in, f, unnamed_types, named_types);
+ parseFields(in, f, unnamed_types, named_types, 1);
break;
default:
in->error(in, "expecting </event> or <field >");
* f : field
* unnamed_types : array of unamed types
* named_types : array of named types
+ * tag : is field surrounded by a <field> </field> tag ?
****************************************************************************/
void parseFields(parse_file_t *in, field_t *f,
sequence_t * unnamed_types,
- table_t * named_types)
+ table_t * named_types,
+ int tag)
{
char * token;
+ if(tag) {
+ //<field name=field_name> <description> <type> </field>
+ getFieldAttributes(in, f);
+ if(f->name == NULL) in->error(in, "Field not named");
+ getRAnglebracket(in);
- //<field name=field_name> <description> <type> </field>
- getFieldAttributes(in, f);
- if(f->name == NULL) in->error(in, "Field not named");
- getRAnglebracket(in);
-
- f->description = getDescription(in);
+ f->description = getDescription(in);
+ }
//<int size=...>
getLAnglebracket(in);
f->type = parseType(in,NULL, unnamed_types, named_types);
- getLAnglebracket(in);
- getForwardslash(in);
- token = getName(in);
- if(strcmp("field",token))in->error(in,"not a valid field definition");
- getRAnglebracket(in); //</field>
+ if(tag) {
+ getLAnglebracket(in);
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("field",token))in->error(in,"not a valid field definition");
+ getRAnglebracket(in); //</field>
+ }
}
f = (field_t *)memAlloc(sizeof(field_t));
sequence_push(&(t->fields),f);
- parseFields(in, f, unnamed_types, named_types);
+ parseFields(in, f, unnamed_types, named_types, 1);
//next field
getLAnglebracket(in);
while(strcmp("field",token) == 0){
f = (field_t *)memAlloc(sizeof(field_t));
sequence_push(&(t->fields),f);
- parseFields(in, f, unnamed_types, named_types);
+ parseFields(in, f, unnamed_types, named_types, 1);
//next field
getLAnglebracket(in);
}
else if(strcmp(token,"array") == 0) {
t->type = ARRAY;
+ sequence_init(&(t->fields));
getTypeAttributes(in, t, unnamed_types, named_types);
if(t->size == 0) in->error(in, "Array has empty size");
getForwardslash(in);
getRAnglebracket(in); //<array size=n>
- getLAnglebracket(in); //<type struct>
- t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+ //getLAnglebracket(in); //<subtype>
+ /* subfield */
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+ parseFields(in, f, unnamed_types, named_types, 0);
+
+ //getLAnglebracket(in); //<type struct>
+ //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
getLAnglebracket(in); //</array>
getForwardslash(in);
}
else if(strcmp(token,"sequence") == 0) {
t->type = SEQUENCE;
+ sequence_init(&(t->fields));
//getTypeAttributes(in, t, unnamed_types, named_types);
//getForwardslash(in);
getRAnglebracket(in); //<sequence>
- getLAnglebracket(in); //<type sequence>
- t->length_type = parseType(in, NULL, unnamed_types, named_types);
+ //getLAnglebracket(in); //<sequence size type>
+ /* subfield */
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+ parseFields(in, f, unnamed_types, named_types, 0);
+
+ //getLAnglebracket(in); //<subtype>
+ /* subfield */
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+ parseFields(in, f, unnamed_types, named_types, 0);
- getLAnglebracket(in); //<type sequence>
+ //getLAnglebracket(in); //<type sequence>
+ //t->length_type = parseType(in, NULL, unnamed_types, named_types);
- t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+ //getLAnglebracket(in); //<type sequence>
- if(t->length_type == NULL) in->error(in, "Sequence has no length type");
- switch(t->length_type->type) {
+ //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+
+ if(t->fields.position < 1) in->error(in, "Sequence has no length type");
+ if(t->fields.position < 2) in->error(in, "Sequence has no subtype");
+ switch(((field_t*)t->fields.array[0])->type->type) {
case UINT_FIXED :
case UCHAR :
case USHORT :
in->error(in, "Wrong length type for sequence");
}
-
- if(t->nested_type == NULL) in->error(in, "Sequence has no nested type");
getLAnglebracket(in); //</sequence>
getForwardslash(in);
token = getName(in);
}
else if(strcmp(token,"char") == 0) {
t->type = CHAR;
+ t->size = 1;
getTypeAttributes(in, t, unnamed_types, named_types);
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"uchar") == 0) {
t->type = UCHAR;
+ t->size = 1;
getTypeAttributes(in, t, unnamed_types, named_types);
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"short") == 0) {
t->type = SHORT;
+ t->size = 2;
getTypeAttributes(in, t, unnamed_types, named_types);
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"ushort") == 0) {
t->type = USHORT;
+ t->size = 2;
getTypeAttributes(in, t, unnamed_types, named_types);
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"typeref") == 0){
// Must be a named type
- if(inType != NULL)
- in->error(in,"Named type cannot refer to a named type");
- else {
- free(t);
- sequence_pop(unnamed_types);
- token = getNameAttribute(in);
- t = find_named_type(token, named_types);
- getForwardslash(in); //<typeref name=type_name/>
- getRAnglebracket(in);
- return t;
- }
+ free(t);
+ sequence_pop(unnamed_types);
+ token = getNameAttribute(in);
+ t = find_named_type(token, named_types);
+ if(t == NULL) in->error(in,"Named referred to must be pre-declared.");
+ getForwardslash(in); //<typeref name=type_name/>
+ getRAnglebracket(in);
+ return t;
}else in->error(in,"not a valid type");
return t;
type_descriptor_t *t;
t = table_find(named_types,name);
- if(t == NULL) {
- t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
- t->type_name = allocAndCopy(name);
- t->type = NONE;
- t->fmt = NULL;
- table_insert(named_types,t->type_name,t);
- // table_insert(named_types,allocAndCopy(name),t);
- }
+
return t;
-}
+}
+
+type_descriptor_t * create_named_type(char *name, table_t * named_types)
+{
+ type_descriptor_t *t;
+
+ t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
+ t->type_name = allocAndCopy(name);
+ t->type = NONE;
+ t->fmt = NULL;
+ table_insert(named_types,t->type_name,t);
+ // table_insert(named_types,allocAndCopy(name),t);
+ return t;
+}
/*****************************************************************************
*Function name
token = getNameAttribute(in);
if(token == NULL) in->error(in, "Type has empty name");
- t = find_named_type(token, named_types);
+ t = create_named_type(token, named_types);
if(t->type != NONE) in->error(in,"redefinition of named type");
getRAnglebracket(in); //<type name=type_name>
****************************************************************************/
void generateChecksum(char* facName,
- unsigned long * checksum, sequence_t * events)
+ unsigned int * checksum, sequence_t * events)
{
unsigned long crc ;
int pos;
flag = 1;
break;
case ARRAY:
- sprintf(buf,"%llu", type->size);
+ sprintf(buf,"%zu", type->size);
str = appendString("array ",buf);
flag = 1;
break;
case SEQUENCE:
- sprintf(buf,"%llu", type->size);
+ sprintf(buf,"%zu", type->size);
str = appendString("sequence ",buf);
flag = 1;
break;
if(type->fmt) crc = partial_crc32(type->fmt,crc);
- if(type->type == ARRAY || type->type == SEQUENCE){
- crc = getTypeChecksum(crc,type->nested_type);
- }else if(type->type == STRUCT || type->type == UNION){
+ if(type->type == ARRAY){
+ crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+ } else if(type->type ==SEQUENCE) {
+ crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+ crc = getTypeChecksum(crc,((field_t*)type->fields.array[1])->type);
+ } else if(type->type == STRUCT || type->type == UNION){
for(pos =0; pos < type->fields.position; pos++){
fld = (field_t *) type->fields.array[pos];
crc = partial_crc32(fld->name,crc);