Moved customVarCompare from ArrayUsageCheck to UsageCheck and used it to derive Ord for the Var type

This commit is contained in:
Neil Brown 2008-01-25 16:34:18 +00:00
parent c2c761ab7d
commit 64a9292b75
2 changed files with 12 additions and 4 deletions

View File

@ -142,6 +142,8 @@ data FlattenedExp
| Modulo (Set.Set FlattenedExp) (Set.Set FlattenedExp)
| Divide (Set.Set FlattenedExp) (Set.Set FlattenedExp)
--TODO change the A.Variable to Var, and automatically derive Eq and Ord
instance Eq FlattenedExp where
a == b = EQ == compare a b
@ -159,10 +161,6 @@ instance Ord FlattenedExp where
compare (Divide ltop lbottom) (Divide rtop rbottom)
= combineCompare [compare ltop rtop, compare lbottom rbottom]
customVarCompare :: A.Variable -> A.Variable -> Ordering
customVarCompare (A.Variable _ (A.Name _ _ lname)) (A.Variable _ (A.Name _ _ rname)) = compare lname rname
-- TODO the rest
onlyConst :: [FlattenedExp] -> Maybe Integer
onlyConst [] = Just 0
onlyConst ((Const n):es) = liftM2 (+) (return n) $ onlyConst es

View File

@ -29,6 +29,16 @@ import Metadata
newtype Var = Var A.Variable
customVarCompare :: A.Variable -> A.Variable -> Ordering
customVarCompare (A.Variable _ (A.Name _ _ lname)) (A.Variable _ (A.Name _ _ rname)) = compare lname rname
-- TODO the rest
instance Eq Var where
a == b = EQ == compare a b
instance Ord Var where
compare (Var a) (Var b) = customVarCompare a b
data Vars = Vars {
readVars :: Set.Set Var
,writtenVars :: Set.Set Var