-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Analysis and generation of C code -- -- Language C is a haskell library for the analysis and generation of C -- code. It features a complete, well tested parser and pretty printer -- for all of C99 and a large set of GNU extensions. @package language-c @version 0.3.0 -- | Unary, binary and asssignment operators. Exported via AST. module Language.C.Syntax.Ops -- | C assignment operators (K&R A7.17) data CAssignOp CAssignOp :: CAssignOp CMulAssOp :: CAssignOp CDivAssOp :: CAssignOp -- | remainder and assignment CRmdAssOp :: CAssignOp CAddAssOp :: CAssignOp CSubAssOp :: CAssignOp CShlAssOp :: CAssignOp CShrAssOp :: CAssignOp CAndAssOp :: CAssignOp CXorAssOp :: CAssignOp COrAssOp :: CAssignOp -- | C unary operator (K&R A7.3-4) data CUnaryOp -- | prefix increment operator CPreIncOp :: CUnaryOp -- | prefix decrement operator CPreDecOp :: CUnaryOp -- | postfix increment operator CPostIncOp :: CUnaryOp -- | postfix decrement operator CPostDecOp :: CUnaryOp -- | address operator CAdrOp :: CUnaryOp -- | indirection operator CIndOp :: CUnaryOp -- | prefix plus CPlusOp :: CUnaryOp -- | prefix minus CMinOp :: CUnaryOp -- | one's complement CCompOp :: CUnaryOp -- | logical negation CNegOp :: CUnaryOp -- | C binary operators (K&R A7.6-15) data CBinaryOp CMulOp :: CBinaryOp CDivOp :: CBinaryOp -- | remainder of division CRmdOp :: CBinaryOp CAddOp :: CBinaryOp CSubOp :: CBinaryOp -- | shift left CShlOp :: CBinaryOp -- | shift right CShrOp :: CBinaryOp -- | less CLeOp :: CBinaryOp -- | greater CGrOp :: CBinaryOp -- | less or equal CLeqOp :: CBinaryOp -- | greater or equal CGeqOp :: CBinaryOp -- | equal CEqOp :: CBinaryOp -- | not equal CNeqOp :: CBinaryOp -- | bitwise and CAndOp :: CBinaryOp -- | exclusive bitwise or CXorOp :: CBinaryOp -- | inclusive bitwise or COrOp :: CBinaryOp -- | logical and CLndOp :: CBinaryOp -- | logical or CLorOp :: CBinaryOp instance Typeable CUnaryOp instance Typeable CBinaryOp instance Typeable CAssignOp instance Eq CUnaryOp instance Ord CUnaryOp instance Data CUnaryOp instance Eq CBinaryOp instance Ord CBinaryOp instance Data CBinaryOp instance Eq CAssignOp instance Ord CAssignOp instance Data CAssignOp instance Show CUnaryOp instance Show CBinaryOp instance Show CAssignOp -- | Source code position module Language.C.Data.Position -- | uniform representation of source file positions; the order of the -- arguments is important as it leads to the desired ordering of source -- positions data Position Position :: String -> !!Int -> !!Int -> Position -- | get the source file of the specified position. Fails unless -- isSourcePos pos. posFile :: Position -> String -- | get the line number of the specified position. Fails unless -- isSourcePos pos posRow :: Position -> Int -- | get the column of the specified position. Fails unless isSourcePos -- pos posColumn :: Position -> Int -- | returns True if the given position refers to an actual source -- file isSourcePos :: Position -> Bool -- | no position (for unknown position information) nopos :: Position isNoPos :: Position -> Bool -- | position attached to built-in objects builtinPos :: Position -- | returns True if the given position refers to a builtin -- definition isBuiltinPos :: Position -> Bool -- | position used for internal errors internalPos :: Position -- | returns True if the given position is internal isInternalPos :: Position -> Bool -- | advance column incPos :: Position -> Int -> Position -- | advance column to next tab positions (tabs are considered to be at -- every 8th column) tabPos :: Position -> Position -- | advance to next line retPos :: Position -> Position -- | class of type which aggregate a source code location class Pos a posOf :: (Pos a) => a -> Position instance Typeable Position instance Eq Position instance Ord Position instance Data Position instance Read Position instance Show Position -- | Unique Names with fast equality (newtype Int) module Language.C.Data.Name -- | Name is a unique identifier newtype Name Name :: Int -> Name nameId :: Name -> Int -- | get the infinite stream of unique names starting from the given -- integer namesStartingFrom :: Int -> [Name] -- | NameMap is currently just an alias for IntMap, but that might change -- in the future type NameMap = IntMap emptyNameMap :: NameMap v instance Typeable Name instance Show Name instance Read Name instance Eq Name instance Ord Name instance Ix Name instance Data Name instance Enum Name -- | source position and unqiue name module Language.C.Data.Node -- | Parsed entity attribute data NodeInfo OnlyPos :: Position -> NodeInfo NodeInfo :: Position -> Name -> NodeInfo internalNode :: NodeInfo -- | Given only a source position, create a new attribute identifier mkNodeInfoOnlyPos :: Position -> NodeInfo -- | Given a source position and a unique name, create a new attribute -- identifier mkNodeInfo :: Position -> Name -> NodeInfo -- | a class for convenient access to the attributes of an attributed -- object class CNode a nodeInfo :: (CNode a) => a -> NodeInfo fileOfNode :: (CNode a) => a -> FilePath posOfNode :: NodeInfo -> Position nameOfNode :: NodeInfo -> Maybe Name -- | equality by name eqByName :: (CNode a) => a -> a -> Bool instance Typeable NodeInfo instance Show NodeInfo instance Read NodeInfo instance Data NodeInfo instance (CNode a, CNode b) => CNode (Either a b) instance CNode NodeInfo instance Pos NodeInfo instance Ord NodeInfo instance Eq NodeInfo -- | This module provides support for representing, checking and exporting -- c constants, i.e. integral, float, character and string constants. module Language.C.Syntax.Constants escapeChar :: Char -> String unescapeChar :: String -> (Char, String) unescapeString :: String -> String newtype Flags f Flags :: Integer -> Flags f noFlags :: Flags f setFlag :: (Enum f) => f -> Flags f -> Flags f clearFlag :: (Enum f) => f -> Flags f -> Flags f testFlag :: (Enum f) => f -> Flags f -> Bool -- | construct a character constant from a haskell Char Use -- cchar_w if you want a wide character constant. cChar :: Char -> CChar -- | construct a wide chararacter constant cChar_w :: Char -> CChar -- | create a multi-character character constant cChars :: [Char] -> Bool -> CChar -- | C char constants (abstract) data CChar CChar :: !!Char -> !!Bool -> CChar CChars :: [Char] -> !!Bool -> CChar -- | get the haskell representation of a char constant getCChar :: CChar -> [Char] -- | get integer value of a C char constant undefined result for multi-char -- char constants getCCharAsInt :: CChar -> Integer -- | return true if the character constant is wide. isWideChar :: CChar -> Bool -- | showCharConst c prepends _a_ String representing the C char -- constant corresponding to c. If neccessary uses octal or -- hexadecimal escape sequences. showCharConst :: Char -> ShowS -- | datatype representing type flags for integers data CIntFlag FlagUnsigned :: CIntFlag FlagLong :: CIntFlag FlagLongLong :: CIntFlag FlagImag :: CIntFlag -- | datatype for memorizing the representation of an integer data CIntRepr DecRepr :: CIntRepr HexRepr :: CIntRepr OctalRepr :: CIntRepr -- | construct a integer constant (without type flags) from a haskell -- integer cInteger :: Integer -> CInteger data CInteger CInteger :: !!Integer -> !!CIntRepr -> !!Flags CIntFlag -> CInteger getCInteger :: CInteger -> Integer readCInteger :: CIntRepr -> String -> Either String CInteger cFloat :: Float -> CFloat -- | Floats (represented as strings) data CFloat CFloat :: !!String -> CFloat readCFloat :: String -> CFloat cString :: String -> CString cString_w :: String -> CString -- | C String literals data CString CString :: [Char] -> Bool -> CString getCString :: CString -> String -- | showStringLiteral s prepends a String representing the C -- string literal corresponding to s. If neccessary it uses -- octal or hexadecimal escape sequences. showStringLit :: String -> ShowS -- | concatenate a list of C string literals concatCStrings :: [CString] -> CString instance Typeable1 Flags instance Typeable CString instance Typeable CFloat instance Typeable CInteger instance Typeable CIntFlag instance Typeable CIntRepr instance Typeable CChar instance Eq (Flags f) instance Ord (Flags f) instance (Data f) => Data (Flags f) instance Eq CString instance Ord CString instance Data CString instance Eq CFloat instance Ord CFloat instance Data CFloat instance Eq CInteger instance Ord CInteger instance Data CInteger instance Eq CIntFlag instance Ord CIntFlag instance Enum CIntFlag instance Bounded CIntFlag instance Data CIntFlag instance Eq CIntRepr instance Ord CIntRepr instance Enum CIntRepr instance Bounded CIntRepr instance Data CIntRepr instance Eq CChar instance Ord CChar instance Data CChar instance Show CString instance Show CFloat instance Show CInteger instance Show CIntFlag instance Show CChar -- | This module provides the notion of identifiers in C, speed up using -- hashing. Identifiers are associated optionally associated with a -- NodeInfo, i.e. with a unique Name and a source location -- (Position). The ordering relation on identifiers is based on -- the hash and does not follow the lexical order. module Language.C.Data.Ident -- | C identifiers data Ident Ident :: String -> !Int -> NodeInfo -> Ident -- | References uniquely determining a struct, union or enum type. Those -- are either identified by an string identifier, or by a unique name -- (anonymous types). data SUERef AnonymousRef :: Name -> SUERef NamedRef :: Ident -> SUERef -- | Return true if the struct/union/enum reference is anonymous. isAnonymousRef :: SUERef -> Bool -- | build an identifier from a string. -- -- mkIdent :: Position -> String -> Name -> Ident -- | returns a builtin identifier (has builtin position and no -- unique name) builtinIdent :: String -> Ident -- | returns an internal identifier (has internal position and no -- unique name) internalIdent :: String -> Ident -- | return an internal identifier with position info internalIdentAt :: Position -> String -> Ident -- | return True if the given identifier is internal isInternalIdent :: Ident -> Bool -- | string of an identifier identToString :: Ident -> String -- | dump the identifier string and its positions for debugging purposes dumpIdent :: Ident -> String instance Typeable Ident instance Typeable SUERef instance Data Ident instance Data SUERef instance Ord SUERef instance Eq SUERef instance Pos Ident instance CNode Ident instance Show Ident instance Ord Ident instance Eq Ident instance Show SUERef -- | Abstract syntax of C source and header files. -- -- The tree structure is based on the grammar in Appendix A of K&R. -- The abstract syntax simplifies the concrete syntax by merging similar -- concrete constructs into a single type of abstract tree structure: -- declarations are merged with structure declarations, parameter -- declarations and type names, and declarators are merged with abstract -- declarators. -- -- With K&R we refer to ``The C Programming Language'', second -- edition, Brain W. Kernighan and Dennis M. Ritchie, Prentice Hall, -- 1988. The AST supports all of C99 -- http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf and -- several GNU extensions -- http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html. module Language.C.Syntax.AST -- | Complete C tranlsation unit (C99 6.9, K&R A10) -- -- A complete C translation unit, for example representing a C header or -- source file. It consists of a list of external (i.e. toplevel) -- declarations. data CTranslUnit CTranslUnit :: [CExtDecl] -> NodeInfo -> CTranslUnit -- | External C declaration (C99 6.9, K&R A10) -- -- Either a toplevel declaration, function definition or external -- assembler. data CExtDecl CDeclExt :: CDecl -> CExtDecl CFDefExt :: CFunDef -> CExtDecl CAsmExt :: CStrLit -> CExtDecl -- | C function definition (C99 6.9.1, K&R A10.1) -- -- A function definition is of the form CFunDef specifiers declarator -- decllist? stmt. -- -- data CFunDef CFunDef :: [CDeclSpec] -> CDeclr -> [CDecl] -> CStat -> NodeInfo -> CFunDef -- | C declarations (K&R A8, C99 6.7), including structure -- declarations, parameter declarations and type names. -- -- A declaration is of the form CDecl specifiers -- init-declarator-list, where the form of the declarator list's -- elements depends on the kind of declaration: -- -- 1) Toplevel declarations (K&R A8, C99 6.7 declaration) -- -- -- -- 2) Structure declarations (K&R A8.3, C99 6.7.2.1 -- struct-declaration) -- -- Those are the declarations of a structure's members. -- -- -- -- 3) Parameter declarations (K&R A8.6.3, C99 6.7.5 -- parameter-declaration) -- -- -- -- 4) Type names (A8.8, C99 6.7.6) -- -- data CDecl CDecl :: [CDeclSpec] -> [(Maybe CDeclr, Maybe CInit, Maybe CExpr)] -> NodeInfo -> CDecl -- | C structure or union specifiers (K&R A8.3, C99 6.7.2.1) -- -- CStruct tag identifier struct-decls c-attrs represents a -- struct or union specifier (depending on tag). -- -- -- -- Example: in struct foo x;, the identifier is present, in -- struct { int y; } x the declaration list, and in struct -- foo { int y; } x; both of them. -- -- data CStructUnion CStruct :: CStructTag -> (Maybe Ident) -> (Maybe [CDecl]) -> [CAttr] -> NodeInfo -> CStructUnion -- | A tag to determine wheter we refer to a struct or -- union, see CStructUnion. data CStructTag CStructTag :: CStructTag CUnionTag :: CStructTag -- | C enumeration specifier (K&R A8.4, C99 6.7.2.2) -- -- CEnum identifier enumerator-list attrs represent as enum -- specifier -- -- data CEnum CEnum :: (Maybe Ident) -> (Maybe [(Ident, Maybe CExpr)]) -> [CAttr] -> NodeInfo -> CEnum -- | C declaration specifiers and qualifiers -- -- Declaration specifiers include at most one storage-class specifier -- (C99 6.7.1), type specifiers (6.7.2) and type qualifiers (6.7.3). data CDeclSpec -- | storage-class specifier or typedef CStorageSpec :: CStorageSpec -> CDeclSpec -- | type name CTypeSpec :: CTypeSpec -> CDeclSpec -- | type qualifier CTypeQual :: CTypeQual -> CDeclSpec -- | Seperate the declaration specifiers -- -- Note that inline isn't actually a type qualifier, but a function -- specifier. __attribute__ of a declaration qualify -- declarations or declarators (but not types), and are therefore -- seperated as well. partitionDeclSpecs :: [CDeclSpec] -> ([CStorageSpec], [CAttr], [CTypeQual], [CTypeSpec], Bool) -- | C storage class specifier (and typedefs) (K&R A8.1, C99 6.7.1) data CStorageSpec -- | auto CAuto :: NodeInfo -> CStorageSpec -- | register CRegister :: NodeInfo -> CStorageSpec -- | static CStatic :: NodeInfo -> CStorageSpec -- | extern CExtern :: NodeInfo -> CStorageSpec -- | typedef CTypedef :: NodeInfo -> CStorageSpec -- | GNUC thread local storage CThread :: NodeInfo -> CStorageSpec -- | C type specifier (K&R A8.2, C99 6.7.2) -- -- Type specifiers are either basic types such as char or -- int, struct, union or enum -- specifiers or typedef names. -- -- As a GNU extension, a typeof expression also is a type -- specifier. data CTypeSpec CVoidType :: NodeInfo -> CTypeSpec CCharType :: NodeInfo -> CTypeSpec CShortType :: NodeInfo -> CTypeSpec CIntType :: NodeInfo -> CTypeSpec CLongType :: NodeInfo -> CTypeSpec CFloatType :: NodeInfo -> CTypeSpec CDoubleType :: NodeInfo -> CTypeSpec CSignedType :: NodeInfo -> CTypeSpec CUnsigType :: NodeInfo -> CTypeSpec CBoolType :: NodeInfo -> CTypeSpec CComplexType :: NodeInfo -> CTypeSpec -- | Struct or Union specifier CSUType :: CStructUnion -> NodeInfo -> CTypeSpec -- | Enumeration specifier CEnumType :: CEnum -> NodeInfo -> CTypeSpec -- | Typedef name CTypeDef :: Ident -> NodeInfo -> CTypeSpec -- |
--   typeof(expr)
--   
CTypeOfExpr :: CExpr -> NodeInfo -> CTypeSpec -- |
--   typeof(type)
--   
CTypeOfType :: CDecl -> NodeInfo -> CTypeSpec -- | returns True if the given typespec is a struct, union or enum -- definition isSUEDef :: CTypeSpec -> Bool -- | C type qualifiers (K&R A8.2, C99 6.7.3), function specifiers (C99 -- 6.7.4), and attributes. -- -- const, volatile and restrict type -- qualifiers and inline function specifier. Additionally, -- __attribute__ annotations for declarations and declarators. data CTypeQual CConstQual :: NodeInfo -> CTypeQual CVolatQual :: NodeInfo -> CTypeQual CRestrQual :: NodeInfo -> CTypeQual CInlineQual :: NodeInfo -> CTypeQual CAttrQual :: CAttr -> CTypeQual -- | __attribute__ annotations -- -- Those are of the form CAttr attribute-name -- attribute-parameters, and serve as generic properties of some -- syntax tree elements. data CAttr CAttr :: Ident -> [CExpr] -> NodeInfo -> CAttr -- | C declarator (K&R A8.5, C99 6.7.5) and abstract declarator -- (K&R A8.8, C99 6.7.6) -- -- A declarator declares a single object, function, or type. It is always -- associated with a declaration (CDecl), which specifies the -- declaration's type and the additional storage qualifiers and -- attributes, which apply to the declared object. -- -- A declarator is of the form CDeclr name? indirections asm-name? -- attrs _, where name is the name of the declared object -- (missing for abstract declarators), declquals is a set of -- additional declaration specifiers, asm-name is the optional -- assembler name and attributes is a set of attrs is a set of -- __attribute__ annotations for the declared object. -- -- indirections is a set of pointer, array and function -- declarators, which modify the type of the declared object as described -- below. If the declaration specifies the non-derived type -- T, and we have indirections = [D1, D2, ..., Dn] than -- the declared object has type (D1 indirect (D2 -- indirect ... (Dn indirect T))), where -- -- -- -- Examples (simplified attributes): -- -- -- --
--   int x;
--   CDeclr "x" []
--   
-- -- -- --
--   const int * const * restrict x;
--   CDeclr "x" [CPtrDeclr [restrict], CPtrDeclr [const]]
--   
-- -- -- --
--   int* const f();
--   CDeclr "f" [CFunDeclr [],CPtrDeclr [const]]
--   
-- -- -- --
--   int (* const f)(); ==>
--   CDeclr "f" [CPtrDeclr [const], CFunDeclr []]
--   
data CDeclr CDeclr :: (Maybe Ident) -> [CDerivedDeclr] -> (Maybe CStrLit) -> [CAttr] -> NodeInfo -> CDeclr -- | Derived declarators, see CDeclr -- -- Indirections are qualified using type-qualifiers and generic -- attributes, and additionally -- -- data CDerivedDeclr -- | Pointer declarator CPtrDeclr tyquals declr CPtrDeclr :: [CTypeQual] -> NodeInfo -> CDerivedDeclr -- | Array declarator CArrDeclr declr tyquals size-expr? CArrDeclr :: [CTypeQual] -> (CArrSize) -> NodeInfo -> CDerivedDeclr -- | Function declarator CFunDeclr declr (old-style-params | -- new-style-params) c-attrs CFunDeclr :: (Either [Ident] ([CDecl], Bool)) -> [CAttr] -> NodeInfo -> CDerivedDeclr -- | Size of an array data CArrSize -- |
--   CUnknownSize isCompleteType
--   
CNoArrSize :: Bool -> CArrSize -- |
--   CArrSize isStatic expr
--   
CArrSize :: Bool -> CExpr -> CArrSize -- | C initialization (K&R A8.7, C99 6.7.8) -- -- Initializers are either assignment expressions or initializer lists -- (surrounded in curly braces), whose elements are themselves -- initializers, paired with an optional list of designators. data CInit -- | assignment expression CInitExpr :: CExpr -> NodeInfo -> CInit -- | initialization list (see CInitList) CInitList :: CInitList -> NodeInfo -> CInit -- | Initializer List -- -- The members of an initializer list are of the form -- (designator-list,initializer). designator-list is -- allowed to be empty - in this case the initializer refers to the -- ''next'' member of the compound type (see C99 6.7.8). -- -- Examples (simplified expressions and identifiers): -- --
--   -- { [0], [3] = 4, [2] = 5, 8 }
--   let init1 = ([CArrDesig 0, CArrDesig 3], CInitExpr 4)
--       init2 = ([CArrDesig 2], CInitExpr 5)
--       init3 = ([], CInitExpr 8)
--   in  CInitList [init1, init2, init3]
--   
-- --
--   -- { .s = { {2,3} , .a = { 1 } } }
--   let init_1  = [ ([], CInitExpr 1) ]
--       init_23 = zip (repeat []) [CInitExpr 2, CInitExpr 3]
--       init_s_1 = ([], CInitList init_23)
--       init_s_a = ([CMemberDesig "a"], CInitList init_1)
--       init_s  = ((CMemberDesig "s"), CInitList [init_s_1,init_s_a])
--   in  CInitList [init_s]
--   
type CInitList = [([CDesignator], CInit)] -- | Designators -- -- A designator specifies a member of an object, either an element or -- range of an array, or the named member of a struct / union. data CDesignator -- | array position designator CArrDesig :: CExpr -> NodeInfo -> CDesignator -- | member designator CMemberDesig :: Ident -> NodeInfo -> CDesignator -- | array range designator CRangeDesig from to _ (GNU C) CRangeDesig :: CExpr -> CExpr -> NodeInfo -> CDesignator -- | C statement (K&R A9, C99 6.8) data CStat -- | An (attributed) label followed by a statement CLabel :: Ident -> CStat -> [CAttr] -> NodeInfo -> CStat -- | A statement of the form case expr : stmt CCase :: CExpr -> CStat -> NodeInfo -> CStat -- | A case range of the form case lower ... upper : stmt CCases :: CExpr -> CExpr -> CStat -> NodeInfo -> CStat -- | The default case default : stmt CDefault :: CStat -> NodeInfo -> CStat -- | A simple statement, that is in C: evaluating an expression with -- side-effects and discarding the result. CExpr :: (Maybe CExpr) -> NodeInfo -> CStat -- | compound statement CCompound localLabels blockItems at CCompound :: [Ident] -> [CBlockItem] -> NodeInfo -> CStat -- | conditional statement CIf ifExpr thenStmt maybeElseStmt at CIf :: CExpr -> CStat -> (Maybe CStat) -> NodeInfo -> CStat -- | switch statement CSwitch selectorExpr switchStmt, where -- switchStmt usually includes case, break and -- default statements CSwitch :: CExpr -> CStat -> NodeInfo -> CStat -- | while or do-while statement CWhile guard stmt isDoWhile at CWhile :: CExpr -> CStat -> Bool -> NodeInfo -> CStat -- | for statement CFor init expr-2 expr-3 stmt, where -- init is either a declaration or initializing expression CFor :: (Either (Maybe CExpr) CDecl) -> (Maybe CExpr) -> (Maybe CExpr) -> CStat -> NodeInfo -> CStat -- | goto statement CGoto label CGoto :: Ident -> NodeInfo -> CStat -- | computed goto CGotoPtr labelExpr CGotoPtr :: CExpr -> NodeInfo -> CStat -- | continue statement CCont :: NodeInfo -> CStat -- | break statement CBreak :: NodeInfo -> CStat -- | return statement CReturn returnExpr CReturn :: (Maybe CExpr) -> NodeInfo -> CStat -- | assembly statement CAsm :: CAsmStmt -> NodeInfo -> CStat -- | C99 Block items -- -- Things that may appear in compound statements: either statements, -- declarations or nested function definitions. data CBlockItem -- | A statement CBlockStmt :: CStat -> CBlockItem -- | A local declaration CBlockDecl :: CDecl -> CBlockItem -- | A nested function (GNU C) CNestedFunDef :: CFunDef -> CBlockItem -- | GNU Assembler statement -- --
--   CAsmStatement type-qual? asm-expr out-ops in-ops clobbers _
--   
-- -- is an inline assembler statement. The only type-qualifier (if any) -- allowed is volatile. asm-expr is the actual assembler -- epxression (a string), out-ops and in-ops are the -- input and output operands of the statement. clobbers is a -- list of registers which are clobbered when executing the assembler -- statement data CAsmStmt CAsmStmt :: (Maybe CTypeQual) -> CStrLit -> [CAsmOperand] -> [CAsmOperand] -> [CStrLit] -> NodeInfo -> CAsmStmt -- | Assembler operand -- -- CAsmOperand argName? constraintExpr arg specifies an operand -- for an assembler statement. data CAsmOperand CAsmOperand :: (Maybe Ident) -> CStrLit -> CExpr -> NodeInfo -> CAsmOperand -- | C expression (K&R A7) -- -- data CExpr CComma :: [CExpr] -> NodeInfo -> CExpr CAssign :: CAssignOp -> CExpr -> CExpr -> NodeInfo -> CExpr CCond :: CExpr -> (Maybe CExpr) -> CExpr -> NodeInfo -> CExpr CBinary :: CBinaryOp -> CExpr -> CExpr -> NodeInfo -> CExpr CCast :: CDecl -> CExpr -> NodeInfo -> CExpr CUnary :: CUnaryOp -> CExpr -> NodeInfo -> CExpr CSizeofExpr :: CExpr -> NodeInfo -> CExpr CSizeofType :: CDecl -> NodeInfo -> CExpr CAlignofExpr :: CExpr -> NodeInfo -> CExpr CAlignofType :: CDecl -> NodeInfo -> CExpr CComplexReal :: CExpr -> NodeInfo -> CExpr CComplexImag :: CExpr -> NodeInfo -> CExpr CIndex :: CExpr -> CExpr -> NodeInfo -> CExpr CCall :: CExpr -> [CExpr] -> NodeInfo -> CExpr CMember :: CExpr -> Ident -> Bool -> NodeInfo -> CExpr CVar :: Ident -> NodeInfo -> CExpr -- | integer, character, floating point and string constants CConst :: CConst -> CExpr -- | C99 compound literal CCompoundLit :: CDecl -> CInitList -> NodeInfo -> CExpr -- | GNU C compound statement as expr CStatExpr :: CStat -> NodeInfo -> CExpr -- | GNU C address of label CLabAddrExpr :: Ident -> NodeInfo -> CExpr -- | builtin expressions, see CBuiltin CBuiltinExpr :: CBuiltin -> CExpr -- | C assignment operators (K&R A7.17) data CAssignOp CAssignOp :: CAssignOp CMulAssOp :: CAssignOp CDivAssOp :: CAssignOp -- | remainder and assignment CRmdAssOp :: CAssignOp CAddAssOp :: CAssignOp CSubAssOp :: CAssignOp CShlAssOp :: CAssignOp CShrAssOp :: CAssignOp CAndAssOp :: CAssignOp CXorAssOp :: CAssignOp COrAssOp :: CAssignOp -- | C binary operators (K&R A7.6-15) data CBinaryOp CMulOp :: CBinaryOp CDivOp :: CBinaryOp -- | remainder of division CRmdOp :: CBinaryOp CAddOp :: CBinaryOp CSubOp :: CBinaryOp -- | shift left CShlOp :: CBinaryOp -- | shift right CShrOp :: CBinaryOp -- | less CLeOp :: CBinaryOp -- | greater CGrOp :: CBinaryOp -- | less or equal CLeqOp :: CBinaryOp -- | greater or equal CGeqOp :: CBinaryOp -- | equal CEqOp :: CBinaryOp -- | not equal CNeqOp :: CBinaryOp -- | bitwise and CAndOp :: CBinaryOp -- | exclusive bitwise or CXorOp :: CBinaryOp -- | inclusive bitwise or COrOp :: CBinaryOp -- | logical and CLndOp :: CBinaryOp -- | logical or CLorOp :: CBinaryOp -- | C unary operator (K&R A7.3-4) data CUnaryOp -- | prefix increment operator CPreIncOp :: CUnaryOp -- | prefix decrement operator CPreDecOp :: CUnaryOp -- | postfix increment operator CPostIncOp :: CUnaryOp -- | postfix decrement operator CPostDecOp :: CUnaryOp -- | address operator CAdrOp :: CUnaryOp -- | indirection operator CIndOp :: CUnaryOp -- | prefix plus CPlusOp :: CUnaryOp -- | prefix minus CMinOp :: CUnaryOp -- | one's complement CCompOp :: CUnaryOp -- | logical negation CNegOp :: CUnaryOp -- | GNU Builtins, which cannot be typed in C99 data CBuiltin -- |
--   (expr, type)
--   
CBuiltinVaArg :: CExpr -> CDecl -> NodeInfo -> CBuiltin -- |
--   (type, designator-list)
--   
CBuiltinOffsetOf :: CDecl -> [CDesignator] -> NodeInfo -> CBuiltin -- |
--   (type,type)
--   
CBuiltinTypesCompatible :: CDecl -> CDecl -> NodeInfo -> CBuiltin -- | C constant (K&R A2.5 & A7.2) data CConst CIntConst :: CInteger -> NodeInfo -> CConst CCharConst :: CChar -> NodeInfo -> CConst CFloatConst :: CFloat -> NodeInfo -> CConst CStrConst :: CString -> NodeInfo -> CConst -- | Attributed string literals data CStrLit CStrLit :: CString -> NodeInfo -> CStrLit cstringOfLit :: CStrLit -> CString -- | Lift a string literal to a C constant liftStrLit :: CStrLit -> CConst instance Typeable CStrLit instance Typeable CConst instance Typeable CBuiltin instance Typeable CExpr instance Typeable CAttr instance Typeable CDesignator instance Typeable CInit instance Typeable CEnum instance Typeable CStructTag instance Typeable CStructUnion instance Typeable CTypeQual instance Typeable CTypeSpec instance Typeable CStorageSpec instance Typeable CDeclSpec instance Typeable CBlockItem instance Typeable CAsmOperand instance Typeable CAsmStmt instance Typeable CStat instance Typeable CArrSize instance Typeable CDerivedDeclr instance Typeable CDeclr instance Typeable CDecl instance Typeable CFunDef instance Typeable CExtDecl instance Typeable CTranslUnit instance Data CStrLit instance Data CConst instance Data CBuiltin instance Data CExpr instance Data CAttr instance Data CDesignator instance Data CInit instance Data CEnum instance Eq CStructTag instance Data CStructTag instance Data CStructUnion instance Data CTypeQual instance Data CTypeSpec instance Eq CStorageSpec instance Ord CStorageSpec instance Data CStorageSpec instance Data CDeclSpec instance Data CBlockItem instance Data CAsmOperand instance Data CAsmStmt instance Data CStat instance Data CArrSize instance Data CDerivedDeclr instance Data CDeclr instance Data CDecl instance Data CFunDef instance Data CExtDecl instance Data CTranslUnit instance Pos CStrLit instance CNode CStrLit instance Pos CConst instance CNode CConst instance Pos CBuiltin instance CNode CBuiltin instance Pos CExpr instance CNode CExpr instance Pos CAttr instance CNode CAttr instance Pos CDesignator instance CNode CDesignator instance Pos CInit instance CNode CInit instance Pos CEnum instance CNode CEnum instance Pos CStructUnion instance CNode CStructUnion instance Pos CTypeQual instance CNode CTypeQual instance Pos CTypeSpec instance CNode CTypeSpec instance Pos CStorageSpec instance CNode CStorageSpec instance Pos CDeclSpec instance CNode CDeclSpec instance Pos CBlockItem instance CNode CBlockItem instance Pos CAsmOperand instance CNode CAsmOperand instance Pos CAsmStmt instance CNode CAsmStmt instance Pos CStat instance CNode CStat instance Pos CDerivedDeclr instance CNode CDerivedDeclr instance Pos CDeclr instance CNode CDeclr instance Pos CDecl instance CNode CDecl instance Pos CFunDef instance CNode CFunDef instance Pos CExtDecl instance CNode CExtDecl instance Pos CTranslUnit instance CNode CTranslUnit instance Show CStorageSpec -- | Base type for errors occuring in parsing, analysing and -- pretty-printing. With ideas from Simon Marlow's An extensible -- dynamically-typed hierarchy of execeptions [2006] module Language.C.Data.Error -- | Error levels (severity) data ErrorLevel LevelWarn :: ErrorLevel LevelError :: ErrorLevel LevelFatal :: ErrorLevel -- | return True when the given error makes it impossible to -- continue analysis or compilation. isHardError :: (Error ex) => ex -> Bool -- | errors in Language.C are instance of Error class (Typeable e, Show e) => Error e errorInfo :: (Error e) => e -> ErrorInfo toError :: (Error e) => e -> CError fromError :: (Error e) => CError -> (Maybe e) changeErrorLevel :: (Error e) => e -> ErrorLevel -> e -- | position of an Error errorPos :: (Error e) => e -> Position -- | severity level of an Error errorLevel :: (Error e) => e -> ErrorLevel -- | message lines of an Error errorMsgs :: (Error e) => e -> [String] -- | supertype of all errors data CError CError :: err -> CError -- | information attached to every error in Language.C data ErrorInfo ErrorInfo :: ErrorLevel -> Position -> [String] -> ErrorInfo showError :: (Error e) => String -> e -> String -- | converts an error into a string using a fixed format -- -- -- --
--   <fname>:<row>: (column <col>) [<err lvl>]
--     >>> <line_1>
--     <line_2>
--       ...
--     <line_n>
--   
showErrorInfo :: String -> ErrorInfo -> String mkErrorInfo :: ErrorLevel -> String -> NodeInfo -> ErrorInfo -- | error raised if a operation requires an unsupported or not yet -- implemented feature. data UnsupportedFeature unsupportedFeature :: (Pos a) => String -> a -> UnsupportedFeature unsupportedFeature_ :: String -> UnsupportedFeature -- | unspecified error raised by the user (in case the user does not want -- to define her own error types). data UserError userErr :: String -> UserError -- | raise a fatal internal error; message may have multiple lines internalErr :: String -> a instance Typeable UserError instance Typeable UnsupportedFeature instance Typeable CError instance Typeable ErrorInfo instance Eq ErrorLevel instance Ord ErrorLevel instance Show UserError instance Error UserError instance Show UnsupportedFeature instance Error UnsupportedFeature instance Error CError instance Show CError instance Error ErrorInfo instance Show ErrorInfo instance Show ErrorLevel -- | Compile time input abstraction for the parser. Supports either -- ByteString or String. module Language.C.Data.InputStream type InputStream = ByteString -- | read a file into an InputStream readInputStream :: FilePath -> IO InputStream -- | convert InputStream to String inputStreamToString :: InputStream -> String -- | convert a String to an InputStream inputStreamFromString :: String -> InputStream -- | (c,is') = takeChar is reads and removes the first character -- c from the InputStream is takeChar :: InputStream -> (Char, InputStream) -- | return True if the given input stream is empty inputStreamEmpty :: InputStream -> Bool -- | str = takeChars n is returns the first n characters -- of the given input stream, without removing them takeChars :: Int -> InputStream -> [Char] -- | countLines returns the number of text lines in the given -- InputStream countLines :: InputStream -> Int -- | Invoking external preprocessors. module Language.C.System.Preprocess -- | Preprocessor encapsulates the abstract interface for invoking C -- preprocessors class Preprocessor cpp parseCPPArgs :: (Preprocessor cpp) => cpp -> [String] -> Either String (CppArgs, [String]) runCPP :: (Preprocessor cpp) => cpp -> CppArgs -> IO ExitCode -- | Generic Options for the preprocessor data CppOption IncludeDir :: FilePath -> CppOption Define :: String -> String -> CppOption Undefine :: String -> CppOption IncludeFile :: FilePath -> CppOption -- | Generic arguments for the preprocessor data CppArgs CppArgs :: [CppOption] -> [String] -> Maybe FilePath -> FilePath -> Maybe FilePath -> CppArgs cppOptions :: CppArgs -> [CppOption] extraOptions :: CppArgs -> [String] cppTmpDir :: CppArgs -> Maybe FilePath inputFile :: CppArgs -> FilePath outputFile :: CppArgs -> Maybe FilePath -- | use the given preprocessor arguments without analyzing them rawCppArgs :: [String] -> FilePath -> CppArgs -- | add a typed option to the given preprocessor arguments addCppOption :: CppArgs -> CppOption -> CppArgs -- | add a string option to the given preprocessor arguments addExtraOption :: CppArgs -> String -> CppArgs -- | run the preprocessor and return an InputStream if -- preprocesssing succeeded runPreprocessor :: (Preprocessor cpp) => cpp -> CppArgs -> IO (Either ExitCode InputStream) -- | guess whether a file is preprocessed (file end with .i) isPreprocessed :: FilePath -> Bool -- | Invoking gcc for preprocessing and compiling. module Language.C.System.GCC -- | GCC represents a reference to the gcc compiler data GCC -- | create a reference to gcc newGCC :: FilePath -> GCC instance Preprocessor GCC -- | Syntax of C files: The abstract syntax tree and constants. module Language.C.Syntax -- | Language.C parser module Language.C.Parser -- | parseC input initialPos parses the given preprocessed -- C-source input and returns the AST or a list of parse errors. parseC :: InputStream -> Position -> Either ParseError CTranslUnit newtype ParseError ParseError :: ([String], Position) -> ParseError -- | Common data types for Language.C: Identifiers, unique names, source -- code locations, ast node attributes and extensible errors. module Language.C.Data -- | References uniquely determining a struct, union or enum type. Those -- are either identified by an string identifier, or by a unique name -- (anonymous types). data SUERef AnonymousRef :: Name -> SUERef NamedRef :: Ident -> SUERef -- | Return true if the struct/union/enum reference is anonymous. isAnonymousRef :: SUERef -> Bool -- | C identifiers data Ident -- | build an identifier from a string. -- -- mkIdent :: Position -> String -> Name -> Ident -- | string of an identifier identToString :: Ident -> String -- | returns an internal identifier (has internal position and no -- unique name) internalIdent :: String -> Ident -- | return True if the given identifier is internal isInternalIdent :: Ident -> Bool -- | returns a builtin identifier (has builtin position and no -- unique name) builtinIdent :: String -> Ident -- | Name is a unique identifier newtype Name Name :: Int -> Name nameId :: Name -> Int -- | get the infinite stream of unique names starting from the given -- integer namesStartingFrom :: Int -> [Name] -- | uniform representation of source file positions; the order of the -- arguments is important as it leads to the desired ordering of source -- positions data Position Position :: String -> !!Int -> !!Int -> Position -- | class of type which aggregate a source code location class Pos a posOf :: (Pos a) => a -> Position -- | get the source file of the specified position. Fails unless -- isSourcePos pos. posFile :: Position -> String -- | get the line number of the specified position. Fails unless -- isSourcePos pos posRow :: Position -> Int -- | get the column of the specified position. Fails unless isSourcePos -- pos posColumn :: Position -> Int -- | no position (for unknown position information) nopos :: Position -- | position attached to built-in objects builtinPos :: Position -- | position used for internal errors internalPos :: Position -- | returns True if the given position refers to an actual source -- file isSourcePos :: Position -> Bool -- | returns True if the given position refers to a builtin -- definition isBuiltinPos :: Position -> Bool -- | returns True if the given position is internal isInternalPos :: Position -> Bool -- | Parsed entity attribute data NodeInfo OnlyPos :: Position -> NodeInfo NodeInfo :: Position -> Name -> NodeInfo -- | a class for convenient access to the attributes of an attributed -- object class CNode a nodeInfo :: (CNode a) => a -> NodeInfo fileOfNode :: (CNode a) => a -> FilePath posOfNode :: NodeInfo -> Position nameOfNode :: NodeInfo -> Maybe Name internalNode :: NodeInfo -- | Given only a source position, create a new attribute identifier mkNodeInfoOnlyPos :: Position -> NodeInfo -- | Given a source position and a unique name, create a new attribute -- identifier mkNodeInfo :: Position -> Name -> NodeInfo -- | This module provides a pretty printer for the parse tree -- (Language.C.Syntax.AST). module Language.C.Pretty -- | A class of types which can be pretty printed class Pretty p pretty :: (Pretty p) => p -> Doc prettyPrec :: (Pretty p) => Int -> p -> 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 usefull -- for testing, as otherwise the pretty printed file will be cluttered -- with declarations from system headers. prettyUsingInclude :: CTranslUnit -> Doc instance Pretty CStrLit instance Pretty CConst instance Pretty CUnaryOp instance Pretty CBinaryOp instance Pretty CAssignOp instance Pretty CBuiltin instance Pretty CExpr instance Pretty CAttr instance Pretty CDesignator instance Pretty CInit instance Pretty CArrSize instance Pretty CDeclr instance Pretty CEnum instance Pretty CStructTag instance Pretty CStructUnion instance Pretty CTypeQual instance Pretty CTypeSpec instance Pretty CStorageSpec instance Pretty CDeclSpec instance Pretty CDecl instance Pretty CBlockItem instance Pretty CAsmOperand instance Pretty CAsmStmt instance Pretty CStat instance Pretty CFunDef instance Pretty CExtDecl instance Pretty CTranslUnit -- | This module contains definitions for representing C translation units. -- In contrast to Language.C.Syntax.AST, the representation -- tries to express the semantics of of a translation unit. module Language.C.Analysis.SemRep -- | Composite type definitions (tags) data TagDef CompDef :: CompType -> TagDef EnumDef :: EnumType -> TagDef -- | return the type corresponding to a tag definition typeOfTagDef :: TagDef -> TypeName -- | All datatypes aggregating a declaration are instances of -- Declaration class Declaration n getVarDecl :: (Declaration n) => n -> VarDecl -- | get the variable identifier of a declaration (only safe if the the -- declaration is known to have a name) declIdent :: (Declaration n) => n -> Ident -- | get the variable name of a Declaration declName :: (Declaration n) => n -> VarName -- | get the type of a Declaration declType :: (Declaration n) => n -> Type -- | get the declaration attributes of a Declaration declAttrs :: (Declaration n) => n -> DeclAttrs -- | identifiers, typedefs and enumeration constants (namespace sum) data IdentDecl -- | object or function declaration Declaration :: Decl -> IdentDecl -- | object definition ObjectDef :: ObjDef -> IdentDecl -- | function definition FunctionDef :: FunDef -> IdentDecl -- | definition of an enumerator EnumeratorDef :: Enumerator -> IdentDecl -- | textual description of the kind of an object objKindDescr :: IdentDecl -> String -- | splitIdentDecls includeAllDecls splits a map of object, -- function and enumerator declarations and definitions into one map -- holding declarations, and three maps for object definitions, -- enumerator definitions and function definitions. If -- includeAllDecls is True all declarations are present -- in the first map, otherwise only those where no corresponding -- definition is available. splitIdentDecls :: Bool -> Map Ident IdentDecl -> (Map Ident Decl, (Map Ident Enumerator, Map Ident ObjDef, Map Ident FunDef)) -- | global declaration/definition table returned by the analysis data GlobalDecls GlobalDecls :: Map Ident IdentDecl -> Map SUERef TagDef -> Map Ident TypeDef -> GlobalDecls gObjs :: GlobalDecls -> Map Ident IdentDecl gTags :: GlobalDecls -> Map SUERef TagDef gTypeDefs :: GlobalDecls -> Map Ident TypeDef -- | empty global declaration table emptyGlobalDecls :: GlobalDecls -- | filter global declarations filterGlobalDecls :: (DeclEvent -> Bool) -> GlobalDecls -> GlobalDecls -- | merge global declarations mergeGlobalDecls :: GlobalDecls -> GlobalDecls -> GlobalDecls -- | Declaration events -- -- Those events are reported to callbacks, which are executed during the -- traversal. data DeclEvent -- | file-scope struct/union/enum event TagEvent :: TagDef -> DeclEvent -- | file-scope declaration or definition DeclEvent :: IdentDecl -> DeclEvent -- | a type definition TypeDefEvent :: TypeDef -> DeclEvent -- | assembler block AsmEvent :: AsmBlock -> DeclEvent -- | Declarations, which aren't definitions data Decl Decl :: VarDecl -> NodeInfo -> Decl -- | Object Definitions -- -- An object definition is a declaration together with an initializer. -- -- If the initializer is missing, it is a tentative definition, i.e. a -- definition which might be overriden later on. data ObjDef ObjDef :: VarDecl -> (Maybe Initializer) -> NodeInfo -> ObjDef -- | Returns True if the given object definition is tentative. isTentative :: ObjDef -> Bool -- | Function definitions -- -- A function definition is a declaration together with a statement (the -- function body). data FunDef FunDef :: VarDecl -> Stmt -> NodeInfo -> FunDef -- | Parameter declaration data ParamDecl ParamDecl :: VarDecl -> NodeInfo -> ParamDecl AbstractParamDecl :: VarDecl -> NodeInfo -> ParamDecl -- | Struct/Union member declaration data MemberDecl -- |
--   MemberDecl vardecl bitfieldsize node
--   
MemberDecl :: VarDecl -> (Maybe Expr) -> NodeInfo -> MemberDecl -- |
--   AnonBitField typ size
--   
AnonBitField :: Type -> Expr -> NodeInfo -> MemberDecl -- | typedef definitions. -- -- The identifier is a new name for the given type. data TypeDef TypeDef :: Ident -> Type -> Attributes -> NodeInfo -> TypeDef -- | return the idenitifier of a typedef identOfTypeDef :: TypeDef -> Ident -- | Generic variable declarations data VarDecl VarDecl :: VarName -> DeclAttrs -> Type -> VarDecl -- | Declaration attributes of the form DeclAttrs isInlineFunction -- storage linkage attrs -- -- They specify the storage and linkage of a declared object. data DeclAttrs -- |
--   DeclAttrs inline storage attrs
--   
DeclAttrs :: Bool -> Storage -> Attributes -> DeclAttrs isExtDecl :: (Declaration n) => n -> Bool -- | Storage duration and linkage of a variable data Storage -- | no storage NoStorage :: Storage -- | automatic storage (optional: register) Auto :: Register -> Storage -- | static storage, with linkage and thread local specifier (gnu c) Static :: Linkage -> ThreadLocal -> Storage -- | function, either internal or external linkage FunLinkage :: Linkage -> Storage -- | get the Storage of a declaration declStorage :: (Declaration d) => d -> Storage type ThreadLocal = Bool -- | Linkage: Either internal to the translation unit or external data Linkage InternalLinkage :: Linkage ExternalLinkage :: Linkage -- | types of C objects data Type -- | a non-derived type DirectType :: TypeName -> TypeQuals -> Type -- | pointer type PtrType :: Type -> TypeQuals -> Attributes -> Type -- | array type ArrayType :: Type -> ArraySize -> TypeQuals -> Attributes -> Type -- | function type FunctionType :: FunType -> Type -- | a defined type TypeDefType :: TypeDefRef -> Type -- | (GNU) typeof (broken and should be removed, but we do not yet -- have expression type analysis) TypeOfExpr :: Expr -> Type -- | Function types are of the form FunType return-type params -- isVariadic attrs. -- -- If the parameter types aren't yet known, the function has type -- FunTypeIncomplete type attrs. data FunType FunType :: Type -> [ParamDecl] -> Bool -> Attributes -> FunType FunTypeIncomplete :: Type -> Attributes -> FunType -- | return True if the given type is a function type -- -- Result is undefined in the presence of TypeOfExpr or undefined -- typeDefs isFunctionType :: Type -> Bool -- | resolve typedefs, if possible derefTypeDef :: Type -> Type referencedType :: Type -> Maybe Type hasTypeOfExpr :: Type -> Bool -- | An array type may either have unknown size or a specified array size, -- the latter either variable or constant. Furthermore, when used as a -- function parameters, the size may be qualified as static. In a -- function prototype, the size may be `Unspecified variable size' -- ([*]). data ArraySize -- |
--   UnknownArraySize is-starred
--   
UnknownArraySize :: Bool -> ArraySize -- |
--   FixedSizeArray is-static size-expr
--   
ArraySize :: Bool -> Expr -> ArraySize -- | typdef references If the actual type is known, it is attached for -- convenience data TypeDefRef TypeDefRef :: Ident -> (Maybe Type) -> NodeInfo -> TypeDefRef -- | normalized type representation data TypeName TyVoid :: TypeName TyIntegral :: IntType -> TypeName TyFloating :: FloatType -> TypeName TyComplex :: FloatType -> TypeName TyComp :: CompTypeRef -> TypeName TyEnum :: EnumTypeRef -> TypeName TyBuiltin :: BuiltinType -> TypeName -- | Builtin type (va_list) data BuiltinType TyVaList :: BuiltinType -- | integral types (C99 6.7.2.2) data IntType TyBool :: IntType TyChar :: IntType TySChar :: IntType TyUChar :: IntType TyShort :: IntType TyUShort :: IntType TyInt :: IntType TyUInt :: IntType TyLong :: IntType TyULong :: IntType TyLLong :: IntType TyULLong :: IntType -- | floating point type (C99 6.7.2.2) data FloatType TyFloat :: FloatType TyDouble :: FloatType TyLDouble :: FloatType -- | accessor class : struct/union/enum names class HasSUERef a sueRef :: (HasSUERef a) => a -> SUERef -- | accessor class : composite type tags (struct or union) class HasCompTyKind a compTag :: (HasCompTyKind a) => a -> CompTyKind -- | composite type declarations data CompTypeRef CompTypeRef :: SUERef -> CompTyKind -> NodeInfo -> CompTypeRef -- | Composite type (struct or union). data CompType CompType :: SUERef -> CompTyKind -> [MemberDecl] -> Attributes -> NodeInfo -> CompType -- | return the type of a composite type definition typeOfCompDef :: CompType -> TypeName -- | a tag to determine wheter we refer to a struct or -- union, see CompType. data CompTyKind StructTag :: CompTyKind UnionTag :: CompTyKind data EnumTypeRef EnumTypeRef :: SUERef -> NodeInfo -> EnumTypeRef -- | Representation of C enumeration types data EnumType -- |
--   EnumType name enumeration-constants attrs node
--   
EnumType :: SUERef -> [Enumerator] -> Attributes -> NodeInfo -> EnumType -- | return the type of an enum definition typeOfEnumDef :: EnumType -> TypeName -- | An Enumerator consists of an identifier, a constant expressions and -- the link to its type data Enumerator Enumerator :: Ident -> Expr -> EnumType -> NodeInfo -> Enumerator -- | Type qualifiers: constant, volatile and restrict data TypeQuals TypeQuals :: Bool -> Bool -> Bool -> TypeQuals constant :: TypeQuals -> Bool volatile :: TypeQuals -> Bool restrict :: TypeQuals -> Bool -- | no type qualifiers noTypeQuals :: TypeQuals -- | merge (&&) two type qualifier sets mergeTypeQuals :: TypeQuals -> TypeQuals -> TypeQuals -- | VarName name assembler-name is a name of an declared object data VarName VarName :: Ident -> (Maybe AsmName) -> VarName NoName :: VarName identOfVarName :: VarName -> Ident -- | Assembler name (alias for CStrLit) type AsmName = CStrLit -- | __attribute__ annotations -- -- Those are of the form Attr attribute-name -- attribute-parameters, and serve as generic properties of some -- syntax tree elements. -- -- Some examples: -- -- -- -- TODO: ultimatively, we want to parse attributes and represent -- them in a typed way data Attr Attr :: Ident -> [Expr] -> NodeInfo -> Attr type Attributes = [Attr] -- | Stmt is an alias for CStat (Syntax) type Stmt = CStat -- | Expr is currently an alias for CExpr (Syntax) type Expr = CExpr -- | Initializer is currently an alias for CInit. -- -- We're planning a normalized representation, but this depends on the -- implementation of constant expression evaluation type Initializer = CInit -- | Top level assembler block (alias for CStrLit) type AsmBlock = CStrLit instance Typeable Attr instance Typeable VarName instance Typeable TypeQuals instance Typeable Enumerator instance Typeable EnumType instance Typeable CompTyKind instance Typeable CompType instance Typeable EnumTypeRef instance Typeable CompTypeRef instance Typeable FloatType instance Typeable IntType instance Typeable TypeDefRef instance Typeable BuiltinType instance Typeable TypeName instance Typeable ArraySize instance Typeable FunType instance Typeable Type instance Typeable Linkage instance Typeable Storage instance Typeable DeclAttrs instance Typeable VarDecl instance Typeable TypeDef instance Typeable MemberDecl instance Typeable ParamDecl instance Typeable FunDef instance Typeable ObjDef instance Typeable Decl instance Typeable IdentDecl instance Typeable TagDef instance Data Attr instance Data VarName instance Data TypeQuals instance Data Enumerator instance Data EnumType instance Eq CompTyKind instance Ord CompTyKind instance Data CompTyKind instance Data CompType instance Data EnumTypeRef instance Data CompTypeRef instance Data FloatType instance Eq FloatType instance Ord FloatType instance Data IntType instance Eq IntType instance Ord IntType instance Data TypeDefRef instance Data BuiltinType instance Data TypeName instance Data ArraySize instance Data FunType instance Data Type instance Data Linkage instance Show Linkage instance Eq Linkage instance Ord Linkage instance Data Storage instance Show Storage instance Eq Storage instance Ord Storage instance Data DeclAttrs instance Data VarDecl instance Data TypeDef instance Data MemberDecl instance Data ParamDecl instance Data FunDef instance Data ObjDef instance Data Decl instance Data IdentDecl instance Data TagDef instance Pos Attr instance CNode Attr instance Pos Enumerator instance CNode Enumerator instance Pos EnumType instance CNode EnumType instance Pos CompType instance CNode CompType instance Pos EnumTypeRef instance CNode EnumTypeRef instance Pos CompTypeRef instance CNode CompTypeRef instance Pos TypeDefRef instance CNode TypeDefRef instance Pos TypeDef instance CNode TypeDef instance Pos MemberDecl instance CNode MemberDecl instance Pos ParamDecl instance CNode ParamDecl instance Pos FunDef instance CNode FunDef instance Pos ObjDef instance CNode ObjDef instance Pos Decl instance CNode Decl instance Pos DeclEvent instance CNode DeclEvent instance Pos IdentDecl instance CNode IdentDecl instance Pos TagDef instance CNode TagDef instance Declaration Enumerator instance HasSUERef EnumType instance Show CompTyKind instance HasCompTyKind CompType instance HasSUERef CompType instance HasSUERef EnumTypeRef instance HasCompTyKind CompTypeRef instance HasSUERef CompTypeRef instance Show FloatType instance Show IntType instance Declaration VarDecl instance Declaration MemberDecl instance Declaration ParamDecl instance Declaration FunDef instance Declaration ObjDef instance Declaration Decl instance Declaration IdentDecl instance (Declaration a, Declaration b) => Declaration (Either a b) instance HasSUERef TagDef -- | Errors in the semantic analysis module Language.C.Analysis.SemError -- | InvalidASTError is caused by the violation of an invariant in the AST newtype InvalidASTError InvalidAST :: ErrorInfo -> InvalidASTError invalidAST :: NodeInfo -> String -> InvalidASTError -- | BadSpecifierError is caused by an invalid combination of specifiers newtype BadSpecifierError BadSpecifierError :: ErrorInfo -> BadSpecifierError badSpecifierError :: NodeInfo -> String -> BadSpecifierError data TypeMismatch TypeMismatch :: String -> (NodeInfo, Type) -> (NodeInfo, Type) -> TypeMismatch typeMismatch :: String -> (NodeInfo, Type) -> (NodeInfo, Type) -> TypeMismatch -- | RedefError is caused by an invalid redefinition of the same identifier -- or type data RedefError RedefError :: ErrorLevel -> RedefInfo -> RedefError data RedefInfo RedefInfo :: String -> RedefKind -> NodeInfo -> NodeInfo -> RedefInfo data RedefKind DuplicateDef :: RedefKind DiffKindRedecl :: RedefKind ShadowedDef :: RedefKind redefinition :: ErrorLevel -> String -> RedefKind -> NodeInfo -> NodeInfo -> RedefError instance Typeable TypeMismatch instance Typeable RedefError instance Typeable BadSpecifierError instance Typeable InvalidASTError instance Error BadSpecifierError instance Error InvalidASTError instance Error RedefError instance Show RedefError instance Error TypeMismatch instance Show TypeMismatch instance Show BadSpecifierError instance Show InvalidASTError -- | WARNING : This is just an implementation sketch and not very -- well tested. -- -- Export SemRep entities to AST nodes. module Language.C.Analysis.Export exportType :: Type -> ([CDeclSpec], [CDerivedDeclr]) exportTypeDecl :: Type -> CDecl exportTypeSpec :: TypeName -> [CTypeSpec] exportTypeDef :: TypeDef -> CDecl exportCompType :: CompType -> [CTypeSpec] exportCompTypeDecl :: CompTypeRef -> [CTypeSpec] exportCompTypeRef :: CompType -> [CTypeSpec] exportEnumType :: EnumType -> [CTypeSpec] exportEnumTypeDecl :: EnumTypeRef -> [CTypeSpec] exportEnumTypeRef :: EnumType -> [CTypeSpec] -- | Pretty printing the semantic analysis representation. This is -- currently only intended for debugging purposes. module Language.C.Analysis.Debug globalDeclStats :: (FilePath -> Bool) -> GlobalDecls -> [(String, Int)] prettyAssocs :: (Pretty k, Pretty v) => String -> [(k, v)] -> Doc prettyAssocsWith :: String -> (k -> Doc) -> (v -> Doc) -> [(k, v)] -> Doc instance Pretty Attr instance Pretty Attributes instance Pretty VarName instance Pretty Linkage instance Pretty Storage instance Pretty Enumerator instance Pretty EnumType instance Pretty MemberDecl instance Pretty CompType instance Pretty TypeQuals instance Pretty Type instance Pretty DeclAttrs instance Pretty ParamDecl instance Pretty VarDecl instance Pretty FunDef instance Pretty ObjDef instance Pretty TypeDef instance Pretty Decl instance Pretty IdentDecl instance Pretty TagDef instance Pretty SUERef instance Pretty Ident instance Pretty (Either VarDecl FunDef) instance Pretty (Either VarDecl ObjDef) instance Pretty GlobalDecls -- | This module manages symbols in local and global scopes. -- -- There are four different kind of identifiers: ordinary identifiers -- (henceforth simply called identifier), tag names (names of -- struct/union/enum types), labels and structure members. module Language.C.Analysis.DefTable -- | All ordinary identifiers map to IdenTyDecl: either a typedef -- or a object/function/enumerator type IdentEntry = Either TypeDef IdentDecl identOfTyDecl :: IdentEntry -> Ident -- | Tag names map to forward declarations or definitions of -- struct/union/enum types type TagEntry = Either TagFwdDecl TagDef data TagFwdDecl CompDecl :: CompTypeRef -> TagFwdDecl EnumDecl :: EnumTypeRef -> TagFwdDecl -- | Table holding current definitions data DefTable DefTable :: NameSpaceMap Ident IdentEntry -> NameSpaceMap SUERef TagEntry -> NameSpaceMap Ident Ident -> NameSpaceMap Ident MemberDecl -> NameMap Name -> DefTable -- | declared `ordinary identifiers' identDecls :: DefTable -> NameSpaceMap Ident IdentEntry -- | declared structunionenum tags tagDecls :: DefTable -> NameSpaceMap SUERef TagEntry -- | defined labels labelDefs :: DefTable -> NameSpaceMap Ident Ident -- | member declarations (only local) memberDecls :: DefTable -> NameSpaceMap Ident MemberDecl -- | link names with definitions refTable :: DefTable -> NameMap Name -- | empty definition table, with all name space maps in global scope emptyDefTable :: DefTable -- | get the globally defined entries of a definition table globalDefs :: DefTable -> GlobalDecls -- | Enter function scope (and the corresponding block scope) enterFunctionScope :: DefTable -> DefTable -- | Leave function scope, and return the associated DefTable. Error if not -- in function scope. leaveFunctionScope :: DefTable -> DefTable -- | Enter new block scope enterBlockScope :: DefTable -> DefTable -- | Leave innermost block scope leaveBlockScope :: DefTable -> DefTable -- | Enter new member declaration scope enterMemberDecl :: DefTable -> DefTable -- | Leave innermost member declaration scope leaveMemberDecl :: DefTable -> ([MemberDecl], DefTable) -- | Status of a declaration data DeclarationStatus t -- | new entry NewDecl :: DeclarationStatus t -- | old def was overwritten Redeclared :: t -> DeclarationStatus t -- | new def was discarded KeepDef :: t -> DeclarationStatus t -- | new def shadows one in outer scope Shadowed :: t -> DeclarationStatus t -- | kind mismatch KindMismatch :: t -> DeclarationStatus t declStatusDescr :: DeclarationStatus t -> String defineTypeDef :: Ident -> TypeDef -> DefTable -> (DeclarationStatus IdentEntry, DefTable) -- | declare/define a global object/function/typeDef -- -- returns Redeclared def if there is already an -- object/function/typeDef in global scope, or DifferentKindRedec -- def if the old declaration is of a different kind. defineGlobalIdent :: Ident -> IdentDecl -> DefTable -> (DeclarationStatus IdentEntry, DefTable) -- | declare/define a object/function/typeDef with lexical scope -- -- returns Redeclared def or DifferentKindRedec def if -- there is already an object/function/typeDef in the same scope. defineScopedIdent :: Ident -> IdentDecl -> DefTable -> (DeclarationStatus IdentEntry, DefTable) -- | declare/define a object/function/typeDef with lexical scope, if the -- given predicate holds on the old entry. -- -- returns Keep old_def if the old definition shouldn't be -- overwritten, and otherwise Redeclared def or -- DifferentKindRedec def if there is already an -- object/function/typeDef in the same scope. defineScopedIdentWhen :: (IdentDecl -> Bool) -> Ident -> IdentDecl -> DefTable -> (DeclarationStatus IdentEntry, DefTable) -- | declare a tag (fwd decl in case the struct name isn't defined yet) declareTag :: SUERef -> TagFwdDecl -> DefTable -> (DeclarationStatus TagEntry, DefTable) -- | define a tag defineTag :: SUERef -> TagDef -> DefTable -> (DeclarationStatus TagEntry, DefTable) -- | define a label Return the old label if it is already defined in this -- function's scope defineLabel :: Ident -> DefTable -> (DeclarationStatus Ident, DefTable) -- | lookup identifier (object, function, typeDef, enumerator) lookupIdent :: Ident -> DefTable -> Maybe IdentEntry -- | lookup tag lookupTag :: SUERef -> DefTable -> Maybe TagEntry -- | lookup label lookupLabel :: Ident -> DefTable -> Maybe Ident -- | lookup an object in the innermost scope lookupIdentInner :: Ident -> DefTable -> Maybe IdentEntry -- | lookup an identifier in the innermost scope lookupTagInner :: SUERef -> DefTable -> Maybe TagEntry instance Typeable1 DeclarationStatus instance Eq TagEntryKind instance Ord TagEntryKind instance (Data t) => Data (DeclarationStatus t) instance Show TagEntryKind instance CNode TagFwdDecl instance HasSUERef TagFwdDecl -- | Monad for Traversals of the C AST. -- -- For the traversal, we maintain a symboltable and need MonadError and -- unique name generation facilities. Furthermore, the user may provide -- callbacks to handle declarations and definitions. module Language.C.Analysis.TravMonad -- | Traversal monad class (Monad m) => MonadTrav m throwTravError :: (MonadTrav m, Error e) => e -> m a catchTravError :: (MonadTrav m) => m a -> (CError -> m a) -> m a recordError :: (MonadTrav m, Error e) => e -> m () getErrors :: (MonadTrav m) => m [CError] getDefTable :: (MonadTrav m) => m DefTable withDefTable :: (MonadTrav m) => (DefTable -> (a, DefTable)) -> m a genName :: (MonadTrav m) => m Name handleDecl :: (MonadTrav m) => DeclEvent -> m () -- | forward declaration of a tag. Only neccessary for name analysis, but -- otherwise no semantic consequences. handleTagDecl :: (MonadTrav m) => TagFwdDecl -> m () -- | define the given composite type or enumeration If there is a -- declaration visible, overwrite it with the definition. Otherwise, -- enter a new definition in the current namespace. If there is already a -- definition present, yield an error (redeclaration). handleTagDef :: (MonadTrav m) => TagDef -> m () handleEnumeratorDef :: (MonadTrav m) => Enumerator -> m () handleTypeDef :: (MonadTrav m) => TypeDef -> m () -- | handle object defintions (maybe tentative) handleObjectDef :: (MonadTrav m) => Ident -> ObjDef -> m () -- | handle function definitions handleFunDef :: (MonadTrav m) => Ident -> FunDef -> m () -- | handle variable declarations (external object declarations and -- function prototypes) variable declarations are either function -- prototypes, or external declarations, and not very interesting on -- their own. we only put them in the symbol table and call the handle. -- declarations never override definitions handleVarDecl :: (MonadTrav m) => Decl -> m () -- | handle parameter declaration. The interesting part is that parameters -- can be abstract (if they are part of a type). If they have a name, we -- enter the name (usually in function prototype or function scope), -- checking if there are duplicate definitions. FIXME: I think it would -- be more transparent to handle parameter declarations in a special way handleParamDecl :: (MonadTrav m) => ParamDecl -> m () handleAsmBlock :: (MonadTrav m) => AsmBlock -> m () enterPrototypeScope :: (MonadTrav m) => m () leavePrototypeScope :: (MonadTrav m) => m () enterFunctionScope :: (MonadTrav m) => m () leaveFunctionScope :: (MonadTrav m) => m () enterBlockScope :: (MonadTrav m) => m () leaveBlockScope :: (MonadTrav m) => m () -- | lookup a type definition the 'wrong kind of object' is an internal -- error here, because the parser should distinguish typeDefs and other -- objects lookupTypeDef :: (MonadTrav m) => Ident -> m Type -- | lookup an object, function or enumerator lookupObject :: (MonadTrav m) => Ident -> m (Maybe IdentDecl) -- | create a reference to a struct/union/enum -- -- This currently depends on the fact the structs are tagged with unique -- names. We could use the name generation of TravMonad as well, which -- might be the better choice when dealing with autogenerated code. createSUERef :: (MonadTrav m) => NodeInfo -> Maybe Ident -> m SUERef -- | check wheter non-recoverable errors occured hadHardErrors :: [CError] -> Bool handleTravError :: (MonadTrav m) => m a -> m (Maybe a) -- | raise an error based on an Either argument throwOnLeft :: (MonadTrav m, Error e) => Either e a -> m a -- | raise an error caused by a malformed AST astError :: (MonadTrav m) => NodeInfo -> String -> m a warn :: (Error e, MonadTrav m) => e -> m () -- | simple traversal monad, providing user state and callbacks newtype Trav s a Trav :: (TravState s -> Either CError (a, TravState s)) -> Trav s a unTrav :: Trav s a -> TravState s -> Either CError (a, TravState s) runTrav :: s -> Trav s a -> Either [CError] (a, TravState s) runTrav_ :: Trav () a -> Either [CError] (a, [CError]) data TravState s initTravState :: s -> TravState s withExtDeclHandler :: Trav s a -> (DeclEvent -> Trav s ()) -> Trav s a modifyUserState :: (s -> s) -> Trav s () userState :: TravState s -> s mapMaybeM :: (Monad m) => (Maybe a) -> (a -> m b) -> m (Maybe b) maybeM :: (Monad m) => (Maybe a) -> (a -> m ()) -> m () mapSndM :: (Monad m) => (b -> m c) -> (a, b) -> m (a, c) concatMapM :: (Monad m) => (a -> m [b]) -> [a] -> m [b] instance MonadTrav (Trav s) instance Monad (Trav s) -- | This module performs the analysis of declarations and the translation -- of type specifications in the AST. module Language.C.Analysis.DeclAnalysis -- | get the type of a type declaration -- -- A type declaration T may appear in thre forms: -- -- -- -- Currently, analyseTypeDecl is exlusively used for analysing -- types for GNU's typeof(T). -- -- We move attributes to the type, as they have no meaning for the -- abstract declarator analyseTypeDecl :: (MonadTrav m) => CDecl -> m Type -- | translate a type tType :: (MonadTrav m) => Bool -> NodeInfo -> [CTypeQual] -> [CTypeSpec] -> [CDerivedDeclr] -> [CDecl] -> m Type -- | translate a type without (syntactic) indirections Due to the GNU -- typeof extension and typeDefs, this can be an arbitrary type tDirectType :: (MonadTrav m) => Bool -> NodeInfo -> [CTypeQual] -> [CTypeSpec] -> m Type -- | Mapping from num type specs to C types (C99 6.7.2-2), ignoring the -- complex qualifier. tNumType :: (MonadTrav m) => NumTypeSpec -> m (Either (FloatType, Bool) IntType) tArraySize :: (MonadTrav m) => CArrSize -> m ArraySize tTypeQuals :: (MonadTrav m) => [CTypeQual] -> m (TypeQuals, Attributes) -- | convert old style parameters -- -- This requires matching parameter names and declarations, as in the -- following example: -- --
--   int f(d,c,a,b)
--   char a,*b;
--   int c;
--   { }
--   
-- -- is converted to -- --
--   int f(int d, int c, char a, char* b)
--   
-- -- TODO: This could be moved to syntax, as it operates on the AST only mergeOldStyle :: (MonadTrav m) => NodeInfo -> [CDecl] -> [CDerivedDeclr] -> m [CDerivedDeclr] canonicalTypeSpec :: (MonadTrav m) => [CTypeSpec] -> m TypeSpecAnalysis data NumBaseType NoBaseType :: NumBaseType BaseChar :: NumBaseType BaseInt :: NumBaseType BaseFloat :: NumBaseType BaseDouble :: NumBaseType data SignSpec NoSignSpec :: SignSpec Signed :: SignSpec Unsigned :: SignSpec data SizeMod NoSizeMod :: SizeMod ShortMod :: SizeMod LongMod :: SizeMod LongLongMod :: SizeMod data NumTypeSpec NumTypeSpec :: NumBaseType -> SignSpec -> SizeMod -> Bool -> NumTypeSpec base :: NumTypeSpec -> NumBaseType signSpec :: NumTypeSpec -> SignSpec sizeMod :: NumTypeSpec -> SizeMod isComplex :: NumTypeSpec -> Bool data TypeSpecAnalysis TSNone :: TypeSpecAnalysis TSVoid :: TypeSpecAnalysis TSBool :: TypeSpecAnalysis TSNum :: NumTypeSpec -> TypeSpecAnalysis TSNonBasic :: CTypeSpec -> TypeSpecAnalysis canonicalStorageSpec :: (MonadTrav m) => [CStorageSpec] -> m StorageSpec data StorageSpec NoStorageSpec :: StorageSpec AutoSpec :: StorageSpec RegSpec :: StorageSpec ThreadSpec :: StorageSpec StaticSpec :: Bool -> StorageSpec ExternSpec :: Bool -> StorageSpec hasThreadLocalSpec :: StorageSpec -> Bool data VarDeclInfo VarDeclInfo :: VarName -> Bool -> StorageSpec -> Attributes -> Type -> NodeInfo -> VarDeclInfo -- | translate __attribute__ annotations TODO: This is a unwrap -- and wrap stub tAttr :: (MonadTrav m) => CAttr -> m Attr -- | construct a name for a variable TODO: more or less bogus mkVarName :: (MonadTrav m) => NodeInfo -> Maybe Ident -> Maybe AsmName -> m VarName getOnlyDeclr :: (MonadTrav m) => CDecl -> m CDeclr nameOfDecl :: (MonadTrav m) => CDecl -> m Ident instance Eq SizeMod instance Ord SizeMod instance Eq SignSpec instance Ord SignSpec instance Eq NumBaseType instance Ord NumBaseType instance Eq StorageSpec instance Ord StorageSpec instance Show StorageSpec instance Read StorageSpec -- | Analyse the parse tree -- -- Traverses the AST, analyses declarations and invokes handlers. module Language.C.Analysis.AstAnalysis -- | Analyse the given AST -- -- analyseAST ast results in global declaration dictionaries. If -- you want to perform specific actions on declarations or definitions, -- you may provide callbacks in the MonadTrav m. -- -- Returns the set of global declarations and definitions which where -- successfully translated. It is the users responsibility to check -- whether any hard errors occured (runTrav does this for you). analyseAST :: (MonadTrav m) => CTranslUnit -> m GlobalDecls -- | Analyse an top-level declaration analyseExt :: (MonadTrav m) => CExtDecl -> m () -- | Analyse a function definition analyseFunDef :: (MonadTrav m) => CFunDef -> m () -- | Analyse a top-level declaration other than a function definition analyseExtDecls :: (MonadTrav m) => CDecl -> m () -- | Analysis of the AST. -- -- Currently, we provide a monad for analysis and analyze declarations -- and types. Especially note that there is no direct support for -- analyzing function bodies and constant expressions. -- -- NOTE This is an experimental interface, and therefore the API -- will change in the future. -- -- DONE: -- -- -- -- TODO: -- -- module Language.C.Analysis -- | Library for analysing and generating C code. -- -- See http://www.sivity.net/projects/language.c module Language.C -- | preprocess and parse a C source file -- --
--   Synopsis: parseCFile preprocesssor tmp-dir? cpp-opts file
--   Example:  parseCFile (newGCC "gcc") Nothing ["-I/usr/include/gtk-2.0"] my-gtk-exts.c
--   
parseCFile :: (Preprocessor cpp) => cpp -> (Maybe FilePath) -> [String] -> FilePath -> IO (Either ParseError CTranslUnit)