Ast.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // =============================================================================
  2. //
  3. // This file is part of the qlow compiler.
  4. //
  5. // Copyright (C) 2014-2015 Nicolas Winkler
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. // =============================================================================
  21. #include <string>
  22. #include <vector>
  23. #include <memory>
  24. namespace qlow
  25. {
  26. namespace ast
  27. {
  28. template<typename T>
  29. using List = std::vector<std::unique_ptr<T>>;
  30. struct Class;
  31. struct FeatureDeclaration;
  32. struct FieldDeclaration;
  33. struct MethodDefinition;
  34. struct VariableDeclaration;
  35. struct Statement;
  36. struct Expression;
  37. struct Identifier;
  38. struct BinaryOperation;
  39. struct FunctionCall;
  40. }
  41. }
  42. struct qlow::ast::Class
  43. {
  44. std::string name;
  45. };
  46. struct qlow::ast::FeatureDeclaration
  47. {
  48. std::string name;
  49. std::string type;
  50. };
  51. struct qlow::ast::FieldDeclaration
  52. {
  53. inline MethodDefinition(const std::string& type, const std::string& name) :
  54. FeatureDeclaration(type, name)
  55. {
  56. }
  57. };
  58. struct qlow::ast::MethodDefinition
  59. {
  60. List<ArgumentDeclaration> arguments;
  61. std::unique_ptr<DoEndBlock> body;
  62. inline MethodDefinition(const std::string& type, const std::string& name,
  63. std::unique_ptr<DoEndBlock>&& body) :
  64. FeatureDeclaration(type, name),
  65. body(body)
  66. {
  67. }
  68. };
  69. struct qlow::ast::VariableDeclaration
  70. {
  71. std::string name;
  72. std::string type;
  73. };
  74. struct qlow::ast::Statement
  75. {
  76. };
  77. struct qlow::ast::Expression
  78. {
  79. };
  80. struct qlow::ast::BinaryOperation : public Expression
  81. {
  82. std::unique_ptr<Expression> left;
  83. std::string operator_str;
  84. std::unique_ptr<Expression> right;
  85. };
  86. struct qlow::ast::FunctionCall : public Expression
  87. {
  88. std::string name;
  89. std::vector<std::unique_ptr<Expression>> arguments;
  90. };