aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2019-05-06 17:32:44 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2019-05-10 14:42:32 +0200
commitdf81fb38c941852919246371840c5fdb003ad0fb (patch)
tree5c6b2d60571ab69f2998db68d52f9d5ad2612ed9
parent02d8736514c3c9c1542f50b07524f4ffa0588cb8 (diff)
downloadcompcert-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.
-rw-r--r--cparser/Lexer.mll9
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);