AstVisitor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "Builtin.h"
  7. #include "Type.h"
  8. #include "Scope.h"
  9. #include <memory>
  10. namespace qlow
  11. {
  12. namespace ast
  13. {
  14. template<typename T>
  15. using List = std::vector<std::unique_ptr<T>>;
  16. }
  17. }
  18. namespace qlow
  19. {
  20. class StructureVisitor;
  21. }
  22. class qlow::StructureVisitor :
  23. public Visitor<
  24. std::unique_ptr<sem::SemanticObject>,
  25. sem::Scope&,
  26. ast::Class,
  27. ast::FeatureDeclaration,
  28. ast::FieldDeclaration,
  29. ast::MethodDefinition,
  30. ast::VariableDeclaration,
  31. ast::Statement,
  32. ast::DoEndBlock,
  33. ast::IfElseBlock,
  34. ast::WhileBlock,
  35. ast::Expression,
  36. ast::FeatureCall,
  37. ast::AssignmentStatement,
  38. ast::ReturnStatement,
  39. ast::LocalVariableStatement,
  40. ast::AddressExpression,
  41. ast::ArrayAccessExpression,
  42. ast::IntConst,
  43. ast::StringConst,
  44. ast::UnaryOperation,
  45. ast::BinaryOperation,
  46. ast::NewExpression,
  47. ast::NewArrayExpression,
  48. ast::CastExpression
  49. >
  50. {
  51. public:
  52. using ReturnType = std::unique_ptr<sem::SemanticObject>;
  53. ReturnType visit(ast::Class& ast, sem::Scope& scope) override;
  54. ReturnType visit(ast::FeatureDeclaration& ast, sem::Scope& scope) override;
  55. ReturnType visit(ast::FieldDeclaration& ast, sem::Scope& scope) override;
  56. ReturnType visit(ast::MethodDefinition& ast, sem::Scope& scope) override;
  57. ReturnType visit(ast::VariableDeclaration& ast, sem::Scope& scope) override;
  58. ReturnType visit(ast::Statement& ast, sem::Scope& scope) override;
  59. ReturnType visit(ast::DoEndBlock& ast, sem::Scope& scope) override;
  60. ReturnType visit(ast::IfElseBlock& ast, sem::Scope& scope) override;
  61. ReturnType visit(ast::WhileBlock& ast, sem::Scope& scope) override;
  62. ReturnType visit(ast::Expression& ast, sem::Scope& scope) override;
  63. ReturnType visit(ast::FeatureCall& ast, sem::Scope& scope) override;
  64. ReturnType visit(ast::AssignmentStatement& ast, sem::Scope& scope) override;
  65. ReturnType visit(ast::ReturnStatement& ast, sem::Scope& scope) override;
  66. ReturnType visit(ast::LocalVariableStatement& ast, sem::Scope& scope) override;
  67. ReturnType visit(ast::AddressExpression& ast, sem::Scope& scope) override;
  68. ReturnType visit(ast::ArrayAccessExpression& ast, sem::Scope& scope) override;
  69. ReturnType visit(ast::IntConst& ast, sem::Scope& scope) override;
  70. ReturnType visit(ast::StringConst& ast, sem::Scope& scope) override;
  71. ReturnType visit(ast::UnaryOperation& ast, sem::Scope& scope) override;
  72. ReturnType visit(ast::BinaryOperation& ast, sem::Scope& scope) override;
  73. ReturnType visit(ast::NewExpression& ast, sem::Scope& scope) override;
  74. ReturnType visit(ast::NewArrayExpression& ast, sem::Scope& scope) override;
  75. ReturnType visit(ast::CastExpression& ast, sem::Scope& scope) override;
  76. ReturnType createImplicitCast(std::unique_ptr<sem::Expression>, sem::Type* targetType, sem::Scope& scope);
  77. };
  78. #endif // QLOW_AST_VISITOR_H