@@ -86,6 +86,7 @@ module Language.Fortran.AST
8686 , DoSpecification (.. )
8787 , ProgramUnitName (.. )
8888 , Kind
89+ , BlockConstructStart (.. )
8990
9091 -- * Node annotations & related typeclasses
9192 , A0
@@ -301,6 +302,17 @@ programUnitSubprograms PUComment{} = Nothing
301302newtype Comment a = Comment String
302303 deriving (Eq , Show , Data , Typeable , Generic , Functor )
303304
305+ -- | Common data related to the start of block constructs.
306+ data BlockConstructStart a =
307+ BlockConstructStart a
308+ SrcSpan
309+ -- ^ original block start statement 'SrcSpan'
310+ (Maybe (Expression a ))
311+ -- ^ label
312+ (Maybe String )
313+ -- ^ name
314+ deriving (Eq , Show , Data , Typeable , Generic , Functor )
315+
304316data Block a =
305317 BlStatement a SrcSpan
306318 (Maybe (Expression a )) -- ^ Label
@@ -329,16 +341,14 @@ data Block a =
329341 (Maybe (Expression a )) -- ^ Label to END SELECT
330342
331343 | BlDo a SrcSpan
332- (Maybe (Expression a )) -- ^ Label
333- (Maybe String ) -- ^ Construct name
344+ (BlockConstructStart a )
334345 (Maybe (Expression a )) -- ^ Target label
335346 (Maybe (DoSpecification a )) -- ^ Do Specification
336347 [ Block a ] -- ^ Body
337348 (Maybe (Expression a )) -- ^ Label to END DO
338349
339350 | BlDoWhile a SrcSpan
340- (Maybe (Expression a )) -- ^ Label
341- (Maybe String ) -- ^ Construct name
351+ (BlockConstructStart a )
342352 (Maybe (Expression a )) -- ^ Target label
343353 (Expression a ) -- ^ Condition
344354 [ Block a ] -- ^ Body
@@ -754,6 +764,7 @@ instance FirstParameter (Declarator a) a
754764instance FirstParameter (DimensionDeclarator a ) a
755765instance FirstParameter (ControlPair a ) a
756766instance FirstParameter (AllocOpt a ) a
767+ instance FirstParameter (BlockConstructStart a ) a
757768
758769instance SecondParameter (ProgramUnit a ) SrcSpan
759770instance SecondParameter (Prefix a ) SrcSpan
@@ -783,6 +794,7 @@ instance SecondParameter (Declarator a) SrcSpan
783794instance SecondParameter (DimensionDeclarator a ) SrcSpan
784795instance SecondParameter (ControlPair a ) SrcSpan
785796instance SecondParameter (AllocOpt a ) SrcSpan
797+ instance SecondParameter (BlockConstructStart a ) SrcSpan
786798
787799instance Annotated (AList t )
788800instance Annotated ProgramUnit
@@ -811,6 +823,7 @@ instance Annotated Declarator
811823instance Annotated DimensionDeclarator
812824instance Annotated ControlPair
813825instance Annotated AllocOpt
826+ instance Annotated BlockConstructStart
814827
815828instance Spanned (ProgramUnit a )
816829instance Spanned (Prefix a )
@@ -840,6 +853,7 @@ instance Spanned (Declarator a)
840853instance Spanned (DimensionDeclarator a )
841854instance Spanned (ControlPair a )
842855instance Spanned (AllocOpt a )
856+ instance Spanned (BlockConstructStart a )
843857
844858instance Spanned (ProgramFile a ) where
845859 getSpan (ProgramFile _ pus) =
@@ -854,25 +868,30 @@ class Labeled f where
854868 getLastLabel :: f a -> Maybe (Expression a )
855869 setLabel :: f a -> Expression a -> f a
856870
871+ instance Labeled BlockConstructStart where
872+ getLabel (BlockConstructStart _ _ l _) = l
873+ getLastLabel = const Nothing
874+ setLabel (BlockConstructStart a ss _ s) l = BlockConstructStart a ss (Just l) s
875+
857876instance Labeled Block where
858877 getLabel (BlStatement _ _ l _) = l
859878 getLabel (BlIf _ _ l _ _ _ _) = l
860879 getLabel (BlCase _ _ l _ _ _ _ _) = l
861- getLabel (BlDo _ _ l _ _ _ _ _ ) = l
862- getLabel (BlDoWhile _ _ l _ _ _ _ _ ) = l
880+ getLabel (BlDo _ _ x _ _ _ _) = getLabel x
881+ getLabel (BlDoWhile _ _ x _ _ _ _) = getLabel x
863882 getLabel _ = Nothing
864883
865884 getLastLabel b@ BlStatement {} = getLabel b
866885 getLastLabel (BlIf _ _ _ _ _ _ l) = l
867886 getLastLabel (BlCase _ _ _ _ _ _ _ l) = l
868- getLastLabel (BlDo _ _ _ _ _ _ _ l) = l
869- getLastLabel (BlDoWhile _ _ _ _ _ _ _ l) = l
887+ getLastLabel (BlDo _ _ _ _ _ _ l) = l
888+ getLastLabel (BlDoWhile _ _ _ _ _ _ l) = l
870889 getLastLabel _ = Nothing
871890
872891 setLabel (BlStatement a s _ st) l = BlStatement a s (Just l) st
873892 setLabel (BlIf a s _ mn conds bs el) l = BlIf a s (Just l) mn conds bs el
874- setLabel (BlDo a s _ mn tl spec bs el) l = BlDo a s (Just l) mn tl spec bs el
875- setLabel (BlDoWhile a s _ n tl spec bs el) l = BlDoWhile a s (Just l) n tl spec bs el
893+ setLabel (BlDo a s st tl spec bs el) l = BlDo a s (setLabel st l) tl spec bs el
894+ setLabel (BlDoWhile a s st tl spec bs el) l = BlDoWhile a s (setLabel st l) tl spec bs el
876895 setLabel b _ = b
877896
878897data ProgramUnitName =
@@ -949,6 +968,7 @@ instance Out a => Out (AllocOpt a)
949968instance Out UnaryOp
950969instance Out BinaryOp
951970instance Out a => Out (ForallHeader a )
971+ instance Out a => Out (BlockConstructStart a )
952972
953973-- Classifiers on statement and blocks ASTs
954974
@@ -1042,3 +1062,4 @@ instance NFData BinaryOp
10421062instance NFData Only
10431063instance NFData ModuleNature
10441064instance NFData Intent
1065+ instance NFData a => NFData (BlockConstructStart a )
0 commit comments