AstVisitor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef QLOW_AST_VISITOR_H
  2. #define QLOW_AST_VISITOR_H
  3. #include "Visitor.h"
  4. #include "Ast.h"
  5. #include "Semantic.h"
  6. #include <memory>
  7. namespace qlow
  8. {
  9. namespace ast
  10. {
  11. template<typename T>
  12. using List = std::vector<std::unique_ptr<T>>;
  13. // base class
  14. struct AstObject;
  15. struct Class;
  16. struct FeatureDeclaration;
  17. struct FieldDeclaration;
  18. struct MethodDefinition;
  19. struct VariableDeclaration;
  20. struct ArgumentDeclaration;
  21. struct DoEndBlock;
  22. struct Statement;
  23. struct Expression;
  24. struct FeatureCall;
  25. struct AssignmentStatement;
  26. struct NewVariableStatement;
  27. struct Operation;
  28. struct UnaryOperation;
  29. struct BinaryOperation;
  30. }
  31. }
  32. namespace qlow
  33. {
  34. class StructureVisitor;
  35. }
  36. class qlow::StructureVisitor :
  37. public Visitor<
  38. std::unique_ptr<sem::SemanticObject>,
  39. const sem::SymbolTable<sem::Class>&,
  40. ast::Class,
  41. ast::FeatureDeclaration,
  42. ast::FieldDeclaration,
  43. ast::MethodDefinition,
  44. ast::VariableDeclaration,
  45. ast::ArgumentDeclaration,
  46. ast::DoEndBlock,
  47. ast::Statement,
  48. ast::Expression,
  49. ast::FeatureCall,
  50. ast::AssignmentStatement,
  51. ast::NewVariableStatement,
  52. ast::UnaryOperation,
  53. ast::BinaryOperation
  54. >
  55. {
  56. public:
  57. using ReturnType = std::unique_ptr<sem::SemanticObject>;
  58. /*!
  59. *
  60. * \returns <code>nullptr</code> if type is not found.
  61. */
  62. sem::Class* getType(const std::string& type, const sem::SymbolTable<sem::Class>& classes);
  63. ReturnType visit(ast::Class& ast, const sem::SymbolTable<sem::Class>& classes) override;
  64. ReturnType visit(ast::FeatureDeclaration& ast, const sem::SymbolTable<sem::Class>& classes) override;
  65. ReturnType visit(ast::FieldDeclaration& ast, const sem::SymbolTable<sem::Class>& classes) override;
  66. ReturnType visit(ast::MethodDefinition& ast, const sem::SymbolTable<sem::Class>& classes) override;
  67. ReturnType visit(ast::VariableDeclaration& ast, const sem::SymbolTable<sem::Class>& classes) override;
  68. ReturnType visit(ast::ArgumentDeclaration& ast, const sem::SymbolTable<sem::Class>& classes) override;
  69. ReturnType visit(ast::DoEndBlock& ast, const sem::SymbolTable<sem::Class>& classes) override;
  70. ReturnType visit(ast::Statement& ast, const sem::SymbolTable<sem::Class>& classes) override;
  71. ReturnType visit(ast::Expression& ast, const sem::SymbolTable<sem::Class>& classes) override;
  72. ReturnType visit(ast::FeatureCall& ast, const sem::SymbolTable<sem::Class>& classes) override;
  73. ReturnType visit(ast::AssignmentStatement& ast, const sem::SymbolTable<sem::Class>& classes) override;
  74. ReturnType visit(ast::NewVariableStatement& ast, const sem::SymbolTable<sem::Class>& classes) override;
  75. ReturnType visit(ast::UnaryOperation& ast, const sem::SymbolTable<sem::Class>& classes) override;
  76. ReturnType visit(ast::BinaryOperation& ast, const sem::SymbolTable<sem::Class>& classes) override;
  77. };
  78. #endif // QLOW_AST_VISITOR_H