typecheck.mli 1.3 KB

1234567891011121314151617181920212223242526
  1. (** Type checking: annotate node types and check if expression types are allowed
  2. within their context. *)
  3. (** Leaf expression nodes are annotated with a [Type] annotation, after which
  4. the type is propagated up to parent expressions. During this process, the
  5. following checks are performed (and errors are generated accordingly):
  6. - A void function must not return a value.
  7. - A non-void function must return a value of the correct type.
  8. - Array indices must be of type integer.
  9. - The number of array indices must match the number of array dimensions.
  10. - The type on the right-hand side of an assignment must match the type on the
  11. left-hand side.
  12. - The number of arguments used for a function call must match the number of
  13. parameters for that function.
  14. - The types of the function arguments must match the types of parameters.
  15. - The operands of a unary or binary operation must have valid types.
  16. - The predicate expression of an if, while, or do-while statement must be
  17. a boolean.
  18. - Only values of a basic type can be type cast.
  19. - Imported array pointers may not be used directly. E.g., [a] in
  20. [extern int[n] a] may be used as [a[0]], but not as [foo(a)].
  21. *)
  22. (** Main phase function, called by {!Main}. *)
  23. val phase : Main.phase_func