From af9271a48ea51bd6beb41ac0c293c6e27d352391 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Mon, 30 Oct 2006 23:30:25 +0000 Subject: [PATCH] Some nicer death code --- fco/ASTPasses.hs | 11 +++++------ fco/Metadata.hs | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fco/ASTPasses.hs b/fco/ASTPasses.hs index b03c3fa..9d2cc33 100644 --- a/fco/ASTPasses.hs +++ b/fco/ASTPasses.hs @@ -1,12 +1,12 @@ --- Parses across the AST +-- Passes across the AST ---module ASTPasses (astPasses) where -module ASTPasses where +module ASTPasses (astPasses) where -import qualified AST as A import List import Data.Generics import Control.Monad.State +import Metadata +import qualified AST as A {- FIXME: Passes to add: calculate types @@ -114,8 +114,7 @@ uniqueNamesPass p = evalState (doAny p) (0, []) (_, vars) <- get let s' = case lookup s vars of Just n -> n - Nothing -> "(not-declared-" ++ s ++ ")" - --Nothing -> error $ "Name " ++ s ++ " not declared before use" + Nothing -> dieP m $ "Name " ++ s ++ " not declared before use" return $ A.Name m s' cStyleNamesPass :: A.Process -> A.Process diff --git a/fco/Metadata.hs b/fco/Metadata.hs index 7ddce8d..fde8249 100644 --- a/fco/Metadata.hs +++ b/fco/Metadata.hs @@ -20,3 +20,11 @@ formatSourcePos m = case findSourcePos m of Just (SourcePos f l c) -> "<@" ++ show l ++ ":" ++ show c ++ ">" Nothing -> "" +die :: Monad m => String -> m a +die s = error $ "error: " ++ s + +dieP :: Monad m => Meta -> String -> m a +dieP m s = case findSourcePos m of + Just (SourcePos f l c) -> die $ f ++ ":" ++ (show l) ++ ":" ++ (show c) ++ ": " ++ s + Nothing -> die $ "unknown position: " ++ s +