diff options
Diffstat (limited to 'Source/CParse/cscanner.c')
-rw-r--r-- | Source/CParse/cscanner.c | 118 |
1 files changed, 12 insertions, 106 deletions
diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 14a4f4bd0..e91dfb3d3 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -9,14 +9,12 @@ * scanner.c * * SWIG tokenizer. This file is a wrapper around the generic C scanner - * found in Swig/scanner.c. Extra logic is added both to accomodate the + * found in Swig/scanner.c. Extra logic is added both to accommodate the * bison-based grammar and certain peculiarities of C++ parsing (e.g., * operator overloading, typedef resolution, etc.). This code also splits * C identifiers up into keywords and SWIG directives. * ----------------------------------------------------------------------------- */ -char cvsroot_cscanner_c[] = "$Id$"; - #include "cparse.h" #include "parser.h" #include <string.h> @@ -45,8 +43,6 @@ static int num_brace = 0; static int last_brace = 0; static int last_id = 0; static int rename_active = 0; -static int expanding_macro = 0; -static int follow_locators = 0; /* ----------------------------------------------------------------------------- * Swig_cparse_cplusplus() @@ -56,101 +52,6 @@ void Swig_cparse_cplusplus(int v) { cparse_cplusplus = v; } -/* ---------------------------------------------------------------------- - * locator() - * - * Support for locator strings. These are strings of the form - * @SWIG:filename,line,id@ emitted by the SWIG preprocessor. They - * are primarily used for macro line number reporting - * ---------------------------------------------------------------------- */ - -typedef struct Locator { - String *filename; - int line_number; - struct Locator *next; -} Locator; - -static Locator *locs = 0; - -/* we just use the locator to mark when active/deactive the linecounting */ - -static void scanner_locator(String *loc) { - if (!follow_locators) { - if (Equal(loc, "/*@SWIG@*/")) { - /* End locator. */ - if (expanding_macro) - --expanding_macro; - } else { - /* Begin locator. */ - ++expanding_macro; - } - /* Freeze line number processing in Scanner */ - Scanner_freeze_line(scan,expanding_macro); - } else { - int c; - Locator *l; - Seek(loc, 7, SEEK_SET); - c = Getc(loc); - if (c == '@') { - /* Empty locator. We pop the last location off */ - if (locs) { - Scanner_set_location(scan,locs->filename,locs->line_number); - cparse_file = locs->filename; - cparse_line = locs->line_number; - l = locs->next; - free(locs); - locs = l; - } - return; - } - - /* We're going to push a new location */ - l = (Locator *) malloc(sizeof(Locator)); - l->filename = cparse_file; - l->line_number = cparse_line; - l->next = locs; - locs = l; - - /* Now, parse the new location out of the locator string */ - { - String *fn = NewStringEmpty(); - /* Putc(c, fn); */ - - while ((c = Getc(loc)) != EOF) { - if ((c == '@') || (c == ',')) - break; - Putc(c, fn); - } - cparse_file = Swig_copy_string(Char(fn)); - Clear(fn); - cparse_line = 1; - /* Get the line number */ - while ((c = Getc(loc)) != EOF) { - if ((c == '@') || (c == ',')) - break; - Putc(c, fn); - } - cparse_line = atoi(Char(fn)); - Clear(fn); - - /* Get the rest of it */ - while ((c = Getc(loc)) != EOF) { - if (c == '@') - break; - Putc(c, fn); - } - /* Swig_diagnostic(cparse_file, cparse_line, "Scanner_set_location\n"); */ - Scanner_set_location(scan,cparse_file,cparse_line); - Delete(fn); - } - } -} - -void Swig_cparse_follow_locators(int v) { - follow_locators = v; -} - - /* ---------------------------------------------------------------------------- * scanner_init() * @@ -200,10 +101,11 @@ void start_inline(char *text, int line) { * ----------------------------------------------------------------------------- */ void skip_balanced(int startchar, int endchar) { + int start_line = Scanner_line(scan); Clear(scanner_ccode); if (Scanner_skip_balanced(scan,startchar,endchar) < 0) { - Swig_error(Scanner_file(scan),Scanner_errline(scan), "Missing '%c'. Reached end of input.\n", endchar); + Swig_error(cparse_file, start_line, "Missing '%c'. Reached end of input.\n", endchar); return; } @@ -446,7 +348,7 @@ static int yylook(void) { String *cmt = Scanner_text(scan); char *loc = Char(cmt); if ((strncmp(loc,"/*@SWIG",7) == 0) && (loc[Len(cmt)-3] == '@')) { - scanner_locator(cmt); + Scanner_locator(scan, cmt); } } break; @@ -483,7 +385,7 @@ void scanner_clear_rename() { rename_active = 0; } -/* Used to push a ficticious token into the scanner */ +/* Used to push a fictitious token into the scanner */ static int next_token = 0; void scanner_next_token(int tok) { next_token = tok; @@ -820,7 +722,7 @@ int yylex(void) { if (strcmp(yytext, "typename") == 0) return (TYPENAME); if (strcmp(yytext, "template") == 0) { - yylval.ivalue = cparse_line; + yylval.intvalue = cparse_line; return (TEMPLATE); } if (strcmp(yytext, "delete") == 0) { @@ -862,7 +764,7 @@ int yylex(void) { return (SIZEOF); if (strcmp(yytext, "typedef") == 0) { - yylval.ivalue = 0; + yylval.intvalue = 0; return (TYPEDEF); } @@ -893,6 +795,10 @@ int yylex(void) { } if (strcmp(yytext, "%includefile") == 0) return (INCLUDE); + if (strcmp(yytext, "%beginfile") == 0) + return (BEGINFILE); + if (strcmp(yytext, "%endoffile") == 0) + return (ENDOFFILE); if (strcmp(yytext, "%val") == 0) { Swig_warning(WARN_DEPRECATED_VAL, cparse_file, cparse_line, "%%val directive deprecated (ignored).\n"); return (yylex()); @@ -904,7 +810,7 @@ int yylex(void) { if (strcmp(yytext, "%constant") == 0) return (CONSTANT); if (strcmp(yytext, "%typedef") == 0) { - yylval.ivalue = 1; + yylval.intvalue = 1; return (TYPEDEF); } if (strcmp(yytext, "%native") == 0) |