DefMod changes for base types
Tom Hughes
tom at compton.nu
Sat Mar 4 12:49:07 GMT 2000
The attached patch for DefMod implements the base type scheme suggested
by Jonathan to resolve the gadget structure problem.
This patch only fixes the C header file generation. The StrongHelp stuff
should probably also be altered, and possibly the assembly header stuff
although that is a bit problematic.
Tom
--
Tom Hughes (tom at compton.nu)
http://www.compton.nu/
...This fortune intentionally not included.
-------------- next part --------------
Index: ReadMe
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/ReadMe,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 ReadMe
*** ReadMe 2000/02/14 22:37:53 1.1.1.3
--- ReadMe 2000/03/04 10:21:10
***************
*** 761,770 ****
type_defn: ID DESCRIPTION_OPTION | ID EQUALS type DESCRIPTION_OPTION;
type: INT | SHORT | BYTE | CHAR | BITS | BYTES | BOOL | REF type |
! STRING | ASM | DATA | STRUCT OPEN typed_var_LIST ellipsis_OPTION
! CLOSE | UNION OPEN toided_var_LIST CLOSE | SUB const BUS type |
! ID;
toid: type | VOID;
--- 761,772 ----
type_defn: ID DESCRIPTION_OPTION | ID EQUALS type DESCRIPTION_OPTION;
+ base_type: COLON ID
+
type: INT | SHORT | BYTE | CHAR | BITS | BYTES | BOOL | REF type |
! STRING | ASM | DATA | STRUCT base_type_OPTION OPEN typed_var_LIST
! ellipsis_OPTION CLOSE | UNION OPEN toided_var_LIST CLOSE | SUB const
! BUS type | ID;
toid: type | VOID;
***************
*** 1312,1317 ****
--- 1314,1324 ----
<td>26<sup>th</sup> Mar 1999</td>
<td>T V</td>
<td>Amended definition of conversion types for String and Data for Free OSLib 5.4.</td>
+ </tr>
+ <tr>
+ <td>4<sup>th</sup> Mar 2000</td>
+ <td>T J H</td>
+ <td>Added base types for structures to the grammar definition.</td>
</tr>
</table>
Index: c/cheader
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/c/cheader,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 cheader
*** c/cheader 2000/02/16 23:14:46 1.1.1.3
--- c/cheader 2000/03/04 12:33:51
***************
*** 205,210 ****
--- 205,221 ----
)
goto finish;
+ if (t->tag == def_TYPE_STRUCT && t->data AS list.base)
+ {
+ char base [def_ID_LIMIT + 1];
+
+ def_as_macro (base, t->data AS list.base->data AS id);
+
+ if ((rc = fprintf (file, "%s_MEMBERS%s\n%*s ",
+ base, var? " \\": "", 3*(nest + 1), "")) < 0)
+ goto finish;
+ }
+
for (i = 0; i < t->data AS list.count; i++)
{
if (i == t->data AS list.count - 1 &&
***************
*** 726,734 ****
}
}
! if ((rc = Print_Decl (file, t, c_name, NULL, FALSE, 0)) < 0)
! goto finish;
if ((rc = fprintf (file, ";\n\n")) < 0)
goto finish;
--- 737,789 ----
}
}
! if (t->tag == def_TYPE_STRUCT && t->data AS list.ellipsis &&
! t->data AS list.count > 1)
! {
! char macro_name [def_ID_LIMIT + 1];
! int i;
!
! def_as_macro (macro_name, type);
+ if ((rc = fprintf (file, "#define %s_MEMBERS",
+ macro_name)) < 0)
+ goto finish;
+
+ if (t->data AS list.base)
+ {
+ char base [def_ID_LIMIT + 1];
+
+ def_as_macro (base, t->data AS list.base->data AS id);
+
+ if ((rc = fprintf (file, " \\\n %s_MEMBERS", base)) < 0)
+ goto finish;
+ }
+
+ for (i = 0; i < t->data AS list.count - 1; i++)
+ {
+ if ((rc = fprintf (file, " \\\n ")) < 0)
+ goto finish;
+ if ((rc = Print_Decl (file, t->data AS list.members [i],
+ NULL, t->data AS list.members [i]->name, TRUE, 0)) < 0)
+ goto finish;
+ if ((rc = fprintf (file, ";")) < 0)
+ goto finish;
+ }
+
+ if ((rc = fprintf (file,
+ "\n\nstruct %s\n { %s_MEMBERS\n ",
+ c_name, macro_name)) < 0)
+ goto finish;
+ if ((rc = Print_Decl (file, t->data AS list.members [i],
+ NULL, t->data AS list.members [i]->name, TRUE, 0)) < 0)
+ goto finish;
+ if ((rc = fprintf (file, " [UNKNOWN];\n }")) < 0)
+ goto finish;
+ }
+ else
+ if ((rc = Print_Decl (file, t, c_name, NULL, FALSE, 0)) < 0)
+ goto finish;
+
if ((rc = fprintf (file, ";\n\n")) < 0)
goto finish;
***************
*** 739,776 ****
t->data AS list.members
[t->data AS list.count - 1]->value != def_VALUE_VARIABLE)
{
! int i;
char *suffix;
! def_as_macro (c_name, type);
if ((rc = fprintf (file, "#define %s(N) \\\n ",
! c_name)) < 0)
goto finish;
! if ((rc = Print_Decl (file, t, NULL, NULL, TRUE, 1)) < 0)
goto finish;
if ((rc = fprintf (file, "\n\n")) < 0)
goto finish;
/*Also emit a macro to calculate the size of such a type.*/
! if ((suffix = strchr (c_name, '_')) != NULL)
{
if ((rc = fprintf (file,
"#define %.*s_SIZEOF%s(N) \\\n (",
! suffix - c_name, c_name, suffix)) < 0)
goto finish;
}
else
{
if ((rc = fprintf (file, "#define %s_SIZEOF(N) (",
! c_name)) < 0)
goto finish;
}
-
- /*We need the extern form for the rest.*/
- def_as_extern (c_name, type);
/*This calculates an offset (using |offsetof|).*/
if ((i = t->data AS list.count) > 1)
--- 794,836 ----
t->data AS list.members
[t->data AS list.count - 1]->value != def_VALUE_VARIABLE)
{
! char macro_name [def_ID_LIMIT + 1];
! int i = t->data AS list.count - 1;
char *suffix;
! def_as_macro (macro_name, type);
if ((rc = fprintf (file, "#define %s(N) \\\n ",
! macro_name)) < 0)
goto finish;
! if ((rc = fprintf (file,
! "struct \\\n { %s_MEMBERS \\\n ",
! macro_name)) < 0)
! goto finish;
! if ((rc = Print_Decl (file, t->data AS list.members [i],
! NULL, t->data AS list.members [i]->name, TRUE, 0)) < 0)
goto finish;
+ if ((rc = fprintf (file, " [UNKNOWN]; \\\n }")) < 0)
+ goto finish;
if ((rc = fprintf (file, "\n\n")) < 0)
goto finish;
/*Also emit a macro to calculate the size of such a type.*/
! if ((suffix = strchr (macro_name, '_')) != NULL)
{
if ((rc = fprintf (file,
"#define %.*s_SIZEOF%s(N) \\\n (",
! suffix - macro_name, macro_name, suffix)) < 0)
goto finish;
}
else
{
if ((rc = fprintf (file, "#define %s_SIZEOF(N) (",
! macro_name)) < 0)
goto finish;
}
/*This calculates an offset (using |offsetof|).*/
if ((i = t->data AS list.count) > 1)
Index: h/def
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/h/def,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 def
*** h/def 2000/02/14 22:37:54 1.1.1.3
--- h/def 2000/03/04 10:03:30
***************
*** 65,70 ****
--- 65,71 ----
struct
{ int count;
bool ellipsis;
+ struct def_t *base;
struct def_t *members [def_STRUCT_LIMIT + def_UNION_LIMIT];
}
list;
Index: y/defmod
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/y/defmod,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 defmod
*** y/defmod 2000/02/14 22:37:54 1.1.1.3
--- y/defmod 2000/03/04 10:09:23
***************
*** 109,116 ****
exit_condition_LIST exit_condition absent_part description
description_OPTION
! %type <type_defn> type toid typed_var_LIST typed_var toided_var_LIST
! toided_var
%type <description> wordchar_SEQUENCE word word_SEQUENCE word_SEQUENCE_OPTION
DESCRIPTION DESCRIPTION_OPTION
--- 109,116 ----
exit_condition_LIST exit_condition absent_part description
description_OPTION
! %type <type_defn> base_type base_type_OPTION type toid typed_var_LIST
! typed_var toided_var_LIST toided_var
%type <description> wordchar_SEQUENCE word word_SEQUENCE word_SEQUENCE_OPTION
DESCRIPTION DESCRIPTION_OPTION
***************
*** 234,239 ****
--- 234,267 ----
}
};
+ base_type:
+ COLON ID
+ { /*Use it verbatim, but check the type does exist (and find out if
+ it's a struct type or not).*/
+ os_error *error;
+ def_t t;
+
+ if ((error = lookup (types, $2, (void **) &t)) != NULL &&
+ error->errnum != os_GLOBAL_NO_ANY)
+ { yyerror (error->errmess);
+ YYERROR;
+ }
+
+ $$.tag = def_TYPE_ID;
+ $$.name = NULL;
+ if (error != NULL)
+ { /*have to make an optimistic assumption*/
+ $$.value = def_VALUE_VARIABLE;
+ if (Verbose)
+ fprintf (stderr, "warning: type \"%s\" undefined at line "
+ "%d\n", $2, Line_No);
+ }
+ else
+ $$.value = t != NULL? t->value: def_VALUE_VARIABLE;
+ $$.description = NULL;
+ strcpy ($$.data AS id, $2);
+ };
+
type:
INT
{$$.tag = def_TYPE_INT; $$.name = NULL;
***************
*** 275,289 ****
DATA
{$$.tag = def_TYPE_DATA; $$.name = NULL; $$.value = def_VALUE_VARIABLE;
$$.description = NULL;} |
! STRUCT OPEN typed_var_LIST ellipsis_OPTION CLOSE
! { $$ = $3;
$$.tag = def_TYPE_STRUCT;
! if ($4)
$$.value = def_VALUE_VARIABLE;
! else if ($3.value == def_VALUE_REGISTER)
$$.value = def_VALUE_FIXED;
$$.description = NULL;
! $$.data AS list.ellipsis = $4;
} |
UNION OPEN toided_var_LIST CLOSE
{ $$ = $3;
--- 303,323 ----
DATA
{$$.tag = def_TYPE_DATA; $$.name = NULL; $$.value = def_VALUE_VARIABLE;
$$.description = NULL;} |
! STRUCT base_type_OPTION OPEN typed_var_LIST ellipsis_OPTION CLOSE
! { $$ = $4;
$$.tag = def_TYPE_STRUCT;
! if ($5)
$$.value = def_VALUE_VARIABLE;
! else if ($4.value == def_VALUE_REGISTER)
$$.value = def_VALUE_FIXED;
$$.description = NULL;
! if ($2.tag != def_TYPE_VOID)
! { $$.data AS list.base = qalloc (def_sizeof_TYPE ($2.tag));
! memcpy ($$.data AS list.base, &$2, def_sizeof_TYPE ($2.tag));
! }
! else
! $$.data AS list.base = NULL;
! $$.data AS list.ellipsis = $5;
} |
UNION OPEN toided_var_LIST CLOSE
{ $$ = $3;
***************
*** 768,773 ****
--- 802,808 ----
EMPTY:;
/*option*/
+ base_type_OPTION: base_type | EMPTY {$$.tag = def_TYPE_VOID;};
commentchar_SEQUENCE_OPTION: commentchar_SEQUENCE {} | EMPTY {};
condition_part_OPTION: condition_part | EMPTY {$$ = Empty;};
decl_SERIES_OPTION: decl_SERIES | EMPTY;
More information about the oslib-team
mailing list