Changeset 176

Show
Ignore:
Timestamp:
05/18/07 23:08:24 (1 year ago)
Author:
ant_39
Message:
  • Support preprocessing. Test case included.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gcc/gcc/algol60/lang-specs.h

    r62 r176  
    22   for the Algol 60 language.  */ 
    33 
     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 
    412{".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  
    9090  int parser_trace; 
    9191  int lexer_trace; 
     92  int preprocessed; 
    9293} 
    9394a60_options_t; 
     
    128129  a60_options->parser_trace = 0; 
    129130  a60_options->lexer_trace = 0; 
     131  a60_options->preprocessed = 0; 
    130132  return CL_Algol60; 
    131133} 
     
    148150      a60_options->lexer_trace = value; 
    149151      return 1; 
     152    case OPT_fpreprocessed: 
     153      a60_options->preprocessed = value; 
     154      return 1; 
    150155    }; 
    151156  fprintf (stderr, "scode %ul option %s value %d\n", scode, arg, value); 
     
    185190  lexer_t * a_lexer = new_lexer (a60_options->ifile, a60_options->ifname, true); 
    186191  gcc_assert (a_lexer != NULL); 
     192  lexer_set_preprocessed (a_lexer, a60_options->preprocessed); 
    187193  if (a60_options->lexer_trace) 
    188194    lexer_set_logging (a_lexer, ll_debug, false); 
  • trunk/gcc/gcc/algol60/lang.opt

    r104 r176  
    1818Dump AST immediately after the parse 
    1919 
     20fpreprocessed 
     21Algol60 
     22Treat the input file as preprocessed 
     23 
    2024; This comment is to ensure we retain the blank line above. 
  • trunk/gcc/gcc/algol60/lexer.h

    r130 r176  
    6363  ATTRIBUTE_NONNULL(1); 
    6464 
     65/// Query the name of parsed stream, taking into account preprocessing 
     66/// directives. 
     67char const * lexer_pp_filename (lexer_t const * lexer) 
     68  ATTRIBUTE_NONNULL(1); 
     69 
    6570 
    6671/// Fetch new token with given lexer, assign a location of given token, 
     
    9499  ATTRIBUTE_NONNULL(1); 
    95100 
     101/// Whether lexer should recognize preprocessing output (linemarks) in 
     102/// input file. 
     103void lexer_set_preprocessed (lexer_t * lexer, int preprocessed) 
     104  ATTRIBUTE_NONNULL(1); 
     105 
    96106#endif//_AL60L_LEXER_H_ 
  • trunk/gcc/gcc/algol60/lexer.l

    r104 r176  
    1818#include <math.h> 
    1919#include <limits.h> 
     20#include <ctype.h> 
    2021 
    2122static char const* private_lexer_signature = "lexer"; 
     
    3334  token_kind_t current_tok; 
    3435  token_kind_t prev_tok; 
     36  int preprocessed; 
     37  char * pp_filename; 
     38  int pp_lineno; 
     39  int pp_baselineno; 
    3540} lexer_rep_t; 
    3641 
     
    4853%x COMMENT 
    4954%x END_COMMENT 
     55%x PREPROCESSOR 
    5056 
    5157%option noyywrap 
     
    365371 
    366372 
     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 
    367427 /* identifier */ 
    368428{LETTER}({LETTER}|{DIGIT})* { 
     
    449509  return private_lexer_got_eof_token (yyscanner, yylineno, NULL); 
    450510} 
     511 
    451512 
    452513 
     
    498559      ret->prev_tok = -1; 
    499560      ret->managed = manage; 
     561      ret->preprocessed = 0; 
     562 
     563      ret->pp_filename = NULL; 
     564      ret->pp_lineno = 0; 
     565      ret->pp_baselineno = 0; 
    500566      return (void*)ret; 
    501567    } 
     
    555621} 
    556622 
     623char const * 
     624lexer_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 
    557634/// Procedure to write out that bad character has been hit. 
    558635/// Bad characters are considered errors. 
     
    630707  // reentrant scanner anyway. 
    631708  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; 
    633713  loc->first_column = loc->last_column = 0; 
    634714 
     
    679759  return (logger_t const*)lexer->log; 
    680760} 
     761 
     762void 
     763lexer_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  
    5151cr_csr (parser_rep_t * parser, YYLTYPE * loc) 
    5252{ 
    53   return new_cursor (lexer_filename (parser->lexer), loc->first_line); 
     53  return new_cursor (lexer_pp_filename (parser->lexer), loc->first_line); 
    5454} 
    5555 
  • trunk/gcc/gcc/testsuite/algol60.dg/dg.exp

    r106 r176  
    3131# Main loop. 
    3232algol60-dg-runtest [lsort \ 
    33        [glob -nocomplain $srcdir/$subdir/compile/*.\[aA\]60 ] ] $DEFAULT_A60FLAGS 
     33       [glob -nocomplain $srcdir/$subdir/compile/*.\[aA\]\[6lL\]\[0gG\] ] ] $DEFAULT_A60FLAGS 
    3434 
    3535algol60-dg-runtest [lsort \ 
    36        [glob -nocomplain $srcdir/$subdir/fail/*.\[aA\]60 ] ] $DEFAULT_A60FLAGS 
     36       [glob -nocomplain $srcdir/$subdir/fail/*.\[aA\]\[6lL\]\[0gG\] ] ] $DEFAULT_A60FLAGS 
    3737 
    3838# All done.