From bede6807fea5476bd781eafa437d477a1f90a172 Mon Sep 17 00:00:00 2001 From: Pascal Noisette <noisette@users.gforge.inria.fr> Date: Tue, 10 Feb 2009 21:52:38 +0000 Subject: [PATCH] Le test du deuximeme parser _compile_. Qq trucs a debuger encore... --- parser/src/ParserEventDecoder.hpp | 3 +- parser/tests/stub/trace.cpp | 65 +++++++++++++------------ parser/tests/stub/trace.hpp | 20 ++++---- parser/tests/test_parser_definition.cpp | 3 +- parser/tests/test_parser_event.cpp | 56 +++++++++++++++++++++ trace/src/values/Value.hpp | 2 +- 6 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 parser/tests/test_parser_event.cpp diff --git a/parser/src/ParserEventDecoder.hpp b/parser/src/ParserEventDecoder.hpp index 9fc68f08..055fd609 100644 --- a/parser/src/ParserEventDecoder.hpp +++ b/parser/src/ParserEventDecoder.hpp @@ -12,7 +12,8 @@ #include "../../trace/src/values/Integer.hpp" #include "../../trace/src/values/Name.hpp" #include "../../trace/src/values/String.hpp" -#include "../tests/stub/trace.hpp" +#include "../tests/stub/trace.hpp" + /** * \class ParserEventDecoder diff --git a/parser/tests/stub/trace.cpp b/parser/tests/stub/trace.cpp index de8f356e..38b38b8e 100644 --- a/parser/tests/stub/trace.cpp +++ b/parser/tests/stub/trace.cpp @@ -13,15 +13,20 @@ using namespace std; static std::string res; std::string& to_string(const vector<Value*> &opt){ - res = "option(" ; - for (int i=0;i<opt.size();i++) - res.append(opt[i]->to_string() + " "); - res.append(")"); - return res; + if (opt.size()>0){ + res = "option(" ; + for (int i=0;i<opt.size();i++) + res.append(opt[i]->to_string() + " "); + res.append(")"); + } + else{ + res.assign("\0"); + } + return res; } -void define_container_type(Name alias, ContainerType *container_type_parent, const vector<Value*> &opt){ +void Trace::define_container_type(Name alias, ContainerType *container_type_parent, const vector<Value*> &opt){ cout << "define_container_type " << alias.to_string() << " " @@ -33,7 +38,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con - void create_container(Date time, Name alias, ContainerType *type, Container *parent, const vector<Value*> &opt){ + void Trace::create_container(Date time, Name alias, ContainerType *type, Container *parent, const vector<Value*> &opt){ cout << "create_container " << time.to_string() << " " @@ -49,7 +54,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con - void destroy_container(Date time, Name alias, ContainerType *type, const vector<Value*> &opt){ + void Trace::destroy_container(Date time, Name alias, ContainerType *type, const vector<Value*> &opt){ cout << "destroy_container " << time.to_string() << " " @@ -62,7 +67,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con } - void define_event_type(Name alias, ContainerType *container_type, const vector<Value*> &opt){ + void Trace::define_event_type(Name alias, ContainerType *container_type, const vector<Value*> &opt){ cout << "define_event_type " << alias.to_string() << " " @@ -74,7 +79,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con - void define_state_type(Name alias, ContainerType *container_type, const vector<Value*> &opt){ + void Trace::define_state_type(Name alias, ContainerType *container_type, const vector<Value*> &opt){ cout << "define_state_type " << alias.to_string() << " " @@ -85,7 +90,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con } - void define_variable_type(Name alias, ContainerType *container_type, const vector<Value*> &opt){ + void Trace::define_variable_type(Name alias, ContainerType *container_type, const vector<Value*> &opt){ cout << "define_variable_type " << alias.to_string() << " " @@ -97,7 +102,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con - void define_link_type(Name alias, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const vector<Value*> &opt){ + void Trace::define_link_type(Name alias, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const vector<Value*> &opt){ cout << "define_link_type " << alias.to_string() << " " @@ -113,7 +118,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con - void define_entity_value(Name alias, EntityType *entity_type, const vector<Value*> &opt){ + void Trace::define_entity_value(Name alias, EntityType *entity_type, const vector<Value*> &opt){ cout << "define_entity_value " << alias.to_string() << " " @@ -125,7 +130,7 @@ void define_container_type(Name alias, ContainerType *container_type_parent, con -void set_state(Date time, StateType *type, Container *container, EntityValue *value, const vector<Value*> &op){ +void Trace::set_state(Date time, StateType *type, Container *container, EntityValue *value, const vector<Value*> &op){ cout << "set_state " << time.to_string() << " " @@ -141,7 +146,7 @@ void set_state(Date time, StateType *type, Container *container, EntityValue *va -void push_state(Date time, StateType *type, Container *container, EntityValue *value, const vector<Value*> &opt){ +void Trace::push_state(Date time, StateType *type, Container *container, EntityValue *value, const vector<Value*> &opt){ cout << "push_state " << time.to_string() << " " @@ -157,7 +162,7 @@ void push_state(Date time, StateType *type, Container *container, EntityValue *v -void pop_state(Date time, StateType *type, Container *container, const vector<Value*> &opt){ +void Trace::pop_state(Date time, StateType *type, Container *container, const vector<Value*> &opt){ cout << "pop_state " << time.to_string() @@ -172,7 +177,7 @@ void pop_state(Date time, StateType *type, Container *container, const vector<Va -void new_event(Date time, EventType *type, Container *container, EntityValue *value, const vector<Value*> &opt){ +void Trace::new_event(Date time, EventType *type, Container *container, EntityValue *value, const vector<Value*> &opt){ cout << "new_event " << time.to_string() << " " @@ -188,7 +193,7 @@ void new_event(Date time, EventType *type, Container *container, EntityValue *va -void set_variable(Date time, VariableType *type, Container *container, Double value, const vector<Value*> &opt){ +void Trace::set_variable(Date time, VariableType *type, Container *container, Double value, const vector<Value*> &opt){ cout << "set_variable " << time.to_string() @@ -204,7 +209,7 @@ void set_variable(Date time, VariableType *type, Container *container, Double va } -void add_variable(Date time, VariableType *type, Container *container, Double value, const vector<Value*> &opt){ +void Trace::add_variable(Date time, VariableType *type, Container *container, Double value, const vector<Value*> &opt){ cout << "add_variable " << time.to_string() @@ -221,7 +226,7 @@ void add_variable(Date time, VariableType *type, Container *container, Double va -void sub_variable(Date time, VariableType *type, Container *container, Double value, const vector<Value*> &opt){ +void Trace::sub_variable(Date time, VariableType *type, Container *container, Double value, const vector<Value*> &opt){ cout << "sub_variable " << time.to_string() @@ -237,7 +242,7 @@ void sub_variable(Date time, VariableType *type, Container *container, Double va } -void start_link(Date time, LinkType *type, Container *ancestor, Container *source, EntityValue value, Integer key, const vector<Value*> &opt){ +void Trace::start_link(Date time, LinkType *type, Container *ancestor, Container *source, EntityValue value, Integer key, const vector<Value*> &opt){ cout << "start_link " << time.to_string() @@ -258,7 +263,7 @@ void start_link(Date time, LinkType *type, Container *ancestor, Container *sourc -void end_link(Date time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, Integer key, const vector<Value*> &opt){ +void Trace::end_link(Date time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, Integer key, const vector<Value*> &opt){ cout << "start_link " << time.to_string() @@ -281,14 +286,14 @@ void end_link(Date time, LinkType *type, Container *ancestor, Container *destina - Container *search_container_type(String name) + Container *Trace::search_container_type(String name) { res = "search(" + name.to_string() + ")"; return &res; } - Container *search_container(String name) + Container *Trace::search_container(String name) { res = "search(" + name.to_string() + ")"; return &res; @@ -296,7 +301,7 @@ void end_link(Date time, LinkType *type, Container *ancestor, Container *destina - Container *search_event_type(String name) + Container *Trace::search_event_type(String name) { res = "search(" + name.to_string() + ")"; return &res; @@ -304,7 +309,7 @@ void end_link(Date time, LinkType *type, Container *ancestor, Container *destina - Container *search_state_type(String name) + Container *Trace::search_state_type(String name) { res = "search(" + name.to_string() + ")"; return &res; @@ -313,26 +318,26 @@ void end_link(Date time, LinkType *type, Container *ancestor, Container *destina - Container *search_variable_type(String name) { + Container *Trace::search_variable_type(String name) { res = "search(" + name.to_string() + ")"; return &res; } - Container *search_link_type(String name) { + Container *Trace::search_link_type(String name) { res = "search(" + name.to_string() + ")"; return &res; } - Container *search_entity_value(String name) { + Container *Trace::search_entity_value(String name) { res = "search(" + name.to_string() + ")"; return &res; } - Container *search_entity_type(String name) + Container *Trace::search_entity_type(String name) { res = "search(" + name.to_string() + ")"; return &res; diff --git a/parser/tests/stub/trace.hpp b/parser/tests/stub/trace.hpp index af2a9ee6..07f977d7 100644 --- a/parser/tests/stub/trace.hpp +++ b/parser/tests/stub/trace.hpp @@ -29,7 +29,7 @@ typedef std::string EntityValue; typedef std::string EventType; typedef std::string VariableType; typedef std::string LinkType; -typedef std::string Container; + class Trace{ @@ -277,7 +277,7 @@ public : * \brief search a container type by his name or alias * */ - Container *search_container_type(String name) const; + Container *search_container_type(String name) ; /*! * @@ -285,7 +285,7 @@ public : * \brief search a container by his name or alias * */ - Container *search_container(String name) const; + Container *search_container(String name) ; /*! * @@ -293,7 +293,7 @@ public : * \brief search a event type by his name or alias * */ - Container *search_event_type(String name) const; + Container *search_event_type(String name) ; /*! @@ -302,7 +302,7 @@ public : * \brief search a container by his name or alias * */ - Container *search_state_type(String name) const; + Container *search_state_type(String name) ; /*! @@ -311,7 +311,7 @@ public : * \brief search a variable type by his name or alias * */ - Container *search_variable_type(String name) const; + Container *search_variable_type(String name) ; /*! @@ -320,16 +320,14 @@ public : * \brief search a container by his name or alias * */ - VariableType *search_link_type(String name) const; - - /*! + VariableType *search_link_type(String name); /*! * * \fn search_entity_value * \brief search a container by his name or alias * */ - Container *search_entity_value(String name) const; - Container *search_entity_type(String name) const; + Container *search_entity_value(String name) ; + Container *search_entity_type(String name) ; };//end class diff --git a/parser/tests/test_parser_definition.cpp b/parser/tests/test_parser_definition.cpp index 63470c17..09913417 100644 --- a/parser/tests/test_parser_definition.cpp +++ b/parser/tests/test_parser_definition.cpp @@ -1,5 +1,6 @@ #include "../src/Line.hpp" -#include "../src/ParserDefinitionDecoder.hpp" +#include "../src/ParserDefinitionDecoder.hpp" +#include "../tests/stub/trace.hpp" #include <iostream> #include <fstream> diff --git a/parser/tests/test_parser_event.cpp b/parser/tests/test_parser_event.cpp new file mode 100644 index 00000000..b5e8f11c --- /dev/null +++ b/parser/tests/test_parser_event.cpp @@ -0,0 +1,56 @@ +#include "../src/Line.hpp" +#include "../src/ParserDefinitionDecoder.hpp" +#include "../src/ParserEventDecoder.hpp" +#include "../tests/stub/trace.hpp" +#include <iostream> +#include <fstream> + +#define DIE_IF(condition,message) if (condition){ \ + cout << message << endl; \ + return 0;} + + +using namespace std; + +int main(int argc, char **argv){ + + ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder(); + ParserEventDecoder *parserevent = new ParserEventDecoder(); + Trace trace; + Line line("trace_to_parse.trace"); + + int linecount = 0; + static const string percent = "%"; + + while(!line.eof()){ + + line.newline(); + + if(line.starts_with(percent)){ + parserdefinition->store_definition(line); + linecount ++; + + } + else{ + + int event_identity; + string event_identity_string; + DIE_IF(!line.item(0, event_identity_string), "event has no identifier"); + DIE_IF(sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1, "expected identifier for a definition"); + + parserevent->store_event( + parserdefinition->get_definition(event_identity), + line, + trace); + + ; + } + } + + //parserdefinition->print_definitions(); + cout << "lu :" << linecount << endl; + + delete parserdefinition; + delete parserevent; + return EXIT_SUCCESS; +} diff --git a/trace/src/values/Value.hpp b/trace/src/values/Value.hpp index 89c4b141..c02db1ad 100644 --- a/trace/src/values/Value.hpp +++ b/trace/src/values/Value.hpp @@ -27,7 +27,7 @@ public: * */ virtual std::string to_string() const = 0; - virtual ~Value(); + //virtual ~Value(); }; #endif // VALUE_HPP -- GitLab