X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;ds=sidebyside;f=genevent-new%2Fparser.c;h=6dbf402d76fd4f008f8d8c5cce17378df0617b15;hb=ffaf5031680617709c7ae1b7f1a3cf5cdf784805;hp=638aa5ab3d5e47cad40f011a49ead5d5704bd636;hpb=2d2d14a73451144b1f67fb64191a6cef99b90a26;p=lttv.git
diff --git a/genevent-new/parser.c b/genevent-new/parser.c
index 638aa5ab..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);
@@ -468,36 +472,62 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types,
table_t * named_types)
{
char *token;
+ field_t *f;
+ sequence_init(&(ev->fields));
//
getEventAttributes(in, ev);
if(ev->name == NULL) in->error(in, "Event not named");
getRAnglebracket(in);
- //...
+ //...
ev->description = getDescription(in);
- //event can have STRUCT, TYPEREF or NOTHING
- getLAnglebracket(in);
-
- token = getToken(in);
- if(in->type == FORWARDSLASH){ // NOTHING
- ev->type = NULL;
- }else if(in->type == NAME){
- if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
- ungetToken(in);
- ev->type = parseType(in,NULL, unnamed_types, named_types);
- if(ev->type->type != STRUCT && ev->type->type != NONE)
- in->error(in,"type must be a struct");
- }else in->error(in, "not a valid type");
-
- getLAnglebracket(in);
- getForwardslash(in);
- }else in->error(in,"not a struct type");
-
- token = getName(in);
- if(strcmp("event",token))in->error(in,"not an event definition");
- getRAnglebracket(in); //
+ int got_end = 0;
+ /* Events can have multiple fields. each field form at least a function
+ * parameter of the logging function. */
+ while(!got_end) {
+ getLAnglebracket(in);
+ token = getToken(in);
+
+ switch(in->type) {
+ case FORWARDSLASH: /* */
+ token = getName(in);
+ if(strcmp("event",token))in->error(in,"not an event definition");
+ getRAnglebracket(in); //
+ got_end = 1;
+ break;
+ case NAME: /* a field */
+ 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, 1);
+ break;
+ default:
+ in->error(in, "expecting or ");
+ break;
+ }
+ }
+#if 0
+ if(in->type == FORWARDSLASH){ // NOTHING
+ ev->type = NULL;
+ }else if(in->type == NAME){
+ if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
+ ungetToken(in);
+ ev->type = parseType(in,NULL, unnamed_types, named_types);
+ if(ev->type->type != STRUCT && ev->type->type != NONE)
+ in->error(in,"type must be a struct");
+ }else in->error(in, "not a valid type");
+
+ getLAnglebracket(in);
+ getForwardslash(in);
+ }else in->error(in,"not a struct type");
+ getLAnglebracket(in);
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("event",token))in->error(in,"not an event definition");
+ getRAnglebracket(in); //
+#endif //0
}
/*****************************************************************************
@@ -505,37 +535,38 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types,
* parseField : get field infomation from buffer
*Input params
* in : input file handle
- * t : type descriptor
+ * 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, type_descriptor_t *t,
+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;
- field_t *f;
+ if(tag) {
+ //
+ getFieldAttributes(in, f);
+ if(f->name == NULL) in->error(in, "Field not named");
+ getRAnglebracket(in);
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(t->fields),f);
-
- //
- 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); //
+ }
}
@@ -564,6 +595,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
{
char *token;
type_descriptor_t *t;
+ field_t *f;
if(inType == NULL) {
t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t));
@@ -578,13 +610,16 @@ 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);
sequence_init(&(t->fields));
while(strcmp("field",token) == 0){
- parseFields(in,t, unnamed_types, named_types);
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+
+ parseFields(in, f, unnamed_types, named_types, 1);
//next field
getLAnglebracket(in);
@@ -598,14 +633,16 @@ 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); //
token = getToken(in);
sequence_init(&(t->fields));
while(strcmp("field",token) == 0){
- parseFields(in,t, unnamed_types, named_types);
+ f = (field_t *)memAlloc(sizeof(field_t));
+ sequence_push(&(t->fields),f);
+ parseFields(in, f, unnamed_types, named_types, 1);
//next field
getLAnglebracket(in);
@@ -619,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);
@@ -635,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);
@@ -650,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);
//