9front - general discussion about 9front
 help / color / mirror / Atom feed
From: mia soweli <inbox@tachibana-labs.org>
To: 9front@9front.org
Subject: [9front] Re: [9front] [PATCH] cc: support type qualifiers inside array brackets.
Date: Mon, 15 May 2023 08:39:55 +0100	[thread overview]
Message-ID: <8F22ED51-F0B5-4DF9-881E-E8BF258DF795@tachibana-labs.org> (raw)
In-Reply-To: <ZGDBmZ9ELIWFDqzF@one.net.tachibana-labs.org>

allows c99 array declarations with type qualifiers inside the brackets.
for example:

	int list[const 5];
	int list[const restrict 5];
	int list[volatile 5];
	int list[static 5];

i read the standard more closely, the static seems to be an optimization thing that means the array has *at least* however many members, and we should ignore it instead of treating it like static outside the brackets.

diff 090af6255bebf0129c891116b53b31808fe49dc7 uncommitted
--- a/sys/src/cmd/cc/cc.y
+++ b/sys/src/cmd/cc/cc.y
@@ -27,8 +27,8 @@
	vlong	vval;
}
%type	<sym>	ltag
-%type	<lval>	gctname gcname cname gname tname
-%type	<lval>	gctnlist gcnlist zgnlist
+%type	<lval>	gctname gcname cname gname tname aname
+%type	<lval>	gctnlist gcnlist zgnlist zanlist
%type	<type>	tlist sbody complex
%type	<tycl>	types
%type	<node>	zarglist arglist zcexpr
@@ -142,9 +142,11 @@
	{
		$$ = new(OFUNC, $1, $3);
	}
-|	xdecor2 '[' zexpr ']'
+|	xdecor2 '[' zanlist zexpr ']'
	{
-		$$ = new(OARRAY, $1, $3);
+		$$ = new(OARRAY, $1, $4);
+		$$->garb = simpleg($3);
	}

/*
@@ -273,9 +275,11 @@
	{
		$$ = new(OFUNC, $1, $3);
	}
-|	abdecor2 '[' zexpr ']'
+|	abdecor2 '[' zanlist zexpr ']'
	{
-		$$ = new(OARRAY, $1, $3);
+		$$ = new(OARRAY, $1, $4);
+		$$->garb = simpleg($3);
	}

abdecor3:
@@ -283,9 +287,11 @@
	{
		$$ = new(OFUNC, (Z), Z);
	}
-|	'[' zexpr ']'
+|	'[' zanlist zexpr ']'
	{
-		$$ = new(OARRAY, (Z), $2);
+		$$ = new(OARRAY, (Z), $3);
+		$$->garb = simpleg($2);
	}
|	'(' abdecor1 ')'
	{
@@ -1099,6 +1105,15 @@
		$$ = typebitor($1, $2);
	}

+zanlist:
+	{
+		$$ = 0;
+	}
+|	zanlist aname
+	{
+		$$ = typebitor($1, $2);
+	}
+
gctname:
	tname
|	gname
@@ -1152,6 +1167,12 @@
|	LVOLATILE { $$ = BVOLATILE; }
|	LRESTRICT { $$ = 0; }
|	LNORET { $$ = BNORET; }
+
+aname:	/* words allowed in an array declaration */
+	LCONSTNT { $$ = BCONSTNT; }
+|	LVOLATILE { $$ = BVOLATILE; }
+|	LRESTRICT { $$ = 0; }
+|	LSTATIC { $$ = BSTATIC; }

name:
	LNAME

  reply	other threads:[~2023-05-15  7:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-13 23:31 [9front] [PATCH] cc: support const and restrict inside array declarations mia soweli
2023-05-14  5:25 ` ori
2023-05-14 10:20   ` [9front] " mia soweli
2023-05-14  8:10 ` Michael Forney
2023-05-14 10:23   ` [9front] " mia soweli
2023-05-14 11:10 ` [9front] [PATCH] cc: support type qualifiers inside array brackets mia soweli
2023-05-15  7:39   ` mia soweli [this message]
2023-05-15 12:51     ` [9front] " ori
2023-05-15 14:05       ` [9front] " mia soweli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8F22ED51-F0B5-4DF9-881E-E8BF258DF795@tachibana-labs.org \
    --to=inbox@tachibana-labs.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).