Skip to content

Commit

Permalink
Start using language-c >= 0.7
Browse files Browse the repository at this point in the history
The Language.C.Data.Position.Position data type changed (it now includes a
stack of include files), which required changes to callgraph saving and
loading.  For now we simply ignore the include stack when saving the call
graphs.  This will result in somewhat suboptimal error messages for static
inline functions or when we need to report something about function
declarations.

Additionally the test suite has been made less strict when checking that
roundtripping a callgraph to a file works as expected: we now ignore NodeInfo
details except the starting token file, row and column.

Also add language-c 0.7 to extra-deps in stack.yaml because it's not yet
in the nightly resolver.
  • Loading branch information
lambdageek authored and evincarofautumn committed Sep 15, 2017
1 parent 5f528bb commit 6f2d4b8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Ward.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ executable ward
, containers
, filepath
, hashable
, language-c >= 0.6
, language-c >= 0.7
, optparse-applicative
, parsec
, pretty
Expand Down
5 changes: 5 additions & 0 deletions src/DumpCallMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ encodePositionSpan pstart pl
in form "span" False $ mconcat $ intersperse space body

-- N.B. Assumes Pos.isSourcePos would return True
--
-- TODO: Since language-c 0.7 we can now also get the include stack via
-- 'Pos.posParent' which may be useful for error messages for static inline
-- functions. For now we don't both emiting it (or consuming it in
-- "ParseCallMap").
encodeSourcePos :: Pos.Position -> B.Builder
encodeSourcePos p =
let
Expand Down
2 changes: 1 addition & 1 deletion src/ParseCallMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ sourceForm =
intlit = extractSpan <$> intLiteral
in theForm "source" sourceBody
where
mkPos path offset row column = CPos.position offset path row column
mkPos path offset row column = CPos.position offset path row column Nothing

------------------------------------------------------------
-- Parsing S-expression files
Expand Down
3 changes: 2 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resolver: nightly-2017-03-15
packages:
- '.'
extra-deps: []
extra-deps:
- language-c-0.7.0
flags: {}
extra-package-dbs: []
15 changes: 13 additions & 2 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import Data.These
import Data.Traversable (forM)
import Language.C (parseCFile)
import Language.C.Data.Ident (Ident(Ident))
import Language.C.Data.Node (NodeInfo)
import Language.C.Data.Node (NodeInfo, posOfNode)
import Language.C.Data.Position (Position, position, posFile, posRow, posColumn, posOffset)
import Language.C.System.GCC (newGCC)
import Test.HUnit hiding (errors)
import Test.Hspec
Expand Down Expand Up @@ -293,4 +294,14 @@ callMapRoundtripTest args =
txt = Data.Text.Lazy.Encoding.decodeUtf8With Data.Text.Encoding.Error.lenientDecode bs
parseResult = ParseCallMap.fromSource (show (Args.translationUnitPaths args)) txt
in
parseResult `shouldBe` (Right callMap)
parseResult `shouldBeUptoPos` Right callMap

where
shouldBeUptoPos x y = fmap simplifiedPosInfo x `shouldBe` fmap simplifiedPosInfo y

-- the full NodeInfo has things we don't care to preserve (node names), and
-- additionally Position includes the full include stack which we don't
-- preserve in the graph dump.
simplifiedPosInfo :: Functor f => f (NodeInfo, b, c) -> f (Position, b, c)
simplifiedPosInfo = fmap $ \(ni, b, c) -> (simplifyPos (posOfNode ni), b, c)
simplifyPos p = position (posOffset p) (posFile p) (posRow p) (posColumn p) Nothing

0 comments on commit 6f2d4b8

Please sign in to comment.