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