]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Verify that LHS of assignment is an lvalue.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 13:40:18 +0000 (14:40 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 13:40:18 +0000 (14:40 +0100)
src/ParsedOFL.hs

index db234b5b03cf3a3d34280473d597ff6c760873be..4a46e2954ec9a92eb151eed445826649fe45a2b5 100644 (file)
@@ -87,7 +87,7 @@ getType ofl (IndexedIdentifier name _) = getValueType ofl name
 getType ofl (ConstReal _) = Real
 getType ofl (ConstInteger _) = Integer
 getType ofl (Negate e) = getType ofl e 
-getType ofl (Inner _ _) = Function
+getType ofl (Inner _ _) = Real
 getType ofl (Laplacian _) = Function 
 getType ofl (Sum e _) = getType ofl e
 getType ofl (Multiply a b) = promote (getType ofl a) (getType ofl b)
@@ -101,25 +101,31 @@ getType ofl (Derivative e i) = getType ofl e
 emptyOFL :: OFL
 emptyOFL = OFL { assignments = [], symbols = Map.empty }
 
+-- Validation
+data ValidationError = Message String deriving Show
+type ValidationResult = Either ValidationError ()
+validationSuccess = Right ()
+validationFailure = \x -> Left (Message x)
+
 validateAssignment :: OFL -> Assignment -> ValidationResult
 validateAssignment ofl (Assign lhs rhs) = do {
   validateExpression ofl lhs;
   validateExpression ofl rhs;
-  return ()
+  isLValue ofl lhs;
+  case (getType ofl lhs) == (getType ofl rhs) of
+    True -> validationSuccess
+    False -> validationFailure $ "Types of left and right-hand sides of assignment do not match"
 }
 
--- Validation
-
-data ValidationError = Message String deriving Show
-type ValidationResult = Either ValidationError ()
-validationSuccess = Right ()
-validationFailure = \x -> Left (Message x)
+isLValue :: OFL -> Expression -> ValidationResult
+isLValue ofl (IndexedIdentifier name indices) = validationSuccess
+isLValue _ e = validationFailure $ "Expression " ++ show e ++ " is not an assignable value"
 
 indexExists :: OFL -> String -> ValidationResult
 indexExists ofl name = if (hasIndex ofl name) then validationSuccess else validationFailure $ "Unknown index " ++ name
 
 valueExists :: OFL -> String -> ValidationResult
-valueExists ofl name = if (hasValue ofl name) then validationSuccess else validationFailure $ "Unknownm value " ++ name
+valueExists ofl name = if (hasValue ofl name) then validationSuccess else validationFailure $ "Unknown value " ++ name
 
 isFunction :: OFL -> Expression -> ValidationResult
 isFunction ofl e = case (getType ofl e) of