Added support for actually bounds-checking the array based on its declared size
This commit is contained in:
parent
31db71cb83
commit
4b0d29d987
|
@ -54,17 +54,23 @@ checkArrayUsage tree = (mapM_ checkPar $ listify (const True) tree) >> return tr
|
||||||
|
|
||||||
checkIndexes :: Meta -> (String,[A.Expression]) -> PassM ()
|
checkIndexes :: Meta -> (String,[A.Expression]) -> PassM ()
|
||||||
checkIndexes m (arrName, indexes)
|
checkIndexes m (arrName, indexes)
|
||||||
= -- liftIO (putStr $ "Checking: " ++ show (arrName, indexes)) >>
|
= do userArrName <- getRealName (A.Name undefined undefined arrName)
|
||||||
case makeEquations indexes (makeConstant emptyMeta 1000000) of
|
arrType <- typeOfName (A.Name undefined undefined arrName)
|
||||||
Left err -> dieP m $ "Could not work with array indexes for array \"" ++ arrName ++ "\": " ++ err
|
(arrLength,checkable) <- case arrType of
|
||||||
Right [] -> return () -- No problems to work with
|
A.Array (A.Dimension d:_) _ -> return (d,True)
|
||||||
Right problems ->
|
A.Array (A.UnknownDimension:_) _ -> return (undefined, False)
|
||||||
case mapMaybe (\(vm,p) -> seqPair (return vm,uncurry solveProblem p)) problems of
|
_ -> dieP m $ "Cannot usage check array \"" ++ userArrName ++ "\"; found to be of type: " ++ show arrType
|
||||||
-- No solutions; no worries!
|
if not checkable
|
||||||
[] -> return ()
|
then return ()
|
||||||
((varMapping,vm):_) -> do sol <- formatSolution varMapping (getCounterEqs vm)
|
else case makeEquations indexes (makeConstant emptyMeta arrLength) of
|
||||||
arrName' <- getRealName (A.Name undefined undefined arrName)
|
Left err -> dieP m $ "Could not work with array indexes for array \"" ++ userArrName ++ "\": " ++ err
|
||||||
dieP m $ "Overlapping indexes of array \"" ++ arrName' ++ "\" when: " ++ sol
|
Right [] -> return () -- No problems to work with
|
||||||
|
Right problems ->
|
||||||
|
case mapMaybe (\(vm,p) -> seqPair (return vm,uncurry solveProblem p)) problems of
|
||||||
|
-- No solutions; no worries!
|
||||||
|
[] -> return ()
|
||||||
|
((varMapping,vm):_) -> do sol <- formatSolution varMapping (getCounterEqs vm)
|
||||||
|
dieP m $ "Overlapping indexes of array \"" ++ userArrName ++ "\" when: " ++ sol
|
||||||
|
|
||||||
formatSolution :: VarMap -> Map.Map CoeffIndex Integer -> PassM String
|
formatSolution :: VarMap -> Map.Map CoeffIndex Integer -> PassM String
|
||||||
formatSolution varToIndex indexToConst = do names <- mapM valOfVar $ Map.assocs varToIndex
|
formatSolution varToIndex indexToConst = do names <- mapM valOfVar $ Map.assocs varToIndex
|
||||||
|
|
Loading…
Reference in New Issue
Block a user