From 1a9068409e10aafd749c3736d1e17630aba17c56 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sat, 1 Feb 2020 16:40:01 -0500 Subject: [PATCH] forbid illegal macro names --- src/Language/SystemVerilog/Parser/Lex.x | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Language/SystemVerilog/Parser/Lex.x b/src/Language/SystemVerilog/Parser/Lex.x index 5eccb21..d9c322c 100644 --- a/src/Language/SystemVerilog/Parser/Lex.x +++ b/src/Language/SystemVerilog/Parser/Lex.x @@ -918,6 +918,34 @@ defaultMacroArgs (f : fs) (a : as) = do unskippableDirectives :: [String] unskippableDirectives = ["else", "elsif", "endif", "ifdef", "ifndef"] +-- list of all of the supported directive names; used to prevent defining macros +-- with illegal names +directives :: [String] +directives = + [ "timescale" + , "celldefine" + , "endcelldefine" + , "unconnected_drive" + , "nounconnected_drive" + , "default_nettype" + , "pragma" + , "resetall" + , "begin_keywords" + , "end_keywords" + , "__FILE__" + , "__LINE__" + , "line" + , "include" + , "ifdef" + , "ifndef" + , "else" + , "elsif" + , "endif" + , "define" + , "undef" + , "undefineall" + ] + handleDirective :: Action handleDirective (posOrig, _, _, strOrig) len = do let thisTokenStr = take len strOrig @@ -1075,7 +1103,11 @@ handleDirective (posOrig, _, _, strOrig) len = do "define" -> do dropSpaces - name <- takeString + name <- do + str <- takeString + if elem str directives + then lexicalError $ "illegal macro name: " ++ str + else return str defn <- do eof <- atEOF if eof