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 variable occurrence to its 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 whole analysis is done in one traversal. When a declaration node is
  10. encountered, its name and declaration are added to the currect scope (a
  11. mutable hash table). When a variable of fuction use is encountered, the name
  12. and declaration are looked up in the current scope. The scope is duplicated
  13. when entering a function, and restored when exiting the function, so that
  14. functions that are not subroutines of each other, do not share inner variable
  15. definitions. Note that the traversal traverses into functions AFTER it has
  16. found all declarations in the outer scope of the function, since functions
  17. can use any function of variable that is defined within the same scope (also
  18. those defined after the function itself).
  19. *)
  20. (** Traversal that replaces names with declarations. Exported for use in other
  21. phases. *)
  22. val analyse_context : Types.node -> Types.node
  23. (** Main phase function, called by {!Main}. Calls {!analyse_context}. *)
  24. val phase : Main.phase_func