Skip to content

Commit

Permalink
linter + remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
mantkiew committed Jul 21, 2015
1 parent 38bbb02 commit 22036f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
21 changes: 10 additions & 11 deletions src/Language/Clafer/ClaferArgs.hs
Expand Up @@ -26,7 +26,6 @@ See also <http://t3-necsis.cs.uwaterloo.ca:8091/ClaferTools/CommandLineArguments
-}
module Language.Clafer.ClaferArgs where

import System.IO ( stdin, hGetContents )
import System.Console.CmdArgs
import System.Console.CmdArgs.Explicit hiding (mode)
import Data.List
Expand Down Expand Up @@ -102,28 +101,28 @@ clafer = ClaferArgs {
} &= summary ("Clafer " ++ showVersion Paths_clafer.version) &= program "clafer"

mergeArgs :: ClaferArgs -> ClaferArgs -> ClaferArgs
mergeArgs a1 a2 = ClaferArgs (mode a1) (coMergeArg)
mergeArgs a1 a2 = ClaferArgs (mode a1) coMergeArg
(mergeArg flatten_inheritance) (mergeArg timeout_analysis)
(mergeArg no_layout) (mergeArg new_layout)
(mergeArg check_duplicates) (mergeArg skip_resolver)
(mergeArg keep_unused) (mergeArg no_stats)
(mergeArg validate) (mergeArg noalloyruncommand) (toolMergeArg)
(mergeArg validate) (mergeArg noalloyruncommand) toolMergeArg
(mergeArg alloy_mapping) (mergeArg self_contained)
(mergeArg add_graph) (mergeArg show_references)
(mergeArg add_comments) (mergeArg ecore2clafer)
(mergeArg scope_strategy) (mergeArg afm)
(mergeArg meta_data) (mergeArg file)
where
coMergeArg :: Bool
coMergeArg = if (r1 /= False) then r1 else
if (r2 /= False) then r2 else (null $ file a1)
coMergeArg = if r1 then r1 else
if r2 then r2 else (null $ file a1)
where r1 = console_output a1;r2 = console_output a2
toolMergeArg :: String
toolMergeArg = if (r1 /= "") then r1 else
if (r2 /= "") then r2 else "/tools"
toolMergeArg = if r1 /= "" then r1 else
if r2 /= "" then r2 else "/tools"
where r1 = tooldir a1;r2 = tooldir a2
mergeArg :: (Default a, Eq a) => (ClaferArgs -> a) -> a
mergeArg f = (\r -> if (r /= def) then r else f a2) $ f a1
mergeArg f = (\r -> if r /= def then r else f a2) $ f a1

mainArgs :: IO (ClaferArgs, String)
mainArgs = do
Expand All @@ -136,12 +135,12 @@ mainArgs = do
let argsWithDef = if null $ mode argsWithOpts
then argsWithOpts{mode = [ Alloy ]}
else argsWithOpts
return $ (argsWithDef, model)
return (argsWithDef, model)

retrieveModelFromURL :: String -> IO String
retrieveModelFromURL url = do
retrieveModelFromURL url =
case url of
"" -> hGetContents stdin -- this is the pre-module system behavior
"" -> getContents -- this is the pre-module system behavior
('f':'i':'l':'e':':':'/':'/':n) -> readFile n
('h':'t':'t':'p':':':'/':'/':_) -> getURL url
('f':'t':'p':':':'/':'/':_) -> getURL url
Expand Down
2 changes: 0 additions & 2 deletions src/Language/Clafer/Common.hs
Expand Up @@ -50,8 +50,6 @@ mkIdent str = PosIdent ((0, 0), str)
mkInteger :: Read a => PosInteger -> a
mkInteger (PosInteger (_, n)) = read n

type Ident = PosIdent

-- | Returns only [] or [_]
getSuper :: IClafer -> [String]
getSuper claf = case getSuperId <$> _super claf of
Expand Down
26 changes: 11 additions & 15 deletions src/Language/Clafer/Generator/Alloy.hs
Expand Up @@ -91,9 +91,6 @@ mkAssert genEnv name xs = cconcat
, CString "\n\n"
]

mkMetric :: String -> Concat -> Concat
mkMetric goalopname xs = cconcat [ if goalopname == iGMax then CString "maximize" else CString "minimize", CString " ", xs, CString " "]

mkSet :: Concat -> Concat
mkSet xs = cconcat [CString "{ ", xs, CString " }"]

Expand Down Expand Up @@ -183,7 +180,7 @@ genAlloyRel :: String -> String -> String -> String
genAlloyRel name card' rType = concat [name, " : ", card', " ", rType]

