diff --git a/src/Convert/ForDecl.hs b/src/Convert/ForDecl.hs index 8a37316..4eec095 100644 --- a/src/Convert/ForDecl.hs +++ b/src/Convert/ForDecl.hs @@ -19,8 +19,6 @@ convert = traverseStmts convertStmt convertStmt :: Stmt -> Stmt -convertStmt (For (Left []) cc asgns stmt) = - convertStmt $ For (Right []) cc asgns stmt convertStmt (For (Right []) cc asgns stmt) = convertStmt $ For inits cc asgns stmt where inits = Left [dummyDecl $ RawNum 0] @@ -47,12 +45,9 @@ convertStmt (For (Right origPairs) cc asgns stmt) = convertStmt other = other splitDecl :: Decl -> (Decl, (LHS, Expr)) -splitDecl (decl @ (Variable _ _ _ _ Nil)) = - error $ "invalid for loop decl: " ++ show decl -splitDecl (Variable d t ident a e) = - (Variable d t ident a Nil, (LHSIdent ident, e)) splitDecl decl = - error $ "invalid for loop decl: " ++ show decl + (Variable d t ident a Nil, (LHSIdent ident, e)) + where Variable d t ident a e = decl isComment :: Decl -> Bool isComment CommentDecl{} = True diff --git a/src/Language/SystemVerilog/Parser/ParseDecl.hs b/src/Language/SystemVerilog/Parser/ParseDecl.hs index 39f7818..c91a679 100644 --- a/src/Language/SystemVerilog/Parser/ParseDecl.hs +++ b/src/Language/SystemVerilog/Parser/ParseDecl.hs @@ -287,7 +287,7 @@ parseDTsAsDeclsOrAsgns tokens = forbidNonEqAsgn tokens $ if hasLeadingAsgn || tripLookahead tokens then Right $ parseDTsAsAsgns tokens - else Left $ parseDTsAsDecls tokens + else Left $ map checkDecl $ parseDTsAsDecls tokens where hasLeadingAsgn = -- if there is an asgn token before the next comma @@ -295,6 +295,11 @@ parseDTsAsDeclsOrAsgns tokens = (Just a, Just b) -> a > b (Nothing, Just _) -> True _ -> False + checkDecl :: Decl -> Decl + checkDecl (decl @ (Variable _ _ _ _ Nil)) = + error $ "for loop declaration missing initialization: " + ++ init (show decl) + checkDecl decl = decl -- internal parser for basic assignment lists parseDTsAsAsgns :: [DeclToken] -> [(LHS, Expr)] diff --git a/test/error/for_loop_decl_no_init.sv b/test/error/for_loop_decl_no_init.sv new file mode 100644 index 0000000..7478f6a --- /dev/null +++ b/test/error/for_loop_decl_no_init.sv @@ -0,0 +1,6 @@ +// pattern: for loop declaration missing initialization +module top; + initial + for (integer x; x < 3; x = x + 1) + ; +endmodule