|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
patch adding %afterdecls C code sectionThe 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[] = { { 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[] = { ... }; %} But it's more verbose and forbids code such as: G_N_ELEMENTS(things) since things[] is not yet defined in the class code. -- Jean-Yves Lefort <jylefort@...> [gob2-2.0.15-afterdecls.diff] --- 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==0) look_for_includes=1; } +^\%(ad|afterdecls)\{ { + BEGIN(C_CODE); + parenth_depth = 1; + class_after_c = FALSE; + code_type = ADCODE; + clear_cbuf(); + ccode_line = line_no; + } <C_CODE>^\%\} { BEGIN(INITIAL); yylval.cbuf = 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 == C_CCODE || + cc->cctype == AD_CCODE || cc->cctype == A_CCODE || cc->cctype == AT_CCODE || cc->cctype == PH_CCODE) @@ -3633,6 +3634,15 @@ funcbase); } + for (li = nodes; li != NULL; li = li->next) { + Node *node = li->data; + if (node->type == CCODE_NODE) { + CCode *cc = (CCode *)node; + if (cc->cctype == AD_CCODE) + print_ccode_block (cc); + } + } + if (need_dispose) add_dispose (c); @@ -4064,7 +4074,8 @@ if (node->type == CCODE_NODE) { CCode *cc = (CCode *)node; if (cc->cctype != HT_CCODE && - cc->cctype != AT_CCODE) + cc->cctype != AT_CCODE && + cc->cctype != AD_CCODE) print_ccode_block ((CCode *)node); } else if (node->type == 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 %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 = g_list_append(nodes,node); g_string_free($<cbuf>1,FALSE); } + | ADCODE { + Node *node = node_new (CCODE_NODE, + "cctype", AD_CCODE, + "cbuf:steal", ($<cbuf>1)->str, + "line_no", ccode_line, + NULL); + nodes = g_list_append(nodes,node); + g_string_free($<cbuf>1,FALSE); + } | HCODE { Node *node = 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 -- to unsubscribe: send mail to minimalist@... with "unsubscribe gob-list" in the subject |
| Free embeddable forum powered by Nabble | Forum Help |