mirror of https://github.com/zachjs/sv2v.git
improve for decl error messaging
This commit is contained in:
parent
da07619642
commit
77b2f8b6ce
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
// pattern: for loop declaration missing initialization
|
||||
module top;
|
||||
initial
|
||||
for (integer x; x < 3; x = x + 1)
|
||||
;
|
||||
endmodule
|
||||
Loading…
Reference in New Issue