packages feed

struct-inspector 1.0.0 → 1.1.0

raw patch · 2 files changed

+12/−20 lines, 2 filesnew-component:exe:struct-inspector

Files

app/Main.hs view
@@ -41,16 +41,6 @@   , nonZeroOnPadding :: Bool   } deriving Show -defaultOptions :: Options-defaultOptions = Options-  { sizeof           = False-  , uses             = False-  , padding          = True-  , noColor          = False-  , inFile           = "tests/kitchen-sink.c"-  , nonZeroOnPadding = True-  }- data Handles   = Handles   { input  :: Handle@@ -136,6 +126,7 @@ data Field   = FieldNamed     { name :: String+    , declr :: CDeclr     , typeSpec :: CTypeSpec     }   | FieldAnonymousStruct@@ -440,11 +431,11 @@  debugField :: Env -> Int -> String -> String -> Field -> String debugField env n path nextPath = \case-  (FieldNamed name ts) ->+  (FieldNamed name declr ts) ->     let newPath = path <.> name      in printSizePaths env n newPath nextPath        <> printIndent env 4 n-       <> puts env 4 (PP.render (pretty ts) <> " " <> name <> ";")+       <> puts env 4 (PP.render (pretty ts) <> " " <> PP.render (pretty declr) <> ";")   FieldAnonymousStruct{..} ->     printIndent env 4 n     <> puts env 4 "struct {"@@ -527,7 +518,8 @@  getFieldsFromDecl :: CDeclaration NodeInfo -> QM [Field] getFieldsFromDecl (CDecl specs trips _) =-  let names = concatMap (getFieldsFromDeclarators . fst3) trips+  let pairs = concatMap (getFieldsFromDeclarators . fst3) trips+      (names, _) = unzip pairs       typeNode = getTypeFromDeclSpecs specs   in case typeNode of     Nothing -> case names of@@ -553,9 +545,9 @@       pure $ case names of         [] -> [FieldAnonymousUnion fields]         ns -> flip FieldNamedUnion fields <$> ns-    Just t -> case names of+    Just t -> case pairs of       [] -> throwError $ NonStructFieldWithoutName-      ns -> pure $ flip FieldNamed t <$> ns+      ns -> pure $ uncurry FieldNamed <$> ns <*> pure t getFieldsFromDecl _ = pure []  getTypeFromDeclSpecs :: [CDeclarationSpecifier NodeInfo] -> Maybe CTypeSpec@@ -565,6 +557,6 @@ getTypeFromDeclSpec (CTypeSpec a) = Just a getTypeFromDeclSpec _ = Nothing -getFieldsFromDeclarators :: Maybe (CDeclarator NodeInfo) -> [String]-getFieldsFromDeclarators (Just (CDeclr (Just (Ident s _ _)) _ _ _ _)) = [s]+getFieldsFromDeclarators :: Maybe (CDeclarator NodeInfo) -> [(String, CDeclr)]+getFieldsFromDeclarators (Just declr@(CDeclr (Just (Ident s _ _)) _ _ _ _)) = [(s, declr)] getFieldsFromDeclarators _ = []
struct-inspector.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               struct-inspector-version:            1.0.0+version:            1.1.0 author:             Owen Shepherd maintainer:         owen@owen.cafe synopsis:           Inspect the padding and size of C data declarations and their fields@@ -9,10 +9,10 @@ description:        Inspect the padding and size of C data declarations and their fields.                     For more information see <https://github.com/414owen/struct-inspector>. -executable struct-packing-report+executable struct-inspector     main-is:          Main.hs     ghc-options:      -Wall-    build-depends:    base ^>=4.15.1.0+    build-depends:    base >=4.14 && < 5                     , language-c                     , bytestring                     , pretty