11module Kernel.Common.LocationTree
22 ( LocationTree ,
3- LocType (.. ),
43 SymbolName (.. ),
54 empty ,
65 insert ,
@@ -35,39 +34,29 @@ data SymbolName
3534 = Local Int DefSymbolLen
3635 | Global DD. DefiniteDescription IsConstLike
3736 | Foreign EN. ExternalName
38- deriving (Show , Eq , Generic )
39-
40- data LocType
41- = FileLoc
42- | SymbolLoc SymbolName
37+ | StaticFile T. Text
38+ | SourceFile T. Text
4339 deriving (Show , Eq , Generic )
4440
4541instance Binary SymbolName
4642
47- instance Binary LocType
48-
4943type LocationTree =
50- M. Map (Line , ColFrom ) (Line , ColInterval , LocType , SavedHint )
44+ M. Map (Line , ColFrom ) (Line , ColInterval , SymbolName , SavedHint )
5145
5246empty :: LocationTree
5347empty =
5448 M. empty
5549
56- insert :: LocType -> (Line , ColInterval ) -> Hint -> LocationTree -> LocationTree
57- insert lt (l, (cFrom, cTo)) m =
58- M. insert (l, cFrom) (l, (cFrom, cTo), lt , SavedHint m)
50+ insert :: SymbolName -> (Line , ColInterval ) -> Hint -> LocationTree -> LocationTree
51+ insert sym (l, (cFrom, cTo)) m =
52+ M. insert (l, cFrom) (l, (cFrom, cTo), sym , SavedHint m)
5953
60- find :: Line -> Column -> LocationTree -> Maybe (LocType , Hint , ColInterval , DefSymbolLen )
54+ find :: Line -> Column -> LocationTree -> Maybe (SymbolName , Hint , ColInterval , DefSymbolLen )
6155find l c mp = do
62- (line, colInterval@ (colFrom , colTo), lt , SavedHint m) <- snd <$> M. lookupLE (l, c) mp
56+ (line, colInterval@ (_ , colTo), sym , SavedHint m) <- snd <$> M. lookupLE (l, c) mp
6357 if colTo < c || line /= l
6458 then Nothing
65- else do
66- case lt of
67- FileLoc ->
68- return (lt, m, colInterval, colTo - colFrom)
69- SymbolLoc sym ->
70- return (lt, m, colInterval, getLength sym)
59+ else return (sym, m, colInterval, getLength sym)
7160
7261getLength :: SymbolName -> DefSymbolLen
7362getLength s =
@@ -78,19 +67,15 @@ getLength s =
7867 T. length $ DD. localLocator dd
7968 Foreign externalName ->
8069 T. length $ EN. reify externalName
81-
82- isSymLoc :: LocType -> Bool
83- isSymLoc lt =
84- case lt of
85- SymbolLoc _ ->
86- True
87- FileLoc ->
88- False
70+ StaticFile key ->
71+ T. length key
72+ SourceFile locator ->
73+ T. length locator
8974
9075findRef :: Loc -> LocationTree -> [(FilePath , (Line , ColInterval ))]
9176findRef loc t = do
9277 let kvs = M. toList t
93- flip mapMaybe kvs $ \ ((line, _), (_, colInterval, lt , SavedHint m)) -> do
94- if isSymLoc lt && loc == metaLocation m
78+ flip mapMaybe kvs $ \ ((line, _), (_, colInterval, _ , SavedHint m)) -> do
79+ if loc == metaLocation m
9580 then return (metaFileName m, (line, colInterval))
9681 else Nothing
0 commit comments