context.mli 1.5 KB

12345678910111213141516171819202122232425262728
  1. (** Context analysis: find declarations of used variables and functions. *)
  2. (** The desugared CiviC code contains [Var], [FunCall] and [Assign] nodes. These
  3. all use variables or functions identified by a [string] name. The context
  4. analysis phase links each occurrence of this node to a declaration: a
  5. [VarDec], [Param], [Dim], [GlobalDe[cf]] or [FunDe[cf]]. Since the original
  6. nodes only have a [string] field to save the declaration, new node types
  7. have been added which replace the name with a declaration node: [VarUse],
  8. [FunUse], and [VarLet].
  9. The phase traverses into functions, but first finds declarations in the
  10. entire outer scope of the function, since functions can use any function of
  11. variable that is defined within the same scope.
  12. The whole analysis is done in one traversal. When a declaration node is
  13. encountered, its name and declaration are added to the currect scope (a
  14. mutable hash table). When a vairable of fuction use is encountered, the name
  15. and declaration are looked up in the current scope. The scope is duplicated
  16. when entering a function, and restored when exiting the function, so that
  17. functions that are not subroutines of each other, do not share inner variable
  18. definitions. *)
  19. (** Traversal that replaces names with declarations. Exported for use in other
  20. phases. *)
  21. val analyse_context : Types.node -> Types.node
  22. (** Main phase function, called by {!Main}. Calls {!analyse_context}. *)
  23. val phase : Main.phase_func