Commit a26edda8 authored by Johnny Jazeix's avatar Johnny Jazeix

Mise en commentaires des dernieres erreurs (celles du fichier Trace.cpp)

Deplacement des fichiers Errors.* dans le dossier Message afin qu'ils 
gerent toutes les erreurs.
parent f98f2815
......@@ -10,7 +10,7 @@ const string Error::_EXPECT_EVENT_DEF = "expected %EventDef";
const string Error::_EXPECT_NAME_DEF = "the definition is not named";
const string Error::_EXPECT_ID_DEF = "the definition is not identified";
const string Error::_EXTRA_TOKEN_IN_DEF = "there are too much token";
const string Error::_UNKNOWN_EVENT = "unknown fields on event ";
const string Error::_UNKNOWN_EVENT_DEF = "unknown fields on event ";
const string Error::_FIELD_TYPE_MISSING = "a field type is missing ";
const string Error::_FIELD_TYPE_UNKNOWN = "a field type is unknown ";
const string Error::_EMPTY_DEF = "a definition line is empty";
......@@ -21,6 +21,19 @@ const string Error::_UNKNOWN_LINE = "the content of the line is unknown, must qu
const string Error::_BAD_FILE_EXTENSION = "the extension of the file is not .trace";
const string Error::_LINE_TOO_LONG_EVENT = "extra token(s)";
const string Error::_UNKNOWN_CONTAINER_TYPE = "Unknown container type : ";
const string Error::_UNKNOWN_CONTAINER = "Unknown container : ";
const string Error::_UNKNOWN_EVENT_TYPE = "Unknown event type : ";
const string Error::_UNKNOWN_EVENT = "Unknown event : ";
const string Error::_UNKNOWN_STATE_TYPE = "Unknown state type : ";
const string Error::_UNKNOWN_VARIABLE_TYPE = "Unknown variable type : ";
const string Error::_UNKNOWN_LINK_TYPE = "Unknown link type : ";
const string Error::_UNKNOWN_ENTITY_TYPE = "Unknown entity type : ";
const string Error::_UNKNOWN_ENTITY_VALUE = "Unknown entity value : ";
string Error::_content = "";
void Error::set(const string kind_of_error, const int priority){
......@@ -71,14 +84,6 @@ void Error::print(const int priority){
}
}
bool Error::set_and_print_if(bool condition, const string kind_of_error, const unsigned int line_number, const int priority){
if(set_if(condition, kind_of_error, line_number, priority)){
print(priority);
return true;
}
return false;
}
void Error::print_numbers(){
*Message::get_instance() << Error::_errors.size() << " errors and " << Error::_warnings.size() << " warnings were found during parsing.";
......
......@@ -10,7 +10,7 @@
#include <queue>
#include <iostream>
#include <fstream>
#include "../message/Message.hpp"
#include "Message.hpp"
/*! \class Error
* \brief Define errors and warnings used in the parser.
......@@ -64,7 +64,7 @@ public:
/*!
* \brief Define the error when an event doesn't match with the event with the same name know by the parser.
*/
const static std::string _UNKNOWN_EVENT;
const static std::string _UNKNOWN_EVENT_DEF;
/*!
* \brief Define the error when missing the type of a field in a definition.
*/
......@@ -102,6 +102,24 @@ public:
*/
const static std::string _LINE_TOO_LONG_EVENT;
//////
/// Errors from undefined entities
//////
const static std::string _UNKNOWN_CONTAINER_TYPE;
const static std::string _UNKNOWN_CONTAINER;
const static std::string _UNKNOWN_EVENT_TYPE;
const static std::string _UNKNOWN_EVENT;
const static std::string _UNKNOWN_STATE_TYPE;
const static std::string _UNKNOWN_VARIABLE_TYPE;
const static std::string _UNKNOWN_LINK_TYPE;
const static std::string _UNKNOWN_ENTITY_TYPE;
const static std::string _UNKNOWN_ENTITY_VALUE;
/*!
* \fn set(const std::string kind_of_error, const int priority) static void
* \brief raise an error or a warning
......@@ -145,17 +163,6 @@ public:
*/
static bool set_if(bool condition, const std::string kind_of_error, const unsigned int line_number, const int priority);
/*!
* \fn set_and_print_if(bool condition, const std::string kind_of_error ,const unsigned int line_number, const int priority) static bool
* \brief raise and throw to the interface an error or a warning and the line when it occurs is the condition is satisfied
* \param condition : a condition
* \param kind_of_error : content of error
* \param line_number : position of the error in the trace
* \param priority : _ERROR or _WARNING
* \return true is the condition is satisfied
*/
static bool set_and_print_if(bool condition, const std::string kind_of_error, const unsigned int line_number, const int priority);
/*!
* \fn print_numbers() static void
* \brief throw to the interface a message about the number of errors and warnings
......
......@@ -22,7 +22,8 @@ void Definition::store(std::string name, std::string type){
void Definition::print() const{
cout << _event_name << endl;
for(unsigned int i = 0 ; i < _fields.size() ; i ++){
const unsigned int field_size = _fields.size();
for(unsigned int i = 0 ; i < field_size ; i ++){
cout << " " << _fields[i]._name << " " << _fields[i]._type << endl;
}
cout << "______" << endl;
......
......@@ -30,8 +30,9 @@ void Line::open(const char *filename){
}
void Line::print() const{
const unsigned int token_size = _tokens.size();
cout << "-" ;
for(unsigned int i = 0 ; i < _tokens.size() ; i ++)
for(unsigned int i = 0 ; i < token_size ; i ++)
cout << _tokens[i] << " " ;
cout << "-" <<endl ;
}
......
......@@ -3,7 +3,7 @@
#include <string>
#include "Errors.hpp"
#include "../message/Errors.hpp"
/*!
* \class Parser Parser.hpp "../parser/src/Parser.hpp"
......
......@@ -12,36 +12,36 @@ int ParserDefinitionDecoder::definitions_number(){
void ParserDefinitionDecoder::enter_definition(Line &line){
Error::set_and_print_if(_state == _IN_A_DEFINITION, Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR);
if(_state == _IN_A_DEFINITION){
Error::set_and_print(Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR);
}
string definition_name;
Error::set_and_print_if(!line.item(2, definition_name), Error::_EXPECT_NAME_DEF, line.get_line_count(), Error::_ERROR);
//DIE_IF(!line.item(2, definition_name), "Error : a definition need a name");
if(!line.item(2, definition_name)){
Error::set_and_print(Error::_EXPECT_NAME_DEF, line.get_line_count(), Error::_ERROR);
}
unsigned int definition_identity;
string definition_identity_string;
if(Error::set_and_print_if(!line.item(3, definition_identity_string),
Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR)){
if(!line.item(3, definition_identity_string)){
Error::set_and_print(Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR);
return;
}
//DIE_IF(!line.item(3, definition_identity_string), "Error : definition has no identifier");
if(Error::set_and_print_if(sscanf(definition_identity_string.c_str(), "%d", &definition_identity) != 1,
Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR)){
if(sscanf(definition_identity_string.c_str(), "%d", &definition_identity) != 1){
Error::set_and_print(Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR);
return;
}
//DIE_IF(sscanf(definition_identity_string.c_str(), "%d", &definition_identity) != 1, "Error : expected identifier for a definition");
Definition current_definition = Definition(definition_name);
_definitions.insert(pair<unsigned int,Definition>(definition_identity, current_definition));
_current_definition = definition_identity;
Error::set_and_print_if(line.length() > 4, Error::_EXTRA_TOKEN_IN_DEF, line.get_line_count(), Error::_WARNING);
//WARN_IF((line.length() > 4), Error::_EXPECT_EVENT_DEF + line_number);
//"Warning : extra token in %EventDef on line << line_number << endl");
if(line.length() > 4){
Error::set_and_print(Error::_EXTRA_TOKEN_IN_DEF, line.get_line_count(), Error::_WARNING);
}
_state = _IN_A_DEFINITION;
return;
......@@ -49,47 +49,40 @@ void ParserDefinitionDecoder::enter_definition(Line &line){
void ParserDefinitionDecoder::leave_definition(Line &line){
if(Error::set_and_print_if(_state != _IN_A_DEFINITION, Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR)){
if(_state != _IN_A_DEFINITION){
Error::set_and_print(Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR);
return;
}
// DIE_IF(_state != _IN_A_DEFINITION, "Error : expected %EventDef");
_state = _OUT_A_DEFINITION;
if(Error::set_and_print_if(!_definitions[_current_definition].check_definition(),
Error::_UNKNOWN_EVENT + _definitions[_current_definition].get_event_name(),
line.get_line_count(), Error::_ERROR)){
if(!_definitions[_current_definition].check_definition()){
Error::set_and_print(Error::_UNKNOWN_EVENT_DEF + _definitions[_current_definition].get_event_name(), line.get_line_count(), Error::_ERROR);
return;
}
//DIE_IF(!_definitions[_current_definition].check_definition(), "Error : unknown event : " + _definitions[_current_definition].get_event_name());
Error::set_and_print_if(line.length() > 2, Error::_EXTRA_TOKEN_IN_DEF, line.get_line_count(), Error::_WARNING);
//WARN_IF(line.length() > 2, "Warning : extra token in %EventDef");
if(line.length() > 2){
Error::set_and_print(Error::_EXTRA_TOKEN_IN_DEF, line.get_line_count(), Error::_WARNING);
}
}
void ParserDefinitionDecoder::add_field_to_definition(std::string& first_token,Line& line){
if(Error::set_and_print_if(_state == _OUT_A_DEFINITION, Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR)){
if(_state == _OUT_A_DEFINITION){
Error::set_and_print(Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR);
return;
}
//DIE_IF(_state == _OUT_A_DEFINITION, "Error : expected %EventDef");
string field_type;
if(Error::set_and_print_if(!line.item(2, field_type), Error::_FIELD_TYPE_MISSING, line.get_line_count(), Error::_ERROR)){
if(!line.item(2, field_type)){
Error::set_and_print(Error::_FIELD_TYPE_MISSING, line.get_line_count(), Error::_ERROR);
return;
}
// DIE_IF(!line.item(2, field_type), "Error : a field type is missing");
if(Error::set_and_print_if(field_type != "string" && field_type != "int" &&
field_type != "hex" && field_type != "date" &&
field_type != "double" && field_type != "color",
Error::_FIELD_TYPE_UNKNOWN, line.get_line_count(),
Error::_ERROR)){
if(field_type != "string" && field_type != "int" && field_type != "hex" &&
field_type != "date" && field_type != "double" && field_type != "color"){
Error::set_and_print(Error::_FIELD_TYPE_UNKNOWN, line.get_line_count(), Error::_ERROR);
return;
}
// DIE_IF(field_type != "string" && field_type != "int" &&
// field_type != "hex" && field_type != "date" &&
// field_type != "double" && field_type != "color"
// , "Error : unknown type");
_definitions[_current_definition].store(first_token, field_type);
}
......@@ -97,11 +90,11 @@ void ParserDefinitionDecoder::add_field_to_definition(std::string& first_token,L
void ParserDefinitionDecoder::store_definition(Line &line){
string first_token;
if(Error::set_and_print_if(!line.item(1, first_token), Error::_EMPTY_DEF, line.get_line_count(), Error::_WARNING)){
if(!line.item(1, first_token)){
Error::set_and_print(Error::_EMPTY_DEF, line.get_line_count(), Error::_WARNING);
return;
}
//DIE_IF(!line.item(1, first_token), "Warning : a definition line is empty");
if (first_token == "EventDef"){
enter_definition(line);
}
......
......@@ -7,8 +7,7 @@
#include "Definition.hpp"
#include "Line.hpp"
#include "Errors.hpp"
//#include "Macros.hpp"
#include "../message/Errors.hpp"
/*!
*
......
......@@ -173,7 +173,13 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
string event_name = definition.get_event_name();
if(event_name == "PajeDefineContainerType") {
trace.define_container_type(alias_name, trace.search_container_type(container_type), extra_fields);
ContainerType *temp_container_type = trace.search_container_type(container_type);
if(temp_container_type == 0 && container_type.to_string() != "0"){
Error::set_and_print(Error::_UNKNOWN_CONTAINER_TYPE + container_type.to_string(), line.get_line_count(), Error::_ERROR);
}
else{
trace.define_container_type(alias_name, temp_container_type, extra_fields);
}
}
else if(event_name == "PajeCreateContainer") {
......
......@@ -7,7 +7,7 @@
#include "Definition.hpp"
#include "Line.hpp"
#include "../trace/values/Values.hpp"
#include "Errors.hpp"
#include "../message/Errors.hpp"
//#ifdef DEBUG_PRINT_TRACE
//#include "../../tests/parser/stub/trace.hpp"
......
......@@ -9,7 +9,6 @@ void ParserPaje::parse(string filename, Trace &trace){
const unsigned int position_of_dot = filename.find_last_of('.');
if(position_of_dot == string::npos || filename.substr(position_of_dot) != ".trace"){
Error::set_and_print(Error::_BAD_FILE_EXTENSION, Error::_WARNING);
//throw Error::_BAD_FILE_EXTENSION;
}
ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder();
......@@ -34,12 +33,11 @@ void ParserPaje::parse(string filename, Trace &trace){
else{
// We check if we have an event identifier
if(Error::set_and_print_if (sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1,
Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR)){
if(sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1){
Error::set_and_print(Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR);
// We flush the errors
Error::flush_in_file("log.txt");
// The line can not be recognised by the parser Paje, we can not continue.
throw Error::_UNKNOWN_LINE;
//return ;
......
......@@ -9,7 +9,7 @@
#include "ParserEventDecoder.hpp"
#include "Parser.hpp"
#include "Line.hpp"
#include "Errors.hpp"
#include "../message/Errors.hpp"
//#ifdef DEBUG_PRINT_TRACE
//#include "../../tests/parser/stub/trace.hpp"
......
......@@ -15,6 +15,7 @@ INCLUDEPATH += . interface message trace trace/values parser
# Input
HEADERS += message/Message.hpp \
message/Errors.hpp \
main_resource.hpp \
interface/interface.hpp \
interface/interface_console.hpp \
......@@ -62,7 +63,7 @@ SOURCES += message/Message.cpp \
interface/render_area.cpp \
interface/render_svg.cpp \
parser/Definition.cpp \
parser/Errors.cpp \
message/Errors.cpp \
parser/Line.cpp \
parser/ParserDefinitionDecoder.cpp \
parser/ParserEventDecoder.cpp \
......
......@@ -201,7 +201,7 @@ ContainerType *Trace::search_container_type(String name) const {
return r;
}
*Message::get_instance() << "Unknown container type: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown container type: " << name.to_string() << Message::ende;
return 0;
}
......@@ -218,8 +218,8 @@ Container *Trace::search_container(String name) const {
if (r)
return r;
}
*Message::get_instance() << "Unknown container: " << name.to_string() << Message::ende;
//*Message::get_instance() << "Unknown container: " << name.to_string() << Message::ende;
return 0;
}
......@@ -231,7 +231,7 @@ EventType *Trace::search_event_type(String name) const {
return *it;
}
*Message::get_instance() << "Unknown event: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown event: " << name.to_string() << Message::ende;
return 0;
}
......@@ -243,7 +243,7 @@ StateType *Trace::search_state_type(String name) const {
return *it;
}
*Message::get_instance() << "Unknown state type: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown state type: " << name.to_string() << Message::ende;
return 0;
}
......@@ -255,7 +255,7 @@ VariableType *Trace::search_variable_type(String name) const {
return *it;
}
*Message::get_instance() << "Unknown variable type: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown variable type: " << name.to_string() << Message::ende;
return 0;
}
......@@ -267,7 +267,7 @@ LinkType *Trace::search_link_type(String name) const {
return *it;
}
*Message::get_instance() << "Unknown link type: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown link type: " << name.to_string() << Message::ende;
return 0;
}
......@@ -291,7 +291,7 @@ EntityType *Trace::search_entity_type(String name) const {
return *it;
}
*Message::get_instance() << "Unknown entity type: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown entity type: " << name.to_string() << Message::ende;
return 0;
}
......@@ -307,7 +307,7 @@ EntityValue *Trace::search_entity_value(String name) const {
}
}
*Message::get_instance() << "Unknown entity value: " << name.to_string() << Message::ende;
// *Message::get_instance() << "Unknown entity value: " << name.to_string() << Message::ende;
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment