@@ -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,13 @@ programUnitSubprograms PUComment{} = Nothing
301302newtype Comment a = Comment String
302303 deriving (Eq , Show , Data , Typeable , Generic , Functor )
303304
305+ data BlockConstructStart a =
306+ BlockConstructStart a SrcSpan
307+ (Maybe (Expression a ))
308+ (Maybe String )
309+ (Maybe (Comment a ))
310+ deriving (Eq , Show , Data , Typeable , Generic , Functor )
311+
304312data Block a =
305313 BlStatement a SrcSpan
306314 (Maybe (Expression a )) -- ^ Label
@@ -329,16 +337,14 @@ data Block a =
329337 (Maybe (Expression a )) -- ^ Label to END SELECT
330338
331339 | BlDo a SrcSpan
332- (Maybe (Expression a )) -- ^ Label
333- (Maybe String ) -- ^ Construct name
340+ (BlockConstructStart a )
334341 (Maybe (Expression a )) -- ^ Target label
335342 (Maybe (DoSpecification a )) -- ^ Do Specification
336343 [ Block a ] -- ^ Body
337344 (Maybe (Expression a )) -- ^ Label to END DO
338345
339346 | BlDoWhile a SrcSpan
340- (Maybe (Expression a )) -- ^ Label
341- (Maybe String ) -- ^ Construct name
347+ (BlockConstructStart a )
342348 (Maybe (Expression a )) -- ^ Target label
343349 (Expression a ) -- ^ Condition
344350 [ Block a ] -- ^ Body
@@ -754,6 +760,7 @@ instance FirstParameter (Declarator a) a
754760instance FirstParameter (DimensionDeclarator a ) a
755761instance FirstParameter (ControlPair a ) a
756762instance FirstParameter (AllocOpt a ) a
763+ instance FirstParameter (BlockConstructStart a ) a
757764
758765instance SecondParameter (ProgramUnit a ) SrcSpan
759766instance SecondParameter (Prefix a ) SrcSpan
@@ -783,6 +790,7 @@ instance SecondParameter (Declarator a) SrcSpan
783790instance SecondParameter (DimensionDeclarator a ) SrcSpan
784791instance SecondParameter (ControlPair a ) SrcSpan
785792instance SecondParameter (AllocOpt a ) SrcSpan
793+ instance SecondParameter (BlockConstructStart a ) SrcSpan
786794
787795instance Annotated (AList t )
788796instance Annotated ProgramUnit
@@ -811,6 +819,7 @@ instance Annotated Declarator
811819instance Annotated DimensionDeclarator
812820instance Annotated ControlPair
813821instance Annotated AllocOpt
822+ instance Annotated BlockConstructStart
814823
815824instance Spanned (ProgramUnit a )
816825instance Spanned (Prefix a )
@@ -840,6 +849,7 @@ instance Spanned (Declarator a)
840849instance Spanned (DimensionDeclarator a )
841850instance Spanned (ControlPair a )
842851instance Spanned (AllocOpt a )
852+ instance Spanned (BlockConstructStart a )
843853
844854instance Spanned (ProgramFile a ) where
845855 getSpan (ProgramFile _ pus) =
@@ -854,25 +864,30 @@ class Labeled f where
854864 getLastLabel :: f a -> Maybe (Expression a )
855865 setLabel :: f a -> Expression a -> f a
856866
867+ instance Labeled BlockConstructStart where
868+ getLabel (BlockConstructStart _ _ l _ _) = l
869+ getLastLabel = const Nothing
870+ setLabel (BlockConstructStart a ss _ s c) l = BlockConstructStart a ss (Just l) s c
871+
857872instance Labeled Block where
858873 getLabel (BlStatement _ _ l _) = l
859874 getLabel (BlIf _ _ l _ _ _ _) = l
860875 getLabel (BlCase _ _ l _ _ _ _ _) = l
861- getLabel (BlDo _ _ l _ _ _ _ _ ) = l
862- getLabel (BlDoWhile _ _ l _ _ _ _ _ ) = l
876+ getLabel (BlDo _ _ x _ _ _ _) = getLabel x
877+ getLabel (BlDoWhile _ _ x _ _ _ _) = getLabel x
863878 getLabel _ = Nothing
864879
865880 getLastLabel b@ BlStatement {} = getLabel b
866881 getLastLabel (BlIf _ _ _ _ _ _ l) = l
867882 getLastLabel (BlCase _ _ _ _ _ _ _ l) = l
868- getLastLabel (BlDo _ _ _ _ _ _ _ l) = l
869- getLastLabel (BlDoWhile _ _ _ _ _ _ _ l) = l
883+ getLastLabel (BlDo _ _ _ _ _ _ l) = l
884+ getLastLabel (BlDoWhile _ _ _ _ _ _ l) = l
870885 getLastLabel _ = Nothing
871886
872887 setLabel (BlStatement a s _ st) l = BlStatement a s (Just l) st
873888 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
889+ setLabel (BlDo a s st tl spec bs el) l = BlDo a s (setLabel st l) tl spec bs el
890+ setLabel (BlDoWhile a s st tl spec bs el) l = BlDoWhile a s (setLabel st l) tl spec bs el
876891 setLabel b _ = b
877892
878893data ProgramUnitName =
@@ -949,6 +964,7 @@ instance Out a => Out (AllocOpt a)
949964instance Out UnaryOp
950965instance Out BinaryOp
951966instance Out a => Out (ForallHeader a )
967+ instance Out a => Out (BlockConstructStart a )
952968
953969-- Classifiers on statement and blocks ASTs
954970
@@ -1042,3 +1058,4 @@ instance NFData BinaryOp
10421058instance NFData Only
10431059instance NFData ModuleNature
10441060instance NFData Intent
1061+ instance NFData a => NFData (BlockConstructStart a )
0 commit comments