module Camfort.Specification.Stencils.Annotation where
import Camfort.Analysis.Annotations
import Camfort.Analysis.CommentAnnotator
import Camfort.Specification.Stencils.Syntax
import qualified Camfort.Specification.Stencils.Grammar as Gram
import qualified Language.Fortran.AST as F
import qualified Language.Fortran.Analysis as FA
onPrev :: (a -> a) -> FA.Analysis a -> FA.Analysis a
onPrev f ann = ann { FA.prevAnnotation = f (FA.prevAnnotation ann) }
instance ASTEmbeddable (FA.Analysis Annotation) Gram.Specification where
annotateWithAST ann ast =
onPrev (\ann -> ann { stencilSpec = Just $ Left ast }) ann
instance Linkable (FA.Analysis Annotation) where
link ann (b@(F.BlDo {})) =
onPrev (\ann -> ann { stencilBlock = Just b }) ann
link ann (b@(F.BlStatement _ _ _ (F.StExpressionAssign {}))) =
onPrev (\ann -> ann { stencilBlock = Just b }) ann
link ann b = ann