CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
ASTPrinter.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Visitor.hpp"
11
13
17
19
21
22#include <iostream>
23
25
26 // AST debug printer.
27 class ASTPrinter : private Visitor {
28 private:
30 String row; // Source position row as string.
31 String col; // Source position column as string.
32 String label; // AST description label.
33 String value; // AST description value.
35 };
36
41
42 std::size_t mMaxRowStrLen = 0, mMaxColStrLen = 0;
43
44 public:
45 void printAST(Program* program, std::ostream& output = std::cout);
46
47 private:
57
64
71
84
100
101 private: // Helper functions
102 template<typename T> void visitMember(T ast, const String& name) {
103 if(ast) {
104 pushMemberName(name);
105 ast->visit(this, nullptr);
107 }
108 }
109
110 template<typename T> void visitMember(const Vector<T>& astList, const String& name) {
111 for(std::size_t i = 0; i < astList.size(); ++i) {
112 visitMember(astList[i], name + "[" + String::from((UInt64)i) + "]");
113 }
114 }
115
117
118 void print(const PrintableTree& tree, std::ostream& output);
119
120 bool pushPrintable(const AST* ast, const String& label, const String& value = "");
122
123 void printable(const AST* ast, const String& label, const String& value = "");
124
126
127 void pushMemberName(const String& name);
129
130 [[nodiscard]] const String& topMemberName() const;
131 };
132
133} // namespace CeresEngine::ShaderCompiler
#define DECLARATION_VISIT_PROC(CLASS_NAME)
Definition Visitor.hpp:88
static decltype(auto) from(U value, Args &&... args)
Converts a value into it's string representation.
Definition String.hpp:386
Definition ASTPrinter.hpp:27
std::size_t mMaxColStrLen
Definition ASTPrinter.hpp:42
const String & topMemberName() const
Stack< String > mMemberNameStack
Definition ASTPrinter.hpp:40
void print(const PrintableTree &tree, std::ostream &output)
void visitMember(T ast, const String &name)
Definition ASTPrinter.hpp:102
String writeLabel(const String &astName, TypedAST *ast=nullptr)
std::size_t mMaxRowStrLen
Definition ASTPrinter.hpp:42
Vector< bool > mLastSubNodeStack
Definition ASTPrinter.hpp:39
bool pushPrintable(const AST *ast, const String &label, const String &value="")
void printAST(Program *program, std::ostream &output=std::cout)
PrintableTree mTreeRoot
Definition ASTPrinter.hpp:37
Stack< PrintableTree * > mParentNodeStack
Definition ASTPrinter.hpp:38
void visitMember(const Vector< T > &astList, const String &name)
Definition ASTPrinter.hpp:110
void printable(const AST *ast, const String &label, const String &value="")
void pushMemberName(const String &name)
Definition Visitor.hpp:92
Definition AST.hpp:33
std::stack< T, Container > Stack
The Stack class is a container adapter that gives the programmer the functionality of a stack - speci...
Definition Stack.hpp:18
std::uint64_t UInt64
Definition DataTypes.hpp:26
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Vector< PrintableTree > children
Definition ASTPrinter.hpp:34
Definition AST.hpp:1159