{-# LANGUAGE DefaultSignatures #-}

module Language.Fortran.AST.Annotated where

import Language.Fortran.Util.FirstParameter

-- Retrieving SrcSpan and Annotation from nodes
class Annotated f where
  getAnnotation :: f a -> a
  setAnnotation :: a -> f a -> f a
  modifyAnnotation :: (a -> a) -> f a -> f a
  default getAnnotation :: (FirstParameter (f a) a) => f a -> a
  getAnnotation = f a -> a
forall a e. FirstParameter a e => a -> e
getFirstParameter

  default setAnnotation :: (FirstParameter (f a) a) => a -> f a -> f a
  setAnnotation = a -> f a -> f a
forall a e. FirstParameter a e => e -> a -> a
setFirstParameter

  modifyAnnotation a -> a
f f a
x = a -> f a -> f a
forall (f :: * -> *) a. Annotated f => a -> f a -> f a
setAnnotation (a -> a
f (f a -> a
forall (f :: * -> *) a. Annotated f => f a -> a
getAnnotation f a
x)) f a
x