{-# LANGUAGE DeriveDataTypeable #-}------------------------------------------------------------------------------- |-- Module : Language.ObjC.Syntax.Attributes-- Copyright : (c) [1995..1999] Manuel M. T. Chakravarty-- (c) 2008 Benedikt Huber (stripped radically)-- (c) 2012 John W. Lato-- License : BSD-style-- Maintainer : jwlato@gmail.com-- Stability : experimental-- Portability : ghc---- source position and unqiue name-----------------------------------------------------------------------------moduleLanguage.ObjC.Data.Node(NodeInfo(..),undefNode,isUndefNode,mkNodeInfoOnlyPos,mkNodeInfoPosLen,mkNodeInfo,mkNodeInfo',internalNode,-- deprecated, use undefNodeCNode(nodeInfo),fileOfNode,posOfNode,nameOfNode,getLastTokenPos,lengthOfNode,eqByName,)whereimportLanguage.ObjC.Data.PositionimportLanguage.ObjC.Data.Name(Name)importData.Generics-- | Parsed entity attributedataNodeInfo=OnlyPos!Position{-# UNPACK #-}!PosLength-- only pos and last token (for internal stuff only)|NodeInfo!Position{-# UNPACK #-}!PosLength{-# UNPACK #-}!Name-- pos, last token and unique namederiving(Data,Typeable)instanceShowNodeInfowhereshowsPrecd(OnlyPospl)=(showString"(OnlyPos ").(showsPrecdp).(showString" ").(showsPrecdl).(showString")")showsPrecd(NodeInfopln)=(showString"(NodeInfo ").(showsPrecdp).(showString" ").(showsPrecdl).(showString" ").(showsPrecdn).(showString")")-- name equality of attributes, used to define (name) equality of objectsinstanceEqNodeInfowhere(NodeInfo__id1)==(NodeInfo__id2)=id1==id2_==_=error"Attributes: Attempt to compare `OnlyPos' attributes!"-- attribute orderinginstanceOrdNodeInfowhere(NodeInfo__id1)<=(NodeInfo__id2)=id1<=id2_<=_=error"Attributes: Attempt to compare `OnlyPos' attributes!"instancePosNodeInfowhereposOf(OnlyPospos_)=posposOf(NodeInfopos__)=pos-- | get the number of characters an AST node spanslengthOfNode::NodeInfo->MaybeIntlengthOfNodeni=lenwherelen=caseniofNodeInfofirstPoslastTok_->computeLengthfirstPoslastTokOnlyPosfirstPoslastTok->computeLengthfirstPoslastTokcomputeLengthpos(PLlastPoslen')|len'<0=Nothing|otherwise=Just(posOffsetlastPos+len'-posOffsetpos)-- | get the position and length of the last tokengetLastTokenPos::NodeInfo->PosLengthgetLastTokenPos(NodeInfo_lastTok_)=lastTokgetLastTokenPos(OnlyPos_lastTok)=lastTok-- | a class for convenient access to the attributes of an attributed objectclassCNodeawherenodeInfo::a->NodeInfoinstanceCNodeNodeInfowherenodeInfo=idinstance(CNodea,CNodeb)=>CNode(Eitherab)wherenodeInfo=eithernodeInfonodeInfonameOfNode::NodeInfo->MaybeNamenameOfNode(OnlyPos__)=NothingnameOfNode(NodeInfo__name)=JustnameposOfNode::NodeInfo->PositionposOfNodeni=caseniof(OnlyPospos_)->pos;(NodeInfopos__)->posfileOfNode::(CNodea)=>a->MaybeFilePathfileOfNode=fmapposFile.justIfisSourcePos.posOfNode.nodeInfowherejustIfpredicatex|predicatex=Justx|otherwise=Nothing-- | equality by nameeqByName::CNodea=>a->a->BooleqByNameobj1obj2=(nodeInfoobj1)==(nodeInfoobj2)-- attribute identifier creation-- -----------------------------{-# DEPRECATED internalNode "use undefNode instead" #-}internalNode::NodeInfointernalNode=undefNode-- | create a node with neither name nor positional informationundefNode::NodeInfoundefNode=OnlyPosnopos(PLnoposnO)-- | return True if the node carries neither name nor positional informationisUndefNode::NodeInfo->BoolisUndefNode(OnlyPosp_)|isNoPosp=True|otherwise=FalseisUndefNode_=FalsenO::IntnO=(-1)-- |-- | Given only a source position, create a new node attributemkNodeInfoOnlyPos::Position->NodeInfomkNodeInfoOnlyPospos=OnlyPospos(PLnoposnO)-- | Given a source position and the position and length of the last token, create a new node attributemkNodeInfoPosLen::Position->(Position,Int)->NodeInfomkNodeInfoPosLenppl=OnlyPosp(uncurryPLpl)-- | Given a source position and a unique name, create a new attribute-- identifiermkNodeInfo::Position->Name->NodeInfomkNodeInfoposname=NodeInfopos(PLnoposnO)name-- | Given a source position, the position and length of the last token and a unique name, create a new attribute-- identifier. Strict inmkNodeInfo'::Position->(Position,Int)->Name->NodeInfomkNodeInfo'poslasttokname=NodeInfopos(uncurryPLlasttok)name