1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Factor out how we extend bindings.

This commit is contained in:
Rob Rix 2019-07-30 09:21:03 -04:00
parent 100d6a18ff
commit e58dea96fb
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -103,11 +103,11 @@ scopeGraphAnalysis = Analysis{..}
ref <- asks Ref
bindLoc <- asks (Map.lookup addr)
cell <- gets (Map.lookup addr >=> nonEmpty . Set.toList)
maybe (pure Nothing) (foldMapA (pure . Just . mappend (ScopeGraph (maybe Map.empty (\ bindLoc -> Map.singleton (Decl addr bindLoc) (Set.singleton ref)) bindLoc)))) cell
maybe (pure Nothing) (foldMapA (pure . Just . mappend (extendBinding addr ref bindLoc))) cell
assign addr v = do
ref <- asks Ref
bindLoc <- asks (Map.lookup addr)
modify (Map.insertWith (<>) addr (Set.singleton (ScopeGraph (maybe Map.empty (\ bindLoc -> Map.singleton (Decl addr bindLoc) (Set.singleton ref)) bindLoc) <> v)))
modify (Map.insertWith (<>) addr (Set.singleton (extendBinding addr ref bindLoc <> v)))
abstract eval name body = do
addr <- alloc name
assign name (mempty @ScopeGraph)
@ -126,3 +126,5 @@ scopeGraphAnalysis = Analysis{..}
(k, v') <$ assign addr v'
pure (foldMap snd fields')
_ ... m = pure (Just m)
extendBinding addr ref bindLoc = ScopeGraph (maybe Map.empty (\ bindLoc -> Map.singleton (Decl addr bindLoc) (Set.singleton ref)) bindLoc)