Language.C.Pretty

language-c-0.4.5: Analysis and generation of C code

Copyright | Copyright (c) 2007 Bertram Felgenhauer (c) 2008 Benedikt Huber
License | BSD-style
Maintainer | benedikt.huber@gmail.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

Language.C.Pretty

Contents

- Pretty Printing
- Testing

Description

This module provides a pretty printer for the parse tree (`AST`).

Synopsis

- class Pretty p where
  - pretty :: p -> Doc
  - prettyPrec :: Int -> p -> Doc
- prettyUsingInclude :: CTranslUnit -> Doc

# Pretty Printing

class Pretty p where

A class of types which can be pretty printed

Minimal complete definition

Nothing

Methods

pretty :: p -> Doc

pretty print the given value

prettyPrec :: Int -> p -> Doc

`prettyPrec prec p` pretty prints p assuming that the surrounding context has a precedence of `prec`

Instances

Pretty CUnaryOp |
Pretty CBinaryOp |
Pretty CAssignOp |
Pretty Ident |
Pretty SUERef |
Pretty CStrLit |
Pretty CConst |
Pretty CBuiltin |
Pretty CExpr |
Pretty CAttr |
Pretty CDesignator |
Pretty CInit |
Pretty CEnum |
Pretty CStructTag |
Pretty CStructUnion |
Pretty CTypeQual |
Pretty CTypeSpec |
Pretty CStorageSpec |
Pretty CDeclSpec |
Pretty CBlockItem |
Pretty CAsmOperand |
Pretty CAsmStmt |
Pretty CStat |
Pretty CArrSize |
Pretty CDeclr |
Pretty CDecl |
Pretty CFunDef |
Pretty CExtDecl |
Pretty CTranslUnit |
Pretty Attributes |
Pretty Attr |
Pretty VarName |
Pretty TypeQuals |
Pretty Enumerator |
Pretty EnumType |
Pretty CompTyKind |
Pretty CompType |
Pretty EnumTypeRef |
Pretty CompTypeRef |
Pretty Type |
Pretty Linkage |
Pretty Storage |
Pretty DeclAttrs |
Pretty VarDecl |
Pretty TypeDef |
Pretty MemberDecl |
Pretty ParamDecl |
Pretty FunDef |
Pretty ObjDef |
Pretty Decl |
Pretty GlobalDecls |
Pretty IdentDecl |
Pretty TagDef |
Pretty DefTable |
Pretty TagFwdDecl |
(Pretty a, Pretty b) => Pretty (Either a b) |

# Testing

prettyUsingInclude :: CTranslUnit -> Doc

Pretty print the given tranlation unit, but replace declarations from header files with `#include` directives.

The resulting file may not compile (because of missing `#define` directives and similar things), but is very useful for testing, as otherwise the pretty printed file will be cluttered with declarations from system headers.