@@ -493,50 +493,56 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
493
493
k' s (ConditionGuard e) = ConditionGuard <$> g'' s e
494
494
k' s (PatternGuard b e) = PatternGuard <$> h'' s b <*> g'' s e
495
495
496
- data ScopedIdent = LocalIdent Ident | ToplevelIdent Ident
496
+ data ScopedName = LocalName Name | ToplevelName Name
497
497
deriving (Show , Eq , Ord )
498
498
499
- inScope :: Ident -> S. Set ScopedIdent -> Bool
500
- inScope i s = (LocalIdent i `S.member` s) || (ToplevelIdent i `S.member` s)
499
+ inScope' :: (a -> Name ) -> a -> S. Set ScopedName -> Bool
500
+ inScope' ctor i s = (LocalName (ctor i) `S.member` s) || (ToplevelName (ctor i) `S.member` s)
501
+
502
+ inScope :: Ident -> S. Set ScopedName -> Bool
503
+ inScope = inScope' IdentName
504
+
505
+ typeInScope :: ProperName 'TypeName -> S. Set ScopedName -> Bool
506
+ typeInScope = inScope' TyName
501
507
502
508
everythingWithScope
503
509
:: forall r
504
510
. (Monoid r )
505
- => (S. Set ScopedIdent -> Declaration -> r )
506
- -> (S. Set ScopedIdent -> Expr -> r )
507
- -> (S. Set ScopedIdent -> Binder -> r )
508
- -> (S. Set ScopedIdent -> CaseAlternative -> r )
509
- -> (S. Set ScopedIdent -> DoNotationElement -> r )
510
- -> ( S. Set ScopedIdent -> Declaration -> r
511
- , S. Set ScopedIdent -> Expr -> r
512
- , S. Set ScopedIdent -> Binder -> r
513
- , S. Set ScopedIdent -> CaseAlternative -> r
514
- , S. Set ScopedIdent -> DoNotationElement -> r
511
+ => (S. Set ScopedName -> Declaration -> r )
512
+ -> (S. Set ScopedName -> Expr -> r )
513
+ -> (S. Set ScopedName -> Binder -> r )
514
+ -> (S. Set ScopedName -> CaseAlternative -> r )
515
+ -> (S. Set ScopedName -> DoNotationElement -> r )
516
+ -> ( S. Set ScopedName -> Declaration -> r
517
+ , S. Set ScopedName -> Expr -> r
518
+ , S. Set ScopedName -> Binder -> r
519
+ , S. Set ScopedName -> CaseAlternative -> r
520
+ , S. Set ScopedName -> DoNotationElement -> r
515
521
)
516
522
everythingWithScope f g h i j = (f'', g'', h'', i'', \ s -> snd . j'' s)
517
523
where
518
- f'' :: S. Set ScopedIdent -> Declaration -> r
524
+ f'' :: S. Set ScopedName -> Declaration -> r
519
525
f'' s a = f s a <> f' s a
520
526
521
- f' :: S. Set ScopedIdent -> Declaration -> r
527
+ f' :: S. Set ScopedName -> Declaration -> r
522
528
f' s (DataBindingGroupDeclaration ds) =
523
- let s' = S. union s (S. fromList (map ToplevelIdent (mapMaybe getDeclIdent (NEL. toList ds))))
529
+ let s' = S. union s (S. fromList (map ToplevelName (mapMaybe declName (NEL. toList ds))))
524
530
in foldMap (f'' s') ds
525
531
f' s (ValueDecl _ name _ bs val) =
526
- let s' = S. insert (ToplevelIdent name) s
532
+ let s' = S. insert (ToplevelName ( IdentName name) ) s
527
533
s'' = S. union s' (S. fromList (concatMap localBinderNames bs))
528
534
in foldMap (h'' s') bs <> foldMap (l' s'') val
529
535
f' s (BindingGroupDeclaration ds) =
530
- let s' = S. union s (S. fromList (NEL. toList (fmap (\ ((_, name), _, _) -> ToplevelIdent name) ds)))
536
+ let s' = S. union s (S. fromList (NEL. toList (fmap (\ ((_, name), _, _) -> ToplevelName ( IdentName name) ) ds)))
531
537
in foldMap (\ (_, _, val) -> g'' s' val) ds
532
538
f' s (TypeClassDeclaration _ _ _ _ _ ds) = foldMap (f'' s) ds
533
539
f' s (TypeInstanceDeclaration _ _ _ _ _ _ _ (ExplicitInstance ds)) = foldMap (f'' s) ds
534
540
f' _ _ = mempty
535
541
536
- g'' :: S. Set ScopedIdent -> Expr -> r
542
+ g'' :: S. Set ScopedName -> Expr -> r
537
543
g'' s a = g s a <> g' s a
538
544
539
- g' :: S. Set ScopedIdent -> Expr -> r
545
+ g' :: S. Set ScopedName -> Expr -> r
540
546
g' s (Literal _ l) = lit g'' s l
541
547
g' s (UnaryMinus _ v1) = g'' s v1
542
548
g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
@@ -553,7 +559,7 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
553
559
g' s (Case vs alts) = foldMap (g'' s) vs <> foldMap (i'' s) alts
554
560
g' s (TypedValue _ v1 _) = g'' s v1
555
561
g' s (Let _ ds v1) =
556
- let s' = S. union s (S. fromList (map LocalIdent (mapMaybe getDeclIdent ds)))
562
+ let s' = S. union s (S. fromList (map LocalName (mapMaybe declName ds)))
557
563
in foldMap (f'' s') ds <> g'' s' v1
558
564
g' s (Do _ es) = fold . snd . mapAccumL j'' s $ es
559
565
g' s (Ado _ es v1) =
@@ -562,46 +568,46 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
562
568
g' s (PositionedValue _ _ v1) = g'' s v1
563
569
g' _ _ = mempty
564
570
565
- h'' :: S. Set ScopedIdent -> Binder -> r
571
+ h'' :: S. Set ScopedName -> Binder -> r
566
572
h'' s a = h s a <> h' s a
567
573
568
- h' :: S. Set ScopedIdent -> Binder -> r
574
+ h' :: S. Set ScopedName -> Binder -> r
569
575
h' s (LiteralBinder _ l) = lit h'' s l
570
576
h' s (ConstructorBinder _ _ bs) = foldMap (h'' s) bs
571
577
h' s (BinaryNoParensBinder b1 b2 b3) = foldMap (h'' s) [b1, b2, b3]
572
578
h' s (ParensInBinder b) = h'' s b
573
- h' s (NamedBinder _ name b1) = h'' (S. insert (LocalIdent name) s) b1
579
+ h' s (NamedBinder _ name b1) = h'' (S. insert (LocalName ( IdentName name) ) s) b1
574
580
h' s (PositionedBinder _ _ b1) = h'' s b1
575
581
h' s (TypedBinder _ b1) = h'' s b1
576
582
h' _ _ = mempty
577
583
578
- lit :: (S. Set ScopedIdent -> a -> r ) -> S. Set ScopedIdent -> Literal a -> r
584
+ lit :: (S. Set ScopedName -> a -> r ) -> S. Set ScopedName -> Literal a -> r
579
585
lit go s (ArrayLiteral as) = foldMap (go s) as
580
586
lit go s (ObjectLiteral as) = foldMap (go s . snd ) as
581
587
lit _ _ _ = mempty
582
588
583
- i'' :: S. Set ScopedIdent -> CaseAlternative -> r
589
+ i'' :: S. Set ScopedName -> CaseAlternative -> r
584
590
i'' s a = i s a <> i' s a
585
591
586
- i' :: S. Set ScopedIdent -> CaseAlternative -> r
592
+ i' :: S. Set ScopedName -> CaseAlternative -> r
587
593
i' s (CaseAlternative bs gs) =
588
594
let s' = S. union s (S. fromList (concatMap localBinderNames bs))
589
595
in foldMap (h'' s) bs <> foldMap (l' s') gs
590
596
591
- j'' :: S. Set ScopedIdent -> DoNotationElement -> (S. Set ScopedIdent , r )
597
+ j'' :: S. Set ScopedName -> DoNotationElement -> (S. Set ScopedName , r )
592
598
j'' s a = let (s', r) = j' s a in (s', j s a <> r)
593
599
594
- j' :: S. Set ScopedIdent -> DoNotationElement -> (S. Set ScopedIdent , r )
600
+ j' :: S. Set ScopedName -> DoNotationElement -> (S. Set ScopedName , r )
595
601
j' s (DoNotationValue v) = (s, g'' s v)
596
602
j' s (DoNotationBind b v) =
597
603
let s' = S. union (S. fromList (localBinderNames b)) s
598
604
in (s', h'' s b <> g'' s v)
599
605
j' s (DoNotationLet ds) =
600
- let s' = S. union s (S. fromList (map LocalIdent (mapMaybe getDeclIdent ds)))
606
+ let s' = S. union s (S. fromList (map LocalName (mapMaybe declName ds)))
601
607
in (s', foldMap (f'' s') ds)
602
608
j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
603
609
604
- k' :: S. Set ScopedIdent -> Guard -> (S. Set ScopedIdent , r )
610
+ k' :: S. Set ScopedName -> Guard -> (S. Set ScopedName , r )
605
611
k' s (ConditionGuard e) = (s, g'' s e)
606
612
k' s (PatternGuard b e) =
607
613
let s' = S. union (S. fromList (localBinderNames b)) s
@@ -612,12 +618,7 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
612
618
let (s', r) = k' s grd
613
619
in r <> l' s' (GuardedExpr gs e)
614
620
615
- getDeclIdent :: Declaration -> Maybe Ident
616
- getDeclIdent (ValueDeclaration vd) = Just (valdeclIdent vd)
617
- getDeclIdent (TypeDeclaration td) = Just (tydeclIdent td)
618
- getDeclIdent _ = Nothing
619
-
620
- localBinderNames = map LocalIdent . binderNames
621
+ localBinderNames = map (LocalName . IdentName ) . binderNames
621
622
622
623
accumTypes
623
624
:: (Monoid r )
0 commit comments