KSeExpr  4.0.4.0
TypePrinter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2 // SPDX-License-Identifier: LicenseRef-Apache-2.0
3 // SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
6 #pragma once
7 
8 #include <array>
9 #include <cstdio>
10 #include <typeinfo>
11 
12 #include "ExprNode.h"
13 #include "ExprWalker.h"
14 #include "Expression.h"
15 
16 namespace KSeExpr
17 {
18 class TypePrintExaminer : public KSeExpr::Examiner<true> {
19  public:
20  bool examine(const ExprNode* examinee) override;
21  void reset() override {};
22  void post(const ExprNode *) override {};
23 };
24 
25 bool TypePrintExaminer::examine(const ExprNode* examinee) {
26  const ExprNode* curr = examinee;
27  int depth = 0;
28  std::array<char, 1024> buf{};
29  while (curr != nullptr) {
30  depth++;
31  curr = curr->parent();
32  }
33  sprintf(buf.data(), "%*s", depth * 2, " ");
34  std::cout << buf.data() << "'" << examinee->toString() << "' " << typeid(*examinee).name()
35  << " type=" << examinee->type().toString() << std::endl;
36 
37  return true;
38 }
39 } // namespace KSeExpr
std::string toString() const
Access to original string representation of current expression.
Definition: ExprNode.h:95
const ExprNode * parent() const
Access parent node - root node has no parent.
Definition: ExprNode.h:103
const ExprType & type() const
The type of the node.
Definition: ExprNode.h:150
std::string toString() const
Stringify the type into a printable string.
Definition: ExprType.h:253
void reset() override
Definition: TypePrinter.h:21
bool examine(const ExprNode *examinee) override
Definition: TypePrinter.h:25
void post(const ExprNode *) override
Definition: TypePrinter.h:22
KSeExpr::SPrintFuncX sprintf