]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Validate index types.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 14:57:07 +0000 (15:57 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 14:57:07 +0000 (15:57 +0100)
src/ParsedOFL.hs

index 6c7d3f9676877ea82bf97b52eee428806a9bf43c..461e6a80b4a56e29a54de8badd323f4476436744 100644 (file)
@@ -124,6 +124,11 @@ isLValue _ e = validationFailure $ "Expression " ++ show e ++ " is not an assign
 indexExists :: OFL -> String -> ValidationResult
 indexExists ofl name = if (hasIndex ofl name) then validationSuccess else validationFailure $ "Unknown index " ++ name
 
+indexIsType :: OFL -> String -> IndexType -> ValidationResult
+indexIsType ofl name indexType = case indexType == (getIndexType ofl name) of
+  True -> validationSuccess
+  False -> validationFailure $ "Expected index " ++ name ++ " to be be of type " ++ show indexType
+
 valueExists :: OFL -> String -> ValidationResult
 valueExists ofl name = if (hasValue ofl name) then validationSuccess else validationFailure $ "Unknown value " ++ name
 
@@ -191,12 +196,13 @@ validateExpression ofl (Power a b) = do {
   validateExpression ofl b;
 }
 
-
 validateExpression ofl (PositionComponent i) = do {
   indexExists ofl i;
+  indexIsType ofl i SpatialIndex
 }
 
 validateExpression ofl (Derivative e i) = do {
   validateExpression ofl e;
   indexExists ofl i;
+  indexIsType ofl i SpatialIndex
 }