1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 09:55:52 +03:00

Define a default method for the CustomHasCyclomaticComplexity typeclass

This commit is contained in:
Rick Winfrey 2017-12-11 15:39:41 -08:00
parent 01c30abc2d
commit 3028946612

View File

@ -1,4 +1,4 @@
{-# LANGUAGE DataKinds, GeneralizedNewtypeDeriving, MultiParamTypeClasses, ScopedTypeVariables, TypeFamilies, UndecidableInstances #-} {-# LANGUAGE DataKinds, DefaultSignatures, GeneralizedNewtypeDeriving, MultiParamTypeClasses, ScopedTypeVariables, TypeFamilies, UndecidableInstances #-}
module Analysis.CyclomaticComplexity module Analysis.CyclomaticComplexity
( CyclomaticComplexity(..) ( CyclomaticComplexity(..)
, HasCyclomaticComplexity , HasCyclomaticComplexity
@ -57,36 +57,20 @@ class CustomHasCyclomaticComplexity syntax where
-- | Produce a customized 'CyclomaticComplexity' for a given syntax node. -- | Produce a customized 'CyclomaticComplexity' for a given syntax node.
customToCyclomaticComplexity :: syntax CyclomaticComplexity -> CyclomaticComplexity customToCyclomaticComplexity :: syntax CyclomaticComplexity -> CyclomaticComplexity
instance CustomHasCyclomaticComplexity Declaration.Function where -- | Because we perform the same operation wherever we use the custom strategy, we can define the default method for all instances.
customToCyclomaticComplexity = succ . sum default customToCyclomaticComplexity :: Foldable syntax => syntax CyclomaticComplexity -> CyclomaticComplexity
instance CustomHasCyclomaticComplexity Declaration.Method where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.Catch where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.DoWhile where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.Else where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.For where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.ForEach where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.If where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.Pattern where
customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Statement.While where
customToCyclomaticComplexity = succ . sum customToCyclomaticComplexity = succ . sum
instance CustomHasCyclomaticComplexity Declaration.Function
instance CustomHasCyclomaticComplexity Declaration.Method
instance CustomHasCyclomaticComplexity Statement.Catch
instance CustomHasCyclomaticComplexity Statement.DoWhile
instance CustomHasCyclomaticComplexity Statement.Else
instance CustomHasCyclomaticComplexity Statement.For
instance CustomHasCyclomaticComplexity Statement.ForEach
instance CustomHasCyclomaticComplexity Statement.If
instance CustomHasCyclomaticComplexity Statement.Pattern
instance CustomHasCyclomaticComplexity Statement.While
-- | Produce a 'CyclomaticComplexity' for 'Union's using the 'HasCyclomaticComplexity' instance & therefore using a 'CustomHasCyclomaticComplexity' instance when one exists & the type is listed in 'CyclomaticComplexityStrategy'. -- | Produce a 'CyclomaticComplexity' for 'Union's using the 'HasCyclomaticComplexity' instance & therefore using a 'CustomHasCyclomaticComplexity' instance when one exists & the type is listed in 'CyclomaticComplexityStrategy'.
instance Apply HasCyclomaticComplexity fs => CustomHasCyclomaticComplexity (Union fs) where instance Apply HasCyclomaticComplexity fs => CustomHasCyclomaticComplexity (Union fs) where