mescc: Tinycc support: Sizeof struct destruct.

This commit is contained in:
Jan Nieuwenhuizen 2018-05-11 17:13:07 +02:00
parent 07e73b8f9a
commit 6bcc9a91e3
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 12 additions and 13 deletions

View File

@ -243,7 +243,6 @@
((d-sel (ident ,field) ,struct)
(let ((type0 (ast->type struct info)))
(stderr "type0=~s\n" type0)
(ast->type (field-type info type0 field) info)))
((i-sel (ident ,field) ,struct)
@ -1378,14 +1377,10 @@
(* (expr->number info a) (expr->number info b)))
((sub ,a ,b)
(- (expr->number info a) (expr->number info b)))
((sizeof-type (type-name (decl-spec-list (type-spec ,type))))
(ast-type->size info type))
((sizeof-expr (d-sel (ident ,field) (p-expr (ident ,struct))))
(let ((type (ident->type info struct)))
(field-size info type field)))
((sizeof-expr (i-sel (ident ,field) (p-expr (ident ,struct))))
(let ((type (ident->type info struct)))
(field-size info type field)))
((sizeof-type ,type)
(->size (ast->type type info)))
((sizeof-expr ,expr)
(->size (ast->type expr info)))
((lshift ,x ,y)
(ash (expr->number info x) (expr->number info y)))
((rshift ,x ,y)

View File

@ -33,7 +33,8 @@ char *env[] = {"foo", "bar", "baz", 0};
char *list[2] = {"foo\n", "bar\n"};
struct foo {int length; char* string;};
struct foo f = {3, "foo"};
struct foo g_f = {3, "foo"};
struct foo g_g = &g_f;
struct foo g_foes[2];
int g_foe;
@ -45,7 +46,7 @@ struct here {int and;} there;
int
test (struct foo* p)
{
struct foo *g = &f;
struct foo *g = &g_f;
g[0].length = 0;
p[0].length = 0;
}
@ -89,9 +90,9 @@ main (int argc, char* argv[])
return 14;
if (env[3])
return 15;
if (f.length != 3)
if (g_f.length != 3)
return 16;
if (strcmp (f.string, "foo"))
if (strcmp (g_f.string, "foo"))
return 17;
struct foo g = {4, "baar"};
if (g.length != 4)
@ -121,6 +122,9 @@ main (int argc, char* argv[])
if (u.foo != 3) return 24;
if (u.bla != 4) return 25;
char buf[sizeof (g_f.string)];
char buf1[sizeof (g_g->string)];
i = 1;
int lst[6] = {-1, 1 - 1, i, 2, 3};
for (int i = 0; i < 4; i++)