X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=genevent-new%2Fparser.c;h=6dbf402d76fd4f008f8d8c5cce17378df0617b15;hb=1119e2d296c87740378d50b65ec15bd4f01860b4;hp=ce416ed963ac85dcc7b2ccef0a7be86ff1de0a10;hpb=47299663f9a2f077317b95f7e669e8373052364b;p=lttv.git diff --git a/genevent-new/parser.c b/genevent-new/parser.c index ce416ed9..6dbf402d 100644 --- a/genevent-new/parser.c +++ b/genevent-new/parser.c @@ -3,14 +3,15 @@ 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. @@ -174,13 +175,13 @@ char *allocAndCopy(char *str) * **************************************************************************/ -void getTypeAttributes(parse_file_t *in, type_descriptor_t *t) +void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, + sequence_t * unnamed_types, table_t * named_types) { char * token; t->fmt = NULL; t->size = 0; - t->alignment = 0; while(1) { token = getToken(in); @@ -198,12 +199,9 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t) // if(car == EOF) in->error(in,"name was expected"); // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in)); // else t->type_name = allocAndCopy(getName(in)); - } else if(!strcmp("size",token) || !strcmp("lengthsize", token)) { + } else if(!strcmp("size",token)) { getEqual(in); t->size = getSize(in); - } else if(!strcmp("align",token)) { - getEqual(in); - t->alignment = getNumber(in); } } } @@ -269,6 +267,7 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac) char car; fac->name = NULL; + fac->arch = NULL; while(1) { token = getToken(in); @@ -283,7 +282,12 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac) if(car == EOF) in->error(in,"name was expected"); else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in)); else fac->name = allocAndCopy(getName(in)); - } + } else if(!strcmp("arch", token)) { + getEqual(in); + car = seekNextChar(in); + if(car == '\"') fac->name = allocAndCopy(getQuotedString(in)); + else fac->arch = allocAndCopy(getName(in)); + } } } @@ -422,7 +426,7 @@ void parseFacility(parse_file_t *in, facility_t * fac) getFacilityAttributes(in, fac); if(fac->name == NULL) in->error(in, "Attribute not named"); - + fac->capname = allocAndCopy(fac->name); strupper(fac->capname); getRAnglebracket(in); @@ -497,7 +501,7 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, 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 or "); @@ -534,30 +538,35 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, * f : field * unnamed_types : array of unamed types * named_types : array of named types + * tag : is field surrounded by a 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) { + // + getFieldAttributes(in, f); + if(f->name == NULL) in->error(in, "Field not named"); + getRAnglebracket(in); - // - getFieldAttributes(in, f); - if(f->name == NULL) in->error(in, "Field not named"); - getRAnglebracket(in); - - f->description = getDescription(in); + f->description = getDescription(in); + } // 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); // + if(tag) { + getLAnglebracket(in); + getForwardslash(in); + token = getName(in); + if(strcmp("field",token))in->error(in,"not a valid field definition"); + getRAnglebracket(in); // + } } @@ -601,7 +610,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, if(strcmp(token,"struct") == 0) { t->type = STRUCT; - getTypeAttributes(in, t); + getTypeAttributes(in, t, unnamed_types, named_types); getRAnglebracket(in); // getLAnglebracket(in); // token = getToken(in); @@ -610,7 +619,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, 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); @@ -624,7 +633,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, } else if(strcmp(token,"union") == 0) { t->type = UNION; - getTypeAttributes(in, t); + getTypeAttributes(in, t, unnamed_types, named_types); getRAnglebracket(in); // getLAnglebracket(in); // @@ -633,7 +642,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, 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); @@ -647,13 +656,20 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, } else if(strcmp(token,"array") == 0) { t->type = ARRAY; - getTypeAttributes(in, t); + 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); // - getLAnglebracket(in); // - t->nested_type = parseType(in, NULL, unnamed_types, named_types); + //getLAnglebracket(in); // + /* subfield */ + f = (field_t *)memAlloc(sizeof(field_t)); + sequence_push(&(t->fields),f); + parseFields(in, f, unnamed_types, named_types, 0); + + //getLAnglebracket(in); // + //t->nested_type = parseType(in, NULL, unnamed_types, named_types); getLAnglebracket(in); // getForwardslash(in); @@ -663,13 +679,44 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, } else if(strcmp(token,"sequence") == 0) { t->type = SEQUENCE; - getTypeAttributes(in, t); - if(t->size == 0) in->error(in, "Sequence has empty lengthsize"); - getForwardslash(in); - getRAnglebracket(in); // - - getLAnglebracket(in); // - t->nested_type = parseType(in,NULL, unnamed_types, named_types); + sequence_init(&(t->fields)); + //getTypeAttributes(in, t, unnamed_types, named_types); + //getForwardslash(in); + getRAnglebracket(in); // + + //getLAnglebracket(in); // + /* subfield */ + f = (field_t *)memAlloc(sizeof(field_t)); + sequence_push(&(t->fields),f); + parseFields(in, f, unnamed_types, named_types, 0); + + //getLAnglebracket(in); // + /* subfield */ + f = (field_t *)memAlloc(sizeof(field_t)); + sequence_push(&(t->fields),f); + parseFields(in, f, unnamed_types, named_types, 0); + + //getLAnglebracket(in); // + //t->length_type = parseType(in, NULL, unnamed_types, named_types); + + //getLAnglebracket(in); // + + //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 : + case UINT : + case ULONG : + case SIZE_T : + case OFF_T : + break; + default: + in->error(in, "Wrong length type for sequence"); + } getLAnglebracket(in); // getForwardslash(in); @@ -678,34 +725,38 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, getRAnglebracket(in); // } else if(strcmp(token,"enum") == 0) { - char * str, *str1; + char * str; + int value = -1; + t->type = ENUM; sequence_init(&(t->labels)); + sequence_init(&(t->labels_values)); sequence_init(&(t->labels_description)); t->already_printed = 0; - getTypeAttributes(in, t); + getTypeAttributes(in, t, unnamed_types, named_types); //if(t->size == 0) in->error(in, "Sequence has empty size"); - //Mathieu : we fix enum size to 4 bytes. GCC is always like this. + //Mathieu : we fix enum size to target int size. GCC is always like this. //fox copy optimisation. - if(t->size != 0) in->error(in, "Enum has fixed size of 4."); - t->size = 4; + if(t->size != 0) in->error(in, "Enum has fixed size of target int."); + t->size = 0; getRAnglebracket(in); //