declaration.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_AST_DECLARATION_H_
  5. #define EXECUTABLE_SEMANTICS_AST_DECLARATION_H_
  6. #include <list>
  7. #include <string>
  8. #include "executable_semantics/ast/function_definition.h"
  9. #include "executable_semantics/ast/member.h"
  10. #include "executable_semantics/ast/struct_definition.h"
  11. namespace Carbon {
  12. enum class DeclarationKind {
  13. FunctionDeclaration,
  14. StructDeclaration,
  15. ChoiceDeclaration
  16. };
  17. struct Declaration {
  18. DeclarationKind tag;
  19. union {
  20. struct FunctionDefinition* fun_def;
  21. struct StructDefinition* struct_def;
  22. struct {
  23. int line_num;
  24. std::string* name;
  25. std::list<std::pair<std::string, Expression*>>* alternatives;
  26. } choice_def;
  27. } u;
  28. };
  29. auto MakeFunDecl(struct FunctionDefinition* f) -> Declaration*;
  30. auto MakeStructDecl(int line_num, std::string name, std::list<Member*>* members)
  31. -> Declaration*;
  32. auto MakeChoiceDecl(int line_num, std::string name,
  33. std::list<std::pair<std::string, Expression*>>* alts)
  34. -> Declaration*;
  35. void PrintDecl(Declaration* d);
  36. } // namespace Carbon
  37. #endif // EXECUTABLE_SEMANTICS_AST_DECLARATION_H_