mirror of
https://github.com/rgleichman/glance.git
synced 2024-11-29 21:40:48 +03:00
Reduce GHC warnings.
This commit is contained in:
parent
d617914139
commit
02446b5b15
@ -5,19 +5,18 @@ module GraphAlgorithms(
|
||||
nodeWillBeEmbedded
|
||||
) where
|
||||
|
||||
import qualified Data.Graph.Inductive.PatriciaTree as FGR
|
||||
import qualified Data.Graph.Inductive.Graph as ING
|
||||
import Types(SgNamedNode, Edge(..), SyntaxNode(..), sgNamedNodeToSyntaxNode, EdgeEnd(..), NameAndPort(..), IngSyntaxGraph)
|
||||
import Data.Maybe(listToMaybe, catMaybes, isJust, fromMaybe)
|
||||
import Data.List(foldl', find)
|
||||
import Diagrams.Prelude(toName)
|
||||
import qualified Debug.Trace
|
||||
import qualified Data.Graph.Inductive as ING
|
||||
|
||||
import Util(printSelf, maybeBoolToBool)
|
||||
import Data.List(foldl', find)
|
||||
import Data.Maybe(catMaybes, isJust, fromMaybe)
|
||||
--import qualified Debug.Trace
|
||||
|
||||
import Types(SyntaxNode(..), sgNamedNodeToSyntaxNode, IngSyntaxGraph)
|
||||
import Util(maybeBoolToBool)
|
||||
--import Util(printSelf)
|
||||
|
||||
-- See graph_algs.txt for pseudocode
|
||||
|
||||
type LabelledGraphEdge = ING.LEdge Edge
|
||||
data ParentType = ApplyParent | PatternParent | NotAParent
|
||||
|
||||
-- START HELPER functions --
|
||||
@ -48,8 +47,6 @@ parentTypeForNode n = case n of
|
||||
-- The NotAParent case should never occur.
|
||||
_ -> NotAParent
|
||||
|
||||
extractSyntaxNode = snd . snd
|
||||
|
||||
findParents :: ING.Graph gr => IngSyntaxGraph gr -> ING.Node -> [ING.Node]
|
||||
findParents graph node = filter parentFilter $ ING.suc graph node where
|
||||
parentFilter parentNode = parentNode /= node
|
||||
@ -74,7 +71,7 @@ lookupParentType graph node = fromMaybe NotAParent $ parentTypeForNode <$> looku
|
||||
-- | filterNodes returns a list of the nodes in the graph
|
||||
-- where the filter function is true.
|
||||
filterNodes :: ING.DynGraph gr => (ING.Node -> Bool) -> gr a b -> [ING.Node]
|
||||
filterNodes pred gr = ING.nodes $ ING.nfilter pred gr
|
||||
filterNodes condition gr = ING.nodes $ ING.nfilter condition gr
|
||||
|
||||
-- | Replace the a node's label
|
||||
changeNodeLabel :: ING.DynGraph gr => gr a b -> ING.Node -> a -> gr a b
|
||||
@ -182,9 +179,10 @@ edgeGoesToParent parentNode (fromNode, toNode, _)
|
||||
| otherwise = False
|
||||
|
||||
changeEdgeToParent :: ING.Node -> ING.Node -> ING.LEdge b -> ING.LEdge b
|
||||
changeEdgeToParent parentNode childNode (fromNode, toNode, edgeLabel)
|
||||
changeEdgeToParent parentNode childNode lEdge@(fromNode, toNode, edgeLabel)
|
||||
| childNode == fromNode = (parentNode, toNode, edgeLabel)
|
||||
| childNode == toNode = (fromNode, parentNode, edgeLabel)
|
||||
| otherwise = lEdge
|
||||
|
||||
-- | Change the node label of the parent to be nested.
|
||||
embedChildSyntaxNodes :: ING.DynGraph gr => ING.Node -> [ING.Node] -> IngSyntaxGraph gr -> IngSyntaxGraph gr
|
||||
|
14
app/Icons.hs
14
app/Icons.hs
@ -63,7 +63,7 @@ identDiaFunc :: SpecialQDiagram b -> TransformableDia b
|
||||
identDiaFunc dia _ _ = dia
|
||||
|
||||
-- | Names the diagram and puts all sub-names in the namespace of the top level name.
|
||||
nameDiagram :: (SpecialBackend b, IsName nm) => nm -> SpecialQDiagram b -> SpecialQDiagram b
|
||||
nameDiagram :: IsName nm => nm -> SpecialQDiagram b -> SpecialQDiagram b
|
||||
nameDiagram name dia = named name (name .>> dia)
|
||||
|
||||
-- | Make an port with an integer name. Always use <> to add a ports (not === or |||)
|
||||
@ -142,20 +142,20 @@ transformCorrectedTextBox str textCol borderCol reflect angle =
|
||||
|
||||
nestedApplyDia :: SpecialBackend b =>
|
||||
[Maybe (Name, Icon)] -> TransformableDia b
|
||||
nestedApplyDia = generalNestedDia (textBoxC colorScheme) (apply0C colorScheme)
|
||||
nestedApplyDia = generalNestedDia (apply0C colorScheme)
|
||||
|
||||
nestedPAppDia :: SpecialBackend b =>
|
||||
[Maybe (Name, Icon)] -> TransformableDia b
|
||||
nestedPAppDia = generalNestedDia (patternTextC colorScheme) (patternC colorScheme)
|
||||
nestedPAppDia = generalNestedDia (patternC colorScheme)
|
||||
|
||||
generalNestedDia :: SpecialBackend b =>
|
||||
Colour Double -> Colour Double -> [Maybe (Name, Icon)] -> TransformableDia b
|
||||
generalNestedDia textCol borderCol funcNameAndArgs reflect angle = case funcNameAndArgs of
|
||||
Colour Double -> [Maybe (Name, Icon)] -> TransformableDia b
|
||||
generalNestedDia borderCol funcNameAndArgs reflect angle = case funcNameAndArgs of
|
||||
[] -> mempty
|
||||
(maybeFunText:args) -> centerXY $ transformedText ||| centerY finalDia
|
||||
where
|
||||
transformedText = case maybeFunText of
|
||||
Just funText -> makeInnerIcon 0 maybeFunText --transformCorrectedTextBox funText textCol borderCol reflect angle
|
||||
Just _ -> makeInnerIcon 0 maybeFunText
|
||||
Nothing -> mempty
|
||||
seperation = circleRadius * 1.5
|
||||
verticalSeperation = circleRadius
|
||||
@ -201,7 +201,7 @@ multilineComment textColor boxColor t = lwG (0.6 * defaultLineWidth) textDia
|
||||
|
||||
-- | Given the number of letters in a textbox string, make a rectangle that will
|
||||
-- enclose the text box.
|
||||
rectForText :: (InSpace V2 n t, TrailLike t, OrderedField n) => Int -> t
|
||||
rectForText :: (InSpace V2 n t, TrailLike t) => Int -> t
|
||||
rectForText n = rect rectangleWidth (textBoxFontSize * textBoxHeightFactor)
|
||||
where
|
||||
rectangleWidth = fromIntegral n * textBoxFontSize * monoLetterWidthToHeightFraction
|
||||
|
@ -180,7 +180,7 @@ connectedPorts edges name = map edgeToPort $ filter nameInEdge edges
|
||||
-- are minimized.
|
||||
-- Precondition: the diagrams are already centered
|
||||
-- todo: confirm precondition (or use a newtype)
|
||||
rotateNodes :: SpecialBackend b =>
|
||||
rotateNodes ::
|
||||
Map.Map Name (Point V2 Double)
|
||||
-> [(Name, Bool -> Double -> SpecialQDiagram b)]
|
||||
-> [Connection]
|
||||
@ -219,7 +219,7 @@ rotateNodes positionMap nameDiagramMap edges = map rotateDiagram nameDiagramMap
|
||||
minAngle = angleWithMinDist (getFromMapAndScale positionMap name) portEdges
|
||||
|
||||
type LayoutResult a = Gr (GV.AttributeNode Name) (GV.AttributeNode a)
|
||||
placeNodes :: SpecialBackend b =>
|
||||
placeNodes ::
|
||||
LayoutResult a
|
||||
-> [(Name, Bool -> Double -> SpecialQDiagram b)]
|
||||
-> [Connection]
|
||||
@ -252,7 +252,7 @@ customLayoutParams = GV.defaultParams{
|
||||
GV.fmtEdge = const [GV.arrowTo GV.noArrow]
|
||||
}
|
||||
|
||||
doGraphLayout :: SpecialBackend b =>
|
||||
doGraphLayout ::
|
||||
Gr Name e
|
||||
-> [(Name, Bool -> Double -> SpecialQDiagram b)]
|
||||
-> [Connection]
|
||||
|
@ -9,26 +9,26 @@ module Translate(
|
||||
import qualified Diagrams.Prelude as DIA hiding ((#), (&))
|
||||
import Diagrams.Prelude((<>))
|
||||
|
||||
import Language.Haskell.Exts(Decl(..), parseDecl, Name(..), Pat(..), Rhs(..),
|
||||
Exp(..), QName(..), fromParseResult, Match(..), QOp(..), GuardedRhs(..),
|
||||
Stmt(..), Binds(..), Alt(..), Module(..), SpecialCon(..))
|
||||
import qualified Language.Haskell.Exts as Exts
|
||||
import Control.Monad(replicateM)
|
||||
import Control.Monad.State(State, evalState)
|
||||
import Data.Either(partitionEithers)
|
||||
import Data.List(unzip4, partition)
|
||||
import Control.Monad(replicateM)
|
||||
import qualified Language.Haskell.Exts as Exts
|
||||
import Language.Haskell.Exts(Decl(..), parseDecl, Name(..), Pat(..), Rhs(..),
|
||||
Exp(..), QName(..), fromParseResult, Match(..), QOp(..), GuardedRhs(..),
|
||||
Stmt(..), Binds(..), Alt(..), Module(..), SpecialCon(..))
|
||||
--import Data.Maybe(catMaybes)
|
||||
|
||||
import Types(Drawing(..), NameAndPort(..), IDState,
|
||||
initialIdState, Edge, SyntaxNode(..))
|
||||
import Util(toNames, makeSimpleEdge, nameAndPort, justName, mapFst)
|
||||
import GraphAlgorithms(collapseNodes)
|
||||
import TranslateCore(Reference, SyntaxGraph(..), EvalContext, GraphAndRef,
|
||||
syntaxGraphFromNodes, syntaxGraphFromNodesEdges, getUniqueName, combineExpressions,
|
||||
edgesForRefPortList, makeApplyGraph,
|
||||
namesInPattern, lookupReference, deleteBindings, makeEdges,
|
||||
coerceExpressionResult, makeBox, nTupleString, nListString, syntaxGraphToDrawing,
|
||||
coerceExpressionResult, makeBox, nTupleString, nListString,
|
||||
syntaxGraphToFglGraph, ingSyntaxGraphToDrawing)
|
||||
import GraphAlgorithms(collapseNodes)
|
||||
import Types(Drawing(..), NameAndPort(..), IDState,
|
||||
initialIdState, Edge, SyntaxNode(..))
|
||||
import Util(toNames, makeSimpleEdge, nameAndPort, justName, mapFst)
|
||||
|
||||
-- OVERVIEW --
|
||||
-- The core functions and data types used in this module are in TranslateCore.
|
||||
@ -124,7 +124,7 @@ makePatternGraph applyIconName funStr argVals numArgs = (newGraph <> combinedGra
|
||||
newGraph = syntaxGraphFromNodes icons
|
||||
|
||||
evalApp :: EvalContext -> (Exp, [Exp]) -> State IDState (SyntaxGraph, NameAndPort)
|
||||
evalApp c exps@(funExp, argExps) = do
|
||||
evalApp c (funExp, argExps) = do
|
||||
funVal <- evalExp c funExp
|
||||
argVals <- mapM (evalExp c) argExps
|
||||
applyIconName <- DIA.toName <$> getUniqueName "app0"
|
||||
|
@ -81,18 +81,18 @@ getUniqueName base = fmap ((base ++). show) getId
|
||||
|
||||
-- TODO: Refactor with combineExpressions
|
||||
edgesForRefPortList :: Bool -> [(Reference, NameAndPort)] -> SyntaxGraph
|
||||
edgesForRefPortList inPattern portExpPairs = mconcat $ fmap mkGraph portExpPairs where
|
||||
edgesForRefPortList inPattern portExpPairs = mconcat $ fmap makeGraph portExpPairs where
|
||||
edgeOpts = if inPattern then [EdgeInPattern] else []
|
||||
mkGraph (ref, port) = case ref of
|
||||
makeGraph (ref, port) = case ref of
|
||||
Left str -> if inPattern
|
||||
then SyntaxGraph mempty mempty mempty [(str, Right port)]
|
||||
else SyntaxGraph mempty mempty [(str, port)] mempty
|
||||
Right resultPort -> SyntaxGraph mempty [Edge edgeOpts noEnds (resultPort, port)] mempty mempty
|
||||
|
||||
combineExpressions :: Bool -> [(GraphAndRef, NameAndPort)] -> SyntaxGraph
|
||||
combineExpressions inPattern portExpPairs = mconcat $ fmap mkGraph portExpPairs where
|
||||
combineExpressions inPattern portExpPairs = mconcat $ fmap makeGraph portExpPairs where
|
||||
edgeOpts = if inPattern then [EdgeInPattern] else []
|
||||
mkGraph ((graph, ref), port) = graph <> case ref of
|
||||
makeGraph ((graph, ref), port) = graph <> case ref of
|
||||
Left str -> if inPattern
|
||||
then SyntaxGraph mempty mempty mempty [(str, Right port)]
|
||||
else SyntaxGraph mempty mempty [(str, port)] mempty
|
||||
@ -225,7 +225,7 @@ syntaxGraphToFglGraph (SyntaxGraph nodes edges _ _) =
|
||||
|
||||
|
||||
syntaxGraphToDrawing :: SyntaxGraph -> Drawing
|
||||
syntaxGraphToDrawing (SyntaxGraph nodes edges sources sinks) =
|
||||
syntaxGraphToDrawing (SyntaxGraph nodes edges _ _) =
|
||||
Drawing icons edges [] where
|
||||
icons = fmap (second nodeToIcon) nodes
|
||||
|
||||
|
@ -582,6 +582,6 @@ main :: IO ()
|
||||
main = do
|
||||
-- ING.prettyPrint singleApplyGraph
|
||||
renderDrawings drawingsAndNames
|
||||
runTestTT collapseUnitTests
|
||||
_ <- runTestTT collapseUnitTests
|
||||
pure ()
|
||||
--main = testCollapse
|
||||
|
Loading…
Reference in New Issue
Block a user