1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Use higher order declaredName function in Declarations1 instance

This commit is contained in:
Rick Winfrey 2018-07-13 09:32:34 -07:00
parent 435d296b6c
commit b928f7879a
2 changed files with 5 additions and 3 deletions

View File

@ -13,7 +13,7 @@ class Declarations syntax where
class Declarations1 syntax where
-- | Lift a function mapping each element to its set of free variables through a containing structure, collecting the results into a single set.
liftDeclaredName :: Declarations a => (a -> [Name]) -> syntax a -> Maybe Name
liftDeclaredName :: (a -> [Name]) -> syntax a -> Maybe Name
liftDeclaredName _ _ = Nothing
instance Declarations t => Declarations (Subterm t a) where
@ -21,7 +21,7 @@ instance Declarations t => Declarations (Subterm t a) where
deriving instance (Declarations1 syntax, FreeVariables1 syntax) => Declarations (Term syntax ann)
instance (Declarations recur, FreeVariables recur, Declarations1 syntax) => Declarations (TermF syntax ann recur) where
instance (FreeVariables recur, Declarations1 syntax) => Declarations (TermF syntax ann recur) where
declaredName = liftDeclaredName freeVariables . termFOut
instance (Apply Declarations1 fs) => Declarations1 (Sum fs) where

View File

@ -34,7 +34,9 @@ instance Declarations a => Declarations (Function a) where
declaredName Function{..} = declaredName functionName
instance Declarations1 Function where
liftDeclaredName _ = declaredName
liftDeclaredName declaredName Function{..} = case declaredName functionName of
[] -> Nothing
(x:_) -> Just x
data Method a = Method { methodContext :: ![a], methodReceiver :: !a, methodName :: !a, methodParameters :: ![a], methodBody :: !a }
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Mergeable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1)