From 460c3e287f5a6cfd31eba94985b787663c4c8556 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 2 Apr 2009 17:45:31 +0000 Subject: [PATCH] Changed names to be uniquified based on their source position, and fixed the source position for things in pragmas The second part of the patch is essential, given the first. Otherwise names in different pragmas in the same file can overlap -- this already happened in oak! --- data/CompState.hs | 5 +---- frontends/LexOccam.x | 7 +++++-- frontends/ParseOccam.hs | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/data/CompState.hs b/data/CompState.hs index 927c87c..d354aad 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -261,10 +261,7 @@ nameSource n = lookupName n >>* A.ndNameSource -- | Make a name unique by appending a suffix to it. makeUniqueName :: CSM m => Meta -> String -> m String makeUniqueName m s - = do st <- get - let mungedFile = munge $ fromMaybe "" (metaFile m) - put $ st { csNameCounter = csNameCounter st + 1 } - return $ s ++ "_" ++ mungedFile ++ "_u" ++ show (csNameCounter st) + = let mungedFile = munge $ show m in return $ s ++ "_" ++ mungedFile where munge cs = [if c `elem` (['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9']) then c diff --git a/frontends/LexOccam.x b/frontends/LexOccam.x index 9b0aa48..8fcfb68 100644 --- a/frontends/LexOccam.x +++ b/frontends/LexOccam.x @@ -182,8 +182,8 @@ mkState code _ s = (Nothing, code) -- | Run the lexer, returning a list of tokens. -- (This is based on the `alexScanTokens` function that Alex provides.) -runLexer :: Die m => String -> String -> m [Token] -runLexer filename str = go (alexStartPos, '\n', str) 0 +runLexer' :: Die m => (String, Int, Int) -> String -> m [Token] +runLexer' (filename, startLine, startCol) str = go (AlexPn 0 startLine startCol, '\n', str) 0 where go inp@(pos@(AlexPn _ line col), _, str) code = case alexScan inp code of @@ -204,5 +204,8 @@ runLexer filename str = go (alexStartPos, '\n', str) 0 metaColumn = col } +runLexer :: Die m => String -> String -> m [Token] +runLexer fn = runLexer' (fn, 1, 1) + } diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index faf3881..325de96 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -1370,8 +1370,8 @@ structuredTypeField --}}} --{{{ pragmas pragma :: OccParser () -pragma = do Pragma rawP <- genToken isPragma - m <- getPosition >>* sourcePosToMeta +pragma = do m <- getPosition >>* sourcePosToMeta + Pragma rawP <- genToken isPragma let prag :: Maybe (Int, String) prag = join $ find isJust [ (matchRegex (mkRegex pt) rawP >>= listToMaybe) >>* (,) i @@ -1409,7 +1409,7 @@ pragma = do Pragma rawP <- genToken isPragma if pragmaType == 2 then do sPROC n <- newProcName - fs <- formalList >>* map fst + fs <- formalList' sEq integer return (n, ProcName, n, fs, A.Proc m (A.PlainSpec, A.PlainRec) fs (A.Skip m)) @@ -1436,7 +1436,9 @@ pragma = do Pragma rawP <- genToken isPragma } case (prag, mprod) of (Just (_, pragStr), Just prod) -> do - toks <- runLexer "" pragStr + let column = metaColumn m + fromMaybe 0 (findIndex (=='\"') rawP) + toks <- runLexer' (fromMaybe "" $ metaFile m + , metaLine m, column) pragStr cs <- getCompState case runParser (prod >> getState) cs "" toks of Left err -> warnP m WarnUnknownPreprocessorDirective $