5 #include <memory_resource>
9 #include "diagnostics/Location.h"
10 #include "utils/BumpAllocator.h"
11 #include "utils/DotPrinter.h"
12 #include "utils/EnumMacros.h"
19 using utils::DotPrinter;
30 friend class ::Joos1WLexer;
31 friend class ::Joos1WParser;
33 #define NODE_TYPE_LIST(F)
36 F(QualifiedIdentifier)
47 F(ImportDeclarationList)
48 F(SingleTypeImportDeclaration)
49 F(TypeImportOnDemandDeclaration)
55 F(ClassBodyDeclarationList)
56 F(ConstructorDeclaration)
59 F(InterfaceDeclaration)
60 F(InterfaceMemberDeclarationList)
63 F(AbstractMethodDeclaration)
66 F(FormalParameterList)
76 F(StatementExpression)
79 F(LocalVariableDeclaration)
87 F(ArrayCreationExpression)
88 F(ClassInstanceCreationExpression)
101 : loc{loc}, type{type}, args{
nullptr}, num_args{0}, parent_{
nullptr} {}
107 template <
typename... Args>
111 args{
static_cast<
Node**>(alloc.allocate_bytes(
112 sizeof...(Args) *
sizeof(
Node*),
alignof(
Node*)))},
113 num_args{
sizeof...(Args)} {
114 static_assert(
sizeof...(Args) > 0,
"Must have at least one child");
115 static_assert(std::conjunction_v<std::is_convertible<Args,
Node*>...>,
116 "All arguments must be convertible to Node*");
117 std::array<
Node*,
sizeof...(Args)> tmp{std::forward<Args>(args)...};
118 for(size_t i = 0; i <
sizeof...(Args); i++) {
119 this->args[i] = tmp[i];
120 if(
this->args[i] !=
nullptr)
this->args[i]->parent_ =
this;
132 std::string
type_string()
const {
return Type_to_string(type,
"Unknown Type"); }
135 return Type_to_string(type,
"Unknown Type");
139 if(type == Type::Poison)
142 for(size_t i = 0; i < num_args; i++) {
143 if(args[i] ==
nullptr)
continue;
153 Node* parent() {
return parent_; }
154 void mark() { marked =
true; }
155 bool is_marked()
const {
return marked; }
159 virtual std::ostream&
print(std::ostream& os)
const;
161 std::ostream&
printDot(std::ostream& os)
const;
169 int printDotRecursive(DotPrinter& dp,
const Node& node)
const;
181 std::ostream& operator<<(std::ostream& os,
Node const& n);
187 friend class ::Joos1WLexer;
188 friend class ::Joos1WParser;
190 #define LITERAL_TYPE_LIST(F)
201 #undef LITERAL_TYPE_LIST
204 Literal(
SourceRange loc, BumpAllocator
const& alloc, Type type,
209 value{value, alloc} {}
213 std::ostream&
print(std::ostream& os)
const override;
215 void setNegative() { isNegative_ =
true; }
216 bool isNegative()
const {
return isNegative_; }
218 bool isValid()
const;
220 Type get_type()
const {
return type; }
222 std::string_view get_value()
const {
return value; }
230 std::pmr::string value;
237 friend class ::Joos1WLexer;
238 friend class ::Joos1WParser;
241 Identifier(
SourceRange loc, BumpAllocator
const& alloc,
char const* name)
242 :
Node{loc
, Node::Type::Identifier
}, name{name, alloc} {}
246 std::string_view get_name()
const {
return name; }
248 std::ostream&
print(std::ostream& os)
const override;
254 std::pmr::string name;
261 friend class ::Joos1WLexer;
262 friend class ::Joos1WParser;
296 std::ostream&
print(std::ostream& os)
const override {
297 return os << to_string();
300 std::string to_string()
const;
302 Type get_type()
const {
return type; }
315 friend class ::Joos1WLexer;
316 friend class ::Joos1WParser;
318 #define MODIFIER_TYPE_LIST(F)
330 #undef MODIFIER_TYPE_LIST
338 Type get_type()
const {
return modty; }
340 std::ostream&
print(std::ostream& os)
const override;
353 friend class ::Joos1WLexer;
354 friend class ::Joos1WParser;
356 #define BASIC_TYPE_LIST(F)
367 #undef BASIC_TYPE_LIST
375 Type get_type()
const {
return type; }
377 std::ostream&
print(std::ostream& os)
const override;