<commit_before>%include polycode.fmt

%if false
  Error: DSL for error definition
   
  Copyright (c) 2009 ETH Zurich.
  All rights reserved.
  
  This file is distributed under the terms in the attached LICENSE file.
  If you do not find this file, copies can be found by writing to:
  ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
%endif

%if false

> {-# LANGUAGE BangPatterns #-}

> module HamletAst where

> import Debug.Trace
> import Text.PrettyPrint.HughesPJ as Pprinter 
> import Data.List

%endif


> class Pretty a where
>     pretty :: a -> Doc

> data Capabilities = Capabilities { defines :: ![Define],
>                                    capabilities :: ![Capability] }
>                   deriving Show

> vcat' :: [Doc] -> Doc
> vcat' = foldr ($+$) empty 


> instance Pretty Capabilities where
>     pretty (Capabilities defs caps) =
>         text "Capabilities:" $+$
>         nest 4 ( text "Defines:" $+$
>                  nest 4 (vcat' $ map pretty defs) $+$
>                  text "Caps:" $+$
>                  nest 4 (vcat' $ map pretty caps))
                 

> data Define = Define !String !Int
>             deriving Show

> instance Pretty Define where
>     pretty (Define name val) = text name <+> char '=' <+> int val


> data Capability = Capability { name :: !CapName,
>                                generalEquality :: !(Maybe Bool),
>                                from :: !(Maybe CapName),
>                                fromSelf :: Bool,
>                                fields :: ![CapField],
>                                rangeExpr :: !(Maybe (AddressExpr, SizeExpr)),
>                                eqFields :: ![NameField] }
>                 deriving Show

> instance Pretty Capability where
>     pretty (Capability (CapName name)
>                        genEq 
>                        from
>                        fromSelf
>                        fields
>                        rangeExpr
>                        eqFields) =
>        text name $+$
>        nest 4 (text "General Equality:" <+> text (show genEq) $+$
>                case from of
>                    Nothing -> text $ if fromSelf then "From self" else "From nothing"
>                    Just (CapName fromName) ->
>                        text "From:" <+> text fromName <> text (if fromSelf then " and self" else "")
>                $+$
>                text "Fields:" $+$
>                nest 4 (vcat' (map pretty fields)) $+$
>                (case rangeExpr of
>                     Nothing -> text "Not addressable"
>                     Just (addressExpr, sizeExprE) ->
>                         (text "Address expr:" <+> pretty addressExpr $+$
>                          text "Size expr:" <+> (pretty sizeExprE)))
>                $+$
>                text "Equality fields:" <+> (text $ intercalate ", " $ map (\(NameField n) -> n) eqFields))

> data CapName = CapName !String
>              deriving Show

> data CapField = CapField !Type !NameField 
>               deriving Show
> instance Pretty CapField where
>     pretty (CapField typ (NameField name)) = 
>         text (show typ) <+> text name

> data NameField = NameField !String
>                deriving Show

> data Type = UInt8
>           | UInt16
>           | UInt32
>           | UInt64
>           | Int
>           | GenPAddr
>           | LPAddr
>           | GenVAddr
>           | LVAddr<commit_msg>Minor improvement to pretty for Capability in Hamlet.<commit_after>%include polycode.fmt

%if false
  Error: DSL for error definition
   
  Copyright (c) 2009 ETH Zurich.
  All rights reserved.
  
  This file is distributed under the terms in the attached LICENSE file.
  If you do not find this file, copies can be found by writing to:
  ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
%endif

%if false

> {-# LANGUAGE BangPatterns #-}

> module HamletAst where

> import Debug.Trace
> import Text.PrettyPrint.HughesPJ as Pprinter 
> import Data.List

%endif


> class Pretty a where
>     pretty :: a -> Doc

> data Capabilities = Capabilities { defines :: ![Define],
>                                    capabilities :: ![Capability] }
>                   deriving Show

> vcat' :: [Doc] -> Doc
> vcat' = foldr ($+$) empty 


> instance Pretty Capabilities where
>     pretty (Capabilities defs caps) =
>         text "Capabilities:" $+$
>         nest 4 ( text "Defines:" $+$
>                  nest 4 (vcat' $ map pretty defs) $+$
>                  text "Caps:" $+$
>                  nest 4 (vcat' $ map pretty caps))
                 

> data Define = Define !String !Int
>             deriving Show

> instance Pretty Define where
>     pretty (Define name val) = text name <+> char '=' <+> int val


> data Capability = Capability { name :: !CapName,
>                                generalEquality :: !(Maybe Bool),
>                                from :: !(Maybe CapName),
>                                fromSelf :: Bool,
>                                fields :: ![CapField],
>                                rangeExpr :: !(Maybe (AddressExpr, SizeExpr)),
>                                eqFields :: ![NameField] }
>                 deriving Show

> instance Pretty Capability where
>     pretty (Capability (CapName name)
>                        genEq 
>                        from
>                        fromSelf
>                        fields
>                        rangeExpr
>                        eqFields) =
>        text name $+$
>        nest 4 (text "General Equality:" <+> text (show genEq) $+$
>                case from of
>                    Nothing -> text $ if fromSelf then "From self" else "From nothing"
>                    Just (CapName fromName) ->
>                        text "From:" <+> text fromName <> text (if fromSelf then " and self" else "")
>                $+$
>                text "Fields:" <> text (if null fields then " None" else "") $+$
>                nest 4 (vcat' (map pretty fields)) $+$
>                (case rangeExpr of
>                     Nothing -> text "Not addressable"
>                     Just (addressExpr, sizeExprE) ->
>                         (text "Address expr:" <+> pretty addressExpr $+$
>                          text "Size expr:" <+> (pretty sizeExprE)))
>                $+$
>                text "Equality fields:" <+> (text $ intercalate ", " $ map (\(NameField n) -> n) eqFields))

> data CapName = CapName !String
>              deriving Show

> data CapField = CapField !Type !NameField 
>               deriving Show
> instance Pretty CapField where
>     pretty (CapField typ (NameField name)) = 
>         text (show typ) <+> text name

> data NameField = NameField !String
>                deriving Show

> data Type = UInt8
>           | UInt16
>           | UInt32
>           | UInt64
>           | Int
>           | GenPAddr
>           | LPAddr
>           | GenVAddr
>           | LVAddr
{'fraction_non_alphanumeric': 0.10803443328550932, 'fraction_numerical': 0.006025824964131995, 'mean_word_length': 1.4382651276670164, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 182, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2237235', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1836, 'n_words': 605}