Commit 071d56a1 by Zachary Snow

more accurate handling of tagged blocks

parent 35d8644f
...@@ -452,10 +452,12 @@ traverseNestedGenItemsM :: Monad m => MapperM m GenItem -> MapperM m GenItem ...@@ -452,10 +452,12 @@ traverseNestedGenItemsM :: Monad m => MapperM m GenItem -> MapperM m GenItem
traverseNestedGenItemsM mapper = fullMapper traverseNestedGenItemsM mapper = fullMapper
where where
fullMapper genItem = gim genItem >>= mapper fullMapper genItem = gim genItem >>= mapper
gim (GenBlock x subItems) = gim (GenBlock x subItems) = do
mapM fullMapper subItems >>= return . GenBlock x subItems' <- mapM fullMapper subItems
gim (GenFor a b c d subItems) = return $ GenBlock x (concatMap flattenBlocks subItems')
mapM fullMapper subItems >>= return . GenFor a b c d gim (GenFor a b c d subItems) = do
subItems' <- mapM fullMapper subItems
return $ GenFor a b c d (concatMap flattenBlocks subItems')
gim (GenIf e i1 i2) = do gim (GenIf e i1 i2) = do
i1' <- fullMapper i1 i1' <- fullMapper i1
i2' <- fullMapper i2 i2' <- fullMapper i2
...@@ -468,6 +470,9 @@ traverseNestedGenItemsM mapper = fullMapper ...@@ -468,6 +470,9 @@ traverseNestedGenItemsM mapper = fullMapper
gim (GenModuleItem moduleItem) = gim (GenModuleItem moduleItem) =
return $ GenModuleItem moduleItem return $ GenModuleItem moduleItem
gim (GenNull) = return GenNull gim (GenNull) = return GenNull
flattenBlocks :: GenItem -> [GenItem]
flattenBlocks (GenBlock Nothing items) = items
flattenBlocks other = [other]
traverseAsgnsM :: Monad m => MapperM m (LHS, Expr) -> MapperM m ModuleItem traverseAsgnsM :: Monad m => MapperM m (LHS, Expr) -> MapperM m ModuleItem
traverseAsgnsM mapper = moduleItemMapper traverseAsgnsM mapper = moduleItemMapper
......
...@@ -425,8 +425,7 @@ Stmt :: { Stmt } ...@@ -425,8 +425,7 @@ Stmt :: { Stmt }
| Identifier ";" { Subroutine $1 [] } | Identifier ";" { Subroutine $1 [] }
StmtNonAsgn :: { Stmt } StmtNonAsgn :: { Stmt }
: ";" { Null } : ";" { Null }
| "begin" DeclsAndStmts "end" opt(Tag) { Block Nothing (fst $2) (snd $2) } | "begin" opt(Tag) DeclsAndStmts "end" opt(Tag) { Block (combineTags $2 $5) (fst $3) (snd $3) }
| "begin" ":" Identifier DeclsAndStmts "end" opt(Tag) { Block (Just $3) (fst $4) (snd $4) }
| "if" "(" Expr ")" Stmt "else" Stmt { If $3 $5 $7 } | "if" "(" Expr ")" Stmt "else" Stmt { If $3 $5 $7 }
| "if" "(" Expr ")" Stmt %prec NoElse { If $3 $5 Null } | "if" "(" Expr ")" Stmt %prec NoElse { If $3 $5 Null }
| "for" "(" Identifier "=" Expr ";" Expr ";" Identifier "=" Expr ")" Stmt { For ($3, $5) $7 ($9, $11) $13 } | "for" "(" Identifier "=" Expr ";" Expr ";" Identifier "=" Expr ")" Stmt { For ($3, $5) $7 ($9, $11) $13 }
...@@ -588,8 +587,7 @@ GenItem :: { GenItem } ...@@ -588,8 +587,7 @@ GenItem :: { GenItem }
| ModuleItem { genItemsToGenItem $ map GenModuleItem $1 } | ModuleItem { genItemsToGenItem $ map GenModuleItem $1 }
GenBlock :: { (Maybe Identifier, [GenItem]) } GenBlock :: { (Maybe Identifier, [GenItem]) }
: "begin" GenItems "end" opt(Tag) { (Nothing, $2) } : "begin" opt(Tag) GenItems "end" opt(Tag) { (combineTags $2 $5, $3) }
| "begin" ":" Identifier GenItems "end" opt(Tag) { (Just $3, $4) }
GenCases :: { [GenCase] } GenCases :: { [GenCase] }
: {- empty -} { [] } : {- empty -} { [] }
...@@ -649,4 +647,12 @@ defaultFuncInput (Variable Input (Implicit rs) x a me) = ...@@ -649,4 +647,12 @@ defaultFuncInput (Variable Input (Implicit rs) x a me) =
Variable Input (Logic rs) x a me Variable Input (Logic rs) x a me
defaultFuncInput other = other defaultFuncInput other = other
combineTags :: Maybe Identifier -> Maybe Identifier -> Maybe Identifier
combineTags (Just a) (Just b) =
if a == b
then Just a
else error $ "tag mismatch: " ++ show (a, b)
combineTags Nothing other = other
combineTags other _ = other
} }
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