From 2310330e7d4d724bf6641339836be8523f95c916 Mon Sep 17 00:00:00 2001 From: George Lebl Date: Tue, 16 Nov 1999 11:00:00 -0800 Subject: [PATCH] Release 0.90.4 --- ChangeLog | 32 +++ NEWS | 6 + README | 9 +- configure | 2 +- configure.in | 2 +- doc/gob.1.in | 84 +++++- gob.spec | 2 +- src/Makefile.in | 2 +- src/lexer.c | 714 +++++++++++++++++++++++++----------------------- src/lexer.l | 15 + src/main.c | 297 +++++++++++++------- src/out.c | 7 +- src/parse.c | 62 ++--- src/parse.y | 14 +- src/test.gob | 2 +- 15 files changed, 738 insertions(+), 512 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f913fb..687bdc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +Tue Nov 16 01:23:45 1999 George Lebl + + * src/main.c: support a "no-touch-headers" mode in which the + headers are not touched unless they actually really changed, + not on by default as it confuses automake + +Tue Nov 16 00:36:42 1999 George Lebl + + * src/{main.c,lexer.l,parser.y,out.c}: Implement a C++ mode, get + rid of C++ errors/warnings when in C++ mode, and get rid of + the 'this' pointer finally (it's been deprecated long enough) + +Mon Nov 15 23:45:37 1999 George Lebl + + * src/main.c: add prototype for the really bad hack function to + avoid warning + +Mon Nov 15 23:42:06 1999 George Lebl + + * src/main.c: generate correct function pointers in the structure + for signals and virtuals. Also use a much nicer system instead + of the method name defines, we now just set a bunch of static + pointers, this removes a whole lot of headaches actually + + * doc/gob.1.in: repair to reflect the above (I removed the define + BUGS paragraph) + +Sun Nov 14 17:57:34 1999 George Lebl + + * doc/gob.1.in: repair some things that confused troff and add + a C preprocessor warning to BUGS + Sat Nov 13 17:22:49 1999 George Lebl * **/Makefile.am, configure.in: fix the conditional installation diff --git a/NEWS b/NEWS index e21dbac..5fa1488 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +0.90.4 + * fix buggy class structure generation + * can generate C++ friendly code + * function aliases are now done by static pointers rather then defines + * more... + 0.90.3 * does not require popt * don't kill comments from C code blocks diff --git a/README b/README index 454ed59..c20e5ba 100644 --- a/README +++ b/README @@ -16,7 +16,8 @@ To build: run "./configure;make" To install: - run "make install" as root + run "make install" as root, or just take the gob binary and place + it anywhere you want. To use: run gob with the .gob file on the command line @@ -27,8 +28,10 @@ What's generated: How to write .gob files? 1) read "man gob" for some documenation on how to use GOB - 2) if you can't find what you need, read src/test.gob and - src/lexer.l and src/parse.y (in other words: RTFS) + 2) if you can't find what you need, read src/test.gob for an + example of GOB code + 3) If you still can't find what you need, read src/lexer.l + and src/parse.y (in other words: RTFS) How to include gob inside your project: diff --git a/configure b/configure index 1c3665e..fb8174c 100755 --- a/configure +++ b/configure @@ -703,7 +703,7 @@ fi PACKAGE=gob -VERSION=0.90.3 +VERSION=0.90.4 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/configure.in b/configure.in index 325f17a..cc2e1eb 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.2) AC_INIT(src/tree.h) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(gob,0.90.3) +AM_INIT_AUTOMAKE(gob,0.90.4) if test -f ../NOINST_GOB ; then DOINSTGOB= diff --git a/doc/gob.1.in b/doc/gob.1.in index 82f31ab..7691736 100644 --- a/doc/gob.1.in +++ b/doc/gob.1.in @@ -10,13 +10,39 @@ GOB \- The GTK+ Object Builder .SH SYNOPSIS .PP -.B gob +.B gob [-?] [-h] [-w] [--exit-on-warn] [--no-exit-on-warn] [--for-cpp] +[--no-touch-headers] file .SH DESCRIPTION .PP GTK+ Object Builder is a simple preprocessor for easily creating GTK+ objects. It does not parse any C code and ignores any C errors. It is in spirit similar to things like lex or yacc. +.SH OPTIONS +.PP +.TP +.B -? +.TP +.B -h +Display a simple help screen. +.TP +.B -w +.TP +.B --exit-on-warn +Exit with an errorcode even when you encounter a warning. +.TP +.B --no-exit-on-warn +Exit with an error only on errors, not on warnings, this is the default. +.TP +.B --for-cpp +Generate C++ code. +.TP +.B --no-touch-headers +Don't touch the generated header file unless it really changed, this avoids +spurious rebuilds, but can confuse some make systems (automake in particular), +so it is not enabled by default. + + .SH TYPENAMES .PP Because we need to parse out different parts of the typename, @@ -35,19 +61,22 @@ separated by '-' and all in lower case. For example for an object named .SH INCLUDING NORMAL C CODE IN THE OUTPUT FILES .PP -To include some code directly in the output C file begin with -'%{' on an empty line and end the code with a '%{' on an empty line. To +To include some code directly in the output C file begin with '%{' +on an empty line and end the code with a '%}' on an empty line. To put the code in the output header file, start the code with a '%h{'. For example: .nf %h{ + /* will be included in the header */ void somefunc(int i); %} + %{ + /* will be included in the C file */ void somefunc(int i) { - /* some code */ + /* some code */ } %} @@ -242,8 +271,9 @@ get warnings during compilation. Example: .PP Calling methods: .PP -Inside the code, defines are set for the methods, so that you don't -have to type the class name before each call. Example: +Inside the code, pointers are set for the methods, so that you don't +have to type the class name before each call, just the name of the method. +Example: .nf private int @@ -276,6 +306,17 @@ will fetch a new object, so a fairly standard new method would look like: .fi +.SH C++ MODE +.PP +There is a C++ mode so that gob creates C++ compiler friendly files. You need +to use the --for-cpp argument to gob. This will make the generated file have +a .cc instead of a .c extention, and several things will be adjusted to +make it all work for a C++ compiler. One thing that will be missing is an +alias to the new method, as that clashes with C++, so instead you'll have to +use the full name of the method inside your code. Also note that gob does +not use any C++ features, this option will just make the generated code +compile with a C++ compiler. + .SH BUGS .PP The generated header file is included as the first file in the .c file, no @@ -287,15 +328,36 @@ cases or maybe even some not so corner cases of C syntax might confuse gob completely. If you find any, send me the source that makes it go gaga and I'll try to make the lexer try to handle it properly, but no promises. .PP -Gob uses a lot of #define's so sometimes it can confuse your code. One way -to make sure you don't get confused is not to use method names for absolutely -anything else since gob will use defines of the type: +Another thing is that gob ignores preprocessor macros. Since gob counts +braces, the following code won't work: .nf - #define method_name class_name_method_name + #ifdef SOME_DEFINE + if(foo) { + #else + if(bar) { + #endif + blah(); + } + +.fi +To make this work, you'd have to do this: +.nf + + #ifdef SOME_DEFINE + if(foo) + #else + if(bar) + #endif + { + blah(); + } .fi -For your class code. +There is no real good way we can handle this without parsing C code, so we +probably never will. In the future, I might add #if 0 as a comment but +that's about as far as I can really take it and even that is problematic. +Basically, if you use gob, just don't use the C preprocessor too extensively. .SH AUTHOR .PP diff --git a/gob.spec b/gob.spec index 7bfc8f2..bd03877 100644 --- a/gob.spec +++ b/gob.spec @@ -1,4 +1,4 @@ -%define ver 0.90.3 +%define ver 0.90.4 %define rel 1 %define prefix /usr diff --git a/src/Makefile.in b/src/Makefile.in index 2cf3140..00aff17 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -318,7 +318,7 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done -lexer.o: lexer.c ../config.h parse.h +lexer.o: lexer.c ../config.h parse.h main.h main.o: main.c ../config.h tree.h parse.h out.h main.h out.o: out.c out.h parse.o: parse.c ../config.h tree.h main.h diff --git a/src/lexer.c b/src/lexer.c index 0902fb5..770320c 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -284,76 +284,78 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); *yy_cp = '\0'; \ yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 65 -#define YY_END_OF_BUFFER 66 -static yyconst short int yy_acclist[323] = +#define YY_NUM_RULES 66 +#define YY_END_OF_BUFFER 67 +static yyconst short int yy_acclist[336] = { 0, - 66, 63, 65, 62, 63, 65, 1, 64, 65, 63, - 64, 65, 63, 65, 63, 65, 63, 65, 63, 65, - 12, 63, 65, 1, 13, 64, 65, 12, 63, 64, - 65, 12, 63, 65, 12, 63, 65, 31, 63, 65, - 1, 32, 64, 65, 31, 63, 64, 65, 24, 31, - 63, 65, 31, 63, 65, 31, 63, 65, 31, 63, - 65, 31, 63, 65, 29, 31, 63, 65, 30, 31, - 63, 65, 31, 63, 65, 27, 63, 65, 1, 28, - 64, 65, 27, 63, 64, 65, 26, 27, 63, 65, - 27, 63, 65, 27, 63, 65, 63, 65, 63, 65, - - 58, 63, 65, 58, 63, 65, 58, 63, 65, 59, - 63, 65, 63, 65, 63, 65, 56, 63, 65, 56, - 63, 65, 58, 63, 65, 58, 63, 65, 58, 63, - 65, 58, 63, 65, 58, 63, 65, 58, 63, 65, - 58, 63, 65, 58, 63, 65, 58, 63, 65, 58, - 63, 65, 58, 63, 65, 58, 63, 65, 60, 63, - 65, 61, 63, 65, 7, 15, 11, 8, 23, 16, - 25, 9, 58, 57, 58, 58, 56, 10, 56, 56, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 3, 14, - - 21, 17, 19, 4, 5, 57, 58, 58, 48, 56, - 6, 56, 56, 58, 58, 58, 58, 58, 58, 43, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 58, 22, 18, 20, 58, 34, 58, 58, - 46, 58, 58, 58, 38, 58, 58, 41, 58, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 35, - 58, 33, 58, 58, 47, 58, 58, 44, 58, 58, - 58, 58, 58, 42, 58, 58, 58, 58, 37, 58, - 58, 58, 58, 58, 45, 58, 58, 58, 58, 49, - 58, 53, 58, 39, 58, 36, 58, 58, 58, 58, - - 58, 55, 58, 58, 50, 58, 58, 52, 58, 58, - 51, 58, 54, 58, 40, 58, 58, 58, 58, 2, - 2, 58 + 67, 64, 66, 63, 64, 66, 1, 65, 66, 64, + 65, 66, 64, 66, 64, 66, 64, 66, 64, 66, + 12, 64, 66, 1, 13, 65, 66, 12, 64, 65, + 66, 12, 64, 66, 12, 64, 66, 31, 64, 66, + 1, 32, 65, 66, 31, 64, 65, 66, 24, 31, + 64, 66, 31, 64, 66, 31, 64, 66, 31, 64, + 66, 31, 64, 66, 29, 31, 64, 66, 30, 31, + 64, 66, 31, 64, 66, 27, 64, 66, 1, 28, + 65, 66, 27, 64, 65, 66, 26, 27, 64, 66, + 27, 64, 66, 27, 64, 66, 64, 66, 64, 66, + + 59, 64, 66, 59, 64, 66, 59, 64, 66, 59, + 64, 66, 59, 64, 66, 60, 64, 66, 64, 66, + 64, 66, 57, 64, 66, 57, 64, 66, 59, 64, + 66, 59, 64, 66, 59, 64, 66, 59, 64, 66, + 59, 64, 66, 59, 64, 66, 59, 64, 66, 59, + 64, 66, 59, 64, 66, 59, 64, 66, 59, 64, + 66, 59, 64, 66, 61, 64, 66, 62, 64, 66, + 7, 15, 11, 8, 23, 16, 25, 9, 59, 58, + 59, 59, 59, 59, 57, 10, 57, 57, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + + 59, 59, 59, 59, 59, 59, 3, 14, 21, 17, + 19, 4, 5, 58, 59, 59, 59, 59, 49, 57, + 6, 57, 57, 59, 59, 59, 59, 59, 59, 44, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 22, 18, 20, 59, 59, 35, 59, + 34, 59, 59, 47, 59, 59, 59, 39, 59, 59, + 42, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 36, 59, 33, 59, 59, 48, 59, 59, + 45, 59, 59, 59, 59, 59, 43, 59, 59, 59, + 59, 38, 59, 59, 59, 59, 59, 46, 59, 59, + + 59, 59, 50, 59, 54, 59, 40, 59, 37, 59, + 59, 59, 59, 59, 56, 59, 59, 51, 59, 59, + 53, 59, 59, 52, 59, 55, 59, 41, 59, 59, + 59, 59, 2, 2, 59 } ; -static yyconst short int yy_accept[241] = +static yyconst short int yy_accept[249] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 7, 10, 13, 15, 17, 19, 21, 24, 28, 32, 35, 38, 41, 45, 49, 53, 56, 59, 62, 65, 69, 73, 76, 79, 83, 87, 91, 94, 97, 99, 101, 104, 107, 110, 113, - 115, 117, 120, 123, 126, 129, 132, 135, 138, 141, - 144, 147, 150, 153, 156, 159, 162, 165, 166, 166, - 166, 166, 166, 167, 168, 168, 168, 168, 168, 169, - 169, 170, 171, 172, 173, 173, 173, 174, 175, 176, - 177, 177, 178, 179, 179, 179, 180, 180, 180, 181, - - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 199, 200, - 200, 200, 201, 202, 202, 202, 202, 203, 204, 204, - 205, 205, 206, 206, 207, 208, 209, 210, 211, 211, - 212, 213, 214, 215, 216, 217, 218, 219, 220, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, - 233, 234, 234, 234, 235, 236, 237, 238, 240, 241, - 243, 244, 245, 247, 248, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 262, 262, 263, 264, - 265, 267, 268, 270, 271, 272, 273, 274, 276, 277, - - 278, 279, 281, 282, 283, 283, 284, 285, 287, 288, - 289, 290, 292, 294, 296, 298, 299, 300, 300, 301, - 302, 304, 305, 307, 308, 310, 310, 311, 313, 315, - 317, 317, 318, 318, 319, 319, 320, 321, 323, 323 + 116, 119, 121, 123, 126, 129, 132, 135, 138, 141, + 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, + 172, 172, 172, 172, 172, 173, 174, 174, 174, 174, + 174, 175, 175, 176, 177, 178, 179, 179, 179, 180, + 181, 182, 183, 184, 185, 185, 186, 187, 187, 187, + + 188, 188, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, + 206, 207, 207, 208, 208, 208, 209, 210, 210, 210, + 210, 211, 212, 212, 213, 213, 214, 214, 215, 216, + 217, 218, 219, 220, 221, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 232, 233, 234, 235, 236, + 237, 238, 239, 240, 241, 242, 243, 244, 244, 244, + 245, 246, 247, 248, 249, 251, 253, 254, 256, 257, + 258, 260, 261, 263, 264, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 275, 275, 276, 277, 278, 280, + + 281, 283, 284, 285, 286, 287, 289, 290, 291, 292, + 294, 295, 296, 296, 297, 298, 300, 301, 302, 303, + 305, 307, 309, 311, 312, 313, 313, 314, 315, 317, + 318, 320, 321, 323, 323, 324, 326, 328, 330, 330, + 331, 331, 332, 332, 333, 334, 336, 336 } ; static yyconst int yy_ec[256] = @@ -397,198 +399,204 @@ static yyconst int yy_meta[50] = 6, 6, 6, 6, 6, 6, 6, 1, 1 } ; -static yyconst short int yy_base[256] = +static yyconst short int yy_base[263] = { 0, - 0, 3, 12, 15, 35, 82, 24, 44, 131, 180, - 221, 0, 509, 510, 510, 510, 510, 4, 485, 470, - 6, 510, 510, 510, 496, 482, 510, 510, 510, 510, - 16, 16, 481, 0, 510, 510, 454, 510, 510, 510, - 510, 479, 0, 42, 0, 487, 21, 17, 510, 61, - 45, 66, 82, 18, 62, 42, 22, 44, 66, 76, - 82, 84, 111, 85, 87, 510, 510, 510, 497, 474, - 470, 449, 510, 510, 489, 58, 488, 487, 510, 490, - 510, 510, 510, 510, 489, 477, 476, 475, 86, 108, - 479, 56, 510, 484, 106, 148, 154, 0, 159, 135, - - 148, 136, 106, 159, 138, 181, 160, 182, 183, 184, - 187, 163, 192, 194, 203, 195, 186, 483, 510, 465, - 441, 510, 510, 476, 475, 474, 510, 510, 477, 510, - 476, 510, 464, 463, 94, 197, 510, 229, 473, 510, - 232, 0, 205, 196, 204, 198, 210, 245, 461, 241, - 242, 246, 249, 254, 251, 257, 258, 260, 262, 263, - 266, 457, 430, 510, 510, 510, 98, 458, 264, 457, - 265, 267, 456, 268, 455, 269, 271, 273, 272, 275, - 278, 191, 276, 280, 285, 454, 443, 510, 302, 291, - 452, 303, 451, 304, 306, 307, 308, 450, 310, 314, - - 311, 449, 313, 315, 444, 318, 317, 446, 319, 323, - 325, 402, 396, 363, 362, 326, 327, 349, 320, 334, - 360, 335, 359, 339, 358, 355, 140, 355, 354, 352, - 344, 89, 346, 345, 199, 336, 510, 3, 510, 378, - 384, 390, 396, 402, 408, 414, 416, 420, 426, 432, - 438, 442, 446, 452, 456 + 0, 3, 12, 15, 35, 82, 24, 44, 131, 0, + 172, 0, 530, 531, 531, 531, 531, 4, 506, 491, + 6, 531, 531, 531, 517, 503, 531, 531, 531, 531, + 16, 16, 502, 0, 531, 531, 475, 531, 531, 531, + 531, 500, 0, 42, 0, 508, 21, 18, 17, 39, + 531, 64, 48, 69, 82, 54, 65, 58, 22, 53, + 83, 85, 177, 180, 175, 87, 192, 531, 531, 531, + 518, 495, 491, 470, 531, 531, 510, 58, 509, 508, + 531, 511, 531, 531, 531, 531, 510, 498, 497, 496, + 89, 96, 174, 193, 500, 100, 531, 505, 106, 184, + + 222, 0, 227, 94, 101, 185, 212, 213, 216, 223, + 227, 228, 229, 232, 172, 230, 231, 233, 235, 234, + 236, 504, 531, 486, 462, 531, 531, 497, 496, 495, + 531, 531, 498, 531, 497, 531, 485, 484, 107, 237, + 239, 238, 531, 251, 494, 531, 271, 0, 240, 245, + 255, 259, 241, 272, 482, 260, 275, 276, 277, 278, + 279, 281, 282, 285, 283, 287, 291, 478, 451, 531, + 531, 531, 106, 289, 479, 478, 288, 477, 290, 292, + 476, 293, 475, 294, 296, 300, 297, 295, 316, 310, + 302, 321, 298, 474, 463, 531, 46, 328, 472, 331, + + 471, 332, 333, 335, 336, 470, 337, 339, 338, 469, + 342, 340, 464, 343, 344, 467, 345, 353, 348, 465, + 421, 415, 388, 357, 351, 375, 350, 359, 386, 361, + 385, 363, 384, 381, 176, 377, 376, 299, 177, 364, + 170, 378, 45, 372, 531, 3, 531, 403, 409, 415, + 421, 427, 433, 435, 439, 445, 451, 457, 461, 465, + 471, 475 } ; -static yyconst short int yy_def[256] = +static yyconst short int yy_def[263] = { 0, - 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, - 10, 11, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 245, 239, 239, 239, 239, 239, 239, - 239, 239, 246, 239, 247, 248, 248, 248, 239, 239, - 239, 239, 239, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 239, 239, 239, 249, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 250, - 239, 239, 239, 239, 251, 252, 248, 253, 248, 248, - 239, 239, 239, 254, 239, 239, 239, 255, 239, 248, - - 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 249, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 250, 239, - 251, 239, 252, 253, 248, 248, 239, 239, 254, 239, - 239, 255, 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 248, 239, 239, 239, 239, 239, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 239, 239, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - - 248, 248, 248, 248, 239, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 239, 248, 248, - 248, 248, 248, 248, 248, 239, 248, 248, 248, 248, - 239, 248, 239, 248, 239, 248, 239, 248, 0, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239 + 248, 248, 249, 249, 250, 250, 251, 251, 247, 9, + 9, 11, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 252, 247, 247, 247, 247, 247, 247, + 247, 247, 253, 247, 254, 255, 255, 255, 255, 255, + 247, 247, 247, 247, 247, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 247, 247, 247, + 256, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 257, 247, 247, 247, 247, 258, 259, 255, 260, + 255, 255, 255, 255, 247, 247, 247, 261, 247, 247, + + 247, 262, 247, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 256, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 257, 247, 258, 247, 259, 260, 255, 255, + 255, 255, 247, 247, 261, 247, 247, 262, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 247, 247, 247, + 247, 247, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 247, 247, 255, 255, 255, 255, + + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 247, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 247, 255, 255, 255, 255, + 255, 255, 255, 247, 255, 255, 255, 255, 247, 255, + 247, 255, 247, 255, 247, 255, 0, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247 } ; -static yyconst short int yy_nxt[560] = +static yyconst short int yy_nxt[581] = { 0, - 239, 15, 16, 17, 15, 16, 17, 239, 21, 18, - 239, 68, 18, 69, 23, 24, 88, 23, 24, 25, - 75, 19, 25, 79, 19, 80, 39, 40, 41, 20, - 88, 88, 20, 26, 88, 88, 26, 28, 29, 30, - 72, 31, 76, 89, 32, 42, 39, 40, 41, 84, - 43, 85, 93, 73, 94, 88, 33, 88, 90, 100, - 104, 34, 124, 77, 78, 42, 138, 138, 138, 91, - 43, 92, 92, 92, 95, 88, 96, 96, 97, 88, - 105, 103, 35, 36, 28, 29, 30, 37, 31, 88, - 95, 32, 99, 99, 99, 88, 101, 88, 88, 88, - - 88, 102, 88, 33, 106, 125, 126, 88, 34, 234, - 135, 88, 98, 167, 189, 107, 141, 141, 141, 88, - 108, 88, 116, 115, 88, 110, 117, 109, 111, 35, + 247, 15, 16, 17, 15, 16, 17, 247, 21, 18, + 247, 70, 18, 71, 23, 24, 90, 23, 24, 25, + 77, 19, 25, 81, 19, 82, 39, 40, 41, 20, + 90, 90, 20, 26, 90, 90, 26, 28, 29, 30, + 74, 31, 78, 91, 32, 42, 39, 40, 41, 86, + 43, 87, 90, 75, 92, 97, 33, 98, 93, 90, + 108, 34, 128, 79, 80, 42, 90, 90, 245, 214, + 43, 90, 95, 94, 96, 96, 96, 99, 90, 100, + 100, 101, 35, 36, 28, 29, 30, 37, 31, 109, + 99, 32, 103, 103, 103, 104, 90, 107, 90, 105, + + 90, 92, 90, 33, 106, 129, 130, 90, 34, 90, + 144, 144, 144, 139, 90, 102, 147, 147, 147, 90, + 90, 110, 197, 140, 111, 119, 173, 149, 150, 35, 36, 14, 15, 16, 17, 14, 14, 14, 14, 14, - 44, 14, 14, 14, 45, 112, 113, 136, 88, 88, - 146, 88, 47, 88, 114, 232, 95, 14, 96, 96, - 97, 88, 95, 48, 97, 97, 97, 95, 143, 99, - 99, 99, 88, 88, 145, 144, 88, 148, 49, 14, - 14, 15, 16, 17, 14, 14, 14, 14, 14, 44, - 14, 14, 14, 45, 88, 88, 88, 88, 150, 88, - - 88, 47, 155, 147, 88, 88, 14, 88, 88, 88, - 88, 88, 48, 151, 152, 154, 88, 88, 88, 153, - 201, 161, 237, 88, 149, 156, 172, 49, 14, 50, - 51, 52, 53, 53, 168, 157, 160, 170, 158, 138, - 138, 138, 141, 141, 141, 159, 171, 173, 54, 169, - 55, 56, 57, 58, 88, 88, 59, 60, 88, 88, - 61, 62, 88, 63, 88, 64, 65, 88, 66, 67, - 88, 88, 174, 88, 175, 88, 88, 88, 88, 88, - 88, 88, 88, 176, 88, 88, 88, 177, 88, 88, - 179, 88, 180, 88, 178, 181, 186, 184, 88, 183, - - 196, 190, 182, 192, 88, 199, 185, 197, 191, 200, - 194, 193, 195, 203, 202, 88, 88, 88, 198, 88, - 88, 88, 207, 88, 88, 206, 88, 88, 88, 204, - 88, 88, 88, 88, 208, 219, 88, 212, 88, 88, - 88, 210, 217, 209, 214, 227, 213, 88, 88, 88, - 211, 216, 88, 222, 215, 220, 223, 224, 88, 238, - 221, 236, 235, 225, 233, 88, 229, 88, 88, 230, - 231, 88, 88, 88, 226, 88, 88, 228, 14, 14, - 14, 14, 14, 14, 22, 22, 22, 22, 22, 22, - 27, 27, 27, 27, 27, 27, 38, 38, 38, 38, - - 38, 38, 46, 46, 46, 46, 46, 46, 81, 88, - 81, 81, 81, 81, 83, 88, 83, 83, 83, 83, - 86, 86, 87, 87, 87, 87, 118, 118, 118, 118, - 118, 118, 129, 129, 129, 129, 129, 129, 131, 131, - 131, 131, 131, 131, 133, 133, 133, 133, 134, 134, - 134, 134, 139, 139, 139, 139, 139, 139, 142, 88, - 142, 218, 88, 88, 88, 88, 205, 88, 88, 88, - 88, 88, 188, 187, 88, 140, 88, 88, 132, 130, - 166, 165, 164, 163, 162, 119, 140, 137, 88, 88, - 88, 132, 130, 128, 127, 123, 122, 121, 120, 119, - - 88, 70, 82, 70, 70, 74, 71, 70, 239, 13, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239 + 44, 14, 14, 14, 45, 46, 46, 46, 46, 46, + 46, 46, 47, 46, 46, 46, 46, 14, 46, 46, + 48, 46, 46, 49, 46, 46, 46, 46, 46, 46, + 46, 46, 46, 46, 50, 46, 46, 46, 51, 14, + 52, 53, 54, 55, 55, 90, 243, 90, 90, 90, + 90, 240, 99, 90, 100, 100, 101, 241, 90, 56, + + 160, 57, 58, 59, 60, 90, 90, 61, 62, 116, + 117, 63, 64, 141, 65, 112, 66, 67, 118, 68, + 69, 114, 113, 151, 115, 90, 90, 120, 142, 90, + 99, 121, 101, 101, 101, 99, 90, 103, 103, 103, + 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, + 90, 90, 90, 90, 90, 154, 152, 153, 90, 157, + 158, 144, 144, 144, 162, 156, 155, 159, 90, 161, + 164, 167, 90, 90, 163, 166, 175, 165, 181, 174, + 176, 147, 147, 147, 177, 90, 178, 180, 90, 90, + 90, 90, 90, 183, 90, 90, 90, 179, 90, 182, + + 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, + 90, 90, 90, 90, 187, 90, 184, 185, 192, 189, + 188, 194, 186, 90, 191, 198, 190, 204, 200, 90, + 193, 176, 205, 199, 90, 202, 201, 203, 206, 209, + 210, 90, 212, 207, 90, 90, 90, 208, 90, 90, + 90, 90, 90, 90, 211, 90, 90, 90, 90, 215, + 227, 90, 216, 90, 90, 220, 90, 225, 218, 222, + 90, 217, 90, 221, 90, 235, 90, 90, 219, 231, + 224, 223, 228, 230, 242, 90, 229, 233, 232, 90, + 90, 90, 237, 238, 244, 246, 239, 90, 90, 90, + + 234, 90, 236, 14, 14, 14, 14, 14, 14, 22, + 22, 22, 22, 22, 22, 27, 27, 27, 27, 27, + 27, 38, 38, 38, 38, 38, 38, 83, 90, 83, + 83, 83, 83, 85, 90, 85, 85, 85, 85, 88, + 88, 89, 89, 89, 89, 122, 122, 122, 122, 122, + 122, 133, 133, 133, 133, 133, 133, 135, 135, 135, + 135, 135, 135, 137, 137, 137, 137, 138, 138, 138, + 138, 145, 145, 145, 145, 145, 145, 148, 90, 148, + 90, 226, 90, 90, 90, 90, 213, 90, 90, 90, + 90, 90, 90, 196, 195, 90, 146, 90, 90, 136, + + 134, 172, 171, 170, 169, 168, 123, 146, 143, 90, + 90, 90, 136, 134, 132, 131, 127, 126, 125, 124, + 123, 90, 72, 84, 72, 72, 76, 73, 72, 247, + 13, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247 } ; -static yyconst short int yy_chk[560] = +static yyconst short int yy_chk[581] = { 0, 0, 1, 1, 1, 2, 2, 2, 0, 2, 1, - 0, 18, 2, 18, 3, 3, 238, 4, 4, 3, + 0, 18, 2, 18, 3, 3, 246, 4, 4, 3, 31, 1, 4, 32, 2, 32, 7, 7, 7, 1, - 48, 54, 2, 3, 47, 57, 4, 5, 5, 5, + 49, 48, 2, 3, 47, 59, 4, 5, 5, 5, 21, 5, 31, 47, 5, 7, 8, 8, 8, 44, - 7, 44, 51, 21, 51, 56, 5, 58, 48, 54, - 57, 5, 76, 31, 31, 8, 92, 92, 92, 50, - 8, 50, 50, 50, 52, 55, 52, 52, 52, 59, - 58, 56, 5, 5, 6, 6, 6, 6, 6, 60, - 53, 6, 53, 53, 53, 61, 55, 62, 64, 89, - - 65, 55, 232, 6, 59, 76, 76, 135, 6, 232, - 89, 167, 52, 135, 167, 60, 95, 95, 95, 103, - 61, 90, 65, 64, 63, 62, 65, 61, 62, 6, + 7, 44, 50, 21, 48, 53, 5, 53, 49, 197, + 59, 5, 78, 31, 31, 8, 60, 56, 243, 197, + 8, 58, 52, 50, 52, 52, 52, 54, 57, 54, + 54, 54, 5, 5, 6, 6, 6, 6, 6, 60, + 55, 6, 55, 55, 55, 56, 61, 58, 62, 57, + + 66, 57, 91, 6, 57, 78, 78, 104, 6, 92, + 96, 96, 96, 91, 105, 54, 99, 99, 99, 173, + 139, 61, 173, 92, 62, 66, 139, 104, 105, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 63, 63, 90, 100, 102, - 103, 105, 9, 227, 63, 227, 96, 9, 96, 96, - 96, 101, 97, 9, 97, 97, 97, 99, 100, 99, - 99, 99, 104, 107, 102, 101, 112, 105, 9, 9, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 106, 108, 109, 110, 107, 117, - - 111, 10, 112, 104, 182, 113, 10, 114, 116, 144, - 136, 146, 10, 108, 109, 111, 115, 145, 143, 110, - 182, 117, 235, 147, 106, 113, 146, 10, 10, 11, - 11, 11, 11, 11, 136, 114, 116, 144, 115, 138, - 138, 138, 141, 141, 141, 115, 145, 147, 11, 143, - 11, 11, 11, 11, 150, 151, 11, 11, 148, 152, - 11, 11, 153, 11, 155, 11, 11, 154, 11, 11, - 156, 157, 148, 158, 150, 159, 160, 169, 171, 161, - 172, 174, 176, 151, 177, 179, 178, 152, 180, 183, - 154, 181, 155, 184, 153, 156, 161, 159, 185, 158, - - 178, 169, 157, 172, 190, 181, 160, 179, 171, 181, - 176, 174, 177, 184, 183, 189, 192, 194, 180, 195, - 196, 197, 190, 199, 201, 189, 203, 200, 204, 185, - 207, 206, 209, 219, 192, 206, 210, 197, 211, 216, - 217, 195, 204, 194, 200, 219, 199, 220, 222, 236, - 196, 203, 224, 210, 201, 207, 211, 216, 234, 236, - 209, 234, 233, 217, 231, 230, 222, 229, 228, 224, - 226, 225, 223, 221, 218, 215, 214, 220, 240, 240, - 240, 240, 240, 240, 241, 241, 241, 241, 241, 241, - 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, - - 243, 243, 244, 244, 244, 244, 244, 244, 245, 213, - 245, 245, 245, 245, 246, 212, 246, 246, 246, 246, - 247, 247, 248, 248, 248, 248, 249, 249, 249, 249, - 249, 249, 250, 250, 250, 250, 250, 250, 251, 251, - 251, 251, 251, 251, 252, 252, 252, 252, 253, 253, - 253, 253, 254, 254, 254, 254, 254, 254, 255, 208, - 255, 205, 202, 198, 193, 191, 187, 186, 175, 173, - 170, 168, 163, 162, 149, 139, 134, 133, 131, 129, - 126, 125, 124, 121, 120, 118, 94, 91, 88, 87, - 86, 85, 80, 78, 77, 75, 72, 71, 70, 69, - - 46, 42, 37, 33, 26, 25, 20, 19, 13, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239 + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 11, 11, 11, 11, 11, 115, 241, 93, 65, 235, + 63, 235, 100, 64, 100, 100, 100, 239, 106, 11, + + 115, 11, 11, 11, 11, 67, 94, 11, 11, 65, + 65, 11, 11, 93, 11, 63, 11, 11, 65, 11, + 11, 64, 63, 106, 64, 107, 108, 67, 94, 109, + 101, 67, 101, 101, 101, 103, 110, 103, 103, 103, + 111, 112, 113, 116, 117, 114, 118, 120, 119, 121, + 140, 142, 141, 149, 153, 109, 107, 108, 150, 112, + 113, 144, 144, 144, 117, 111, 110, 114, 151, 116, + 119, 121, 152, 156, 118, 120, 141, 119, 153, 140, + 142, 147, 147, 147, 149, 154, 150, 152, 157, 158, + 159, 160, 161, 156, 162, 163, 165, 151, 164, 154, + + 166, 177, 174, 179, 167, 180, 182, 184, 188, 185, + 187, 193, 238, 186, 160, 191, 157, 158, 165, 162, + 161, 167, 159, 190, 164, 177, 163, 186, 180, 189, + 166, 174, 187, 179, 192, 184, 182, 185, 188, 190, + 191, 198, 193, 189, 200, 202, 203, 189, 204, 205, + 207, 209, 208, 212, 192, 211, 214, 215, 217, 198, + 214, 219, 200, 227, 225, 205, 218, 212, 203, 208, + 224, 202, 228, 207, 230, 227, 232, 240, 204, 219, + 211, 209, 215, 218, 240, 244, 217, 225, 224, 237, + 236, 242, 230, 232, 242, 244, 234, 233, 231, 229, + + 226, 223, 228, 248, 248, 248, 248, 248, 248, 249, + 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, + 250, 251, 251, 251, 251, 251, 251, 252, 222, 252, + 252, 252, 252, 253, 221, 253, 253, 253, 253, 254, + 254, 255, 255, 255, 255, 256, 256, 256, 256, 256, + 256, 257, 257, 257, 257, 257, 257, 258, 258, 258, + 258, 258, 258, 259, 259, 259, 259, 260, 260, 260, + 260, 261, 261, 261, 261, 261, 261, 262, 220, 262, + 216, 213, 210, 206, 201, 199, 195, 194, 183, 181, + 178, 176, 175, 169, 168, 155, 145, 138, 137, 135, + + 133, 130, 129, 128, 125, 124, 122, 98, 95, 90, + 89, 88, 87, 82, 80, 79, 77, 74, 73, 72, + 71, 46, 42, 37, 33, 26, 25, 20, 19, 13, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 247, 247, 247, 247, 247, 247, 247, 247, 247 } ; static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr; @@ -633,6 +641,9 @@ char *yytext; #include #include "parse.h" +#include "main.h" + +extern gboolean for_cpp; static int parenth_depth = 0; static int before_comment = INITIAL; @@ -674,7 +685,7 @@ add_to_cbuf(char *s) #define CLASS_CODE_I 5 -#line 678 "lex.yy.c" +#line 689 "lex.yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -828,10 +839,10 @@ YY_DECL register char *yy_cp = NULL, *yy_bp = NULL; register int yy_act; -#line 66 "lexer.l" +#line 69 "lexer.l" -#line 835 "lex.yy.c" +#line 846 "lex.yy.c" if ( yy_init ) { @@ -880,14 +891,14 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 240 ) + if ( yy_current_state >= 248 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; *yy_state_ptr++ = yy_current_state; ++yy_cp; } - while ( yy_base[yy_current_state] != 510 ); + while ( yy_base[yy_current_state] != 531 ); yy_find_action: yy_current_state = *--yy_state_ptr; @@ -918,12 +929,12 @@ do_action: /* This label is used only to access EOF actions. */ { /* beginning of action switch */ case 1: YY_RULE_SETUP -#line 68 "lexer.l" +#line 71 "lexer.l" { line_no++; REJECT; } YY_BREAK case 2: YY_RULE_SETUP -#line 70 "lexer.l" +#line 73 "lexer.l" { fprintf(stderr,"You are a bad bad person!\n"); REJECT; } YY_BREAK case 3: @@ -931,7 +942,7 @@ case 3: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 72 "lexer.l" +#line 75 "lexer.l" { ; /*comment, ignore*/ } YY_BREAK case 4: @@ -939,7 +950,7 @@ case 4: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 73 "lexer.l" +#line 76 "lexer.l" { add_to_cbuf(yytext); /*comment, ignore*/ } YY_BREAK case 5: @@ -947,7 +958,7 @@ case 5: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 74 "lexer.l" +#line 77 "lexer.l" { ; /*comment, ignore*/ } YY_BREAK case 6: @@ -955,17 +966,17 @@ case 6: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 75 "lexer.l" +#line 78 "lexer.l" { ; /*comment, ignore*/ } YY_BREAK case 7: YY_RULE_SETUP -#line 76 "lexer.l" +#line 79 "lexer.l" {BEGIN(COMMENT); before_comment = INITIAL; } YY_BREAK case 8: YY_RULE_SETUP -#line 77 "lexer.l" +#line 80 "lexer.l" { add_to_cbuf(yytext); BEGIN(COMMENT); @@ -974,17 +985,17 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 82 "lexer.l" +#line 85 "lexer.l" {BEGIN(COMMENT); before_comment = CLASS_CODE; } YY_BREAK case 10: YY_RULE_SETUP -#line 83 "lexer.l" +#line 86 "lexer.l" {BEGIN(COMMENT); before_comment = CLASS_CODE_I; } YY_BREAK case 11: YY_RULE_SETUP -#line 84 "lexer.l" +#line 87 "lexer.l" { if(before_comment == C_CODE) add_to_cbuf(yytext); BEGIN(before_comment); @@ -992,7 +1003,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 88 "lexer.l" +#line 91 "lexer.l" { /* comment, ignore */ if(before_comment == C_CODE) add_to_cbuf(yytext); @@ -1000,7 +1011,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 92 "lexer.l" +#line 95 "lexer.l" { /* comment, ignore */ if(before_comment == C_CODE) add_to_cbuf(yytext); @@ -1008,7 +1019,7 @@ YY_RULE_SETUP YY_BREAK case 14: YY_RULE_SETUP -#line 97 "lexer.l" +#line 100 "lexer.l" { BEGIN(C_CODE); parenth_depth = 1; @@ -1020,7 +1031,7 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 105 "lexer.l" +#line 108 "lexer.l" { BEGIN(C_CODE); parenth_depth = 1; @@ -1032,7 +1043,7 @@ YY_RULE_SETUP YY_BREAK case 16: YY_RULE_SETUP -#line 113 "lexer.l" +#line 116 "lexer.l" { BEGIN(INITIAL); yylval.cbuf = cbuf; @@ -1045,42 +1056,42 @@ YY_RULE_SETUP YY_BREAK case 17: YY_RULE_SETUP -#line 123 "lexer.l" +#line 126 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 18: YY_RULE_SETUP -#line 124 "lexer.l" +#line 127 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 19: YY_RULE_SETUP -#line 125 "lexer.l" +#line 128 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 20: YY_RULE_SETUP -#line 126 "lexer.l" +#line 129 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 21: YY_RULE_SETUP -#line 127 "lexer.l" +#line 130 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 22: YY_RULE_SETUP -#line 128 "lexer.l" +#line 131 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 23: YY_RULE_SETUP -#line 130 "lexer.l" +#line 133 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 24: YY_RULE_SETUP -#line 131 "lexer.l" +#line 134 "lexer.l" { BEGIN(C_CODE_STRING); add_to_cbuf(yytext); @@ -1088,12 +1099,12 @@ YY_RULE_SETUP YY_BREAK case 25: YY_RULE_SETUP -#line 135 "lexer.l" +#line 138 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 26: YY_RULE_SETUP -#line 136 "lexer.l" +#line 139 "lexer.l" { BEGIN(C_CODE); add_to_cbuf(yytext); @@ -1101,17 +1112,17 @@ YY_RULE_SETUP YY_BREAK case 27: YY_RULE_SETUP -#line 140 "lexer.l" +#line 143 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 28: YY_RULE_SETUP -#line 141 "lexer.l" +#line 144 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 29: YY_RULE_SETUP -#line 143 "lexer.l" +#line 146 "lexer.l" { parenth_depth++; add_to_cbuf(yytext); @@ -1119,7 +1130,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 147 "lexer.l" +#line 150 "lexer.l" { parenth_depth--; if(parenth_depth<0) { @@ -1135,17 +1146,17 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 160 "lexer.l" +#line 163 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 32: YY_RULE_SETUP -#line 161 "lexer.l" +#line 164 "lexer.l" { add_to_cbuf(yytext); } YY_BREAK case 33: YY_RULE_SETUP -#line 163 "lexer.l" +#line 166 "lexer.l" { BEGIN(CLASS_CODE); return CLASS; @@ -1153,149 +1164,164 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 168 "lexer.l" -{return FROM;} +#line 171 "lexer.l" +{ + if(for_cpp) { + char *s; + s = g_strdup_printf("'%s' keyword should not " + "be used when generating " + "C++ code",yytext); + print_error(TRUE,s, line_no); + g_free(s); + } + REJECT; + } YY_BREAK case 35: YY_RULE_SETUP -#line 170 "lexer.l" -{return VOID;} +#line 183 "lexer.l" +{return FROM;} YY_BREAK case 36: YY_RULE_SETUP -#line 171 "lexer.l" -{return STRUCT;} +#line 185 "lexer.l" +{return VOID;} YY_BREAK case 37: YY_RULE_SETUP -#line 172 "lexer.l" -{return UNION;} +#line 186 "lexer.l" +{return STRUCT;} YY_BREAK case 38: YY_RULE_SETUP -#line 173 "lexer.l" -{return ENUM;} +#line 187 "lexer.l" +{return UNION;} YY_BREAK case 39: YY_RULE_SETUP -#line 174 "lexer.l" -{return SIGNED;} +#line 188 "lexer.l" +{return ENUM;} YY_BREAK case 40: YY_RULE_SETUP -#line 175 "lexer.l" -{return UNSIGNED;} +#line 189 "lexer.l" +{return SIGNED;} YY_BREAK case 41: YY_RULE_SETUP -#line 176 "lexer.l" -{return LONG;} +#line 190 "lexer.l" +{return UNSIGNED;} YY_BREAK case 42: YY_RULE_SETUP -#line 177 "lexer.l" -{return SHORT;} +#line 191 "lexer.l" +{return LONG;} YY_BREAK case 43: YY_RULE_SETUP -#line 178 "lexer.l" -{return INT;} +#line 192 "lexer.l" +{return SHORT;} YY_BREAK case 44: YY_RULE_SETUP -#line 179 "lexer.l" -{return FLOAT;} +#line 193 "lexer.l" +{return INT;} YY_BREAK case 45: YY_RULE_SETUP -#line 180 "lexer.l" -{return DOUBLE;} +#line 194 "lexer.l" +{return FLOAT;} YY_BREAK case 46: YY_RULE_SETUP -#line 181 "lexer.l" -{return CHAR;} +#line 195 "lexer.l" +{return DOUBLE;} YY_BREAK case 47: YY_RULE_SETUP -#line 182 "lexer.l" -{return CONST;} +#line 196 "lexer.l" +{return CHAR;} YY_BREAK case 48: YY_RULE_SETUP -#line 184 "lexer.l" -{return THREEDOTS;} +#line 197 "lexer.l" +{return CONST;} YY_BREAK case 49: YY_RULE_SETUP -#line 186 "lexer.l" -{yylval.line = line_no; return PUBLIC;} +#line 199 "lexer.l" +{return THREEDOTS;} YY_BREAK case 50: YY_RULE_SETUP -#line 187 "lexer.l" -{yylval.line = line_no; return PRIVATE;} +#line 201 "lexer.l" +{yylval.line = line_no; return PUBLIC;} YY_BREAK case 51: YY_RULE_SETUP -#line 188 "lexer.l" -{yylval.line = line_no; return ARGUMENT;} +#line 202 "lexer.l" +{yylval.line = line_no; return PRIVATE;} YY_BREAK case 52: YY_RULE_SETUP -#line 189 "lexer.l" -{yylval.line = line_no; return VIRTUAL;} +#line 203 "lexer.l" +{yylval.line = line_no; return ARGUMENT;} YY_BREAK case 53: YY_RULE_SETUP -#line 190 "lexer.l" -{yylval.line = line_no; return SIGNAL;} +#line 204 "lexer.l" +{yylval.line = line_no; return VIRTUAL;} YY_BREAK case 54: YY_RULE_SETUP -#line 191 "lexer.l" -{yylval.line = line_no; return OVERRIDE;} +#line 205 "lexer.l" +{yylval.line = line_no; return SIGNAL;} YY_BREAK case 55: YY_RULE_SETUP -#line 192 "lexer.l" -{return ONERROR;} +#line 206 "lexer.l" +{yylval.line = line_no; return OVERRIDE;} YY_BREAK case 56: YY_RULE_SETUP -#line 193 "lexer.l" +#line 207 "lexer.l" +{return ONERROR;} + YY_BREAK +case 57: +YY_RULE_SETUP +#line 208 "lexer.l" { yylval.id = g_strdup(yytext); return NUMBER; } YY_BREAK -case 57: +case 58: YY_RULE_SETUP -#line 197 "lexer.l" +#line 212 "lexer.l" { yylval.id = g_strdup(yytext); return TYPETOKEN; } YY_BREAK -case 58: +case 59: YY_RULE_SETUP -#line 201 "lexer.l" +#line 216 "lexer.l" { yylval.id = g_strdup(yytext); return TOKEN; } YY_BREAK -case 59: +case 60: YY_RULE_SETUP -#line 206 "lexer.l" +#line 221 "lexer.l" { BEGIN(CLASS_CODE_I); return '{'; } YY_BREAK -case 60: +case 61: YY_RULE_SETUP -#line 210 "lexer.l" +#line 225 "lexer.l" { BEGIN(C_CODE); parenth_depth=1; @@ -1305,38 +1331,38 @@ YY_RULE_SETUP return '{'; } YY_BREAK -case 61: +case 62: YY_RULE_SETUP -#line 218 "lexer.l" +#line 233 "lexer.l" { BEGIN(INITIAL); return '}'; } YY_BREAK -case 62: +case 63: YY_RULE_SETUP -#line 223 "lexer.l" +#line 238 "lexer.l" ; /*ignore*/ YY_BREAK -case 63: +case 64: YY_RULE_SETUP -#line 225 "lexer.l" +#line 240 "lexer.l" { yylval.line = line_no; return yytext[0]; } YY_BREAK -case 64: +case 65: YY_RULE_SETUP -#line 230 "lexer.l" +#line 245 "lexer.l" ; /*ignore*/ YY_BREAK -case 65: +case 66: YY_RULE_SETUP -#line 231 "lexer.l" +#line 246 "lexer.l" ECHO; YY_BREAK -#line 1340 "lex.yy.c" +#line 1366 "lex.yy.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(COMMENT): case YY_STATE_EOF(C_CODE): @@ -1631,7 +1657,7 @@ static yy_state_type yy_get_previous_state() while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 240 ) + if ( yy_current_state >= 248 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1661,11 +1687,11 @@ yy_state_type yy_current_state; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 240 ) + if ( yy_current_state >= 248 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 239); + yy_is_jam = (yy_current_state == 247); if ( ! yy_is_jam ) *yy_state_ptr++ = yy_current_state; @@ -2223,4 +2249,4 @@ int main() return 0; } #endif -#line 231 "lexer.l" +#line 246 "lexer.l" diff --git a/src/lexer.l b/src/lexer.l index 0037b85..aabc7ad 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -24,6 +24,9 @@ #include #include "parse.h" +#include "main.h" + +extern gboolean for_cpp; static int parenth_depth = 0; static int before_comment = INITIAL; @@ -165,6 +168,18 @@ class { return CLASS; } +class|this { + if(for_cpp) { + char *s; + s = g_strdup_printf("'%s' keyword should not " + "be used when generating " + "C++ code",yytext); + print_error(TRUE,s, line_no); + g_free(s); + } + REJECT; + } + from {return FROM;} void {return VOID;} diff --git a/src/main.c b/src/main.c index d706cef..35ebda6 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "tree.h" #include "parse.h" @@ -57,9 +59,11 @@ static int overrides = 0; FILE *out; FILE *outh; -int exit_on_warn = FALSE; -int exit_on_error = TRUE; -int got_error = FALSE; +gboolean no_touch_headers = FALSE; +gboolean for_cpp = FALSE; +gboolean exit_on_warn = FALSE; +gboolean exit_on_error = TRUE; +gboolean got_error = FALSE; void print_error(int is_warn, char *error,int line) @@ -171,7 +175,55 @@ make_bases(void) } static void -def_methods(Class *c) +print_type(FILE *fp, Type *t) +{ + char *s; + int i; + s = remove_sep(t->name); + out_printf(fp,"%s ",s); + g_free(s); + + for(i=0;istars;i++) + out_printf(fp,"*"); +} + +static void +print_method(FILE *fp, char *typeprefix, char *nameprefix, + char *namepostfix,char *postfix, Method *m, + gboolean no_funcbase) +{ + GList *li; + + out_printf(fp,"%s",typeprefix); + print_type(fp,m->mtype); + if(no_funcbase) + out_printf(fp,"%s%s%s(", + nameprefix,m->id,namepostfix); + else + out_printf(fp,"%s%s_%s%s(", + nameprefix,funcbase,m->id,namepostfix); + + if(m->args) { + for(li=m->args;li;li=g_list_next(li)) { + FuncArg *arg = li->data; + print_type(fp,arg->atype); + if(li->next) + out_printf(fp,"%s, ",arg->name); + else + out_printf(fp,"%s",arg->name); + + } + if(m->vararg) + out_printf(fp,", ..."); + } else { + out_printf(fp,"void"); + } + out_printf(fp,")%s",postfix); +} + + +static void +make_method_pointers(Class *c) { GList *li; @@ -185,46 +237,50 @@ def_methods(Class *c) m->scope == CLASS_INIT_METHOD || m->scope == OVERRIDE_METHOD) continue; - - out_printf(out,"#define %s %s_%s\n",m->id,funcbase,m->id); + + /* in C++ mode don't alias new */ + if(for_cpp && strcmp(m->id,"new")==0) + continue; + + print_method(out,"static ","(* ",") ","",m,TRUE); + out_printf(out," = %s_%s;\n",funcbase,m->id); } } out_printf(out,"\n"); } static void -undef_methods(Class *c) +add_bad_hack_to_avoid_unused_warnings(Class *c) { GList *li; - out_printf(out,"\n"); + out_printf(out,"\n\n/*REALLY BAD HACK\n" + " This is to avoid unused warnings if you don't call\n" + " some method, it pollutes the namespace but the call\n" + " is weird enough. I need to find a better way to do\n" + " this */\n"); + out_printf(out,"void __%s_really_bad_hack_to_avoid_warnings(void);\n", + funcbase); + out_printf(out,"void\n__%s_really_bad_hack_to_avoid_warnings(void)\n" + "{\n",funcbase); for(li=c->nodes;li;li=g_list_next(li)) { Node *node = li->data; if(node->type == METHOD_NODE) { Method *m = (Method *)node; - + if(m->scope == INIT_METHOD || m->scope == CLASS_INIT_METHOD || m->scope == OVERRIDE_METHOD) continue; - - out_printf(out,"#undef %s\n",m->id); + + /* in C++ mode we don't alias new */ + if(for_cpp && strcmp(m->id,"new")==0) + continue; + + out_printf(out,"\t((void (*)(void))%s)();\n",m->id); } } - out_printf(out,"\n"); -} - -static void -print_type(FILE *fp, Type *t) -{ - char *s; - int i; - s = remove_sep(t->name); - out_printf(fp,"%s ",s); - g_free(s); - - for(i=0;istars;i++) - out_printf(fp,"*"); + out_printf(out,"}\n\n"); } static void @@ -238,35 +294,6 @@ put_variable(Variable *v) out_printf(outh,"%s;\n",v->id); } -static void -print_method(FILE *fp, char *typeprefix, char *nameprefix, - char *namepostfix,char *postfix, Method *m) -{ - GList *li; - - out_printf(fp,"%s",typeprefix); - print_type(fp,m->mtype); - out_printf(fp,"%s%s_%s%s(", - nameprefix,funcbase,m->id,namepostfix); - - if(m->args) { - for(li=m->args;li;li=g_list_next(li)) { - FuncArg *arg = li->data; - print_type(fp,arg->atype); - if(li->next) - out_printf(fp,"%s, ",arg->name); - else - out_printf(fp,"%s",arg->name); - - } - if(m->vararg) - out_printf(fp,", ..."); - } else { - out_printf(fp,"void"); - } - out_printf(fp,")%s\n",postfix); -} - static void put_vs_method(Method *m) { @@ -278,7 +305,7 @@ put_vs_method(Method *m) m->scope != PRIVATE_VIRTUAL_METHOD) return; - print_method(outh,"\t","(* ",") ",";",m); + print_method(outh,"\t","(* ",") ",";\n",m,TRUE); } static void @@ -293,7 +320,7 @@ put_pub_method(Method *m) m->scope == PRIVATE_VIRTUAL_METHOD) return; - print_method(outh,"","\t","\t",";",m); + print_method(outh,"","\t","\t",";\n",m,FALSE); } static void @@ -306,16 +333,16 @@ put_priv_method_prot(Method *m) m->scope == PRIVATE_SIGNAL_FIRST_METHOD || m->scope == PRIVATE_VIRTUAL_METHOD) { if(m->cbuf) - print_method(out,"static ","_real_"," ",";",m); - print_method(out,"static ",""," ",";",m); + print_method(out,"static ","_real_"," ",";\n",m,FALSE); + print_method(out,"static ",""," ",";\n",m,FALSE); } else if(m->scope == SIGNAL_LAST_METHOD || m->scope == SIGNAL_FIRST_METHOD || m->scope == VIRTUAL_METHOD) { if(!m->cbuf) return; - print_method(out,"static ","_real_"," ",";",m); + print_method(out,"static ","_real_"," ",";\n",m,FALSE); } else { - print_method(out,"static ",""," ",";",m); + print_method(out,"static ",""," ",";\n",m,FALSE); } } @@ -427,10 +454,21 @@ add_signal_prots(Method *m) "\trfunc = (%s)func;\n\n" "\t(*rfunc)((%s *)object",s,s,typebase); if(strcmp(m->gtktypes->next->data,"NONE")!=0) { + GList *ali = m->args->next; for(i=0,li=m->gtktypes->next;li; i++,li=g_list_next(li)) { - out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])", - (char *)li->data,i); + if(!for_cpp || !ali) + out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])", + (char *)li->data,i); + else { + FuncArg *fa = ali->data; + out_printf(out, ",\n\t\t("); + print_type(out,fa->atype); + out_printf(out, ")GTK_VALUE_%s(args[%d])", + (char *)li->data,i); + } + + if(ali) ali = ali->next; } } out_printf(out, ",\n\t\tfunc_data);\n}\n\n"); @@ -445,10 +483,21 @@ add_signal_prots(Method *m) s,(char *)m->gtktypes->data, g_list_length(m->gtktypes)-1,typebase); if(strcmp(m->gtktypes->next->data,"NONE")!=0) { + GList *ali = m->args->next; for(i=0,li=m->gtktypes->next;li; i++,li=g_list_next(li)) { - out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])", - (char *)li->data,i); + if(!for_cpp || !ali) + out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])", + (char *)li->data,i); + else { + FuncArg *fa = ali->data; + out_printf(out, ",\n\t\t("); + print_type(out,fa->atype); + out_printf(out, ")GTK_VALUE_%s(args[%d])", + (char *)li->data,i); + } + + if(ali) ali = ali->next; } } out_printf(out, ",\n\t\tfunc_data);\n}\n\n"); @@ -729,14 +778,14 @@ add_inits(Class *c) if(m->scope == INIT_METHOD) { if(m->line_no>0) out_addline_infile(out,m->line_no); - print_method(out,"static ","\n"," ","",m); + print_method(out,"static ","\n"," ","\n",m,FALSE); if(m->line_no>0) out_addline_outfile(out); out_printf(out,"{\n"); } else if(m->scope == CLASS_INIT_METHOD) { if(m->line_no>0) out_addline_infile(out,m->line_no); - print_method(out,"static ","\n"," ","",m); + print_method(out,"static ","\n"," ","\n",m,FALSE); if(m->line_no>0) out_addline_outfile(out); out_printf(out,"{\n"); @@ -747,15 +796,17 @@ add_inits(Class *c) "gtk_object_class = " "(GtkObjectClass*) %s;\n", ((FuncArg *)m->args->data)->name); - + if(overrides>0) add_overrides(c, ((FuncArg *)m->args->data)->name, (signals>0 || arguments>0)); - out_printf(out,"\n\tparent_class = " - "gtk_type_class (%s_get_type ());\n", - pfuncbase); + out_printf(out,"\n\tparent_class = "); + if(for_cpp) + out_printf(out,"(%sClass *)",ptypebase); + out_printf(out,"gtk_type_class (%s_get_type ());\n", + pfuncbase); if(signals>0) add_signals(c); @@ -764,6 +815,7 @@ add_inits(Class *c) if(arguments>0) make_arguments(c); + } else continue; @@ -789,8 +841,8 @@ add_getset_arg(Class *c, int is_set) "\tGtkArg *arg,\n" "\tguint arg_id)\n" "{\n" - "\t%s *self, *this;\n\n" - "\tself = this = %s (object);\n\n" + "\t%s *self;\n\n" + "\tself = %s (object);\n\n" "\tswitch (arg_id) {\n", is_set?"set":"get",typebase,macrobase); @@ -921,12 +973,12 @@ put_method(Method *m) switch(m->scope) { case PUBLIC_SCOPE: out_addline_infile(out,m->line_no); - print_method(out,"","\n"," ","",m); + print_method(out,"","\n"," ","\n",m,FALSE); print_method_body(m,TRUE); break; case PRIVATE_SCOPE: out_addline_infile(out,m->line_no); - print_method(out,"static ","\n"," ","",m); + print_method(out,"static ","\n"," ","\n",m,FALSE); print_method_body(m,TRUE); break; case PRIVATE_SIGNAL_FIRST_METHOD: @@ -935,7 +987,7 @@ put_method(Method *m) case SIGNAL_FIRST_METHOD: case SIGNAL_LAST_METHOD: out_addline_infile(out,m->line_no); - print_method(out,private?"static ":"","\n"," ","",m); + print_method(out,private?"static ":"","\n"," ","\n",m,FALSE); out_addline_outfile(out); out_printf(out,"{\n"); s = g_strdup(m->id); @@ -973,25 +1025,25 @@ put_method(Method *m) if(!m->cbuf) break; out_addline_infile(out,m->line_no); - print_method(out,"static ","\n_real_"," ","",m); + print_method(out,"static ","\n_real_"," ","\n",m,FALSE); print_method_body(m,FALSE); break; case PRIVATE_VIRTUAL_METHOD: private = TRUE; case VIRTUAL_METHOD: out_addline_infile(out,m->line_no); - print_method(out,private?"static ":"","\n"," ","",m); + print_method(out,private?"static ":"","\n"," ","\n",m,FALSE); out_addline_outfile(out); out_printf(out,"{\n" - "\t%sClass *class;\n",typebase); + "\t%sClass *klass;\n",typebase); print_preconditions(m); - out_printf(out,"\tclass = %s_CLASS(GTK_OBJECT(%s)->klass);\n\n" - "\tif(class->%s)\n", + out_printf(out,"\tklass = %s_CLASS(GTK_OBJECT(%s)->klass);\n\n" + "\tif(klass->%s)\n", macrobase, ((FuncArg *)m->args->data)->name, m->id); if(strcmp(m->mtype->name,"void")==0 && m->mtype->stars==0) { GList *li; - out_printf(out,"\t\t(*class->%s)(%s",m->id, + out_printf(out,"\t\t(*klass->%s)(%s",m->id, ((FuncArg *)m->args->data)->name); for(li=m->args->next;li;li=g_list_next(li)) { FuncArg *fa = li->data; @@ -1000,7 +1052,7 @@ put_method(Method *m) out_printf(out,");\n}\n"); } else { GList *li; - out_printf(out,"\t\treturn (*class->%s)(%s",m->id, + out_printf(out,"\t\treturn (*klass->%s)(%s",m->id, ((FuncArg *)m->args->data)->name); for(li=m->args->next;li;li=g_list_next(li)) { FuncArg *fa = li->data; @@ -1017,12 +1069,12 @@ put_method(Method *m) if(!m->cbuf) break; out_addline_infile(out,m->line_no); - print_method(out,"static ","\n_real_"," ","",m); + print_method(out,"static ","\n_real_"," ","\n",m,FALSE); print_method_body(m,FALSE); break; case OVERRIDE_METHOD: out_addline_infile(out,m->line_no); - print_method(out,"static ","\n"," ","",m); + print_method(out,"static ","\n"," ","\n",m,FALSE); print_method_body(m,TRUE); break; default: @@ -1231,8 +1283,14 @@ open_files(void) { char *outfile,*outfileh; - outfile = g_strconcat(filebase,".c",NULL); - outfileh = g_strconcat(filebase,".h",NULL); + if(!for_cpp) + outfile = g_strconcat(filebase,".c",NULL); + else + outfile = g_strconcat(filebase,".cc",NULL); + if(no_touch_headers) + outfileh = g_strconcat("#gob#",filebase,".h#gob#",NULL); + else + outfileh = g_strconcat(filebase,".h",NULL); out = fopen(outfile,"w"); if(!out) { @@ -1252,8 +1310,8 @@ generate_outfiles(void) time_t curtime; time(&curtime); - out_printf(outh,"/* Generated by GOB (v%s) on %s" - " (do not edit directly) */\n\n",VERSION,ctime(&curtime)); + out_printf(outh,"/* Generated by GOB (v%s)" + " (do not edit directly) */\n\n",VERSION); out_printf(out,"/* Generated by GOB (v%s) on %s" " (do not edit directly) */\n\n",VERSION,ctime(&curtime)); @@ -1263,9 +1321,10 @@ generate_outfiles(void) "#include \n\n",p,p); g_free(p); - out_printf(outh,"#ifdef __cplusplus\n" - "extern \"C\" {\n" - "#endif /* __cplusplus */\n\n"); + if(!for_cpp) + out_printf(outh,"#ifdef __cplusplus\n" + "extern \"C\" {\n" + "#endif /* __cplusplus */\n\n"); out_printf(out,"#include \"%s.h\"\n\n",filebase); @@ -1360,11 +1419,11 @@ generate_outfiles(void) add_get_type(); - def_methods(c); + make_method_pointers(c); out_printf(out,"#define GET_NEW (gtk_type_new(%s_get_type()))\n", - funcbase); - + funcbase); + add_inits(c); if(arguments>0) { @@ -1381,7 +1440,7 @@ generate_outfiles(void) out_printf(out,"#undef GET_NEW\n"); - undef_methods(c); + add_bad_hack_to_avoid_unused_warnings(c); g_free(otype); g_free(ptype); @@ -1389,10 +1448,11 @@ generate_outfiles(void) g_assert_not_reached(); } - out_printf(outh,"\n#ifdef __cplusplus\n" - "}\n" - "#endif /* __cplusplus */\n\n" - "#endif"); + if(!for_cpp) + out_printf(outh,"\n#ifdef __cplusplus\n" + "}\n" + "#endif /* __cplusplus */\n"); + out_printf(outh,"\n#endif"); } #if 0 @@ -1412,7 +1472,10 @@ print_help(void) fprintf(stderr,"Options:\n" "\t--help,-h,-? Display this help\n" "\t--exit-on-warn,-w Exit with an error on warnings\n" - "\t--no-exit-on-warn Don't exit on warnings [default]\n"); + "\t--no-exit-on-warn Don't exit on warnings [default]\n" + "\t--for-cpp Create C++ files\n" + "\t--no-touch-headers Don't touch headers unless they " + "really changed\n"); } static void @@ -1441,6 +1504,10 @@ parse_options(int argc, char *argv[]) exit_on_warn = TRUE; } else if(strcmp(argv[i],"--no-exit-on-warn")==0) { exit_on_warn = FALSE; + } else if(strcmp(argv[i],"--for-cpp")==0) { + for_cpp = TRUE; + } else if(strcmp(argv[i],"--no-touch-headers")==0) { + no_touch_headers = TRUE; } else if(strcmp(argv[i],"--")==0) { /*further arguments are files*/ no_opts = TRUE; @@ -1473,6 +1540,33 @@ parse_options(int argc, char *argv[]) } } +static void +compare_and_move_header(void) +{ + char *hfnew = g_strconcat("#gob#",filebase,".h#gob#",NULL); + char *hf = g_strconcat(filebase,".h",NULL); + struct stat s; + if(stat(hf,&s)==0) { + char *s; + s = g_strdup_printf("cmp '%s' '%s' > /dev/null",hf,hfnew); + if(system(s)==0) { + if(unlink(hfnew)!=0) + print_error(FALSE,"Can't remove new header file",0); + g_free(hfnew); + g_free(hf); + g_free(s); + return; + } + g_free(s); + if(unlink(hf)!=0) + print_error(FALSE,"Can't remove old header file",0); + } + if(rename(hfnew,hf)!=0) + print_error(FALSE,"Can't rename new header file",0); + g_free(hfnew); + g_free(hf); +} + int main(int argc, char *argv[]) { @@ -1544,6 +1638,9 @@ main(int argc, char *argv[]) fclose(out); fclose(outh); + + if(no_touch_headers) + compare_and_move_header(); #if 0 poptFreeContext(optCon); diff --git a/src/out.c b/src/out.c index 3183635..6b3f48f 100644 --- a/src/out.c +++ b/src/out.c @@ -7,6 +7,8 @@ extern FILE *out; extern FILE *outh; +extern gboolean for_cpp; + extern char *filename; extern char *filebase; @@ -62,7 +64,10 @@ out_addline_outfile(FILE *fp) { if(fp == out) { outline++; - fprintf(fp,"#line %d \"%s.c\"\n",outline,filebase); + if(!for_cpp) + fprintf(fp,"#line %d \"%s.c\"\n",outline,filebase); + else + fprintf(fp,"#line %d \"%s.cc\"\n",outline,filebase); } else if(fp == outh) { outhline++; fprintf(fp,"#line %d \"%s.h\"\n",outhline,filebase); diff --git a/src/parse.c b/src/parse.c index 51a215a..101d2e6 100644 --- a/src/parse.c +++ b/src/parse.c @@ -293,9 +293,9 @@ static const short yyrline[] = { 0, 357, 360, 363, 366, 369, 374, 377, 380, 385, 386, 389, 401, 413, 416, 428, 433, 438, 441, 446, 447, 451, 461, 471, 481, 487, 492, 497, 518, 519, 523, - 524, 527, 528, 544, 559, 562, 563, 566, 567, 570, - 573, 583, 584, 587, 600, 604, 608, 612, 616, 620, - 626, 627, 631 + 524, 527, 528, 539, 549, 552, 553, 556, 557, 560, + 563, 573, 574, 577, 590, 594, 598, 602, 606, 610, + 616, 617, 621 }; #endif @@ -1531,12 +1531,7 @@ case 73: { vararg = FALSE; has_self = TRUE; - if(strcmp(yyvsp[0].id,"this")==0) { - push_self(yyvsp[0].id); - print_error(TRUE,_("Use of 'this' is " - "depreciated, use 'self' " - "instead"),line_no); - } else if(strcmp(yyvsp[0].id,"self")==0) + if(strcmp(yyvsp[0].id,"self")==0) push_self(yyvsp[0].id); else { g_free(yyvsp[0].id); @@ -1546,15 +1541,10 @@ case 73: ; break;} case 74: -#line 544 "parse.y" +#line 539 "parse.y" { has_self = TRUE; - if(strcmp(yyvsp[-2].id,"this")==0) { - push_self(yyvsp[-2].id); - print_error(TRUE,_("Use of 'this' is " - "depreciated, use 'self' " - "instead"),line_no); - } else if(strcmp(yyvsp[-2].id,"self")==0) + if(strcmp(yyvsp[-2].id,"self")==0) push_self(yyvsp[-2].id); else { g_free(yyvsp[-2].id); @@ -1564,33 +1554,33 @@ case 74: ; break;} case 75: -#line 559 "parse.y" +#line 549 "parse.y" { has_self = FALSE; ; break;} case 76: -#line 562 "parse.y" +#line 552 "parse.y" { vararg = TRUE; ; break;} case 77: -#line 563 "parse.y" +#line 553 "parse.y" { vararg = FALSE; ; break;} case 78: -#line 566 "parse.y" +#line 556 "parse.y" { ; ; break;} case 79: -#line 567 "parse.y" +#line 557 "parse.y" { ; ; break;} case 80: -#line 570 "parse.y" +#line 560 "parse.y" { push_funcarg(yyvsp[0].id); ; break;} case 81: -#line 573 "parse.y" +#line 563 "parse.y" { if(strcmp(yyvsp[-2].id,"check")!=0) { yyerror(_("parse error")); @@ -1601,15 +1591,15 @@ case 81: ; break;} case 82: -#line 583 "parse.y" +#line 573 "parse.y" { ; ; break;} case 83: -#line 584 "parse.y" +#line 574 "parse.y" { ; ; break;} case 84: -#line 587 "parse.y" +#line 577 "parse.y" { if(strcmp(yyvsp[0].id,"type")==0) { Node *node = new_check(TYPE_CHECK,NULL); @@ -1625,60 +1615,60 @@ case 84: ; break;} case 85: -#line 600 "parse.y" +#line 590 "parse.y" { Node *node = new_check(GT_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 86: -#line 604 "parse.y" +#line 594 "parse.y" { Node *node = new_check(LT_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 87: -#line 608 "parse.y" +#line 598 "parse.y" { Node *node = new_check(GE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 88: -#line 612 "parse.y" +#line 602 "parse.y" { Node *node = new_check(LE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 89: -#line 616 "parse.y" +#line 606 "parse.y" { Node *node = new_check(EQ_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 90: -#line 620 "parse.y" +#line 610 "parse.y" { Node *node = new_check(NE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 91: -#line 626 "parse.y" +#line 616 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 92: -#line 627 "parse.y" +#line 617 "parse.y" { yyval.id = g_strconcat("-",yyvsp[0].id,NULL); g_free(yyvsp[0].id); ; break;} case 93: -#line 631 "parse.y" +#line 621 "parse.y" { yyval.id = yyvsp[0].id; ; break;} } @@ -1903,5 +1893,5 @@ yyerrhandle: } return 1; } -#line 634 "parse.y" +#line 624 "parse.y" diff --git a/src/parse.y b/src/parse.y index 7648232..46fdf6e 100644 --- a/src/parse.y +++ b/src/parse.y @@ -528,12 +528,7 @@ funcargs: VOID { vararg = FALSE; has_self = FALSE; } | TOKEN { vararg = FALSE; has_self = TRUE; - if(strcmp($1,"this")==0) { - push_self($1); - print_error(TRUE,_("Use of 'this' is " - "depreciated, use 'self' " - "instead"),line_no); - } else if(strcmp($1,"self")==0) + if(strcmp($1,"self")==0) push_self($1); else { g_free($1); @@ -543,12 +538,7 @@ funcargs: VOID { vararg = FALSE; has_self = FALSE; } } | TOKEN ',' arglist { has_self = TRUE; - if(strcmp($1,"this")==0) { - push_self($1); - print_error(TRUE,_("Use of 'this' is " - "depreciated, use 'self' " - "instead"),line_no); - } else if(strcmp($1,"self")==0) + if(strcmp($1,"self")==0) push_self($1); else { g_free($1); diff --git a/src/test.gob b/src/test.gob index 1c522a6..5dd5c2e 100644 --- a/src/test.gob +++ b/src/test.gob @@ -18,7 +18,7 @@ class Gtk:Weird:Button from Gtk:Button { GtkWeirdButton *but = GTK_WEIRD_BUTTON(object); but->i=0; } - class_init(class); + class_init(klass); public GtkWidget * new(int j (check > 0)) { GtkWidget *ret; ret = GTK_WIDGET (GET_NEW); -- 2.43.0