Commit bc33b8d2 authored by Claes Sjofors's avatar Claes Sjofors

Remote buffer include file parser, support for alignment in classes (refs #138)

parent 2d6dc9a1
...@@ -138,6 +138,7 @@ typedef struct s_element { ...@@ -138,6 +138,7 @@ typedef struct s_element {
int type; int type;
int size; int size;
int elements; int elements;
int alignment;
int undefined; int undefined;
char typestr[40]; char typestr[40];
char struct_begin; char struct_begin;
......
...@@ -467,6 +467,7 @@ static int add_element( t_ctx ctx, ...@@ -467,6 +467,7 @@ static int add_element( t_ctx ctx,
int undefined; int undefined;
int struct_begin; int struct_begin;
unsigned int mask; unsigned int mask;
int alignment = 0;
memset( line_elem, 0, sizeof(line_elem)); memset( line_elem, 0, sizeof(line_elem));
nr = dcli_parse( line, " ;", "", nr = dcli_parse( line, " ;", "",
...@@ -489,8 +490,6 @@ static int add_element( t_ctx ctx, ...@@ -489,8 +490,6 @@ static int add_element( t_ctx ctx,
if ( nr == 0) if ( nr == 0)
return DCLI__SUCCESS; return DCLI__SUCCESS;
undefined = 0; undefined = 0;
if ( strncmp( line_elem[0], "/*", 2) == 0) if ( strncmp( line_elem[0], "/*", 2) == 0)
{ {
...@@ -742,6 +741,15 @@ static int add_element( t_ctx ctx, ...@@ -742,6 +741,15 @@ static int add_element( t_ctx ctx,
size = 0; size = 0;
} }
/* Third arg is alignment */
alignment = 0;
if ( nr > 2) {
if ( strcmp( line_elem[2], "pwr_dAlignLW") == 0)
alignment = 8;
else if ( strcmp( line_elem[2], "pwr_dAlignW") == 0)
alignment = 4;
}
/* Second arg is name */ /* Second arg is name */
if ( nr < 2) if ( nr < 2)
return DCLI__SUCCESS; return DCLI__SUCCESS;
...@@ -792,6 +800,7 @@ static int add_element( t_ctx ctx, ...@@ -792,6 +800,7 @@ static int add_element( t_ctx ctx,
strcpy( element_ptr->name, line_elem[1]); strcpy( element_ptr->name, line_elem[1]);
element_ptr->type = type; element_ptr->type = type;
element_ptr->size = size; element_ptr->size = size;
element_ptr->alignment = alignment;
strcpy( element_ptr->filename, filectx->filename); strcpy( element_ptr->filename, filectx->filename);
element_ptr->line_nr = filectx->lines; element_ptr->line_nr = filectx->lines;
element_ptr->mask = mask; element_ptr->mask = mask;
...@@ -902,15 +911,17 @@ static int find_struct( t_ctx ctx, ...@@ -902,15 +911,17 @@ static int find_struct( t_ctx ctx,
int sts; int sts;
int struct_found; int struct_found;
int name_found; int name_found;
int type_found;
int start_found; int start_found;
int typedef_line; int typedef_line;
int begin_line; int begin_line;
int begin_typedef, end_typedef; int begin_typedef, end_typedef;
int end_of_typedef; int end_of_typedef;
int parlevel; int parlevel;
char *s, *t; char *s, *t, *u;
char *begin_addr, *end_addr; char *begin_addr, *end_addr;
char name[40]; char name[80];
char typename[80];
int i, j, k; int i, j, k;
dcli_sStructElement *element_p, *e_p, *e_ptr, *element_ptr; dcli_sStructElement *element_p, *e_p, *e_ptr, *element_ptr;
dcli_sStructElement *element_list; dcli_sStructElement *element_list;
...@@ -1032,6 +1043,7 @@ static int find_struct( t_ctx ctx, ...@@ -1032,6 +1043,7 @@ static int find_struct( t_ctx ctx,
parlevel = 0; parlevel = 0;
end_of_typedef = 0; end_of_typedef = 0;
name_found = 0; name_found = 0;
type_found = 0;
begin_line = filectx->lines; begin_line = filectx->lines;
begin_typedef = filectx->lines; begin_typedef = filectx->lines;
begin_addr = s + strlen("typedef"); begin_addr = s + strlen("typedef");
...@@ -1075,18 +1087,33 @@ static int find_struct( t_ctx ctx, ...@@ -1075,18 +1087,33 @@ static int find_struct( t_ctx ctx,
*end_addr = 0; *end_addr = 0;
begin_addr++; begin_addr++;
start_found = 0; start_found = 0;
int space_found = 0;
t = name; t = name;
for ( s = begin_addr; *s; s++) for ( s = begin_addr; *s; s++)
{ {
if ( *s == ' ' || *s == 9) if ( *s == ' ' || *s == 9)
{ {
if ( !start_found) if ( !name_found)
continue; continue;
else else
break; space_found = 1;
} }
else else
{ {
if ( name_found && space_found) {
/* Type name */
*t = 0;
strncpy( typename, name, sizeof(typename));
type_found = 1;
for ( u = typename; *u; u++) {
if ( *u == ' ' || *u == 9) {
*u = 0;
break;
}
}
t = name;
space_found = 0;
}
name_found = 1; name_found = 1;
*t = *s; *t = *s;
t++; t++;
...@@ -1127,6 +1154,27 @@ static int find_struct( t_ctx ctx, ...@@ -1127,6 +1154,27 @@ static int find_struct( t_ctx ctx,
goto readstruct_error_return; goto readstruct_error_return;
} }
if ( type_found) {
dcli_sStructElement *e = calloc( 1, sizeof( *element_ptr));
*e_list = e;
if ( strcmp( typename, "pwr_tEnum") == 0 ||
strcmp( typename, "pwr_tMask") == 0) {
e->type = pwr_eType_UInt32;
e->size = sizeof(pwr_tUInt32);
strcpy( e->typestr, typename);
}
else {
free_filectx( filectx);
return_sts = DCLI__STRUCTNOTFOUND;
goto readstruct_error_return;
}
free_filectx( filectx);
if ( caller == READSTRUCT_CALLER_ROOT)
free( ctx);
return DCLI__NOSTRUCT;
}
file = fopen( normfilename, "r"); file = fopen( normfilename, "r");
if ( file == NULL) if ( file == NULL)
{ {
...@@ -1206,6 +1254,15 @@ static int find_struct( t_ctx ctx, ...@@ -1206,6 +1254,15 @@ static int find_struct( t_ctx ctx,
return_sts = DCLI__TYPEUNDEF; return_sts = DCLI__TYPEUNDEF;
goto readstruct_error_return; goto readstruct_error_return;
} }
if ( sts == DCLI__NOSTRUCT) {
e_ptr->size = element_list->size;
e_ptr->type = element_list->type;
strcpy( e_ptr->typestr, element_list->typestr);
e_ptr->undefined = 0;
free( element_list);
element_list = 0;
}
else {
e_ptr->undefined = 0; e_ptr->undefined = 0;
e_ptr->struct_begin = 1; e_ptr->struct_begin = 1;
...@@ -1215,13 +1272,11 @@ static int find_struct( t_ctx ctx, ...@@ -1215,13 +1272,11 @@ static int find_struct( t_ctx ctx,
elnumcount = 0; elnumcount = 0;
struct_element = element_list; struct_element = element_list;
i = 0; i = 0;
while ( (s2 = strchr( s1, '[')) != 0) while ( (s2 = strchr( s1, '[')) != 0) {
{
/* Extract number of elements */ /* Extract number of elements */
*s2 = 0; *s2 = 0;
s2++; s2++;
if ( (s1 = strchr( s2, ']')) == 0) if ( (s1 = strchr( s2, ']')) == 0) {
{
strcpy( ctx->error_file, filectx->filename); strcpy( ctx->error_file, filectx->filename);
ctx->error_line = filectx->lines; ctx->error_line = filectx->lines;
return_sts = DCLI__ELEMSYNTAX; return_sts = DCLI__ELEMSYNTAX;
...@@ -1230,11 +1285,9 @@ static int find_struct( t_ctx ctx, ...@@ -1230,11 +1285,9 @@ static int find_struct( t_ctx ctx,
*s1 = 0; *s1 = 0;
s1++; s1++;
nr = sscanf( s2, "%d", &elnum[i]); nr = sscanf( s2, "%d", &elnum[i]);
if ( nr != 1) if ( nr != 1) {
{
sts = find_define( filectx, s2, &elnum[i]); sts = find_define( filectx, s2, &elnum[i]);
if ( EVEN(sts)) if ( EVEN(sts)) {
{
strcpy( ctx->error_file, filectx->filename); strcpy( ctx->error_file, filectx->filename);
ctx->error_line = filectx->lines; ctx->error_line = filectx->lines;
return_sts = DCLI__ELEMSYNTAX; return_sts = DCLI__ELEMSYNTAX;
...@@ -1247,23 +1300,18 @@ static int find_struct( t_ctx ctx, ...@@ -1247,23 +1300,18 @@ static int find_struct( t_ctx ctx,
count = 0; count = 0;
for ( element_p = struct_element; element_p; element_p = element_p->next) for ( element_p = struct_element; element_p; element_p = element_p->next)
count++; count++;
if ( elnumcount == 0) if ( elnumcount == 0) {
{ for ( element_p = struct_element; element_p; element_p = element_p->next) {
for ( element_p = struct_element; element_p; element_p = element_p->next)
{
strcpy( tmp, element_p->name); strcpy( tmp, element_p->name);
strcpy( element_p->name, e_ptr->name); strcpy( element_p->name, e_ptr->name);
strcat( element_p->name, "."); strcat( element_p->name, ".");
strcat( element_p->name, tmp); strcat( element_p->name, tmp);
} }
} }
else if ( elnumcount == 1) else if ( elnumcount == 1) {
{ for ( i = 1; i < elnum[0]; i++) {
for ( i = 1; i < elnum[0]; i++)
{
element_p = struct_element; element_p = struct_element;
for ( j = 0; j < count; j++) for ( j = 0; j < count; j++) {
{
element_ptr = calloc( 1, sizeof( *element_ptr)); element_ptr = calloc( 1, sizeof( *element_ptr));
memcpy( element_ptr, element_p, sizeof(*element_p)); memcpy( element_ptr, element_p, sizeof(*element_p));
...@@ -1276,27 +1324,21 @@ static int find_struct( t_ctx ctx, ...@@ -1276,27 +1324,21 @@ static int find_struct( t_ctx ctx,
} }
} }
element_p = struct_element; element_p = struct_element;
for ( i = 0; i < elnum[0]; i++) for ( i = 0; i < elnum[0]; i++) {
{ for ( j = 0; j < count; j++) {
for ( j = 0; j < count; j++)
{
strcpy( tmp, element_p->name); strcpy( tmp, element_p->name);
sprintf( element_p->name, "%s[%d].%s", e_ptr->name, i, tmp); sprintf( element_p->name, "%s[%d].%s", e_ptr->name, i, tmp);
element_p = element_p->next; element_p = element_p->next;
} }
} }
} }
else if ( elnumcount == 2) else if ( elnumcount == 2) {
{ for ( i = 0; i < elnum[0]; i++) {
for ( i = 0; i < elnum[0]; i++) for ( k = 0; k < elnum[1]; k++) {
{
for ( k = 0; k < elnum[1]; k++)
{
if ( i == 0 && k == 0) if ( i == 0 && k == 0)
continue; continue;
element_p = struct_element; element_p = struct_element;
for ( j = 0; j < count; j++) for ( j = 0; j < count; j++) {
{
element_ptr = calloc( 1, sizeof( *element_ptr)); element_ptr = calloc( 1, sizeof( *element_ptr));
memcpy( element_ptr, element_p, sizeof(*element_p)); memcpy( element_ptr, element_p, sizeof(*element_p));
...@@ -1311,12 +1353,9 @@ static int find_struct( t_ctx ctx, ...@@ -1311,12 +1353,9 @@ static int find_struct( t_ctx ctx,
} }
element_p = struct_element; element_p = struct_element;
for ( i = 0; i < elnum[0]; i++) for ( i = 0; i < elnum[0]; i++) {
{ for ( k = 0; k < elnum[1]; k++) {
for ( k = 0; k < elnum[1]; k++) for ( j = 0; j < count; j++) {
{
for ( j = 0; j < count; j++)
{
strcpy( tmp, element_p->name); strcpy( tmp, element_p->name);
sprintf( element_p->name, "%s[%d][%d].%s", e_ptr->name, i, k,tmp); sprintf( element_p->name, "%s[%d][%d].%s", e_ptr->name, i, k,tmp);
element_p = element_p->next; element_p = element_p->next;
...@@ -1324,8 +1363,7 @@ static int find_struct( t_ctx ctx, ...@@ -1324,8 +1363,7 @@ static int find_struct( t_ctx ctx,
} }
} }
} }
else else {
{
strcpy( ctx->error_file, filectx->filename); strcpy( ctx->error_file, filectx->filename);
ctx->error_line = filectx->lines; ctx->error_line = filectx->lines;
return_sts = DCLI__ARRAYDIM; return_sts = DCLI__ARRAYDIM;
...@@ -1339,7 +1377,7 @@ static int find_struct( t_ctx ctx, ...@@ -1339,7 +1377,7 @@ static int find_struct( t_ctx ctx,
e_p->next = next_ptr; e_p->next = next_ptr;
if ( next_ptr) if ( next_ptr)
next_ptr->prev = e_p; next_ptr->prev = e_p;
}
} }
} }
......
...@@ -69,4 +69,4 @@ eof <end of file> /error ...@@ -69,4 +69,4 @@ eof <end of file> /error
undeferr <undefined error> /error undeferr <undefined error> /error
typeundef <undefined type> /error typeundef <undefined type> /error
toolong <qualifier value is too long> /error toolong <qualifier value is too long> /error
nostruct <no struct> /info
...@@ -4167,6 +4167,9 @@ int XNav::show_object_as_struct( ...@@ -4167,6 +4167,9 @@ int XNav::show_object_as_struct(
sprintf( attr_str, "_A_ %d %d %d %d", objid.vid, objid.oix, sprintf( attr_str, "_A_ %d %d %d %d", objid.vid, objid.oix,
(int)(parameter_ptr - object_ptr), e_ptr->size); (int)(parameter_ptr - object_ptr), e_ptr->size);
if ( e_ptr->alignment)
parameter_ptr = (char *)pwr_Align( (size_t)parameter_ptr, e_ptr->alignment);
new ItemObjectStruct( brow, e_ptr->name, attr_str, new ItemObjectStruct( brow, e_ptr->name, attr_str,
e_ptr->type, e_ptr->size, 0, e_ptr->type, e_ptr->size, 0,
(void *) parameter_ptr, objid, subid, NULL, flow_eDest_IntoLast); (void *) parameter_ptr, objid, subid, NULL, flow_eDest_IntoLast);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment