Changeset 176
- Timestamp:
- 05/18/07 23:08:24 (1 year ago)
- Files:
-
- trunk/gcc/gcc/algol60/lang-specs.h (modified) (1 diff)
- trunk/gcc/gcc/algol60/lang.c (modified) (4 diffs)
- trunk/gcc/gcc/algol60/lang.opt (modified) (1 diff)
- trunk/gcc/gcc/algol60/lexer.h (modified) (2 diffs)
- trunk/gcc/gcc/algol60/lexer.l (modified) (9 diffs)
- trunk/gcc/gcc/algol60/parser.y (modified) (1 diff)
- trunk/gcc/gcc/testsuite/algol60.dg/compile/preproc.ALG (added)
- trunk/gcc/gcc/testsuite/algol60.dg/dg.exp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gcc/gcc/algol60/lang-specs.h
r62 r176 2 2 for the Algol 60 language. */ 3 3 4 {".A60", "@a60-cpp-input", 0, 0, 0}, 5 {".ALG", "@a60-cpp-input", 0, 0, 0}, 6 {"@a60-cpp-input", 7 "cc1 -E -traditional-cpp -D_ALGOL60_ %(cpp_options) \ 8 %{E|M|MM:%(cpp_debug_options)}\ 9 %{!M:%{!MM:%{!E: -o %|.a60 |\n\ 10 algol601 -fpreprocessed %|.a60 %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0}, 11 4 12 {".a60", "@a60", 0, 0, 0}, 5 {". A60", "@a60", 0, 0, 0},6 {"@a60", "%{!E: algol601 %i %(cc1_options) %{I*}\7 %{!fsyntax-only:%(invoke_as)}} \n", 0, 0, 0},13 {".alg", "@a60", 0, 0, 0}, 14 {"@a60", "%{!E:%{!MM:%{!M:algol601 %i %(cc1_options) %{I*}\ 15 %{!fsyntax-only:%(invoke_as)}}}}\n", 0, 0, 0}, trunk/gcc/gcc/algol60/lang.c
r131 r176 90 90 int parser_trace; 91 91 int lexer_trace; 92 int preprocessed; 92 93 } 93 94 a60_options_t; … … 128 129 a60_options->parser_trace = 0; 129 130 a60_options->lexer_trace = 0; 131 a60_options->preprocessed = 0; 130 132 return CL_Algol60; 131 133 } … … 148 150 a60_options->lexer_trace = value; 149 151 return 1; 152 case OPT_fpreprocessed: 153 a60_options->preprocessed = value; 154 return 1; 150 155 }; 151 156 fprintf (stderr, "scode %ul option %s value %d\n", scode, arg, value); … … 185 190 lexer_t * a_lexer = new_lexer (a60_options->ifile, a60_options->ifname, true); 186 191 gcc_assert (a_lexer != NULL); 192 lexer_set_preprocessed (a_lexer, a60_options->preprocessed); 187 193 if (a60_options->lexer_trace) 188 194 lexer_set_logging (a_lexer, ll_debug, false); trunk/gcc/gcc/algol60/lang.opt
r104 r176 18 18 Dump AST immediately after the parse 19 19 20 fpreprocessed 21 Algol60 22 Treat the input file as preprocessed 23 20 24 ; This comment is to ensure we retain the blank line above. trunk/gcc/gcc/algol60/lexer.h
r130 r176 63 63 ATTRIBUTE_NONNULL(1); 64 64 65 /// Query the name of parsed stream, taking into account preprocessing 66 /// directives. 67 char const * lexer_pp_filename (lexer_t const * lexer) 68 ATTRIBUTE_NONNULL(1); 69 65 70 66 71 /// Fetch new token with given lexer, assign a location of given token, … … 94 99 ATTRIBUTE_NONNULL(1); 95 100 101 /// Whether lexer should recognize preprocessing output (linemarks) in 102 /// input file. 103 void lexer_set_preprocessed (lexer_t * lexer, int preprocessed) 104 ATTRIBUTE_NONNULL(1); 105 96 106 #endif//_AL60L_LEXER_H_ trunk/gcc/gcc/algol60/lexer.l
r104 r176 18 18 #include <math.h> 19 19 #include <limits.h> 20 #include <ctype.h> 20 21 21 22 static char const* private_lexer_signature = "lexer"; … … 33 34 token_kind_t current_tok; 34 35 token_kind_t prev_tok; 36 int preprocessed; 37 char * pp_filename; 38 int pp_lineno; 39 int pp_baselineno; 35 40 } lexer_rep_t; 36 41 … … 48 53 %x COMMENT 49 54 %x END_COMMENT 55 %x PREPROCESSOR 50 56 51 57 %option noyywrap … … 365 371 366 372 373 /* Preprocessor linemarker. */ 374 ^"#" { 375 lexer_rep_t * lexer = yyget_extra (yyscanner); 376 if (lexer->preprocessed) 377 BEGIN PREPROCESSOR; 378 else 379 private_lexer_invalid_character (lexer, yylineno, *yyget_text (yyscanner)); 380 } 381 382 <PREPROCESSOR>[ \t]*{DIGIT}*[ \t]*"\""[^\"]*"\""[ \t]*.*$ { 383 lexer_rep_t * lexer = yyget_extra (yyscanner); 384 char * linemarker = yyget_text (yyscanner); 385 386 // It's strange to parse tokens inside lexical analyzer by hand, but 387 // it's the easies approach... At least we know that the string 388 // matches the rule regexp, and don't have to be paranoid. 389 390 while (isspace (*linemarker)) 391 ++linemarker; 392 393 // line number... 394 char * linenumber = linemarker; 395 while (*linemarker && isdigit (*linemarker)) 396 ++linemarker; 397 *linemarker++ = 0; 398 399 while (*linemarker && isspace (*linemarker)) 400 ++linemarker; 401 402 // file name... remember to skip "\"" 403 ++linemarker; 404 char * filename = linemarker; 405 while (*linemarker != '\"') 406 ++linemarker; 407 *linemarker = 0; 408 409 free (lexer->pp_filename); 410 lexer->pp_filename = strdup (filename); 411 lexer->pp_lineno = atoi (linenumber); 412 lexer->pp_baselineno = yylineno + 1; // linemarker refers line ahead 413 414 BEGIN INITIAL; 415 } 416 417 <PREPROCESSOR>.*$ { 418 lexer_rep_t * lexer = yyget_extra (yyscanner); 419 cursor_t * csr = new_cursor (lexer->filename, yylineno); 420 log_printfc (lexer->log, ll_error, csr, 421 "unrecognized preprocessing directive"); 422 delete_cursor (csr); 423 BEGIN INITIAL; 424 } 425 426 367 427 /* identifier */ 368 428 {LETTER}({LETTER}|{DIGIT})* { … … 449 509 return private_lexer_got_eof_token (yyscanner, yylineno, NULL); 450 510 } 511 451 512 452 513 … … 498 559 ret->prev_tok = -1; 499 560 ret->managed = manage; 561 ret->preprocessed = 0; 562 563 ret->pp_filename = NULL; 564 ret->pp_lineno = 0; 565 ret->pp_baselineno = 0; 500 566 return (void*)ret; 501 567 } … … 555 621 } 556 622 623 char const * 624 lexer_pp_filename (lexer_t const * _lexer) 625 { 626 assert (_lexer != NULL); 627 lexer_rep_t * lexer = (void*)_lexer; 628 if (lexer->pp_filename) 629 return lexer->pp_filename; 630 else 631 return lexer->filename; 632 } 633 557 634 /// Procedure to write out that bad character has been hit. 558 635 /// Bad characters are considered errors. … … 630 707 // reentrant scanner anyway. 631 708 struct yyguts_t * yyg = (void*)lexer->flex_scanner; 632 loc->first_line = loc->last_line = yylineno; 709 710 int actual_lineno = yylineno; 711 int pp_lineno = actual_lineno - lexer->pp_baselineno + lexer->pp_lineno; 712 loc->first_line = loc->last_line = pp_lineno; 633 713 loc->first_column = loc->last_column = 0; 634 714 … … 679 759 return (logger_t const*)lexer->log; 680 760 } 761 762 void 763 lexer_set_preprocessed (lexer_t * _lexer, int preprocessed) 764 { 765 assert (_lexer != NULL); 766 lexer_rep_t * lexer = (void*)_lexer; 767 lexer->preprocessed = preprocessed; 768 } trunk/gcc/gcc/algol60/parser.y
r168 r176 51 51 cr_csr (parser_rep_t * parser, YYLTYPE * loc) 52 52 { 53 return new_cursor (lexer_ filename (parser->lexer), loc->first_line);53 return new_cursor (lexer_pp_filename (parser->lexer), loc->first_line); 54 54 } 55 55 trunk/gcc/gcc/testsuite/algol60.dg/dg.exp
r106 r176 31 31 # Main loop. 32 32 algol60-dg-runtest [lsort \ 33 [glob -nocomplain $srcdir/$subdir/compile/*.\[aA\] 60] ] $DEFAULT_A60FLAGS33 [glob -nocomplain $srcdir/$subdir/compile/*.\[aA\]\[6lL\]\[0gG\] ] ] $DEFAULT_A60FLAGS 34 34 35 35 algol60-dg-runtest [lsort \ 36 [glob -nocomplain $srcdir/$subdir/fail/*.\[aA\] 60] ] $DEFAULT_A60FLAGS36 [glob -nocomplain $srcdir/$subdir/fail/*.\[aA\]\[6lL\]\[0gG\] ] ] $DEFAULT_A60FLAGS 37 37 38 38 # All done.
