-- Copyright (c) 2006-2011-- The President and Fellows of Harvard College.---- Redistribution and use in source and binary forms, with or without-- modification, are permitted provided that the following conditions-- are met:-- 1. Redistributions of source code must retain the above copyright-- notice, this list of conditions and the following disclaimer.-- 2. Redistributions in binary form must reproduce the above copyright-- notice, this list of conditions and the following disclaimer in the-- documentation and/or other materials provided with the distribution.-- 3. Neither the name of the University nor the names of its contributors-- may be used to endorse or promote products derived from this software-- without specific prior written permission.-- THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE-- ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF-- SUCH DAMAGE.---------------------------------------------------------------------------------- |-- Module : Language.C.Syntax-- Copyright : (c) Harvard University 2006-2011-- License : BSD-style-- Maintainer : mainland@eecs.harvard.edu----------------------------------------------------------------------------------{-# LANGUAGE CPP #-}{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE FlexibleInstances #-}moduleLanguage.C.SyntaxwhereimportData.GenericsimportData.LocdataExtensions=Antiquotation|Gcc|CUDA|OpenCLderiving(Eq,Ord,Enum,Show)dataId=IdString!SrcLoc|AntiIdString!SrcLocderiving(Eq,Ord,Data,Typeable)dataStorage=Tauto!SrcLoc|Tregister!SrcLoc|Tstatic!SrcLoc|Textern!SrcLoc|TexternLString!SrcLoc|Ttypedef!SrcLocderiving(Eq,Ord,Data,Typeable)dataTypeQual=Tconst!SrcLoc|Tvolatile!SrcLoc|Tinline!SrcLoc-- C99|Trestrict!SrcLoc-- CUDA|TCUDAdevice!SrcLoc|TCUDAglobal!SrcLoc|TCUDAhost!SrcLoc|TCUDAconstant!SrcLoc|TCUDAshared!SrcLoc|TCUDAnoinline!SrcLoc-- OpenCL|TCLprivate!SrcLoc|TCLlocal!SrcLoc|TCLglobal!SrcLoc|TCLconstant!SrcLoc|TCLreadonly!SrcLoc|TCLwriteonly!SrcLoc|TCLkernel!SrcLocderiving(Eq,Ord,Data,Typeable)dataSign=Tsigned!SrcLoc|Tunsigned!SrcLocderiving(Eq,Ord,Data,Typeable)dataTypeSpec=Tvoid!SrcLoc|Tchar(MaybeSign)!SrcLoc|Tshort(MaybeSign)!SrcLoc|Tint(MaybeSign)!SrcLoc|Tlong(MaybeSign)!SrcLoc|Tlong_long(MaybeSign)!SrcLoc|Tfloat!SrcLoc|Tdouble!SrcLoc|Tlong_double!SrcLoc|Tstruct(MaybeId)(Maybe[FieldGroup])[Attr]!SrcLoc|Tunion(MaybeId)(Maybe[FieldGroup])[Attr]!SrcLoc|Tenum(MaybeId)[CEnum][Attr]!SrcLoc|TnamedId!SrcLoc|TtypeofExpExp!SrcLoc|TtypeofTypeType!SrcLoc|Tva_list!SrcLocderiving(Eq,Ord,Data,Typeable)dataDeclSpec=DeclSpec[Storage][TypeQual]TypeSpec!SrcLoc|AntiDeclSpecString!SrcLoc|AntiTypeDeclSpec[Storage][TypeQual]String!SrcLocderiving(Eq,Ord,Data,Typeable)-- | There are two types of declarators in C, regular declarators and abstract-- declarators. The former is for declaring variables, function parameters,-- typedefs, etc. and the latter for abstract types---@typedef int-- ({*}foo)(void)@ vs. @\tt int ({*})(void)@. The difference between the two is-- just whether or not an identifier is attached to the declarator. We therefore-- only define one 'Decl' type and use it for both cases.dataArraySize=ArraySizeBoolExp!SrcLoc|VariableArraySize!SrcLoc|NoArraySize!SrcLocderiving(Eq,Ord,Data,Typeable)dataDecl=DeclRoot!SrcLoc|Ptr[TypeQual]Decl!SrcLoc|Array[TypeQual]ArraySizeDecl!SrcLoc|ProtoDeclParams!SrcLoc|OldProtoDecl[Id]!SrcLoc|AntiTypeDeclString!SrcLocderiving(Eq,Ord,Data,Typeable)dataType=TypeDeclSpecDecl!SrcLoc|AntiTypeString!SrcLocderiving(Eq,Ord,Data,Typeable)dataDesignator=IndexDesignatorExp!SrcLoc|MemberDesignatorId!SrcLocderiving(Eq,Ord,Data,Typeable)dataDesignation=Designation[Designator]!SrcLocderiving(Eq,Ord,Data,Typeable)dataInitializer=ExpInitializerExp!SrcLoc|CompoundInitializer[(MaybeDesignation,Initializer)]!SrcLocderiving(Eq,Ord,Data,Typeable)typeAsmLabel=StringdataInit=InitIdDecl(MaybeAsmLabel)(MaybeInitializer)[Attr]!SrcLocderiving(Eq,Ord,Data,Typeable)dataTypedef=TypedefIdDecl[Attr]!SrcLocderiving(Eq,Ord,Data,Typeable)dataInitGroup=InitGroupDeclSpec[Attr][Init]!SrcLoc|TypedefGroupDeclSpec[Attr][Typedef]!SrcLoc|AntiDeclString!SrcLoc|AntiDeclsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataField=Field(MaybeId)(MaybeDecl)(MaybeExp)!SrcLocderiving(Eq,Ord,Data,Typeable)dataFieldGroup=FieldGroupDeclSpec[Field]!SrcLoc|AntiSdeclString!SrcLoc|AntiSdeclsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataCEnum=CEnumId(MaybeExp)!SrcLoc|AntiEnumString!SrcLoc|AntiEnumsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataAttr=AttrId[Exp]!SrcLocderiving(Eq,Ord,Data,Typeable)dataParam=Param(MaybeId)DeclSpecDecl!SrcLoc|AntiParamString!SrcLoc|AntiParamsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataParams=Params[Param]Bool!SrcLocderiving(Eq,Ord,Data,Typeable)dataFunc=FuncDeclSpecIdDeclParams[BlockItem]!SrcLoc|OldFuncDeclSpecIdDecl[Id](Maybe[InitGroup])[BlockItem]!SrcLocderiving(Eq,Ord,Data,Typeable)dataDefinition=FuncDefFunc!SrcLoc|DecDefInitGroup!SrcLoc|EscDefString!SrcLoc|AntiFuncString!SrcLoc|AntiEscString!SrcLoc|AntiEdeclString!SrcLoc|AntiEdeclsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataStm=LabelIdStm!SrcLoc|CaseExpStm!SrcLoc|DefaultStm!SrcLoc|Exp(MaybeExp)!SrcLoc|Block[BlockItem]!SrcLoc|IfExpStm(MaybeStm)!SrcLoc|SwitchExpStm!SrcLoc|WhileExpStm!SrcLoc|DoWhileStmExp!SrcLoc|For(EitherInitGroup(MaybeExp))(MaybeExp)(MaybeExp)Stm!SrcLoc|GotoId!SrcLoc|Continue!SrcLoc|Break!SrcLoc|Return(MaybeExp)!SrcLoc|AsmBool[Attr][String][(String,Exp)][(String,Exp)][String]!SrcLoc|AntiStmString!SrcLoc|AntiStmsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataBlockItem=BlockDeclInitGroup|BlockStmStm|AntiBlockItemString!SrcLoc|AntiBlockItemsString!SrcLocderiving(Eq,Ord,Data,Typeable)funcProto::Func->InitGroupfuncProtof@(Funcdecl_speciddeclparams__)=InitGroupdecl_spec[][Initid(Protodeclparamsloc)NothingNothing[]loc]locwhereloc=locOfffuncProtof@(OldFuncdecl_speciddeclparams___)=InitGroupdecl_spec[][Initid(OldProtodeclparamsloc)NothingNothing[]loc]locwhereloc=locOffisPtr::Type->BoolisPtr(Type_decl_)=godeclwherego(DeclRoot_)=Falsego(Ptr___)=Truego(Array____)=Truego(Proto___)=Falsego(OldProto___)=Falsego(AntiTypeDecl__)=error"isPtr: encountered antiquoted type declaration"isPtr(AntiType__)=error"isPtr: encountered antiquoted type"dataSigned=Signed|Unsignedderiving(Eq,Ord,Data,Typeable)dataConst=IntConstStringSignedInteger!SrcLoc|LongIntConstStringSignedInteger!SrcLoc|LongLongIntConstStringSignedInteger!SrcLoc|FloatConstStringRational!SrcLoc|DoubleConstStringRational!SrcLoc|LongDoubleConstStringRational!SrcLoc|CharConstStringChar!SrcLoc|StringConst[String]String!SrcLoc|AntiIntString!SrcLoc|AntiUIntString!SrcLoc|AntiLIntString!SrcLoc|AntiULIntString!SrcLoc|AntiFloatString!SrcLoc|AntiDoubleString!SrcLoc|AntiLongDoubleString!SrcLoc|AntiCharString!SrcLoc|AntiStringString!SrcLocderiving(Eq,Ord,Data,Typeable)dataExeConfig=ExeConfig{exeGridDim::Exp,exeBlockDim::Exp,exeSharedSize::MaybeExp,exeStream::MaybeExp,exeLoc::!SrcLoc}deriving(Eq,Ord,Data,Typeable)dataExp=VarId!SrcLoc|ConstConst!SrcLoc|BinOpBinOpExpExp!SrcLoc|AssignExpAssignOpExp!SrcLoc|PreIncExp!SrcLoc|PostIncExp!SrcLoc|PreDecExp!SrcLoc|PostDecExp!SrcLoc|UnOpUnOpExp!SrcLoc|SizeofExpExp!SrcLoc|SizeofTypeType!SrcLoc|CastTypeExp!SrcLoc|CondExpExpExp!SrcLoc|MemberExpId!SrcLoc|PtrMemberExpId!SrcLoc|IndexExpExp!SrcLoc|FnCallExp[Exp]!SrcLoc|CudaCallExpExeConfig[Exp]!SrcLoc|SeqExpExp!SrcLoc|CompoundLitType[(MaybeDesignation,Initializer)]!SrcLoc|StmExpr[BlockItem]!SrcLoc|BuiltinVaArgExpType!SrcLoc|AntiExpString!SrcLoc|AntiArgsString!SrcLocderiving(Eq,Ord,Data,Typeable)dataBinOp=Add|Sub|Mul|Div|Mod|Eq|Ne|Lt|Gt|Le|Ge|Land|Lor|And|Or|Xor|Lsh|Rshderiving(Eq,Ord,Data,Typeable)dataAssignOp=JustAssign|AddAssign|SubAssign|MulAssign|DivAssign|ModAssign|LshAssign|RshAssign|AndAssign|XorAssign|OrAssignderiving(Eq,Ord,Data,Typeable)dataUnOp=AddrOf|Deref|Positive|Negate|Not|Lnotderiving(Eq,Ord,Data,Typeable)instanceLocatedIdwheregetLoc(Id_loc)=getLoclocgetLoc(AntiId_loc)=getLoclocinstanceLocatedStoragewheregetLoc(Tautoloc)=getLoclocgetLoc(Tregisterloc)=getLoclocgetLoc(Tstaticloc)=getLoclocgetLoc(Texternloc)=getLoclocgetLoc(TexternL_loc)=getLoclocgetLoc(Ttypedefloc)=getLoclocinstanceLocatedTypeQualwheregetLoc(Tconstloc)=getLoclocgetLoc(Tvolatileloc)=getLoclocgetLoc(Tinlineloc)=getLoclocgetLoc(Trestrictloc)=getLoclocgetLoc(TCUDAdeviceloc)=getLoclocgetLoc(TCUDAgloballoc)=getLoclocgetLoc(TCUDAhostloc)=getLoclocgetLoc(TCUDAconstantloc)=getLoclocgetLoc(TCUDAsharedloc)=getLoclocgetLoc(TCUDAnoinlineloc)=getLoclocgetLoc(TCLprivateloc)=getLoclocgetLoc(TCLlocalloc)=getLoclocgetLoc(TCLgloballoc)=getLoclocgetLoc(TCLconstantloc)=getLoclocgetLoc(TCLreadonlyloc)=getLoclocgetLoc(TCLwriteonlyloc)=getLoclocgetLoc(TCLkernelloc)=getLoclocinstanceLocatedSignwheregetLoc(Tsignedloc)=getLoclocgetLoc(Tunsignedloc)=getLoclocinstanceLocatedTypeSpecwheregetLoc(Tvoidloc)=getLoclocgetLoc(Tchar_loc)=getLoclocgetLoc(Tshort_loc)=getLoclocgetLoc(Tint_loc)=getLoclocgetLoc(Tlong_loc)=getLoclocgetLoc(Tlong_long_loc)=getLoclocgetLoc(Tfloatloc)=getLoclocgetLoc(Tdoubleloc)=getLoclocgetLoc(Tlong_doubleloc)=getLoclocgetLoc(Tstruct___loc)=getLoclocgetLoc(Tunion___loc)=getLoclocgetLoc(Tenum___loc)=getLoclocgetLoc(Tnamed_loc)=getLoclocgetLoc(TtypeofExp_loc)=getLoclocgetLoc(TtypeofType_loc)=getLoclocgetLoc(Tva_listloc)=getLoclocinstanceLocatedDeclSpecwheregetLoc(DeclSpec___loc)=getLoclocgetLoc(AntiDeclSpec_loc)=getLoclocgetLoc(AntiTypeDeclSpec___loc)=getLoclocinstanceLocatedArraySizewheregetLoc(ArraySize__loc)=getLoclocgetLoc(VariableArraySizeloc)=getLoclocgetLoc(NoArraySizeloc)=getLoclocinstanceLocatedDeclwheregetLoc(DeclRootloc)=getLoclocgetLoc(Ptr__loc)=getLoclocgetLoc(Array___loc)=getLoclocgetLoc(Proto__loc)=getLoclocgetLoc(OldProto__loc)=getLoclocgetLoc(AntiTypeDecl_loc)=getLoclocinstanceLocatedTypewheregetLoc(Type__loc)=getLoclocgetLoc(AntiType_loc)=getLoclocinstanceLocatedDesignatorwheregetLoc(IndexDesignator_loc)=getLoclocgetLoc(MemberDesignator_loc)=getLoclocinstanceLocatedDesignationwheregetLoc(Designation_loc)=getLoclocinstanceLocatedInitializerwheregetLoc(ExpInitializer_loc)=getLoclocgetLoc(CompoundInitializer_loc)=getLoclocinstanceLocatedInitwheregetLoc(Init_____loc)=getLoclocinstanceLocatedTypedefwheregetLoc(Typedef___loc)=getLoclocinstanceLocatedInitGroupwheregetLoc(InitGroup___loc)=getLoclocgetLoc(TypedefGroup___loc)=getLoclocgetLoc(AntiDecl_loc)=getLoclocgetLoc(AntiDecls_loc)=getLoclocinstanceLocatedFieldwheregetLoc(Field___loc)=getLoclocinstanceLocatedFieldGroupwheregetLoc(FieldGroup__loc)=getLoclocgetLoc(AntiSdecl_loc)=getLoclocgetLoc(AntiSdecls_loc)=getLoclocinstanceLocatedCEnumwheregetLoc(CEnum__loc)=getLoclocgetLoc(AntiEnum_loc)=getLoclocgetLoc(AntiEnums_loc)=getLoclocinstanceLocatedAttrwheregetLoc(Attr__loc)=getLoclocinstanceLocatedParamwheregetLoc(Param___loc)=getLoclocgetLoc(AntiParam_loc)=getLoclocgetLoc(AntiParams_loc)=getLoclocinstanceLocatedParamswheregetLoc(Params__loc)=getLoclocinstanceLocatedFuncwheregetLoc(Func_____loc)=getLoclocgetLoc(OldFunc______loc)=getLoclocinstanceLocatedDefinitionwheregetLoc(FuncDef_loc)=getLoclocgetLoc(DecDef_loc)=getLoclocgetLoc(EscDef_loc)=getLoclocgetLoc(AntiFunc_loc)=getLoclocgetLoc(AntiEsc_loc)=getLoclocgetLoc(AntiEdecl_loc)=getLoclocgetLoc(AntiEdecls_loc)=getLoclocinstanceLocatedStmwheregetLoc(Label__loc)=getLoclocgetLoc(Case__loc)=getLoclocgetLoc(Default_loc)=getLoclocgetLoc(Exp_loc)=getLoclocgetLoc(Block_loc)=getLoclocgetLoc(If___loc)=getLoclocgetLoc(Switch__loc)=getLoclocgetLoc(While__loc)=getLoclocgetLoc(DoWhile__loc)=getLoclocgetLoc(For____loc)=getLoclocgetLoc(Goto_loc)=getLoclocgetLoc(Continueloc)=getLoclocgetLoc(Breakloc)=getLoclocgetLoc(Return_loc)=getLoclocgetLoc(Asm______loc)=getLoclocgetLoc(AntiStm_loc)=getLoclocgetLoc(AntiStms_loc)=getLoclocinstanceLocatedBlockItemwheregetLoc(BlockDecldecl)=getLocdeclgetLoc(BlockStmstm)=getLocstmgetLoc(AntiBlockItem_loc)=getLoclocgetLoc(AntiBlockItems_loc)=getLoclocinstanceLocatedConstwheregetLoc(IntConst___loc)=getLoclocgetLoc(LongIntConst___loc)=getLoclocgetLoc(LongLongIntConst___loc)=getLoclocgetLoc(FloatConst__loc)=getLoclocgetLoc(DoubleConst__loc)=getLoclocgetLoc(LongDoubleConst__loc)=getLoclocgetLoc(CharConst__loc)=getLoclocgetLoc(StringConst__loc)=getLoclocgetLoc(AntiInt_loc)=getLoclocgetLoc(AntiUInt_loc)=getLoclocgetLoc(AntiLInt_loc)=getLoclocgetLoc(AntiULInt_loc)=getLoclocgetLoc(AntiFloat_loc)=getLoclocgetLoc(AntiDouble_loc)=getLoclocgetLoc(AntiLongDouble_loc)=getLoclocgetLoc(AntiChar_loc)=getLoclocgetLoc(AntiString_loc)=getLoclocinstanceLocatedExeConfigwheregetLocconf=getLoc(exeLocconf)instanceLocatedExpwheregetLoc(Var_loc)=getLoclocgetLoc(Const_loc)=getLoclocgetLoc(BinOp___loc)=getLoclocgetLoc(Assign___loc)=getLoclocgetLoc(PreInc_loc)=getLoclocgetLoc(PostInc_loc)=getLoclocgetLoc(PreDec_loc)=getLoclocgetLoc(PostDec_loc)=getLoclocgetLoc(UnOp__loc)=getLoclocgetLoc(SizeofExp_loc)=getLoclocgetLoc(SizeofType_loc)=getLoclocgetLoc(Cast__loc)=getLoclocgetLoc(Cond___loc)=getLoclocgetLoc(Member__loc)=getLoclocgetLoc(PtrMember__loc)=getLoclocgetLoc(Index__loc)=getLoclocgetLoc(FnCall__loc)=getLoclocgetLoc(CudaCall___loc)=getLoclocgetLoc(Seq__loc)=getLoclocgetLoc(CompoundLit__loc)=getLoclocgetLoc(StmExpr_loc)=getLoclocgetLoc(BuiltinVaArg__loc)=getLoclocgetLoc(AntiExp_loc)=getLoclocgetLoc(AntiArgs_loc)=getLoclocctypedef::Id->Decl->[Attr]->Typedefctypedefiddeclattrs=Typedefiddeclattrs((id<-->decl::Loc)<-->attrs)cdeclSpec::[Storage]->[TypeQual]->TypeSpec->DeclSpeccdeclSpecstoragequalsspec=DeclSpecstoragequalsspec((storage<-->quals::Loc)<-->spec)cinitGroup::DeclSpec->[Attr]->[Init]->InitGroupcinitGroupdspecattrsinis=InitGroupdspecattrsinis((dspec<-->attrs::Loc)<-->inis)ctypedefGroup::DeclSpec->[Attr]->[Typedef]->InitGroupctypedefGroupdspecattrstypedefs=TypedefGroupdspecattrstypedefs((dspec<-->attrs::Loc)<-->typedefs)