+//DONE
+//make the change for arrays and sequences
+//no more root field. -> change this for an array of fields.
+// Compute the field size here.
+// Flag fields as "VARIABLE OFFSET" or "FIXED OFFSET" : as soon as
+// a field with a variable size is found, all the following fields must
+// be flagged with "VARIABLE OFFSET", this will be done by the offset
+// precomputation.
+
+
+void construct_fields(LttFacility *fac,
+ LttField *field,
+ field_t *fld)
+{
+ guint len;
+ type_descriptor_t *td;
+ LttType *type;
+
+ if(fld->name)
+ field->name = g_quark_from_string(fld->name);
+ else
+ fld->name = 0;
+
+ if(fld->description) {
+ len = strlen(fld->description);
+ field->description = g_new(gchar, len+1);
+ strcpy(field->description, fld->description);
+ }
+ field->dynamic_offsets = NULL;
+ type = &field->field_type;
+ td = fld->type;
+
+ type->enum_map = NULL;
+ type->fields = NULL;
+ type->fields_by_name = NULL;
+ type->network = td->network;
+
+ switch(td->type) {
+ case INT_FIXED:
+ type->type_class = LTT_INT_FIXED;
+ type->size = td->size;
+ break;
+ case UINT_FIXED:
+ type->type_class = LTT_UINT_FIXED;
+ type->size = td->size;
+ break;
+ case POINTER:
+ type->type_class = LTT_POINTER;
+ type->size = fac->pointer_size;
+ break;
+ case CHAR:
+ type->type_class = LTT_CHAR;
+ type->size = td->size;
+ break;
+ case UCHAR:
+ type->type_class = LTT_UCHAR;
+ type->size = td->size;
+ g_assert(type->size != 0);
+ break;
+ case SHORT:
+ type->type_class = LTT_SHORT;
+ type->size = td->size;
+ break;
+ case USHORT:
+ type->type_class = LTT_USHORT;
+ type->size = td->size;
+ break;
+ case INT:
+ type->type_class = LTT_INT;
+ type->size = fac->int_size;
+ break;
+ case UINT:
+ type->type_class = LTT_UINT;
+ type->size = fac->int_size;
+ g_assert(type->size != 0);
+ break;
+ case LONG:
+ type->type_class = LTT_LONG;
+ type->size = fac->long_size;
+ break;
+ case ULONG:
+ type->type_class = LTT_ULONG;
+ type->size = fac->long_size;
+ break;
+ case SIZE_T:
+ type->type_class = LTT_SIZE_T;
+ type->size = fac->size_t_size;
+ break;
+ case SSIZE_T:
+ type->type_class = LTT_SSIZE_T;
+ type->size = fac->size_t_size;
+ break;
+ case OFF_T:
+ type->type_class = LTT_OFF_T;
+ type->size = fac->size_t_size;
+ break;
+ case FLOAT:
+ type->type_class = LTT_FLOAT;
+ type->size = td->size;
+ break;
+ case STRING:
+ type->type_class = LTT_STRING;
+ type->size = 0;
+ break;
+ case ENUM:
+ type->type_class = LTT_ENUM;
+ type->size = fac->int_size;
+ {
+ guint i;
+ type->enum_map = g_hash_table_new(g_direct_hash, g_direct_equal);
+ for(i=0; i<td->labels.position; i++) {
+ GQuark value = g_quark_from_string((char*)td->labels.array[i]);
+ gint key = *(int*)td->labels_values.array[i];
+ g_hash_table_insert(type->enum_map, (gpointer)key, (gpointer)value);
+ }
+ }
+ g_assert(type->size != 0);
+ break;
+ case ARRAY:
+ type->type_class = LTT_ARRAY;
+ type->size = td->size;
+ type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
+ td->fields.position);
+ type->fields = g_array_set_size(type->fields, td->fields.position);
+ {
+ guint i;
+
+ for(i=0; i<td->fields.position; i++) {
+ field_t *schild = (field_t*)td->fields.array[i];
+ LttField *dchild = &g_array_index(type->fields, LttField, i);
+
+ construct_fields(fac, dchild, schild);
+ }
+ }
+ break;
+ case SEQUENCE:
+ type->type_class = LTT_SEQUENCE;
+ type->size = 0;
+ type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
+ td->fields.position);
+ type->fields = g_array_set_size(type->fields, td->fields.position);
+ {
+ guint i;
+
+ for(i=0; i<td->fields.position; i++) {
+ field_t *schild = (field_t*)td->fields.array[i];
+ LttField *dchild = &g_array_index(type->fields, LttField, i);
+
+ construct_fields(fac, dchild, schild);
+ }
+ }
+ break;
+ case STRUCT:
+ type->type_class = LTT_STRUCT;
+ type->size = 0; // Size not calculated by the parser.
+ type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
+ td->fields.position);
+ type->fields = g_array_set_size(type->fields, td->fields.position);
+ g_datalist_init(&type->fields_by_name);
+ {
+ guint i;
+
+ for(i=0; i<td->fields.position; i++) {
+ field_t *schild = (field_t*)td->fields.array[i];
+ LttField *dchild = &g_array_index(type->fields, LttField, i);
+
+ construct_fields(fac, dchild, schild);
+ g_datalist_id_set_data(&type->fields_by_name,
+ dchild->name,
+ dchild);
+ }
+ }
+ break;
+ case UNION:
+ type->type_class = LTT_UNION;
+ type->size = 0; // Size not calculated by the parser.
+ type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
+ td->fields.position);
+ type->fields = g_array_set_size(type->fields, td->fields.position);
+ g_datalist_init(&type->fields_by_name);
+ {
+ guint i;
+
+ for(i=0; i<td->fields.position; i++) {
+ field_t *schild = (field_t*)td->fields.array[i];
+ LttField *dchild = &g_array_index(type->fields, LttField, i);
+
+ construct_fields(fac, dchild, schild);
+ g_datalist_id_set_data(&type->fields_by_name,
+ dchild->name,
+ dchild);
+ }
+ }
+ break;
+ case NONE:
+ default:
+ g_error("construct_fields : unknown type");
+ }
+
+ field->field_size = type->size;