1{-# LANGUAGE DeriveDataTypeable #-} 2{-# LANGUAGE TypeSynonymInstances #-} 3----------------------------------------------------------------------------- 4-- | 5-- Module : Language.C.Syntax.AST 6-- Copyright : (c) [1999..2007] Manuel M T Chakravarty 7-- (c) 2008 Benedikt Huber 8-- License : BSD-style 9-- Maintainer : benedikt.huber@gmail.com 10-- Stability : experimental 11-- Portability : ghc 12-- 13-- Abstract syntax of C source and header files. 14-- 15-- The tree structure is based on the grammar in Appendix A of K&R. The 16-- abstract syntax simplifies the concrete syntax by merging similar concrete 17-- constructs into a single type of abstract tree structure: declarations are 18-- merged with structure declarations, parameter declarations and type names, 19-- and declarators are merged with abstract declarators. 20-- 21-- With K&R we refer to ``The C Programming Language'', second edition, Brain 22-- W. Kernighan and Dennis M. Ritchie, Prentice Hall, 1988. The AST supports all 23-- of C99 <http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf> and several 24-- GNU extensions <http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html>. 25----------------------------------------------------------------------------- 26module Language.C.Syntax.AST ( 27 -- * C translation units 28 CTranslUnit, CExtDecl, 29 CTranslationUnit(..), CExternalDeclaration(..), 30 -- * Declarations 31 CFunDef, CDecl, CStructUnion, CEnum, 32 CFunctionDef(..), CDeclaration(..), 33 CStructTag(..), CStructureUnion(..), CEnumeration(..), 34 -- * Declaration attributes 35 CDeclSpec, partitionDeclSpecs, 36 CStorageSpec, CTypeSpec, isSUEDef, CTypeQual, CFunSpec, CAlignSpec, CAttr, 37 CFunctionSpecifier(..), CDeclarationSpecifier(..), CStorageSpecifier(..), CTypeSpecifier(..), 38 CAlignmentSpecifier(..), 39 CTypeQualifier(..), CAttribute(..), 40 -- * Declarators 41 CDeclr,CDerivedDeclr,CArrSize, 42 CDeclarator(..), CDerivedDeclarator(..), CArraySize(..), 43 -- * Initialization 44 CInit, CInitList, CDesignator, 45 CInitializer(..), CInitializerList, CPartDesignator(..), 46 -- * Statements 47 CStat, CBlockItem, CAsmStmt, CAsmOperand, 48 CStatement(..), CCompoundBlockItem(..), 49 CAssemblyStatement(..), CAssemblyOperand(..), 50 -- * Expressions 51 CExpr, CExpression(..), 52 CAssignOp(..), CBinaryOp(..), CUnaryOp(..), 53 CBuiltin, CBuiltinThing(..), 54 -- * Constants 55 CConst, CStrLit, cstringOfLit, liftStrLit, 56 CConstant(..), CStringLiteral(..), 57 -- * Annoated type class 58 Annotated(..) 59) where 60import Language.C.Syntax.Constants 61import Language.C.Syntax.Ops 62import Language.C.Data.Ident 63import Language.C.Data.Node 64import Language.C.Data.Position 65import Data.Generics hiding (Generic) 66import GHC.Generics (Generic, Generic1) 67import Control.DeepSeq (NFData) 68 69-- | Complete C tranlsation unit (C99 6.9, K&R A10) 70-- 71-- A complete C translation unit, for example representing a C header or source file. 72-- It consists of a list of external (i.e. toplevel) declarations. 73type CTranslUnit = CTranslationUnit NodeInfo 74data CTranslationUnit a 75 = CTranslUnit [CExternalDeclaration a] a 76 deriving (Show, Data, Typeable, Generic, Generic1 {-! ,CNode ,Functor, Annotated !-}) 77 78instance NFData a => NFData (CTranslationUnit a) 79 80-- | External C declaration (C99 6.9, K&R A10) 81-- 82-- Either a toplevel declaration, function definition or external assembler. 83type CExtDecl = CExternalDeclaration NodeInfo 84data CExternalDeclaration a 85 = CDeclExt (CDeclaration a) 86 | CFDefExt (CFunctionDef a) 87 | CAsmExt (CStringLiteral a) a 88 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor, Annotated !-}) 89 90instance NFData a => NFData (CExternalDeclaration a) 91 92-- | C function definition (C99 6.9.1, K&R A10.1) 93-- 94-- A function definition is of the form @CFunDef specifiers declarator decllist? stmt@. 95-- 96-- * @specifiers@ are the type and storage-class specifiers of the function. 97-- The only storage-class specifiers allowed are /extern/ and /static/. 98-- 99-- * The @declarator@ must be such that the declared identifier has /function type/. 100-- The return type shall be void or an object type other than array type. 101-- 102-- * The optional declaration list @decllist@ is for old-style function declarations. 103-- 104-- * The statement @stmt@ is a compound statement. 105type CFunDef = CFunctionDef NodeInfo 106data CFunctionDef a 107 = CFunDef 108 [CDeclarationSpecifier a] -- type specifier and qualifier 109 (CDeclarator a) -- declarator 110 [CDeclaration a] -- optional declaration list 111 (CStatement a) -- compound statement 112 a 113 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 114 115instance NFData a => NFData (CFunctionDef a) 116 117-- | C declarations (K&R A8, C99 6.7), including structure declarations, parameter 118-- declarations and type names. 119-- 120-- A declaration is of the form @CDecl specifiers init-declarator-list@, where the form of the declarator list's 121-- elements depends on the kind of declaration: 122-- 123-- 1) Toplevel declarations (K&R A8, C99 6.7 declaration) 124-- 125-- * C99 requires that there is at least one specifier, though this is merely a syntactic restriction 126-- 127-- * at most one storage class specifier is allowed per declaration 128-- 129-- * the elements of the non-empty @init-declarator-list@ are of the form @(Just declr, init?, Nothing)@. 130-- The declarator @declr@ has to be present and non-abstract and the initialization expression is 131-- optional. 132-- 133-- 2) Structure declarations (K&R A8.3, C99 6.7.2.1 struct-declaration) 134-- 135-- Those are the declarations of a structure's members. 136-- 137-- * do not allow storage specifiers 138-- 139-- * in strict C99, the list of declarators has to be non-empty 140-- 141-- * the elements of @init-declarator-list@ are either of the form @(Just declr, Nothing, size?)@, 142-- representing a member with optional bit-field size, or of the form @(Nothing, Nothing, Just size)@, 143-- for unnamed bitfields. @declr@ has to be non-abstract. 144-- 145-- * no member of a structure shall have incomplete type 146-- 147-- 3) Parameter declarations (K&R A8.6.3, C99 6.7.5 parameter-declaration) 148-- 149-- * @init-declarator-list@ must contain at most one triple of the form @(Just declr, Nothing, Nothing)@, 150-- i.e. consist of a single declarator, which is allowed to be abstract (i.e. unnamed). 151-- 152-- 4) Type names (A8.8, C99 6.7.6) 153-- 154-- * do not allow storage specifiers 155-- 156-- * @init-declarator-list@ must contain at most one triple of the form @(Just declr, Nothing, Nothing)@. 157-- where @declr@ is an abstract declarator (i.e. doesn't contain a declared identifier) 158-- 159type CDecl = CDeclaration NodeInfo 160data CDeclaration a 161 = CDecl 162 [CDeclarationSpecifier a] -- type specifier and qualifier, __attribute__ 163 [(Maybe (CDeclarator a), -- declarator (may be omitted) 164 Maybe (CInitializer a), -- optional initialize 165 Maybe (CExpression a))] -- optional size (const expr) 166 a -- annotation 167 | CStaticAssert 168 (CExpression a) -- assert expression 169 (CStringLiteral a) -- assert text 170 a -- annotation 171 deriving (Show, Data,Typeable, Generic {-! ,CNode ,Annotated !-}) 172 173instance NFData a => NFData (CDeclaration a) 174 175-- Derive instance is a little bit ugly 176instance Functor CDeclaration where 177 fmap f (CDecl specs declarators annot) = 178 CDecl (map (fmap f) specs) (map fmap3m declarators) (f annot) 179 where fmap3m (a,b,c) = (fmap (fmap f) a, fmap (fmap f) b, fmap (fmap f) c) 180 fmap f (CStaticAssert expression strlit annot) = 181 CStaticAssert (fmap f expression) (fmap f strlit) (f annot) 182 183-- | C declarator (K&R A8.5, C99 6.7.5) and abstract declarator (K&R A8.8, C99 6.7.6) 184-- 185-- A declarator declares a single object, function, or type. It is always associated with 186-- a declaration ('CDecl'), which specifies the declaration's type and the additional storage qualifiers and 187-- attributes, which apply to the declared object. 188-- 189-- A declarator is of the form @CDeclr name? indirections asm-name? attrs _@, where 190-- @name@ is the name of the declared object (missing for abstract declarators), 191-- @declquals@ is a set of additional declaration specifiers, 192-- @asm-name@ is the optional assembler name and attributes is a set of 193-- attrs is a set of @__attribute__@ annotations for the declared object. 194-- 195-- @indirections@ is a set of pointer, array and function declarators, which modify the type of the declared object as 196-- described below. If the /declaration/ specifies the non-derived type @T@, 197-- and we have @indirections = [D1, D2, ..., Dn]@ than the declared object has type 198-- @(D1 `indirect` (D2 `indirect` ... (Dn `indirect` T)))@, where 199-- 200-- * @(CPtrDeclr attrs) `indirect` T@ is /attributed pointer to T/ 201-- 202-- * @(CFunDeclr attrs) `indirect` T@ is /attributed function returning T/ 203-- 204-- * @(CArrayDeclr attrs) `indirect` T@ is /attributed array of elemements of type T/ 205-- 206-- Examples (simplified attributes): 207-- 208-- * /x/ is an int 209-- 210-- > int x; 211-- > CDeclr "x" [] 212-- 213-- * /x/ is a restrict pointer to a const pointer to int 214-- 215-- > const int * const * restrict x; 216-- > CDeclr "x" [CPtrDeclr [restrict], CPtrDeclr [const]] 217-- 218-- * /f/ is an function return a constant pointer to int 219-- 220-- > int* const f(); 221-- > CDeclr "f" [CFunDeclr [],CPtrDeclr [const]] 222-- 223-- * /f/ is a constant pointer to a function returning int 224-- 225-- > int (* const f)(); ==> 226-- > CDeclr "f" [CPtrDeclr [const], CFunDeclr []] 227type CDeclr = CDeclarator NodeInfo 228data CDeclarator a 229 = CDeclr (Maybe Ident) [CDerivedDeclarator a] (Maybe (CStringLiteral a)) [CAttribute a] a 230 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 231 232instance NFData a => NFData (CDeclarator a) 233 234 235-- | Derived declarators, see 'CDeclr' 236-- 237-- Indirections are qualified using type-qualifiers and generic attributes, and additionally 238-- 239-- * The size of an array is either a constant expression, variable length ('*') or missing; in the last case, the 240-- type of the array is incomplete. The qualifier static is allowed for function arguments only, indicating that 241-- the supplied argument is an array of at least the given size. 242-- 243-- * New style parameter lists have the form @Right (declarations, isVariadic)@, old style parameter lists have the 244-- form @Left (parameter-names)@ 245type CDerivedDeclr = CDerivedDeclarator NodeInfo 246data CDerivedDeclarator a 247 = CPtrDeclr [CTypeQualifier a] a 248 -- ^ Pointer declarator @CPtrDeclr tyquals declr@ 249 | CArrDeclr [CTypeQualifier a] (CArraySize a) a 250 -- ^ Array declarator @CArrDeclr declr tyquals size-expr?@ 251 | CFunDeclr (Either [Ident] ([CDeclaration a],Bool)) [CAttribute a] a 252 -- ^ Function declarator @CFunDeclr declr (old-style-params | new-style-params) c-attrs@ 253 deriving (Show, Data,Typeable, Generic {-! ,CNode , Annotated !-}) 254 255instance NFData a => NFData (CDerivedDeclarator a) 256 257-- Derived instance relies on fmap2 258instance Functor CDerivedDeclarator where 259 fmap _f (CPtrDeclr a1 a2) = CPtrDeclr (fmap (fmap _f) a1) (_f a2) 260 fmap _f (CArrDeclr a1 a2 a3) 261 = CArrDeclr (fmap (fmap _f) a1) (fmap _f a2) (_f a3) 262 fmap _f (CFunDeclr a1 a2 a3) 263 = CFunDeclr (fmap (fmapFirst (fmap (fmap _f))) a1) (fmap (fmap _f) a2) 264 (_f a3) 265 where fmapFirst f (a,b) = (f a, b) 266 267-- | Size of an array 268type CArrSize = CArraySize NodeInfo 269data CArraySize a 270 = CNoArrSize Bool -- ^ @CUnknownSize isCompleteType@ 271 | CArrSize Bool (CExpression a) -- ^ @CArrSize isStatic expr@ 272 deriving (Show, Data,Typeable, Generic, Generic1 {-! , Functor !-}) 273 274instance NFData a => NFData (CArraySize a) 275 276-- | C statement (K&R A9, C99 6.8) 277-- 278type CStat = CStatement NodeInfo 279data CStatement a 280 -- | An (attributed) label followed by a statement 281 = CLabel Ident (CStatement a) [CAttribute a] a 282 -- | A statement of the form @case expr : stmt@ 283 | CCase (CExpression a) (CStatement a) a 284 -- | A case range of the form @case lower ... upper : stmt@ 285 | CCases (CExpression a) (CExpression a) (CStatement a) a 286 -- | The default case @default : stmt@ 287 | CDefault (CStatement a) a 288 -- | A simple statement, that is in C: evaluating an expression with 289 -- side-effects and discarding the result. 290 | CExpr (Maybe (CExpression a)) a 291 -- | compound statement @CCompound localLabels blockItems at@ 292 | CCompound [Ident] [CCompoundBlockItem a] a 293 -- | conditional statement @CIf ifExpr thenStmt maybeElseStmt at@ 294 | CIf (CExpression a) (CStatement a) (Maybe (CStatement a)) a 295 -- | switch statement @CSwitch selectorExpr switchStmt@, where 296 -- @switchStmt@ usually includes /case/, /break/ and /default/ 297 -- statements 298 | CSwitch (CExpression a) (CStatement a) a 299 -- | while or do-while statement @CWhile guard stmt isDoWhile at@ 300 | CWhile (CExpression a) (CStatement a) Bool a 301 -- | for statement @CFor init expr-2 expr-3 stmt@, where @init@ is 302 -- either a declaration or initializing expression 303 | CFor (Either (Maybe (CExpression a)) (CDeclaration a)) 304 (Maybe (CExpression a)) 305 (Maybe (CExpression a)) 306 (CStatement a) 307 a 308 -- | goto statement @CGoto label@ 309 | CGoto Ident a 310 -- | computed goto @CGotoPtr labelExpr@ 311 | CGotoPtr (CExpression a) a 312 -- | continue statement 313 | CCont a 314 -- | break statement 315 | CBreak a 316 -- | return statement @CReturn returnExpr@ 317 | CReturn (Maybe (CExpression a)) a 318 -- | assembly statement 319 | CAsm (CAssemblyStatement a) a 320 deriving (Show, Data,Typeable, Generic {-! , CNode , Annotated !-}) 321 322instance NFData a => NFData (CStatement a) 323 324-- Derived instance relies on fmap2 :( 325instance Functor CStatement where 326 fmap _f (CLabel a1 a2 a3 a4) 327 = CLabel a1 (fmap _f a2) (fmap (fmap _f) a3) (_f a4) 328 fmap _f (CCase a1 a2 a3) = CCase (fmap _f a1) (fmap _f a2) (_f a3) 329 fmap _f (CCases a1 a2 a3 a4) 330 = CCases (fmap _f a1) (fmap _f a2) (fmap _f a3) (_f a4) 331 fmap _f (CDefault a1 a2) = CDefault (fmap _f a1) (_f a2) 332 fmap _f (CExpr a1 a2) = CExpr (fmap (fmap _f) a1) (_f a2) 333 fmap _f (CCompound a1 a2 a3) 334 = CCompound a1 (fmap (fmap _f) a2) (_f a3) 335 fmap _f (CIf a1 a2 a3 a4) 336 = CIf (fmap _f a1) (fmap _f a2) (fmap (fmap _f) a3) (_f a4) 337 fmap _f (CSwitch a1 a2 a3) 338 = CSwitch (fmap _f a1) (fmap _f a2) (_f a3) 339 fmap _f (CWhile a1 a2 a3 a4) 340 = CWhile (fmap _f a1) (fmap _f a2) a3 (_f a4) 341 fmap _f (CFor a1 a2 a3 a4 a5) 342 = CFor (mapEither (fmap (fmap _f)) (fmap _f) a1) 343 (fmap (fmap _f) a2) (fmap (fmap _f) a3) (fmap _f a4) 344 (_f a5) 345 where mapEither f1 f2 = either (Left . f1) (Right . f2) 346 fmap _f (CGoto a1 a2) = CGoto a1 (_f a2) 347 fmap _f (CGotoPtr a1 a2) = CGotoPtr (fmap _f a1) (_f a2) 348 fmap _f (CCont a1) = CCont (_f a1) 349 fmap _f (CBreak a1) = CBreak (_f a1) 350 fmap _f (CReturn a1 a2) = CReturn (fmap (fmap _f) a1) (_f a2) 351 fmap _f (CAsm a1 a2) = CAsm (fmap _f a1) (_f a2) 352 353-- | GNU Assembler statement 354-- 355-- > CAssemblyStatement type-qual? asm-expr out-ops in-ops clobbers _ 356-- 357-- is an inline assembler statement. 358-- The only type-qualifier (if any) allowed is /volatile/. 359-- @asm-expr@ is the actual assembler epxression (a string), @out-ops@ and @in-ops@ are the input 360-- and output operands of the statement. 361-- @clobbers@ is a list of registers which are clobbered when executing the assembler statement 362type CAsmStmt = CAssemblyStatement NodeInfo 363data CAssemblyStatement a 364 = CAsmStmt 365 (Maybe (CTypeQualifier a)) -- maybe volatile 366 (CStringLiteral a) -- assembler expression (String) 367 [CAssemblyOperand a] -- output operands 368 [CAssemblyOperand a] -- input operands 369 [CStringLiteral a] -- Clobbers 370 a 371 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 372 373instance NFData a => NFData (CAssemblyStatement a) 374 375-- | Assembler operand 376-- 377-- @CAsmOperand argName? constraintExpr arg@ specifies an operand for an assembler 378-- statement. 379type CAsmOperand = CAssemblyOperand NodeInfo 380data CAssemblyOperand a 381 = CAsmOperand 382 (Maybe Ident) -- argument name 383 (CStringLiteral a) -- constraint expr 384 (CExpression a) -- argument 385 a 386 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 387 388instance NFData a => NFData (CAssemblyOperand a) 389 390-- | C99 Block items 391-- 392-- Things that may appear in compound statements: either statements, declarations 393-- or nested function definitions. 394type CBlockItem = CCompoundBlockItem NodeInfo 395data CCompoundBlockItem a 396 = CBlockStmt (CStatement a) -- ^ A statement 397 | CBlockDecl (CDeclaration a) -- ^ A local declaration 398 | CNestedFunDef (CFunctionDef a) -- ^ A nested function (GNU C) 399 deriving (Show, Data,Typeable, Generic, Generic1 {-! , CNode , Functor, Annotated !-}) 400 401instance NFData a => NFData (CCompoundBlockItem a) 402 403-- | C declaration specifiers and qualifiers 404-- 405-- Declaration specifiers include at most one storage-class specifier (C99 6.7.1), 406-- type specifiers (6.7.2) and type qualifiers (6.7.3). 407type CDeclSpec = CDeclarationSpecifier NodeInfo 408data CDeclarationSpecifier a 409 = CStorageSpec (CStorageSpecifier a) -- ^ storage-class specifier or typedef 410 | CTypeSpec (CTypeSpecifier a) -- ^ type name 411 | CTypeQual (CTypeQualifier a) -- ^ type qualifier 412 | CFunSpec (CFunctionSpecifier a) -- ^ function specifier 413 | CAlignSpec (CAlignmentSpecifier a) -- ^ alignment specifier 414 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor, Annotated !-}) 415 416instance NFData a => NFData (CDeclarationSpecifier a) 417 418-- | Separate the declaration specifiers 419-- 420-- @__attribute__@ of a declaration qualify declarations or declarators (but not types), 421-- and are therefore separated as well. 422partitionDeclSpecs :: [CDeclarationSpecifier a] 423 -> ( [CStorageSpecifier a], [CAttribute a] 424 , [CTypeQualifier a], [CTypeSpecifier a] 425 , [CFunctionSpecifier a], [CAlignmentSpecifier a]) 426partitionDeclSpecs = foldr deals ([],[],[],[],[],[]) where 427 deals (CStorageSpec sp) (sts,ats,tqs,tss,fss,ass) = (sp:sts,ats,tqs,tss,fss,ass) 428 deals (CTypeQual (CAttrQual attr)) (sts,ats,tqs,tss,fss,ass) = (sts,attr:ats,tqs,tss,fss,ass) 429 deals (CTypeQual tq) (sts,ats,tqs,tss,fss,ass) = (sts,ats,tq:tqs,tss,fss,ass) 430 deals (CTypeSpec ts) (sts,ats,tqs,tss,fss,ass) = (sts,ats,tqs,ts:tss,fss,ass) 431 deals (CFunSpec fs) (sts,ats,tqs,tss,fss,ass) = (sts,ats,tqs,tss,fs:fss,ass) 432 deals (CAlignSpec as) (sts,ats,tqs,tss,fss,ass) = (sts,ats,tqs,tss,fss,as:ass) 433 434-- | C storage class specifier (and typedefs) (K&R A8.1, C99 6.7.1) 435type CStorageSpec = CStorageSpecifier NodeInfo 436data CStorageSpecifier a 437 = CAuto a -- ^ auto 438 | CRegister a -- ^ register 439 | CStatic a -- ^ static 440 | CExtern a -- ^ extern 441 | CTypedef a -- ^ typedef 442 | CThread a -- ^ C11/GNUC thread local storage 443 | CClKernel a -- ^ OpenCL kernel function 444 | CClGlobal a -- ^ OpenCL __global variable 445 | CClLocal a -- ^ OpenCL __local variable 446 deriving (Show, Eq,Ord,Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 447 448instance NFData a => NFData (CStorageSpecifier a) 449 450-- | C type specifier (K&R A8.2, C99 6.7.2) 451-- 452-- Type specifiers are either basic types such as @char@ or @int@, 453-- @struct@, @union@ or @enum@ specifiers or typedef names. 454-- 455-- As a GNU extension, a @typeof@ expression also is a type specifier. 456type CTypeSpec = CTypeSpecifier NodeInfo 457data CTypeSpecifier a 458 = CVoidType a 459 | CCharType a 460 | CShortType a 461 | CIntType a 462 | CLongType a 463 | CFloatType a 464 | CDoubleType a 465 | CSignedType a 466 | CUnsigType a 467 | CBoolType a 468 | CComplexType a 469 | CInt128Type a 470 | CFloatNType Int Bool a -- ^ IEC 60227: width (32,64,128), extended flag 471 | CSUType (CStructureUnion a) a -- ^ Struct or Union specifier 472 | CEnumType (CEnumeration a) a -- ^ Enumeration specifier 473 | CTypeDef Ident a -- ^ Typedef name 474 | CTypeOfExpr (CExpression a) a -- ^ @typeof(expr)@ 475 | CTypeOfType (CDeclaration a) a -- ^ @typeof(type)@ 476 | CAtomicType (CDeclaration a) a -- ^ @_Atomic(type)@ 477 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 478 479instance NFData a => NFData (CTypeSpecifier a) 480 481-- | returns @True@ if the given typespec is a struct, union or enum /definition/ 482isSUEDef :: CTypeSpecifier a -> Bool 483isSUEDef (CSUType (CStruct _ _ (Just _) _ _) _) = True 484isSUEDef (CEnumType (CEnum _ (Just _) _ _) _) = True 485isSUEDef _ = False 486 487-- | C type qualifiers (K&R A8.2, C99 6.7.3) and attributes. 488-- 489-- @const@, @volatile@ and @restrict@ type qualifiers 490-- Additionally, @__attribute__@ annotations for declarations and declarators, and 491-- function specifiers 492type CTypeQual = CTypeQualifier NodeInfo 493data CTypeQualifier a 494 = CConstQual a 495 | CVolatQual a 496 | CRestrQual a 497 | CAtomicQual a 498 | CAttrQual (CAttribute a) 499 | CNullableQual a 500 | CNonnullQual a 501 | CClRdOnlyQual a 502 | CClWrOnlyQual a 503 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 504 505instance NFData a => NFData (CTypeQualifier a) 506 507-- | C function specifiers (C99 6.7.4) 508-- 509-- function specifiers @inline@ and @_Noreturn@ 510type CFunSpec = CFunctionSpecifier NodeInfo 511data CFunctionSpecifier a 512 = CInlineQual a 513 | CNoreturnQual a 514 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 515 516instance NFData a => NFData (CFunctionSpecifier a) 517 518-- | C alignment specifiers (C99 6.7.5) 519-- 520type CAlignSpec = CAlignmentSpecifier NodeInfo 521data CAlignmentSpecifier a 522 = CAlignAsType (CDeclaration a) a -- ^ @_Alignas(type)@ 523 | CAlignAsExpr (CExpression a) a -- ^ @_Alignas(expr)@ 524 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 525 526instance NFData a => NFData (CAlignmentSpecifier a) 527 528-- | C structure or union specifiers (K&R A8.3, C99 6.7.2.1) 529-- 530-- @CStruct tag identifier struct-decls c-attrs@ represents a struct or union specifier (depending on @tag@). 531-- 532-- * either @identifier@ or the declaration list @struct-decls@ (or both) have to be present. 533-- 534-- Example: in @struct foo x;@, the identifier is present, in @struct { int y; } x@ the declaration list, and 535-- in @struct foo { int y; } x;@ both of them. 536-- 537-- * @c-attrs@ is a list of @__attribute__@ annotations associated with the struct or union specifier 538type CStructUnion = CStructureUnion NodeInfo 539data CStructureUnion a 540 = CStruct 541 CStructTag 542 (Maybe Ident) 543 (Maybe [CDeclaration a]) -- member declarations 544 [CAttribute a] -- __attribute__s 545 a 546 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 547 548instance NFData a => NFData (CStructureUnion a) 549 550-- | A tag to determine wheter we refer to a @struct@ or @union@, see 'CStructUnion'. 551data CStructTag = CStructTag 552 | CUnionTag 553 deriving (Show, Eq,Data,Typeable, Generic) 554 555instance NFData CStructTag 556 557-- | C enumeration specifier (K&R A8.4, C99 6.7.2.2) 558-- 559-- @CEnum identifier enumerator-list attrs@ represent as enum specifier 560-- 561-- * Either the identifier or the enumerator-list (or both) have to be present. 562-- 563-- * If @enumerator-list@ is present, it has to be non-empty. 564-- 565-- * The enumerator list is of the form @(enumeration-constant, enumeration-value?)@, where the latter 566-- is an optional constant integral expression. 567-- 568-- * @attrs@ is a list of @__attribute__@ annotations associated with the enumeration specifier 569type CEnum = CEnumeration NodeInfo 570data CEnumeration a 571 = CEnum 572 (Maybe Ident) 573 (Maybe [(Ident, -- variant name 574 Maybe (CExpression a))]) -- explicit variant value 575 [CAttribute a] -- __attribute__s 576 a 577 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 578 579instance NFData a => NFData (CEnumeration a) 580 581-- | C initialization (K&R A8.7, C99 6.7.8) 582-- 583-- Initializers are either assignment expressions or initializer lists 584-- (surrounded in curly braces), whose elements are themselves 585-- initializers, paired with an optional list of designators. 586type CInit = CInitializer NodeInfo 587data CInitializer a 588 -- | assignment expression 589 = CInitExpr (CExpression a) a 590 -- | initialization list (see 'CInitList') 591 | CInitList (CInitializerList a) a 592 deriving (Show, Data,Typeable, Generic {-! ,CNode , Annotated !-}) 593 594instance NFData a => NFData (CInitializer a) 595 596-- deriving Functor does not work (type synonym) 597instance Functor CInitializer where 598 fmap _f (CInitExpr a1 a2) = CInitExpr (fmap _f a1) (_f a2) 599 fmap _f (CInitList a1 a2) = CInitList (fmapInitList _f a1) (_f a2) 600fmapInitList :: (a->b) -> (CInitializerList a) -> (CInitializerList b) 601fmapInitList _f = map (\(desigs, initializer) -> (fmap (fmap _f) desigs, fmap _f initializer)) 602 603-- | Initializer List 604-- 605-- The members of an initializer list are of the form @(designator-list,initializer)@. 606-- The @designator-list@ specifies one member of the compound type which is initialized. 607-- It is allowed to be empty - in this case the initializer refers to the 608-- ''next'' member of the compound type (see C99 6.7.8). 609-- 610-- Examples (simplified expressions and identifiers): 611-- 612-- > -- int x[3][4] = { [0][3] = 4, [2] = 5, 8 }; 613-- > -- corresponds to the assignments 614-- > -- x[0][3] = 4; x[2][0] = 5; x[2][1] = 8; 615-- > let init1 = ([CArrDesig 0, CArrDesig 3], CInitExpr 4) 616-- > init2 = ([CArrDesig 2] , CInitExpr 5) 617-- > init3 = ([] , CInitExpr 8) 618-- > in CInitList [init1, init2, init3] 619-- 620-- > -- struct { struct { int a[2]; int b[2]; int c[2]; } s; } x = { .s = { {2,3} , .c[0] = 1 } }; 621-- > -- corresponds to the assignments 622-- > -- x.s.a[0] = 2; x.s.a[1] = 3; x.s.c[0] = 1; 623-- > let init_s_0 = CInitList [ ([], CInitExpr 2), ([], CInitExpr 3)] 624-- > init_s = CInitList [ 625-- > ([], init_s_0), 626-- > ([CMemberDesig "c", CArrDesig 0], CInitExpr 1) 627-- > ] 628-- > in CInitList [(CMemberDesig "s", init_s)] 629type CInitList = CInitializerList NodeInfo 630type CInitializerList a = [([CPartDesignator a], CInitializer a)] 631 632-- | Designators 633-- 634-- A designator specifies a member of an object, either an element or range of an array, 635-- or the named member of a struct \/ union. 636type CDesignator = CPartDesignator NodeInfo 637data CPartDesignator a 638 -- | array position designator 639 = CArrDesig (CExpression a) a 640 -- | member designator 641 | CMemberDesig Ident a 642 -- | array range designator @CRangeDesig from to _@ (GNU C) 643 | CRangeDesig (CExpression a) (CExpression a) a 644 deriving (Show, Data,Typeable, Generic {-! ,CNode ,Functor ,Annotated !-}) 645 646instance NFData a => NFData (CPartDesignator a) 647 648-- | @__attribute__@ annotations 649-- 650-- Those are of the form @CAttr attribute-name attribute-parameters@, 651-- and serve as generic properties of some syntax tree elements. 652type CAttr = CAttribute NodeInfo 653data CAttribute a = CAttr Ident [CExpression a] a 654 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 655 656instance NFData a => NFData (CAttribute a) 657 658-- | C expression (K&R A7) 659-- 660-- * these can be arbitrary expression, as the argument of `sizeof' can be 661-- arbitrary, even if appearing in a constant expression 662-- 663-- * GNU C extensions: @alignof@, @__real@, @__imag@, @({ stmt-expr })@, @&& label@ and built-ins 664-- 665type CExpr = CExpression NodeInfo 666data CExpression a 667 = CComma [CExpression a] -- comma expression list, n >= 2 668 a 669 | CAssign CAssignOp -- assignment operator 670 (CExpression a) -- l-value 671 (CExpression a) -- r-value 672 a 673 | CCond (CExpression a) -- conditional 674 (Maybe (CExpression a)) -- true-expression (GNU allows omitting) 675 (CExpression a) -- false-expression 676 a 677 | CBinary CBinaryOp -- binary operator 678 (CExpression a) -- lhs 679 (CExpression a) -- rhs 680 a 681 | CCast (CDeclaration a) -- type name 682 (CExpression a) 683 a 684 | CUnary CUnaryOp -- unary operator 685 (CExpression a) 686 a 687 | CSizeofExpr (CExpression a) 688 a 689 | CSizeofType (CDeclaration a) -- type name 690 a 691 | CAlignofExpr (CExpression a) 692 a 693 | CAlignofType (CDeclaration a) -- type name 694 a 695 | CComplexReal (CExpression a) -- real part of complex number 696 a 697 | CComplexImag (CExpression a) -- imaginary part of complex number 698 a 699 | CIndex (CExpression a) -- array 700 (CExpression a) -- index 701 a 702 | CCall (CExpression a) -- function 703 [CExpression a] -- arguments 704 a 705 | CMember (CExpression a) -- structure 706 Ident -- member name 707 Bool -- deref structure? (True for `->') 708 a 709 | CVar Ident -- identifier (incl. enumeration const) 710 a 711 | CConst (CConstant a) -- ^ integer, character, floating point and string constants 712 | CCompoundLit (CDeclaration a) 713 (CInitializerList a) -- type name & initialiser list 714 a -- ^ C99 compound literal 715 | CGenericSelection (CExpression a) [(Maybe (CDeclaration a), CExpression a)] a -- ^ C11 generic selection 716 | CStatExpr (CStatement a) a -- ^ GNU C compound statement as expr 717 | CLabAddrExpr Ident a -- ^ GNU C address of label 718 | CBuiltinExpr (CBuiltinThing a) -- ^ builtin expressions, see 'CBuiltin' 719 deriving (Data,Typeable,Show, Generic {-! ,CNode , Annotated !-}) 720 721instance NFData a => NFData (CExpression a) 722 723-- deriving Functor does not work (type synonyms) 724instance Functor CExpression where 725 fmap _f (CComma a1 a2) = CComma (fmap (fmap _f) a1) (_f a2) 726 fmap _f (CAssign a1 a2 a3 a4) 727 = CAssign a1 (fmap _f a2) (fmap _f a3) (_f a4) 728 fmap _f (CCond a1 a2 a3 a4) 729 = CCond (fmap _f a1) (fmap (fmap _f) a2) (fmap _f a3) (_f a4) 730 fmap _f (CBinary a1 a2 a3 a4) 731 = CBinary a1 (fmap _f a2) (fmap _f a3) (_f a4) 732 fmap _f (CCast a1 a2 a3) = CCast (fmap _f a1) (fmap _f a2) (_f a3) 733 fmap _f (CUnary a1 a2 a3) = CUnary a1 (fmap _f a2) (_f a3) 734 fmap _f (CSizeofExpr a1 a2) = CSizeofExpr (fmap _f a1) (_f a2) 735 fmap _f (CSizeofType a1 a2) = CSizeofType (fmap _f a1) (_f a2) 736 fmap _f (CAlignofExpr a1 a2) = CAlignofExpr (fmap _f a1) (_f a2) 737 fmap _f (CAlignofType a1 a2) = CAlignofType (fmap _f a1) (_f a2) 738 fmap _f (CComplexReal a1 a2) = CComplexReal (fmap _f a1) (_f a2) 739 fmap _f (CComplexImag a1 a2) = CComplexImag (fmap _f a1) (_f a2) 740 fmap _f (CIndex a1 a2 a3) 741 = CIndex (fmap _f a1) (fmap _f a2) (_f a3) 742 fmap _f (CCall a1 a2 a3) 743 = CCall (fmap _f a1) (fmap (fmap _f) a2) (_f a3) 744 fmap _f (CMember a1 a2 a3 a4) = CMember (fmap _f a1) a2 a3 (_f a4) 745 fmap _f (CVar a1 a2) = CVar a1 (_f a2) 746 fmap _f (CConst a1) = CConst (fmap _f a1) 747 fmap _f (CCompoundLit a1 a2 a3) 748 = CCompoundLit (fmap _f a1) (fmapInitList _f a2) (_f a3) 749 fmap _f (CStatExpr a1 a2) = CStatExpr (fmap _f a1) (_f a2) 750 fmap _f (CLabAddrExpr a1 a2) = CLabAddrExpr a1 (_f a2) 751 fmap _f (CBuiltinExpr a1) = CBuiltinExpr (fmap _f a1) 752 fmap _f (CGenericSelection expr list annot) = 753 CGenericSelection (fmap _f expr) (map fmap_helper list) (_f annot) 754 where 755 fmap_helper (ma1, a2) = (fmap (fmap _f) ma1, fmap _f a2) 756 757-- | GNU Builtins, which cannot be typed in C99 758type CBuiltin = CBuiltinThing NodeInfo 759data CBuiltinThing a 760 = CBuiltinVaArg (CExpression a) (CDeclaration a) a -- ^ @(expr, type)@ 761 | CBuiltinOffsetOf (CDeclaration a) [CPartDesignator a] a -- ^ @(type, designator-list)@ 762 | CBuiltinTypesCompatible (CDeclaration a) (CDeclaration a) a -- ^ @(type,type)@ 763 | CBuiltinConvertVector (CExpression a) (CDeclaration a) a -- ^ @(expr, type)@ 764 deriving (Show, Data,Typeable, Generic {-! ,CNode ,Functor ,Annotated !-}) 765 766instance NFData a => NFData (CBuiltinThing a) 767 768-- | C constant (K&R A2.5 & A7.2) 769type CConst = CConstant NodeInfo 770data CConstant a 771 = CIntConst CInteger a 772 | CCharConst CChar a 773 | CFloatConst CFloat a 774 | CStrConst CString a 775 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 776 777instance NFData a => NFData (CConstant a) 778 779-- | Attributed string literals 780type CStrLit = CStringLiteral NodeInfo 781data CStringLiteral a = CStrLit CString a 782 deriving (Show, Data,Typeable, Generic, Generic1 {-! ,CNode ,Functor ,Annotated !-}) 783 784instance NFData a => NFData (CStringLiteral a) 785 786cstringOfLit :: CStringLiteral a -> CString 787cstringOfLit (CStrLit cstr _) = cstr 788 789-- | Lift a string literal to a C constant 790liftStrLit :: CStringLiteral a -> CConstant a 791liftStrLit (CStrLit str at) = CStrConst str at 792 793-- | All AST nodes are annotated. Inspired by the Annotated 794-- class of Niklas Broberg's haskell-src-exts package. 795-- In principle, we could have Copointed superclass instead 796-- of @ann@, for the price of another dependency. 797class (Functor ast) => Annotated ast where 798 -- | get the annotation of an AST node 799 annotation :: ast a -> a 800 -- | change the annotation (non-recursively) 801 -- of an AST node. Use fmap for recursively 802 -- modifying the annotation. 803 amap :: (a->a) -> ast a -> ast a 804 805-- fmap2 :: (a->a') -> (a,b) -> (a',b) 806-- fmap2 f (a,b) = (f a, b) 807 808-- Instances generated using derive-2.* 809-- GENERATED START 810 811instance CNode t1 => CNode (CTranslationUnit t1) where 812 nodeInfo (CTranslUnit _ n) = nodeInfo n 813instance CNode t1 => Pos (CTranslationUnit t1) where 814 posOf x = posOf (nodeInfo x) 815 816instance Functor CTranslationUnit where 817 fmap _f (CTranslUnit a1 a2) 818 = CTranslUnit (fmap (fmap _f) a1) (_f a2) 819 820instance Annotated CTranslationUnit where 821 annotation (CTranslUnit _ n) = n 822 amap f (CTranslUnit a_1 a_2) = CTranslUnit a_1 (f a_2) 823 824instance CNode t1 => CNode (CExternalDeclaration t1) where 825 nodeInfo (CDeclExt d) = nodeInfo d 826 nodeInfo (CFDefExt d) = nodeInfo d 827 nodeInfo (CAsmExt _ n) = nodeInfo n 828instance CNode t1 => Pos (CExternalDeclaration t1) where 829 posOf x = posOf (nodeInfo x) 830 831instance Functor CExternalDeclaration where 832 fmap _f (CDeclExt a1) = CDeclExt (fmap _f a1) 833 fmap _f (CFDefExt a1) = CFDefExt (fmap _f a1) 834 fmap _f (CAsmExt a1 a2) = CAsmExt (fmap _f a1) (_f a2) 835 836instance Annotated CExternalDeclaration where 837 annotation (CDeclExt n) = annotation n 838 annotation (CFDefExt n) = annotation n 839 annotation (CAsmExt _ n) = n 840 amap f (CDeclExt n) = CDeclExt (amap f n) 841 amap f (CFDefExt n) = CFDefExt (amap f n) 842 amap f (CAsmExt a_1 a_2) = CAsmExt a_1 (f a_2) 843 844instance CNode t1 => CNode (CFunctionDef t1) where 845 nodeInfo (CFunDef _ _ _ _ n) = nodeInfo n 846instance CNode t1 => Pos (CFunctionDef t1) where 847 posOf x = posOf (nodeInfo x) 848 849instance Functor CFunctionDef where 850 fmap _f (CFunDef a1 a2 a3 a4 a5) 851 = CFunDef (fmap (fmap _f) a1) (fmap _f a2) (fmap (fmap _f) a3) 852 (fmap _f a4) 853 (_f a5) 854 855instance Annotated CFunctionDef where 856 annotation (CFunDef _ _ _ _ n) = n 857 amap f (CFunDef a_1 a_2 a_3 a_4 a_5) 858 = CFunDef a_1 a_2 a_3 a_4 (f a_5) 859 860instance CNode t1 => CNode (CDeclaration t1) where 861 nodeInfo (CDecl _ _ n) = nodeInfo n 862 nodeInfo (CStaticAssert _ _ n) = nodeInfo n 863instance CNode t1 => Pos (CDeclaration t1) where 864 posOf x = posOf (nodeInfo x) 865 866instance Annotated CDeclaration where 867 annotation (CDecl _ _ n) = n 868 annotation (CStaticAssert _ _ n) = n 869 amap f (CDecl a_1 a_2 a_3) = CDecl a_1 a_2 (f a_3) 870 amap f (CStaticAssert a_1 a_2 a_3) = CStaticAssert a_1 a_2 (f a_3) 871 872instance CNode t1 => CNode (CDeclarator t1) where 873 nodeInfo (CDeclr _ _ _ _ n) = nodeInfo n 874instance CNode t1 => Pos (CDeclarator t1) where 875 posOf x = posOf (nodeInfo x) 876 877instance Functor CDeclarator where 878 fmap _f (CDeclr a1 a2 a3 a4 a5) 879 = CDeclr a1 (fmap (fmap _f) a2) (fmap (fmap _f) a3) 880 (fmap (fmap _f) a4) 881 (_f a5) 882 883instance Annotated CDeclarator where 884 annotation (CDeclr _ _ _ _ n) = n 885 amap f (CDeclr a_1 a_2 a_3 a_4 a_5) 886 = CDeclr a_1 a_2 a_3 a_4 (f a_5) 887 888instance CNode t1 => CNode (CDerivedDeclarator t1) where 889 nodeInfo (CPtrDeclr _ n) = nodeInfo n 890 nodeInfo (CArrDeclr _ _ n) = nodeInfo n 891 nodeInfo (CFunDeclr _ _ n) = nodeInfo n 892instance CNode t1 => Pos (CDerivedDeclarator t1) where 893 posOf x = posOf (nodeInfo x) 894 895instance Annotated CDerivedDeclarator where 896 annotation (CPtrDeclr _ n) = n 897 annotation (CArrDeclr _ _ n) = n 898 annotation (CFunDeclr _ _ n) = n 899 amap f (CPtrDeclr a_1 a_2) = CPtrDeclr a_1 (f a_2) 900 amap f (CArrDeclr a_1 a_2 a_3) = CArrDeclr a_1 a_2 (f a_3) 901 amap f (CFunDeclr a_1 a_2 a_3) = CFunDeclr a_1 a_2 (f a_3) 902 903instance Functor CArraySize where 904 fmap _ (CNoArrSize a1) = CNoArrSize a1 905 fmap _f (CArrSize a1 a2) = CArrSize a1 (fmap _f a2) 906 907instance CNode t1 => CNode (CStatement t1) where 908 nodeInfo (CLabel _ _ _ n) = nodeInfo n 909 nodeInfo (CCase _ _ n) = nodeInfo n 910 nodeInfo (CCases _ _ _ n) = nodeInfo n 911 nodeInfo (CDefault _ n) = nodeInfo n 912 nodeInfo (CExpr _ n) = nodeInfo n 913 nodeInfo (CCompound _ _ n) = nodeInfo n 914 nodeInfo (CIf _ _ _ n) = nodeInfo n 915 nodeInfo (CSwitch _ _ n) = nodeInfo n 916 nodeInfo (CWhile _ _ _ n) = nodeInfo n 917 nodeInfo (CFor _ _ _ _ n) = nodeInfo n 918 nodeInfo (CGoto _ n) = nodeInfo n 919 nodeInfo (CGotoPtr _ n) = nodeInfo n 920 nodeInfo (CCont d) = nodeInfo d 921 nodeInfo (CBreak d) = nodeInfo d 922 nodeInfo (CReturn _ n) = nodeInfo n 923 nodeInfo (CAsm _ n) = nodeInfo n 924instance CNode t1 => Pos (CStatement t1) where 925 posOf x = posOf (nodeInfo x) 926 927instance Annotated CStatement where 928 annotation (CLabel _ _ _ n) = n 929 annotation (CCase _ _ n) = n 930 annotation (CCases _ _ _ n) = n 931 annotation (CDefault _ n) = n 932 annotation (CExpr _ n) = n 933 annotation (CCompound _ _ n) = n 934 annotation (CIf _ _ _ n) = n 935 annotation (CSwitch _ _ n) = n 936 annotation (CWhile _ _ _ n) = n 937 annotation (CFor _ _ _ _ n) = n 938 annotation (CGoto _ n) = n 939 annotation (CGotoPtr _ n) = n 940 annotation (CCont n) = n 941 annotation (CBreak n) = n 942 annotation (CReturn _ n) = n 943 annotation (CAsm _ n) = n 944 amap f (CLabel a_1 a_2 a_3 a_4) = CLabel a_1 a_2 a_3 (f a_4) 945 amap f (CCase a_1 a_2 a_3) = CCase a_1 a_2 (f a_3) 946 amap f (CCases a_1 a_2 a_3 a_4) = CCases a_1 a_2 a_3 (f a_4) 947 amap f (CDefault a_1 a_2) = CDefault a_1 (f a_2) 948 amap f (CExpr a_1 a_2) = CExpr a_1 (f a_2) 949 amap f (CCompound a_1 a_2 a_3) = CCompound a_1 a_2 (f a_3) 950 amap f (CIf a_1 a_2 a_3 a_4) = CIf a_1 a_2 a_3 (f a_4) 951 amap f (CSwitch a_1 a_2 a_3) = CSwitch a_1 a_2 (f a_3) 952 amap f (CWhile a_1 a_2 a_3 a_4) = CWhile a_1 a_2 a_3 (f a_4) 953 amap f (CFor a_1 a_2 a_3 a_4 a_5) = CFor a_1 a_2 a_3 a_4 (f a_5) 954 amap f (CGoto a_1 a_2) = CGoto a_1 (f a_2) 955 amap f (CGotoPtr a_1 a_2) = CGotoPtr a_1 (f a_2) 956 amap f (CCont a_1) = CCont (f a_1) 957 amap f (CBreak a_1) = CBreak (f a_1) 958 amap f (CReturn a_1 a_2) = CReturn a_1 (f a_2) 959 amap f (CAsm a_1 a_2) = CAsm a_1 (f a_2) 960 961instance CNode t1 => CNode (CAssemblyStatement t1) where 962 nodeInfo (CAsmStmt _ _ _ _ _ n) = nodeInfo n 963instance CNode t1 => Pos (CAssemblyStatement t1) where 964 posOf x = posOf (nodeInfo x) 965 966instance Functor CAssemblyStatement where 967 fmap _f (CAsmStmt a1 a2 a3 a4 a5 a6) 968 = CAsmStmt (fmap (fmap _f) a1) (fmap _f a2) (fmap (fmap _f) a3) 969 (fmap (fmap _f) a4) 970 (fmap (fmap _f) a5) 971 (_f a6) 972 973instance Annotated CAssemblyStatement where 974 annotation (CAsmStmt _ _ _ _ _ n) = n 975 amap f (CAsmStmt a_1 a_2 a_3 a_4 a_5 a_6) 976 = CAsmStmt a_1 a_2 a_3 a_4 a_5 (f a_6) 977 978instance CNode t1 => CNode (CAssemblyOperand t1) where 979 nodeInfo (CAsmOperand _ _ _ n) = nodeInfo n 980instance CNode t1 => Pos (CAssemblyOperand t1) where 981 posOf x = posOf (nodeInfo x) 982 983instance Functor CAssemblyOperand where 984 fmap _f (CAsmOperand a1 a2 a3 a4) 985 = CAsmOperand a1 (fmap _f a2) (fmap _f a3) (_f a4) 986 987instance Annotated CAssemblyOperand where 988 annotation (CAsmOperand _ _ _ n) = n 989 amap f (CAsmOperand a_1 a_2 a_3 a_4) 990 = CAsmOperand a_1 a_2 a_3 (f a_4) 991 992instance CNode t1 => CNode (CCompoundBlockItem t1) where 993 nodeInfo (CBlockStmt d) = nodeInfo d 994 nodeInfo (CBlockDecl d) = nodeInfo d 995 nodeInfo (CNestedFunDef d) = nodeInfo d 996instance CNode t1 => Pos (CCompoundBlockItem t1) where 997 posOf x = posOf (nodeInfo x) 998 999instance Functor CCompoundBlockItem where 1000 fmap _f (CBlockStmt a1) = CBlockStmt (fmap _f a1) 1001 fmap _f (CBlockDecl a1) = CBlockDecl (fmap _f a1) 1002 fmap _f (CNestedFunDef a1) = CNestedFunDef (fmap _f a1) 1003 1004instance Annotated CCompoundBlockItem where 1005 annotation (CBlockStmt n) = annotation n 1006 annotation (CBlockDecl n) = annotation n 1007 annotation (CNestedFunDef n) = annotation n 1008 amap f (CBlockStmt n) = CBlockStmt (amap f n) 1009 amap f (CBlockDecl n) = CBlockDecl (amap f n) 1010 amap f (CNestedFunDef n) = CNestedFunDef (amap f n) 1011 1012instance CNode t1 => CNode (CDeclarationSpecifier t1) where 1013 nodeInfo (CStorageSpec d) = nodeInfo d 1014 nodeInfo (CTypeSpec d) = nodeInfo d 1015 nodeInfo (CTypeQual d) = nodeInfo d 1016 nodeInfo (CFunSpec d) = nodeInfo d 1017 nodeInfo (CAlignSpec d) = nodeInfo d 1018instance CNode t1 => Pos (CDeclarationSpecifier t1) where 1019 posOf x = posOf (nodeInfo x) 1020 1021instance Functor CDeclarationSpecifier where 1022 fmap _f (CStorageSpec a1) = CStorageSpec (fmap _f a1) 1023 fmap _f (CTypeSpec a1) = CTypeSpec (fmap _f a1) 1024 fmap _f (CTypeQual a1) = CTypeQual (fmap _f a1) 1025 fmap _f (CFunSpec a1) = CFunSpec (fmap _f a1) 1026 fmap _f (CAlignSpec a1) = CAlignSpec (fmap _f a1) 1027 1028instance Annotated CDeclarationSpecifier where 1029 annotation (CStorageSpec n) = annotation n 1030 annotation (CTypeSpec n) = annotation n 1031 annotation (CTypeQual n) = annotation n 1032 annotation (CFunSpec n) = annotation n 1033 annotation (CAlignSpec n) = annotation n 1034 amap f (CStorageSpec n) = CStorageSpec (amap f n) 1035 amap f (CTypeSpec n) = CTypeSpec (amap f n) 1036 amap f (CTypeQual n) = CTypeQual (amap f n) 1037 amap f (CFunSpec n) = CFunSpec (amap f n) 1038 amap f (CAlignSpec n) = CAlignSpec (amap f n) 1039 1040instance CNode t1 => CNode (CStorageSpecifier t1) where 1041 nodeInfo (CAuto d) = nodeInfo d 1042 nodeInfo (CRegister d) = nodeInfo d 1043 nodeInfo (CStatic d) = nodeInfo d 1044 nodeInfo (CExtern d) = nodeInfo d 1045 nodeInfo (CTypedef d) = nodeInfo d 1046 nodeInfo (CThread d) = nodeInfo d 1047 nodeInfo (CClKernel d) = nodeInfo d 1048 nodeInfo (CClGlobal d) = nodeInfo d 1049 nodeInfo (CClLocal d) = nodeInfo d 1050instance CNode t1 => Pos (CStorageSpecifier t1) where 1051 posOf x = posOf (nodeInfo x) 1052 1053instance Functor CStorageSpecifier where 1054 fmap _f (CAuto a1) = CAuto (_f a1) 1055 fmap _f (CRegister a1) = CRegister (_f a1) 1056 fmap _f (CStatic a1) = CStatic (_f a1) 1057 fmap _f (CExtern a1) = CExtern (_f a1) 1058 fmap _f (CTypedef a1) = CTypedef (_f a1) 1059 fmap _f (CThread a1) = CThread (_f a1) 1060 fmap _f (CClKernel a1) = CClKernel (_f a1) 1061 fmap _f (CClGlobal a1) = CClGlobal (_f a1) 1062 fmap _f (CClLocal a1) = CClLocal (_f a1) 1063 1064instance Annotated CStorageSpecifier where 1065 annotation (CAuto n) = n 1066 annotation (CRegister n) = n 1067 annotation (CStatic n) = n 1068 annotation (CExtern n) = n 1069 annotation (CTypedef n) = n 1070 annotation (CThread n) = n 1071 annotation (CClKernel n) = n 1072 annotation (CClGlobal n) = n 1073 annotation (CClLocal n) = n 1074 amap f (CAuto a_1) = CAuto (f a_1) 1075 amap f (CRegister a_1) = CRegister (f a_1) 1076 amap f (CStatic a_1) = CStatic (f a_1) 1077 amap f (CExtern a_1) = CExtern (f a_1) 1078 amap f (CTypedef a_1) = CTypedef (f a_1) 1079 amap f (CThread a_1) = CThread (f a_1) 1080 amap f (CClKernel a_1) = CClKernel (f a_1) 1081 amap f (CClGlobal a_1) = CClGlobal (f a_1) 1082 amap f (CClLocal a_1) = CClLocal (f a_1) 1083 1084instance CNode t1 => CNode (CTypeSpecifier t1) where 1085 nodeInfo (CVoidType d) = nodeInfo d 1086 nodeInfo (CCharType d) = nodeInfo d 1087 nodeInfo (CShortType d) = nodeInfo d 1088 nodeInfo (CIntType d) = nodeInfo d 1089 nodeInfo (CLongType d) = nodeInfo d 1090 nodeInfo (CFloatType d) = nodeInfo d 1091 nodeInfo (CFloatNType _ _ d) = nodeInfo d 1092 nodeInfo (CDoubleType d) = nodeInfo d 1093 nodeInfo (CSignedType d) = nodeInfo d 1094 nodeInfo (CUnsigType d) = nodeInfo d 1095 nodeInfo (CBoolType d) = nodeInfo d 1096 nodeInfo (CComplexType d) = nodeInfo d 1097 nodeInfo (CInt128Type d) = nodeInfo d 1098 nodeInfo (CSUType _ n) = nodeInfo n 1099 nodeInfo (CEnumType _ n) = nodeInfo n 1100 nodeInfo (CTypeDef _ n) = nodeInfo n 1101 nodeInfo (CTypeOfExpr _ n) = nodeInfo n 1102 nodeInfo (CTypeOfType _ n) = nodeInfo n 1103 nodeInfo (CAtomicType _ n) = nodeInfo n 1104instance CNode t1 => Pos (CTypeSpecifier t1) where 1105 posOf x = posOf (nodeInfo x) 1106 1107instance Functor CTypeSpecifier where 1108 fmap _f (CVoidType a1) = CVoidType (_f a1) 1109 fmap _f (CCharType a1) = CCharType (_f a1) 1110 fmap _f (CShortType a1) = CShortType (_f a1) 1111 fmap _f (CIntType a1) = CIntType (_f a1) 1112 fmap _f (CLongType a1) = CLongType (_f a1) 1113 fmap _f (CFloatType a1) = CFloatType (_f a1) 1114 fmap _f (CFloatNType n x a1) = CFloatNType n x (_f a1) 1115 fmap _f (CDoubleType a1) = CDoubleType (_f a1) 1116 fmap _f (CSignedType a1) = CSignedType (_f a1) 1117 fmap _f (CUnsigType a1) = CUnsigType (_f a1) 1118 fmap _f (CBoolType a1) = CBoolType (_f a1) 1119 fmap _f (CComplexType a1) = CComplexType (_f a1) 1120 fmap _f (CInt128Type a1) = CInt128Type (_f a1) 1121 fmap _f (CSUType a1 a2) = CSUType (fmap _f a1) (_f a2) 1122 fmap _f (CEnumType a1 a2) = CEnumType (fmap _f a1) (_f a2) 1123 fmap _f (CTypeDef a1 a2) = CTypeDef a1 (_f a2) 1124 fmap _f (CTypeOfExpr a1 a2) = CTypeOfExpr (fmap _f a1) (_f a2) 1125 fmap _f (CTypeOfType a1 a2) = CTypeOfType (fmap _f a1) (_f a2) 1126 fmap _f (CAtomicType a1 a2) = CAtomicType (fmap _f a1) (_f a2) 1127 1128instance Annotated CTypeSpecifier where 1129 annotation (CVoidType n) = n 1130 annotation (CCharType n) = n 1131 annotation (CShortType n) = n 1132 annotation (CIntType n) = n 1133 annotation (CLongType n) = n 1134 annotation (CFloatType n) = n 1135 annotation (CFloatNType _ _ n) = n 1136 annotation (CDoubleType n) = n 1137 annotation (CSignedType n) = n 1138 annotation (CUnsigType n) = n 1139 annotation (CBoolType n) = n 1140 annotation (CComplexType n) = n 1141 annotation (CInt128Type n) = n 1142 annotation (CSUType _ n) = n 1143 annotation (CEnumType _ n) = n 1144 annotation (CTypeDef _ n) = n 1145 annotation (CTypeOfExpr _ n) = n 1146 annotation (CTypeOfType _ n) = n 1147 annotation (CAtomicType _ n) = n 1148 amap f (CVoidType a_1) = CVoidType (f a_1) 1149 amap f (CCharType a_1) = CCharType (f a_1) 1150 amap f (CShortType a_1) = CShortType (f a_1) 1151 amap f (CIntType a_1) = CIntType (f a_1) 1152 amap f (CLongType a_1) = CLongType (f a_1) 1153 amap f (CFloatType a_1) = CFloatType (f a_1) 1154 amap f (CFloatNType n x a_1) = CFloatNType n x (f a_1) 1155 amap f (CDoubleType a_1) = CDoubleType (f a_1) 1156 amap f (CSignedType a_1) = CSignedType (f a_1) 1157 amap f (CUnsigType a_1) = CUnsigType (f a_1) 1158 amap f (CBoolType a_1) = CBoolType (f a_1) 1159 amap f (CComplexType a_1) = CComplexType (f a_1) 1160 amap f (CInt128Type a_1) = CInt128Type (f a_1) 1161 amap f (CSUType a_1 a_2) = CSUType a_1 (f a_2) 1162 amap f (CEnumType a_1 a_2) = CEnumType a_1 (f a_2) 1163 amap f (CTypeDef a_1 a_2) = CTypeDef a_1 (f a_2) 1164 amap f (CTypeOfExpr a_1 a_2) = CTypeOfExpr a_1 (f a_2) 1165 amap f (CTypeOfType a_1 a_2) = CTypeOfType a_1 (f a_2) 1166 amap f (CAtomicType a_1 a_2) = CAtomicType a_1 (f a_2) 1167 1168instance CNode t1 => CNode (CTypeQualifier t1) where 1169 nodeInfo (CConstQual d) = nodeInfo d 1170 nodeInfo (CVolatQual d) = nodeInfo d 1171 nodeInfo (CRestrQual d) = nodeInfo d 1172 nodeInfo (CAtomicQual d) = nodeInfo d 1173 nodeInfo (CAttrQual d) = nodeInfo d 1174 nodeInfo (CNullableQual d) = nodeInfo d 1175 nodeInfo (CNonnullQual d) = nodeInfo d 1176 nodeInfo (CClRdOnlyQual d) = nodeInfo d 1177 nodeInfo (CClWrOnlyQual d) = nodeInfo d 1178 1179instance CNode t1 => Pos (CTypeQualifier t1) where 1180 posOf x = posOf (nodeInfo x) 1181 1182instance Functor CTypeQualifier where 1183 fmap _f (CConstQual a1) = CConstQual (_f a1) 1184 fmap _f (CVolatQual a1) = CVolatQual (_f a1) 1185 fmap _f (CRestrQual a1) = CRestrQual (_f a1) 1186 fmap _f (CAtomicQual a1) = CAtomicQual (_f a1) 1187 fmap _f (CAttrQual a1) = CAttrQual (fmap _f a1) 1188 fmap _f (CNullableQual a1) = CNullableQual (_f a1) 1189 fmap _f (CNonnullQual a1) = CNonnullQual (_f a1) 1190 fmap _f (CClRdOnlyQual a1) = CClRdOnlyQual (_f a1) 1191 fmap _f (CClWrOnlyQual a1) = CClWrOnlyQual (_f a1) 1192 1193instance Annotated CTypeQualifier where 1194 annotation (CConstQual n) = n 1195 annotation (CVolatQual n) = n 1196 annotation (CRestrQual n) = n 1197 annotation (CAtomicQual n) = n 1198 annotation (CAttrQual n) = annotation n 1199 annotation (CNullableQual n) = n 1200 annotation (CNonnullQual n) = n 1201 annotation (CClRdOnlyQual n) = n 1202 annotation (CClWrOnlyQual n) = n 1203 amap f (CConstQual a_1) = CConstQual (f a_1) 1204 amap f (CVolatQual a_1) = CVolatQual (f a_1) 1205 amap f (CRestrQual a_1) = CRestrQual (f a_1) 1206 amap f (CAtomicQual a_1) = CAtomicQual (f a_1) 1207 amap f (CAttrQual n) = CAttrQual (amap f n) 1208 amap f (CNullableQual a_1) = CNullableQual (f a_1) 1209 amap f (CNonnullQual a_1) = CNonnullQual (f a_1) 1210 amap f (CClRdOnlyQual a_1) = CClRdOnlyQual (f a_1) 1211 amap f (CClWrOnlyQual a_1) = CClWrOnlyQual (f a_1) 1212 1213instance CNode t1 => CNode (CFunctionSpecifier t1) where 1214 nodeInfo (CInlineQual d) = nodeInfo d 1215 nodeInfo (CNoreturnQual d) = nodeInfo d 1216instance CNode t1 => Pos (CFunctionSpecifier t1) where 1217 posOf x = posOf (nodeInfo x) 1218 1219instance Functor CFunctionSpecifier where 1220 fmap _f (CInlineQual a1) = CInlineQual (_f a1) 1221 fmap _f (CNoreturnQual a1) = CNoreturnQual (_f a1) 1222 1223instance Annotated CFunctionSpecifier where 1224 annotation (CInlineQual n) = n 1225 annotation (CNoreturnQual n) = n 1226 amap f (CInlineQual a_1) = CInlineQual (f a_1) 1227 amap f (CNoreturnQual a_1) = CNoreturnQual (f a_1) 1228 1229instance CNode t1 => CNode (CAlignmentSpecifier t1) where 1230 nodeInfo (CAlignAsType _ n) = nodeInfo n 1231 nodeInfo (CAlignAsExpr _ n) = nodeInfo n 1232instance CNode t1 => Pos (CAlignmentSpecifier t1) where 1233 posOf x = posOf (nodeInfo x) 1234 1235instance Functor CAlignmentSpecifier where 1236 fmap _f (CAlignAsType a1 a2) = CAlignAsType (fmap _f a1) (_f a2) 1237 fmap _f (CAlignAsExpr a1 a2) = CAlignAsExpr (fmap _f a1) (_f a2) 1238 1239instance Annotated CAlignmentSpecifier where 1240 annotation (CAlignAsType _ n) = n 1241 annotation (CAlignAsExpr _ n) = n 1242 amap f (CAlignAsType a_1 a_2) = CAlignAsType a_1 (f a_2) 1243 amap f (CAlignAsExpr a_1 a_2) = CAlignAsExpr a_1 (f a_2) 1244 1245instance CNode t1 => CNode (CStructureUnion t1) where 1246 nodeInfo (CStruct _ _ _ _ n) = nodeInfo n 1247instance CNode t1 => Pos (CStructureUnion t1) where 1248 posOf x = posOf (nodeInfo x) 1249 1250instance Functor CStructureUnion where 1251 fmap _f (CStruct a1 a2 a3 a4 a5) 1252 = CStruct a1 a2 (fmap (fmap (fmap _f)) a3) (fmap (fmap _f) a4) 1253 (_f a5) 1254 1255instance Annotated CStructureUnion where 1256 annotation (CStruct _ _ _ _ n) = n 1257 amap f (CStruct a_1 a_2 a_3 a_4 a_5) 1258 = CStruct a_1 a_2 a_3 a_4 (f a_5) 1259 1260instance CNode t1 => CNode (CEnumeration t1) where 1261 nodeInfo (CEnum _ _ _ n) = nodeInfo n 1262instance CNode t1 => Pos (CEnumeration t1) where 1263 posOf x = posOf (nodeInfo x) 1264 1265instance Functor CEnumeration where 1266 fmap _f (CEnum a1 a2 a3 a4) 1267 = CEnum a1 (fmap (fmap (fmap (fmap (fmap _f)))) a2) 1268 (fmap (fmap _f) a3) 1269 (_f a4) 1270 1271instance Annotated CEnumeration where 1272 annotation (CEnum _ _ _ n) = n 1273 amap f (CEnum a_1 a_2 a_3 a_4) = CEnum a_1 a_2 a_3 (f a_4) 1274 1275instance CNode t1 => CNode (CInitializer t1) where 1276 nodeInfo (CInitExpr _ n) = nodeInfo n 1277 nodeInfo (CInitList _ n) = nodeInfo n 1278instance CNode t1 => Pos (CInitializer t1) where 1279 posOf x = posOf (nodeInfo x) 1280 1281instance Annotated CInitializer where 1282 annotation (CInitExpr _ n) = n 1283 annotation (CInitList _ n) = n 1284 amap f (CInitExpr a_1 a_2) = CInitExpr a_1 (f a_2) 1285 amap f (CInitList a_1 a_2) = CInitList a_1 (f a_2) 1286 1287instance CNode t1 => CNode (CPartDesignator t1) where 1288 nodeInfo (CArrDesig _ n) = nodeInfo n 1289 nodeInfo (CMemberDesig _ n) = nodeInfo n 1290 nodeInfo (CRangeDesig _ _ n) = nodeInfo n 1291instance CNode t1 => Pos (CPartDesignator t1) where 1292 posOf x = posOf (nodeInfo x) 1293 1294instance Functor CPartDesignator where 1295 fmap _f (CArrDesig a1 a2) = CArrDesig (fmap _f a1) (_f a2) 1296 fmap _f (CMemberDesig a1 a2) = CMemberDesig a1 (_f a2) 1297 fmap _f (CRangeDesig a1 a2 a3) 1298 = CRangeDesig (fmap _f a1) (fmap _f a2) (_f a3) 1299 1300instance Annotated CPartDesignator where 1301 annotation (CArrDesig _ n) = n 1302 annotation (CMemberDesig _ n) = n 1303 annotation (CRangeDesig _ _ n) = n 1304 amap f (CArrDesig a_1 a_2) = CArrDesig a_1 (f a_2) 1305 amap f (CMemberDesig a_1 a_2) = CMemberDesig a_1 (f a_2) 1306 amap f (CRangeDesig a_1 a_2 a_3) = CRangeDesig a_1 a_2 (f a_3) 1307 1308instance CNode t1 => CNode (CAttribute t1) where 1309 nodeInfo (CAttr _ _ n) = nodeInfo n 1310instance CNode t1 => Pos (CAttribute t1) where 1311 posOf x = posOf (nodeInfo x) 1312 1313instance Functor CAttribute where 1314 fmap _f (CAttr a1 a2 a3) = CAttr a1 (fmap (fmap _f) a2) (_f a3) 1315 1316instance Annotated CAttribute where 1317 annotation (CAttr _ _ n) = n 1318 amap f (CAttr a_1 a_2 a_3) = CAttr a_1 a_2 (f a_3) 1319 1320instance CNode t1 => CNode (CExpression t1) where 1321 nodeInfo (CComma _ n) = nodeInfo n 1322 nodeInfo (CAssign _ _ _ n) = nodeInfo n 1323 nodeInfo (CCond _ _ _ n) = nodeInfo n 1324 nodeInfo (CBinary _ _ _ n) = nodeInfo n 1325 nodeInfo (CCast _ _ n) = nodeInfo n 1326 nodeInfo (CUnary _ _ n) = nodeInfo n 1327 nodeInfo (CSizeofExpr _ n) = nodeInfo n 1328 nodeInfo (CSizeofType _ n) = nodeInfo n 1329 nodeInfo (CAlignofExpr _ n) = nodeInfo n 1330 nodeInfo (CAlignofType _ n) = nodeInfo n 1331 nodeInfo (CComplexReal _ n) = nodeInfo n 1332 nodeInfo (CComplexImag _ n) = nodeInfo n 1333 nodeInfo (CIndex _ _ n) = nodeInfo n 1334 nodeInfo (CCall _ _ n) = nodeInfo n 1335 nodeInfo (CMember _ _ _ n) = nodeInfo n 1336 nodeInfo (CVar _ n) = nodeInfo n 1337 nodeInfo (CConst d) = nodeInfo d 1338 nodeInfo (CCompoundLit _ _ n) = nodeInfo n 1339 nodeInfo (CGenericSelection _ _ n) = nodeInfo n 1340 nodeInfo (CStatExpr _ n) = nodeInfo n 1341 nodeInfo (CLabAddrExpr _ n) = nodeInfo n 1342 nodeInfo (CBuiltinExpr d) = nodeInfo d 1343instance CNode t1 => Pos (CExpression t1) where 1344 posOf x = posOf (nodeInfo x) 1345 1346instance Annotated CExpression where 1347 annotation (CComma _ n) = n 1348 annotation (CAssign _ _ _ n) = n 1349 annotation (CCond _ _ _ n) = n 1350 annotation (CBinary _ _ _ n) = n 1351 annotation (CCast _ _ n) = n 1352 annotation (CUnary _ _ n) = n 1353 annotation (CSizeofExpr _ n) = n 1354 annotation (CSizeofType _ n) = n 1355 annotation (CAlignofExpr _ n) = n 1356 annotation (CAlignofType _ n) = n 1357 annotation (CComplexReal _ n) = n 1358 annotation (CComplexImag _ n) = n 1359 annotation (CIndex _ _ n) = n 1360 annotation (CCall _ _ n) = n 1361 annotation (CMember _ _ _ n) = n 1362 annotation (CVar _ n) = n 1363 annotation (CConst n) = annotation n 1364 annotation (CCompoundLit _ _ n) = n 1365 annotation (CGenericSelection _ _ n) = n 1366 annotation (CStatExpr _ n) = n 1367 annotation (CLabAddrExpr _ n) = n 1368 annotation (CBuiltinExpr n) = annotation n 1369 amap f (CComma a_1 a_2) = CComma a_1 (f a_2) 1370 amap f (CAssign a_1 a_2 a_3 a_4) = CAssign a_1 a_2 a_3 (f a_4) 1371 amap f (CCond a_1 a_2 a_3 a_4) = CCond a_1 a_2 a_3 (f a_4) 1372 amap f (CBinary a_1 a_2 a_3 a_4) = CBinary a_1 a_2 a_3 (f a_4) 1373 amap f (CCast a_1 a_2 a_3) = CCast a_1 a_2 (f a_3) 1374 amap f (CUnary a_1 a_2 a_3) = CUnary a_1 a_2 (f a_3) 1375 amap f (CSizeofExpr a_1 a_2) = CSizeofExpr a_1 (f a_2) 1376 amap f (CSizeofType a_1 a_2) = CSizeofType a_1 (f a_2) 1377 amap f (CAlignofExpr a_1 a_2) = CAlignofExpr a_1 (f a_2) 1378 amap f (CAlignofType a_1 a_2) = CAlignofType a_1 (f a_2) 1379 amap f (CComplexReal a_1 a_2) = CComplexReal a_1 (f a_2) 1380 amap f (CComplexImag a_1 a_2) = CComplexImag a_1 (f a_2) 1381 amap f (CIndex a_1 a_2 a_3) = CIndex a_1 a_2 (f a_3) 1382 amap f (CCall a_1 a_2 a_3) = CCall a_1 a_2 (f a_3) 1383 amap f (CMember a_1 a_2 a_3 a_4) = CMember a_1 a_2 a_3 (f a_4) 1384 amap f (CVar a_1 a_2) = CVar a_1 (f a_2) 1385 amap f (CConst n) = CConst (amap f n) 1386 amap f (CCompoundLit a_1 a_2 a_3) = CCompoundLit a_1 a_2 (f a_3) 1387 amap f (CGenericSelection a_1 a_2 a_3) 1388 = CGenericSelection a_1 a_2 (f a_3) 1389 amap f (CStatExpr a_1 a_2) = CStatExpr a_1 (f a_2) 1390 amap f (CLabAddrExpr a_1 a_2) = CLabAddrExpr a_1 (f a_2) 1391 amap f (CBuiltinExpr n) = CBuiltinExpr (amap f n) 1392 1393instance CNode t1 => CNode (CBuiltinThing t1) where 1394 nodeInfo (CBuiltinVaArg _ _ n) = nodeInfo n 1395 nodeInfo (CBuiltinOffsetOf _ _ n) = nodeInfo n 1396 nodeInfo (CBuiltinTypesCompatible _ _ n) = nodeInfo n 1397 nodeInfo (CBuiltinConvertVector _ _ n) = nodeInfo n 1398instance CNode t1 => Pos (CBuiltinThing t1) where 1399 posOf x = posOf (nodeInfo x) 1400 1401instance Functor CBuiltinThing where 1402 fmap _f (CBuiltinVaArg a1 a2 a3) 1403 = CBuiltinVaArg (fmap _f a1) (fmap _f a2) (_f a3) 1404 fmap _f (CBuiltinOffsetOf a1 a2 a3) 1405 = CBuiltinOffsetOf (fmap _f a1) (fmap (fmap _f) a2) (_f a3) 1406 fmap _f (CBuiltinTypesCompatible a1 a2 a3) 1407 = CBuiltinTypesCompatible (fmap _f a1) (fmap _f a2) (_f a3) 1408 fmap _f (CBuiltinConvertVector a1 a2 a3) 1409 = CBuiltinConvertVector (fmap _f a1) (fmap _f a2) (_f a3) 1410 1411instance Annotated CBuiltinThing where 1412 annotation (CBuiltinVaArg _ _ n) = n 1413 annotation (CBuiltinOffsetOf _ _ n) = n 1414 annotation (CBuiltinTypesCompatible _ _ n) = n 1415 annotation (CBuiltinConvertVector _ _ n) = n 1416 amap f (CBuiltinVaArg a_1 a_2 a_3) = CBuiltinVaArg a_1 a_2 (f a_3) 1417 amap f (CBuiltinOffsetOf a_1 a_2 a_3) 1418 = CBuiltinOffsetOf a_1 a_2 (f a_3) 1419 amap f (CBuiltinTypesCompatible a_1 a_2 a_3) 1420 = CBuiltinTypesCompatible a_1 a_2 (f a_3) 1421 amap f (CBuiltinConvertVector a_1 a_2 a_3) = 1422 CBuiltinConvertVector a_1 a_2 (f a_3) 1423 1424instance CNode t1 => CNode (CConstant t1) where 1425 nodeInfo (CIntConst _ n) = nodeInfo n 1426 nodeInfo (CCharConst _ n) = nodeInfo n 1427 nodeInfo (CFloatConst _ n) = nodeInfo n 1428 nodeInfo (CStrConst _ n) = nodeInfo n 1429instance CNode t1 => Pos (CConstant t1) where 1430 posOf x = posOf (nodeInfo x) 1431 1432instance Functor CConstant where 1433 fmap _f (CIntConst a1 a2) = CIntConst a1 (_f a2) 1434 fmap _f (CCharConst a1 a2) = CCharConst a1 (_f a2) 1435 fmap _f (CFloatConst a1 a2) = CFloatConst a1 (_f a2) 1436 fmap _f (CStrConst a1 a2) = CStrConst a1 (_f a2) 1437 1438instance Annotated CConstant where 1439 annotation (CIntConst _ n) = n 1440 annotation (CCharConst _ n) = n 1441 annotation (CFloatConst _ n) = n 1442 annotation (CStrConst _ n) = n 1443 amap f (CIntConst a_1 a_2) = CIntConst a_1 (f a_2) 1444 amap f (CCharConst a_1 a_2) = CCharConst a_1 (f a_2) 1445 amap f (CFloatConst a_1 a_2) = CFloatConst a_1 (f a_2) 1446 amap f (CStrConst a_1 a_2) = CStrConst a_1 (f a_2) 1447 1448instance CNode t1 => CNode (CStringLiteral t1) where 1449 nodeInfo (CStrLit _ n) = nodeInfo n 1450instance CNode t1 => Pos (CStringLiteral t1) where 1451 posOf x = posOf (nodeInfo x) 1452 1453instance Functor CStringLiteral where 1454 fmap _f (CStrLit a1 a2) = CStrLit a1 (_f a2) 1455 1456instance Annotated CStringLiteral where 1457 annotation (CStrLit _ n) = n 1458 amap f (CStrLit a_1 a_2) = CStrLit a_1 (f a_2) 1459-- GENERATED STOP 1460