typecheck.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. enum class TCContext { ValueContext, PatternContext, TypeContext };
  15. struct TCResult {
  16. TCResult(const Expression* e, const Value* t, TypeEnv types)
  17. : exp(e), type(t), types(types) {}
  18. const Expression* exp;
  19. const Value* type;
  20. TypeEnv types;
  21. };
  22. struct TCStatement {
  23. TCStatement(const Statement* s, TypeEnv types) : stmt(s), types(types) {}
  24. const Statement* stmt;
  25. TypeEnv types;
  26. };
  27. auto TypeCheckExp(const Expression* e, TypeEnv types, Env values,
  28. const Value* expected, TCContext context) -> TCResult;
  29. auto TypeCheckStmt(const Statement*, TypeEnv, Env, Value const*&)
  30. -> TCStatement;
  31. auto TypeCheckFunDef(struct FunctionDefinition*, TypeEnv)
  32. -> struct FunctionDefinition*;
  33. auto MakeTypeChecked(const Declaration& decl, const TypeEnv& types,
  34. const Env& values) -> Declaration;
  35. auto TopLevel(std::list<Declaration>* fs) -> TypeCheckContext;
  36. } // namespace Carbon
  37. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_