Commit 77b2f8b6 by Zachary Snow

improve for decl error messaging

parent da076196
......@@ -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)]
......
// pattern: for loop declaration missing initialization
module top;
initial
for (integer x; x < 3; x = x + 1)
;
endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment