From b4200796aab1ec26288a1376c7dd99c0927b5ee9 Mon Sep 17 00:00:00 2001 From: xleroy Date: Thu, 8 May 2014 07:50:13 +0000 Subject: - Added alternate keywords __inline, __restrict, etc, for GCC compatibility - Skip comments that might remain after preprocessing git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2487 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/Lexer.mll | 26 ++++++++++++++++++++++++-- test/spass/misc.h | 2 -- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll index 059c568..7066213 100644 --- a/cparser/Lexer.mll +++ b/cparser/Lexer.mll @@ -35,6 +35,8 @@ let init filename channel : Lexing.lexbuf = ("case", fun loc -> CASE loc); ("char", fun loc -> CHAR loc); ("const", fun loc -> CONST loc); + ("__const", fun loc -> CONST loc); + ("__const__", fun loc -> CONST loc); ("continue", fun loc -> CONTINUE loc); ("default", fun loc -> DEFAULT loc); ("do", fun loc -> DO loc); @@ -47,10 +49,14 @@ let init filename channel : Lexing.lexbuf = ("goto", fun loc -> GOTO loc); ("if", fun loc -> IF loc); ("inline", fun loc -> INLINE loc); + ("__inline", fun loc -> INLINE loc); + ("__inline__", fun loc -> INLINE loc); ("int", fun loc -> INT loc); ("long", fun loc -> LONG loc); ("register", fun loc -> REGISTER loc); ("restrict", fun loc -> RESTRICT loc); + ("__restrict", fun loc -> RESTRICT loc); + ("__restrict__", fun loc -> RESTRICT loc); ("return", fun loc -> RETURN loc); ("short", fun loc -> SHORT loc); ("signed", fun loc -> SIGNED loc); @@ -229,10 +235,11 @@ let string_literal = '"' s_char_sequence? '"' | 'L' '"' s_char_sequence? '"' -(* We assume comments are removed by the preprocessor. *) rule initial = parse | '\n' { new_line lexbuf; initial_linebegin lexbuf } - | whitespace_char_no_newline { initial lexbuf } + | whitespace_char_no_newline + { initial lexbuf } + | "/*" { multiline_comment lexbuf; initial lexbuf } + | "//" { singleline_comment lexbuf; initial lexbuf } | integer_constant as s { CONSTANT (Cabs.CONST_INT s, currentLoc lexbuf) } | decimal_floating_constant { CONSTANT (Cabs.CONST_FLOAT {Cabs.isHex_FI = false; @@ -353,6 +360,21 @@ and hash = parse { Cerrors.fatal_error "%s:%d Error:@ invalid symbol %C" lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum c } +(* Multi-line comment terminated by "*/" *) +and multiline_comment = parse + | "*/" { () } + | eof { Cerrors.error "%s:%d Error: unterminated comment" + lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum } + | '\n' { new_line lexbuf; multiline_comment lexbuf } + | _ { multiline_comment lexbuf } + +(* Single-line comment terminated by a newline *) +and singleline_comment = parse + | '\n' { new_line lexbuf } + | eof { Cerrors.error "%s:%d Error: unterminated comment" + lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum } + | _ { singleline_comment lexbuf } + { open Streams open Specif diff --git a/test/spass/misc.h b/test/spass/misc.h index 6f70a23..69d929d 100644 --- a/test/spass/misc.h +++ b/test/spass/misc.h @@ -48,8 +48,6 @@ #ifndef _MISC_ #define _MISC_ -#define __inline__ inline - /**************************************************************/ /* Includes */ /**************************************************************/ -- cgit v1.2.3