refType :: GenEnv -> IClafer -> Concat
refType genEnv c = fromMaybe (CString "") $ (((genType genEnv).getTarget) <$> (_ref <$> _reference c))
refType genEnv c = fromMaybe (CString "") (((genType genEnv).getTarget) <$> (_ref <$> _reference c))


getTarget :: PExp -> PExp
Expand Down Expand Up @@ -223,7 +220,7 @@ of Connection are nested under all Systems anyway.
-}
: constraints
where
constraints = concat $ map genConst $ _elements c
constraints = concatMap genConst $ _elements c
genConst x = case x of
IEConstraint True pexp -> [ genPExp genEnv ((_uid c) : resPath) pexp ]
IEConstraint False pexp -> [ CString "// Assertion " +++ (genAssertName pexp) +++ CString " ignored since nested assertions are not supported in Alloy.\n"]
Expand Down Expand Up @@ -395,7 +392,7 @@ genPExp' :: GenEnv -> [String] -> PExp -> Concat
genPExp' genEnv resPath (PExp iType' pid' pos exp') = case exp' of
IDeclPExp q d pexp -> Concat (IrPExp pid') $
[ CString $ genQuant q, CString " "
, cintercalate (CString ", ") $ map ((genDecl genEnv resPath)) d
, cintercalate (CString ", ") $ map (genDecl genEnv resPath) d
, CString $ optBar d, genPExp' genEnv resPath pexp]
where
optBar [] = ""
Expand Down Expand Up @@ -454,7 +451,7 @@ genIFunExp pid' genEnv resPath (IFunExp op' exps') =
else Concat (IrPExp pid') $ intl exps'' (map CString $ genOp op')
where
intl
| op' == iSumSet' = flip $ interleave
| op' == iSumSet' = flip interleave
| op' `elem` arithBinOps && length exps' == 2 = interleave
| otherwise = \xs ys -> reverse $ interleave (reverse xs) (reverse ys)
exps'' = map (optBrArg genEnv resPath) exps'
Expand All @@ -465,7 +462,7 @@ optBrArg :: GenEnv -> [String] -> PExp -> Concat
optBrArg genEnv resPath x = brFun (genPExp' genEnv resPath) x
where
brFun = case x of
PExp _ _ _ (IClaferId _ _ _ _) -> ($)
PExp _ _ _ IClaferId{} -> ($)
PExp _ _ _ (IInt _) -> ($)
_ -> brArg

Expand Down Expand Up @@ -511,7 +508,7 @@ adjustIExp resPath x = case x of
where
(adjNav, adjExps) = if op' == iJoin then (aNav, id)
else (id, adjustPExp resPath)
IClaferId _ _ _ _ -> aNav x
IClaferId{} -> aNav x
_ -> x
where
aNav = fst.(adjustNav resPath)
Expand Down Expand Up @@ -546,9 +543,8 @@ genDecl genEnv resPath x = case x of


genDisj :: Bool -> String
genDisj x = case x of
False -> ""
True -> "disj"
genDisj True = "disj"
genDisj False = ""

-- mapping line/columns between Clafer and Alloy code

Expand Down Expand Up @@ -613,12 +609,12 @@ firstLine :: LineNo
firstLine = 1 :: LineNo

removeright :: PExp -> PExp
removeright (PExp _ _ _ (IFunExp _ (x : (PExp _ _ _ (IClaferId _ _ _ _)) : _))) = x
removeright (PExp _ _ _ (IFunExp _ (x : (PExp _ _ _ IClaferId{}) : _))) = x
removeright (PExp _ _ _ (IFunExp _ (x : (PExp _ _ _ (IInt _ )) : _))) = x
removeright (PExp _ _ _ (IFunExp _ (x : (PExp _ _ _ (IStr _ )) : _))) = x
removeright (PExp _ _ _ (IFunExp _ (x : (PExp _ _ _ (IDouble _ )) : _))) = x
removeright (PExp t id' pos (IFunExp o (x1:x2:xs))) = (PExp t id' pos (IFunExp o (x1:(removeright x2):xs)))
removeright x@(PExp _ _ _ _) = error $ "[bug] AlloyGenerator.removeright: expects a PExp with a IFunExp inside but was given: " ++ show x --This should never happen
removeright (PExp t id' pos (IFunExp o (x1:x2:xs))) = PExp t id' pos (IFunExp o (x1:(removeright x2):xs))
removeright x@PExp{} = error $ "[bug] AlloyGenerator.removeright: expects a PExp with a IFunExp inside but was given: " ++ show x --This should never happen

getRight :: PExp -> PExp
getRight (PExp _ _ _ (IFunExp _ (_:x:_))) = getRight x
Expand Down

0 comments on commit 22036f2

Please sign in to comment.