typecheck.h 1.5 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 "executable_semantics/ast/expression.h"
  8. #include "executable_semantics/ast/statement.h"
  9. #include "executable_semantics/interpreter/dictionary.h"
  10. #include "executable_semantics/interpreter/interpreter.h"
  11. namespace Carbon {
  12. using TypeEnv = Dictionary<std::string, const Value*>;
  13. void PrintTypeEnv(TypeEnv types);
  14. enum class TCContext { ValueContext, PatternContext, TypeContext };
  15. struct TCResult {
  16. TCResult(Expression* e, const Value* t, TypeEnv types)
  17. : exp(e), type(t), types(types) {}
  18. Expression* exp;
  19. const Value* type;
  20. TypeEnv types;
  21. };
  22. struct TCStatement {
  23. TCStatement(Statement* s, TypeEnv types) : stmt(s), types(types) {}
  24. Statement* stmt;
  25. TypeEnv types;
  26. };
  27. auto TypeCheckExp(Expression* e, TypeEnv types, Env values,
  28. const Value* expected, TCContext context) -> TCResult;
  29. auto TypeCheckStmt(Statement*, TypeEnv, Env, Value const*&) -> TCStatement;
  30. auto TypeCheckFunDef(struct FunctionDefinition*, TypeEnv)
  31. -> struct FunctionDefinition*;
  32. auto TopLevel(std::list<Declaration>* fs) -> TypeCheckContext;
  33. void PrintErrorString(const std::string& s);
  34. } // namespace Carbon
  35. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_