More work on implementation of Inspector. I started writing tests for

it.
functions
Justyna Ilczuk 2012-12-18 20:55:45 +01:00
parent 1be5804f4c
commit ce22fb3cdf
4 changed files with 114 additions and 4 deletions

View File

@ -9,10 +9,72 @@
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;
}

View File

@ -19,12 +19,19 @@ public:
std::map<std::string, NumberOfNodes> occurences;
virtual void visit(ASTNode * node);
virtual void visit(ConstantExpression * node);
virtual void visit(BasicExpression * node);
std::string inspection_report;
unsigned int depth_level;
void visit(ASTNode * node);
void visit(ConstantExpression * node);
void visit(BasicExpression * node);
void visit(PostfixExpression * node);
void visit(WhileNode * node);
std::string compute_indent();
void write_report(std::string visit_notes);
virtual ~ASTInspector();
};

View File

@ -0,0 +1,18 @@
/*
* TestASTInspector.cpp
*
* Created on: Dec 18, 2012
* Author: att
*/
#include "TestASTInspector.h"
TestASTInspector::TestASTInspector() {
// TODO Auto-generated constructor stub
}
TestASTInspector::~TestASTInspector() {
// TODO Auto-generated destructor stub
}

View File

@ -0,0 +1,23 @@
/*
* TestASTInspector.h
*
* Created on: Dec 18, 2012
* Author: att
*/
#ifndef TESTASTINSPECTOR_H_
#define TESTASTINSPECTOR_H_
#include "TestSuite.h"
#include "../ASTInspector.h"
class TestASTInspector: public TestSuite {
public:
TestASTInspector();
virtual ~TestASTInspector();
std::string test_inspecting_basic_expression();
};
#endif /* TESTASTINSPECTOR_H_ */