typecheck.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_
  5. #define EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_
  6. #include <set>
  7. #include "executable_semantics/ast/expression.h"
  8. #include "executable_semantics/ast/statement.h"
  9. #include "executable_semantics/interpreter/assoc_list.h"
  10. #include "executable_semantics/interpreter/interpreter.h"
  11. namespace Carbon {
  12. using TypeEnv = AssocList<std::string, Value*>;
  13. void PrintTypeEnv(TypeEnv* env);
  14. enum class TCContext { ValueContext, PatternContext, TypeContext };
  15. struct TCResult {
  16. TCResult(Expression* e, Value* t, TypeEnv* env) : exp(e), type(t), env(env) {}
  17. Expression* exp;
  18. Value* type;
  19. TypeEnv* env;
  20. };
  21. struct TCStatement {
  22. TCStatement(Statement* s, TypeEnv* e) : stmt(s), env(e) {}
  23. Statement* stmt;
  24. TypeEnv* env;
  25. };
  26. auto ToType(int line_num, Value* val) -> Value*;
  27. auto TypeCheckExp(Expression* e, TypeEnv* env, Env* ct_env, Value* expected,
  28. TCContext context) -> TCResult;
  29. auto TypeCheckStmt(Statement*, TypeEnv*, Env*, Value*) -> TCStatement;
  30. auto TypeCheckFunDef(struct FunctionDefinition*, TypeEnv*)
  31. -> struct FunctionDefinition*;
  32. auto TopLevel(std::list<Declaration>* fs) -> std::pair<TypeEnv*, Env*>;
  33. void PrintErrorString(const std::string& s);
  34. } // namespace Carbon
  35. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_