81 lines
1.5 KiB
C++
81 lines
1.5 KiB
C++
/*
|
|
* ASTInspector.cpp
|
|
*
|
|
* Created on: Dec 17, 2012
|
|
* Author: att
|
|
*/
|
|
|
|
#include "ASTInspector.h"
|
|
|
|
ASTInspector::ASTInspector() {
|
|
// TODO Auto-generated constructor stub
|
|
depth_level = 0;
|
|
}
|
|
|
|
ASTInspector::~ASTInspector() {
|
|
// TODO Auto-generated destructor stub
|
|
}
|
|
|
|
void ASTInspector::visit(ASTNode * node)
|
|
{
|
|
|
|
}
|
|
|
|
void ASTInspector::visit(ConstantExpression * constant_expression)
|
|
{
|
|
depth_level++;
|
|
std::string visit_notes = "";
|
|
visit_notes += "Constant expression of value:\n";
|
|
visit_notes += constant_expression->value.repr() + "\n";
|
|
write_report(visit_notes);
|
|
depth_level--;
|
|
}
|
|
|
|
void ASTInspector::visit(BasicExpression * basic_expression)
|
|
{
|
|
depth_level++;
|
|
std::string visit_notes = "";
|
|
visit_notes += "Basic expression:\n";
|
|
visit_notes += "Executing " + basic_expression->oper + " on:\n";
|
|
write_report(visit_notes);
|
|
|
|
basic_expression->children[0]->accept(this);
|
|
basic_expression->children[1]->accept(this);
|
|
|
|
write_report("End of basic expression\n");
|
|
depth_level--;
|
|
}
|
|
|
|
void ASTInspector::visit(PostfixExpression * node)
|
|
{
|
|
|
|
}
|
|
|
|
void ASTInspector::visit(WhileNode * node)
|
|
{
|
|
|
|
}
|
|
|
|
void ASTInspector::write_report(std::string visit_notes)
|
|
{
|
|
std::istringstream stream(visit_notes);
|
|
std::string line;
|
|
std::string correct_indentation = compute_indent();
|
|
|
|
while(std::getline(stream, line)) {
|
|
inspection_report += correct_indentation + line + "\n";
|
|
}
|
|
|
|
}
|
|
|
|
std::string ASTInspector::compute_indent()
|
|
{
|
|
std::string indentation = "";
|
|
std::string basic_indent = " ";
|
|
for(int i = 0; i < depth_level; i++)
|
|
{
|
|
indentation += basic_indent;
|
|
}
|
|
return indentation;
|
|
}
|