patch adding %afterdecls C code section

Jean-Yves Lefort <[email protected]> Fri, 1 Feb 2008 14:12:50 +0100
Newsgroups gmane.comp.gnome.devtools.gob.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.

[email protected]
Content-Type: multipart/signed; protocol="application/pgp-signature";
 micalg="PGP-SHA1";
 boundary="Signature=_Fri__1_Feb_2008_14_12_50_+0100_1kGM.M4SooMxceBQ"

--Signature=_Fri__1_Feb_2008_14_12_50_+0100_1kGM.M4SooMxceBQ
Content-Type: multipart/mixed;
 boundary="Multipart=_Fri__1_Feb_2008_14_12_50_+0100_xkuFIx_Yd.2ut+3H"


--Multipart=_Fri__1_Feb_2008_14_12_50_+0100_xkuFIx_Yd.2ut+3H
Content-Type: text/plain; charset=US-ASCII
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

The attached patch allows to insert a C code section (in the .c file)
between the declarations and the method implementations, eg:

	%afterdecls{

	static const struct
	{
		void (*one) (Self *self);
		void (*two) (Self *self);
	} things[] =3D {
	  { self_foo, self_bar },
	};

	%}

	class Foo:Bar
	{
		private void
		foo (self)
		{
		}

		private void
		bar (self)
		{
		}
	}

Without this patch, one has to make methods protected if he wants to
refer to them from the %{} code section.

Or, alternatively, put things[] in a %{} section at the end of the
file:

	%{
	typedef struct
	{
		void (*one) (FooBar *self);
		void (*two) (FooBar *self);
	} Thing;

	static const Thing things[];
	%}

	class Foo:Bar
	{
		...
	}

	%{
	static const Thing things[] =3D {
		...
	};
	%}

But it's more verbose and forbids code such as:

	G_N_ELEMENTS(things)

since things[] is not yet defined in the class code.

--=20
Jean-Yves Lefort <[email protected]>

--Multipart=_Fri__1_Feb_2008_14_12_50_+0100_xkuFIx_Yd.2ut+3H
Content-Type: text/x-diff;
 name="gob2-2.0.15-afterdecls.diff"
Content-Disposition: attachment;
 filename="gob2-2.0.15-afterdecls.diff"
Content-Transfer-Encoding: quoted-printable

--- src/lexer.l.orig	2007-09-28 06:26:49.000000000 +0200
+++ src/lexer.l	2008-02-01 13:33:53.000000000 +0100
@@ -344,6 +344,14 @@
 			if(look_for_includes=3D=3D0)
 				look_for_includes=3D1;
 		}
+^\%(ad|afterdecls)\{		{
+			BEGIN(C_CODE);
+			parenth_depth =3D 1;
+			class_after_c =3D FALSE;
+			code_type =3D ADCODE;
+			clear_cbuf();
+			ccode_line =3D line_no;
+		}
 <C_CODE>^\%\}	{
 			BEGIN(INITIAL);
 			yylval.cbuf =3D cbuf;
--- src/main.c.orig	2007-10-17 16:49:04.000000000 +0200
+++ src/main.c	2008-02-01 13:36:42.000000000 +0100
@@ -3293,6 +3293,7 @@
 	}
 	out_printf(fp, "%s\n", cc->cbuf);
 	if(cc->cctype =3D=3D C_CCODE ||
+	   cc->cctype =3D=3D AD_CCODE ||
 	   cc->cctype =3D=3D A_CCODE ||
 	   cc->cctype =3D=3D AT_CCODE ||
 	   cc->cctype =3D=3D PH_CCODE)
@@ -3633,6 +3634,15 @@
 			    funcbase);
 	}
=20
+	for (li =3D nodes; li !=3D NULL; li =3D li->next) {
+		Node *node =3D li->data;
+		if (node->type =3D=3D CCODE_NODE) {
+			CCode *cc =3D (CCode *)node;
+			if (cc->cctype =3D=3D AD_CCODE)
+				print_ccode_block (cc);
+		}
+	}
+
 	if (need_dispose)
 		add_dispose (c);
=20
@@ -4064,7 +4074,8 @@
 		if (node->type =3D=3D CCODE_NODE) {
 			CCode *cc =3D (CCode *)node;
 			if (cc->cctype !=3D HT_CCODE &&
-			    cc->cctype !=3D AT_CCODE)
+			    cc->cctype !=3D AT_CCODE &&
+			    cc->cctype !=3D AD_CCODE)
 				print_ccode_block ((CCode *)node);
 		} else if (node->type =3D=3D CLASS_NODE) {
 			print_class_block ((Class *)node);
--- src/parse.y.orig	2007-03-09 18:46:14.000000000 +0100
+++ src/parse.y	2008-02-01 13:35:25.000000000 +0100
@@ -678,7 +678,7 @@
 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
=20
 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
-%token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
+%token <cbuf> CCODE ADCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
 %token <line> VIRTUAL SIGNAL OVERRIDE
 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
@@ -701,6 +701,15 @@
 			nodes =3D g_list_append(nodes,node);
 			g_string_free($<cbuf>1,FALSE);
 					}
+	|	ADCODE			{
+			Node *node =3D node_new (CCODE_NODE,
+					       "cctype", AD_CCODE,
+					       "cbuf:steal", ($<cbuf>1)->str,
+					       "line_no", ccode_line,
+					       NULL);
+			nodes =3D g_list_append(nodes,node);
+			g_string_free($<cbuf>1,FALSE);
+					}
 	|	HCODE			{
 			Node *node =3D node_new (CCODE_NODE,
 					       "cctype", H_CCODE,
--- src/treefuncs.def.orig	2007-03-09 18:46:14.000000000 +0100
+++ src/treefuncs.def	2008-02-01 13:33:53.000000000 +0100
@@ -9,6 +9,7 @@
 	A_CCODE,
 	AT_CCODE,
 	C_CCODE,
+	AD_CCODE,
 	H_CCODE,
 	HT_CCODE,
 	PH_CCODE

--Multipart=_Fri__1_Feb_2008_14_12_50_+0100_xkuFIx_Yd.2ut+3H--

--Signature=_Fri__1_Feb_2008_14_12_50_+0100_1kGM.M4SooMxceBQ
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHoxrSyzD7UaO4AGoRAqGWAJ92cWZ82hzJ9paVV6UHof/nWFeCEACfYKd/
lmw6L2HTX7+TZsluhFnf1Gg=
=bVB1
-----END PGP SIGNATURE-----

--Signature=_Fri__1_Feb_2008_14_12_50_+0100_1kGM.M4SooMxceBQ--


[email protected]
Content-Type: text/plain; charset=us-ascii; name="footer.txt"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

--
to unsubscribe:
send mail to [email protected] with "unsubscribe gob-list" in the subject

[email protected]