diff options
author | Bernhard Schommer <bernhardschommer@gmail.com> | 2019-05-06 17:32:44 +0200 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2019-05-10 14:42:32 +0200 |
commit | df81fb38c941852919246371840c5fdb003ad0fb (patch) | |
tree | 5c6b2d60571ab69f2998db68d52f9d5ad2612ed9 /cparser | |
parent | 02d8736514c3c9c1542f50b07524f4ffa0588cb8 (diff) | |
download | compcert-df81fb38c941852919246371840c5fdb003ad0fb.tar.gz compcert-df81fb38c941852919246371840c5fdb003ad0fb.zip |
Check for reserved keywords.
`_Complex` and `_Imaginary` are reserved keywords. Since CompCert does
not support these types they could be used as identifiers. However
the standard requires to reject this.
Diffstat (limited to 'cparser')
-rw-r--r-- | cparser/Lexer.mll | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll index b2a668f0..7cf22eef 100644 --- a/cparser/Lexer.mll +++ b/cparser/Lexer.mll @@ -23,11 +23,18 @@ module SSet = Set.Make(String) let lexicon : (string, Cabs.cabsloc -> token) Hashtbl.t = Hashtbl.create 17 let ignored_keywords : SSet.t ref = ref SSet.empty +let reserved_keyword loc id = + Diagnostics.fatal_error (loc.Cabs.filename, loc.Cabs.lineno) + "illegal use of reserved keyword `%s'" id + let () = List.iter (fun (key, builder) -> Hashtbl.add lexicon key builder) - [ ("_Alignas", fun loc -> ALIGNAS loc); + [ + ("_Alignas", fun loc -> ALIGNAS loc); ("_Alignof", fun loc -> ALIGNOF loc); ("_Bool", fun loc -> UNDERSCORE_BOOL loc); + ("_Complex", fun loc -> reserved_keyword loc "_Complex"); + ("_Imaginary", fun loc -> reserved_keyword loc "_Imaginary"); ("__alignof", fun loc -> ALIGNOF loc); ("__alignof__", fun loc -> ALIGNOF loc); ("__asm", fun loc -> ASM loc); |