typecheck.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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*, TypeEnv, Env, Value const*&)
  36. -> TCStatement;
  37. auto TypeCheckFunDef(struct FunctionDefinition*, TypeEnv)
  38. -> struct FunctionDefinition*;
  39. auto MakeTypeChecked(const Declaration& decl, const TypeEnv& types,
  40. const Env& values) -> Declaration;
  41. auto TopLevel(std::list<Declaration>* fs) -> TypeCheckContext;
  42. } // namespace Carbon
  43. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_TYPECHECK_H_