Browse Source

Documented Typecheck phase

Taddeus Kroes 12 years ago
parent
commit
351b1419e0
2 changed files with 24 additions and 1 deletions
  1. 1 1
      phases/typecheck.ml
  2. 23 0
      phases/typecheck.mli

+ 1 - 1
phases/typecheck.ml

@@ -12,7 +12,7 @@
  * - The operands of a unary or binary operation must have valid types.
  * - The predicate expression of an if, while, or do-while statement must be
  *   a boolean.
- * - Only values having a basic type can be type cast.
+ * - Only values of a basic type can be type cast.
  *)
 open Printf
 open Types

+ 23 - 0
phases/typecheck.mli

@@ -1 +1,24 @@
+(** Type checking: annotate node types and check if expression types are allowed
+    within their context. *)
+
+(** Leaf expression nodes are annotated with a [Type] annotation, after which
+    the type is propagated up to parent expressions. During this process, the
+    following checks are performed (and errors are generated accordingly):
+
+    - A void function must not return a value.
+    - A non-void function must return a value of the correct type.
+    - Array indices must be of type integer.
+    - The number of array indices must match the number of array dimensions.
+    - The type on the right-hand side of an assignment must match the type on the
+      left-hand side.
+    - The number of arguments used for a function call must match the number of
+      parameters for that function.
+    - The types of the function arguments must match the types of parameters.
+    - The operands of a unary or binary operation must have valid types.
+    - The predicate expression of an if, while, or do-while statement must be
+      a boolean.
+    - Only values of a basic type can be type cast.
+    *)
+
+(** Main phase function, called by {!Main}. *)
 val phase : Main.phase_func