X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/7231d76fbf4ae0b501af648e1216b88714aa7353..5d4e3f65125a1e67702b7fbd4096d5e2fd3ec798:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index e102286..1a58a9c 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -1,5 +1,7 @@ /* GOB C Preprocessor - * Copyright (C) 1999 the Free Software Foundation. + * Copyright (C) 1999-2000 the Free Software Foundation. + * Copyright (C) 2000 Eazel, Inc. + * Copyright (C) 2001-2009 George (Jiri) Lebl * * Author: George Lebl * @@ -21,8 +23,10 @@ %{ #include "config.h" -#include +#include #include +#include +#include #include "treefuncs.h" #include "parse.h" @@ -30,7 +34,13 @@ #include "util.h" static int parenth_depth = 0; -static int before_comment = INITIAL; +static int before_comment +/* New flex is on drugs */ +#if defined(FLEX_SCANNER) && ! defined(INITIAL) + = 0; +#else + = INITIAL; +#endif static gboolean class_after_c = FALSE; static int code_type = CCODE; static int before_string; @@ -48,6 +58,8 @@ GList *include_files = NULL; static int look_for_includes = 0; int line_no = 1; +/* last filename parsed from a #line directive */ +char *hline_filename = NULL; static void clear_cbuf(void) @@ -94,6 +106,7 @@ int yylex(void); %x C_CODE %x CODE_STRING %x CLASS_CODE +%x CLASS_STRING %x CLASS_CODE_I %x PROPERTY_CODE %x PROPERTY_CODE_I @@ -138,7 +151,45 @@ REJECT; } \/\/.*$ { ; /*comment, ignore*/ } -^#[ \t]*include[ \t][<"][^\n">]*[>"] { + +<*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? { + char *p; + char *number; + char *filename; + char *str=g_strdup(yytext); + + /* find first digit of line number */ + p=str; + while(*p&&!isdigit(*p)) p++; + number=p; + + /* find end of line number */ + while(*p&&isdigit(*p)) p++; + if(*p) *p++=0; + + /* find beginning of filename */ + p=strchr(p,'"'); + if(p) p++; + filename=p; + + /* find end of filename */ + if(p) p=strchr(p,'"'); + if(p) *p=0; + + /* stash number (minus one because we don't count this line) */ + if(number) line_no=atoi(number)-1; + + /* stash filename */ + if(filename) { + if(hline_filename) g_free(hline_filename); + hline_filename=g_strdup(filename); + } + + /* clean up */ + g_free(str); +} + +^#[ \t]*include[ \t][<"][^\n\r">]*[>"] { if(look_for_includes==1) { char *p; char *file; @@ -148,9 +199,11 @@ REJECT; file++; p = strchr(file,'"'); if(!p) p = strchr(file,'>'); - *p = '\0'; - include_files = g_list_prepend(include_files,g_strdup(file)); - g_free(str); + if (p != NULL) { + *p = '\0'; + include_files = g_list_prepend(include_files,g_strdup(file)); + g_free(str); + } } REJECT; } @@ -189,7 +242,7 @@ REJECT; BEGIN(CLASS_CODE_I); add_gtk_doc_func(); } -^[ \t]*\*\ { +^[ \t]*\*[ \t] { fflush(stdout); add_to_cbuf(" * "); BEGIN(GTK_DOC_LINE); @@ -219,6 +272,7 @@ REJECT; \/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ } \/\/.*$ { ; /*comment, ignore*/ } \/\/.*$ { ; /*comment, ignore*/ } +\/\/.*$ { ; /*comment, ignore*/ } \/\* {BEGIN(COMMENT); before_comment = INITIAL; } \/\* { add_to_cbuf(yytext); @@ -227,6 +281,7 @@ REJECT; } \/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; } \/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; } +\/\* {BEGIN(COMMENT); before_comment = PROPERTY_CODE_I; } \*\/ { if(before_comment == C_CODE) add_to_cbuf(yytext); BEGIN(before_comment); @@ -291,6 +346,14 @@ REJECT; 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; + } ^\%\} { BEGIN(INITIAL); yylval.cbuf = cbuf; @@ -367,6 +430,10 @@ class { return CLASS; } +error { return ERROR; } +enum { return ENUM; } +flags { return FLAGS; } + ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ { int maj = 0, min = 0, pl = 0; int rmaj = 0, rmin = 0, rpl = 0; @@ -403,7 +470,7 @@ class { "(this is %s)\n" "To upgrade your gob, see: " "http://www.5z.com/jirka/gob.html", - maj, VERSION); + effective_maj, VERSION); } } @@ -419,6 +486,22 @@ class { } from {return FROM;} +\" { + BEGIN(CLASS_STRING); + before_string = CLASS_CODE; + add_to_cbuf(yytext); + } +\\. { add_to_cbuf(yytext); } +\" { + BEGIN(before_string); + add_to_cbuf(yytext); + yylval.id = cbuf->str; + g_string_free (cbuf, FALSE); + cbuf = NULL; + return STRING; + } +. { add_to_cbuf(yytext); } +\n { add_to_cbuf(yytext); } void {return VOID;} struct {return STRUCT;} @@ -481,25 +564,34 @@ class { return ')'; } -0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* { +0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* { yylval.id = g_strdup(yytext); return NUMBER; } -[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ { +[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z0-9_]*)+ { + /* This is cpp kind of token thingie */ + if (for_cpp) { + yylval.id = g_strdup(yytext); + return TOKEN; + } else { + REJECT; + } + } +[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z_][A-Za-z0-9_]*)+ { /* this one is for a classname with a namespace */ yylval.id = g_strdup(yytext); return TYPETOKEN; } -:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* { +:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z_][A-Za-z0-9_]*)* { /* this is for a classname with an empty namespace */ yylval.id = g_strdup(yytext); return TYPETOKEN; } -[A-Za-z_][A-Za-z0-9_]* { +[A-Za-z_][A-Za-z0-9_]* { yylval.id = g_strdup(yytext); return TOKEN; } -\'\\.\'|\'.\' { +\'\\.\'|\'.\' { yylval.id = g_strdup(yytext); return SINGLE_CHAR; } @@ -508,12 +600,16 @@ class { yylval.id = g_strdup(yytext); return ARRAY_DIM; } - +:[0-9]+ { + /* cheat for bitfield */ + yylval.id = g_strdup(yytext); + return ARRAY_DIM; + } \{ { BEGIN(CLASS_CODE_I); return '{'; } -\{ { +\{ { BEGIN(C_CODE); parenth_depth=1; class_after_c = TRUE; @@ -527,24 +623,23 @@ class { return '}'; } -[\t ] ; /*ignore*/ +[\f\t ] ; /*ignore*/ + +<*>[\n\r] ; /*ignore*/ + <*>. { yylval.line = line_no; return yytext[0]; } -<*>[\n\r] ; /*ignore*/ +^[ \t]*prealloc[ \t]+[0-9]+[ \t]*$ { + char *p; + int t; + p = strchr (yytext,'p'); + g_assert (p); /* we MUST have found it */ + sscanf (p, "prealloc %d", &t); + prealloc=t; + } %% - -/* Ugly warning avoiding */ -#ifdef FLEX_SCANNER -static void warning_avoider(void) G_GNUC_UNUSED; -static void warning_avoider(void) { - yy_flex_realloc(NULL, 0); - yyunput(0, NULL); - warning_avoider(); -} -#endif -