diff options
author | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-18 20:55:45 +0100 |
---|---|---|
committer | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-18 20:55:45 +0100 |
commit | ce22fb3cdf6f9a529a7f54d22926dfca6356cc29 (patch) | |
tree | be2aba9fa27d1c10d2334433e3beb24c1a73bfe4 | |
parent | 1be5804f4cae0299984764492dc57768b056daae (diff) | |
download | sencha-lang-ce22fb3cdf6f9a529a7f54d22926dfca6356cc29.tar.gz sencha-lang-ce22fb3cdf6f9a529a7f54d22926dfca6356cc29.tar.bz2 sencha-lang-ce22fb3cdf6f9a529a7f54d22926dfca6356cc29.tar.xz sencha-lang-ce22fb3cdf6f9a529a7f54d22926dfca6356cc29.zip |
More work on implementation of Inspector. I started writing tests for
it.
-rw-r--r-- | Sencha-lang/ASTInspector.cpp | 64 | ||||
-rw-r--r-- | Sencha-lang/ASTInspector.h | 13 | ||||
-rw-r--r-- | Sencha-lang/Tests/TestASTInspector.cpp | 18 | ||||
-rw-r--r-- | Sencha-lang/Tests/TestASTInspector.h | 23 |
4 files changed, 114 insertions, 4 deletions
diff --git a/Sencha-lang/ASTInspector.cpp b/Sencha-lang/ASTInspector.cpp index de4edbe..656a6c5 100644 --- a/Sencha-lang/ASTInspector.cpp +++ b/Sencha-lang/ASTInspector.cpp @@ -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; +} diff --git a/Sencha-lang/ASTInspector.h b/Sencha-lang/ASTInspector.h index 609ee82..41fad8f 100644 --- a/Sencha-lang/ASTInspector.h +++ b/Sencha-lang/ASTInspector.h @@ -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(); }; diff --git a/Sencha-lang/Tests/TestASTInspector.cpp b/Sencha-lang/Tests/TestASTInspector.cpp new file mode 100644 index 0000000..17e8e4f --- /dev/null +++ b/Sencha-lang/Tests/TestASTInspector.cpp @@ -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 +} + diff --git a/Sencha-lang/Tests/TestASTInspector.h b/Sencha-lang/Tests/TestASTInspector.h new file mode 100644 index 0000000..962771e --- /dev/null +++ b/Sencha-lang/Tests/TestASTInspector.h @@ -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_ */ |