typecheck.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "common/ostream.h"
  8. #include "executable_semantics/ast/expression.h"
  9. #include "executable_semantics/ast/statement.h"
  10. #include "executable_semantics/interpreter/dictionary.h"
  11. #include "executable_semantics/interpreter/interpreter.h"
  12. namespace Carbon {
  13. using TypeEnv = Dictionary<std::string, const Value*>;
  14. struct TCExpression {
  15. TCExpression(const Expression* e, const Value* t, TypeEnv types)
  16. : exp(e), type(t), types(types) {}
  17. const Expression* exp;
  18. const Value* type;
  19. TypeEnv types;
  20. };
  21. struct TCPattern {
  22. const Pattern* pattern;
  23. const Value* type;
  24. TypeEnv types;
  25. };
  26. struct TCStatement {
  27. TCStatement(const Statement* s, TypeEnv types) : stmt(s), types(types) {}
  28. const Statement* stmt;
  29. TypeEnv types;
  30. };
  31. auto TypeCheckExp(const Expression* e, TypeEnv types, Env values)
  32. -> TCExpression;
  33. auto TypeCheckPattern(const Pattern* p, TypeEnv types, Env values,
  34. const Value* expected) -> TCPattern;
  35. auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
  36. const Value*& ret_type, bool is_omitted_ret_type)
  37. -> TCStatement;
  38. auto MakeTypeChecked(const Declaration& decl, const TypeEnv& types,
  39. const Env& values) -> const Declaration*;
  40. auto TopLevel(const std::list<const Declaration*>& fs) -> TypeCheckContext;
  41. } // namespace Carbon
  42. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_