Commit cd0907f9 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

tests sur le parser qui marchent (de toute facon on les publie pas?)

configure qui  marche sur les mac de l'enseirb
parent 62baf874
......@@ -40,11 +40,16 @@ if "$WHICH" qmake-qt4 >/dev/null 2>&1 ; then
cat >> "$makefile" <<EOF
cd ./src && qmake-qt4 -makefile -o Makefile src.pro && make
EOF
elif "$WHICH" qmake >/dev/null 2>&1 && [ UNAME_SYSTEM = "Darwin" ] ; then # Mac
cat >> "$makefile" <<EOF
cd src/ && qmake -spec macx-xcode src.pro && xcodebuild -project Makefile.xcode\
proj -configuration Debug clean build
EOF
elif "$WHICH" qmake >/dev/null 2>&1 ; then
cat >> "$makefile" <<EOF
cd ./src && qmake -makefile -o Makefile src.pro && make
EOF
elif "$WHICH" qmake-mac >/dev/null 2>&1 ; then
elif "$WHICH" qmake-mac >/dev/null 2>&1 ; then # Mac the return
cat >> "$makefile" <<EOF
cd ./src && qmake-mac -makefile -o Makefile src.pro && make
EOF
......
......@@ -539,7 +539,7 @@ void Interface_graphic::on_about_triggered(){
"Under the CeCILL A licence. The content can be found <a href=\"http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\">here</a>."
"<p><b>Developers:</b><ul><li>Kevin COULOMB</li><li>Johnny JAZEIX</li><li>Olivier LAGRASSE</li><li>Jule MARCOUEILLE</li><li>Pascal NOISETTE</li><li>Arthur REDONDY</li><li>Cl&eacute;ment VUCHENER</li></ul></p>"
"This software was made for a school engineering project for INRIA researchers.<br />"
"The main page project is: <a href=\"https://gforge.inria.fr/projects/vite/\">https://gforge.inria.fr/projects/vite/</a>.<br /><br />"));
"The main page project is: <a href=\"http://vite.gforge.inria.fr/\">http://vite.gforge.inria.fr/</a>.<br /><br />"));
}
......
......@@ -9,6 +9,8 @@ ParserPaje::ParserPaje(){
void ParserPaje::parse(string filename, Trace &trace){
set_file_to_parse(filename);
const unsigned int position_of_dot = filename.find_last_of('.');
if(position_of_dot == string::npos || filename.substr(position_of_dot) != ".trace"){
Error::set(Error::_BAD_FILE_EXTENSION, Error::_WARNING);
......
......@@ -8,7 +8,12 @@
#include <string>
#include <iostream>
#include "../message/Errors.hpp"
#ifndef VITE_DEBUG
#include "../message/Errors.hpp"
#else
// For debugging
#include "../../tests/stubs/Errors.hpp"
#endif
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES) // They do not have mmap
#define BUFFER_SIZE 2048
......
......@@ -24,10 +24,10 @@ all: make_src test_token test_ligne test_parser_definition test_parser_evenement
make_src: Message.o Errors.o $(OBJECT_FILE)
test_token: test_token.cpp
$(CXX) $(CXXFLAGS) $< -o $@ $(TEST_FLAGS) $(INCPATH) $(BIN_DIR)TokenSource.o $(BIN_DIR)Message.o
$(CXX) $(CXXFLAGS) $< -o $@ $(TEST_FLAGS) $(INCPATH) $(BIN_DIR)TokenSource.o $(BIN_DIR)Message.o $(BIN_DIR)Errors.o
test_ligne: test_ligne.cpp
$(CXX) $(CXXFLAGS) $< -o $@ $(TEST_FLAGS) $(INCPATH) $(BIN_DIR)Line.o $(BIN_DIR)TokenSource.o $(BIN_DIR)Message.o
$(CXX) $(CXXFLAGS) $< -o $@ $(TEST_FLAGS) $(INCPATH) $(BIN_DIR)Line.o $(BIN_DIR)TokenSource.o $(BIN_DIR)Message.o $(BIN_DIR)Errors.o
test_parser_definition: test_parser_definition.cpp
$(CXX) $(CXXFLAGS) $< -o $@ $(OBJECT_FILE_BIN) $(TEST_FLAGS) $(INCPATH)
......@@ -66,7 +66,7 @@ String.o: ../stubs/String.cpp ../stubs/String.hpp
$(CXX) -c $(CXXFLAGS) $< -o $(BIN_DIR)$@ $(TEST_FLAGS)
Errors.o: ../../src/message/Errors.cpp ../../src/message/Errors.hpp
Errors.o: ../stubs/Errors.cpp ../stubs/Errors.hpp
$(CXX) -c $(CXXFLAGS) $< -o $(BIN_DIR)$@ $(TEST_FLAGS)
......
......@@ -58,7 +58,6 @@ int main(int argc, char** argv){
//parserdefinition->print_definitions();
cout << "lu :" << linecount << endl;
Message::kill();
delete parserdefinition;
delete parserevent;
return EXIT_SUCCESS;
......
......@@ -2,39 +2,45 @@
using namespace std;
std::queue<std::string> Error::_errors;
std::queue<std::string> Error::_warnings;
queue<string> Error::_errors;
queue<string> Error::_warnings;
const int Error::_EVERYTHING = 0;
const int Error::_WARNING = 1;
const int Error::_ERROR = 2;
string Error::_content = "";
const string Error::_PARSE = "expected \" before end of file";
const string Error::_MMAP = "mmap error";
const string Error::_EMPTY_FILE = "empty file";
const string Error::_FSTAT = "status file error";
const string Error::_OPEN = "open file error";
const string Error::_MUNMAP = "munmap error";
const string Error::_EXPECT_END_DEF = "expected %EndEventDef";
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_DEF = "unknown fields on event ";
const string Error::_UNKNOWN_ID_DEF = "there is no definition with the identity: ";
const string Error::_EXTRA_TOKEN = "extra token(s) ignored";
const string Error::_UNKNOWN_EVENT_DEF = "the following event doesn't match with any event known: ";
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::_FIELD_TYPE_UNKNOWN = "the following field type is unknown: ";
const string Error::_EMPTY_DEF = "a definition line is empty";
const string Error::_INCOMPATIBLE_VALUE_IN_EVENT = "incompatible value : ";
const string Error::_UNKNOWN_TYPE_IN_EVENT = "unknown type : ";
const string Error::_UNKNOWN_EVENT_IN_PARSER_DEF_NOT_FOUND = "unknown field for the event. Should have been found on the definition parser : ";
const string Error::_UNKNOWN_LINE = "the content of the line is unknown, must quit";
const string Error::_INCOMPATIBLE_VALUE_IN_EVENT = "incompatible value: ";
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 : ";
int Error::_priority_printable_min;
const string Error::_LINE_TOO_SHORT_EVENT = "missing field value(s) in an event";
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_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: ";
string Error::_content = "";
void Error::set(const string kind_of_error, const int priority){
Error::_content = kind_of_error;
......@@ -48,6 +54,12 @@ void Error::set(const string kind_of_error, const int priority){
}
}
void Error::set(const string kind_of_error, const unsigned int line_number, const int priority){
char line[10];
sprintf(line, "%d", line_number);
set(kind_of_error + " on line " + line, priority);
}
void Error::set_and_print(const string kind_of_error, const int priority){
set(kind_of_error, priority);
print(priority);
......@@ -72,23 +84,63 @@ bool Error::set_if(bool condition, const string kind_of_error, const unsigned in
}
void Error::print(const int priority){
cout << "print ";
void Error::print(const int priority) {
cerr << _content;
switch(priority){
case _WARNING:
cout << "warning" << endl;
cerr << " warning" << endl;
break;
default:
cout << "error" << endl;
default: // Include the _ERROR
cerr << " error" << endl;
break;
}
}
void Error::print(const string content, const int priority) {
cerr << content;
switch(priority){
case _WARNING:
cerr << " warning" << endl;
break;
default: // Include the _ERROR
cerr << " error" << endl;
break;
}
}
void Error::print_numbers(){
cout << "print_numbers" << endl;
cerr << Error::_errors.size() << " errors and " << Error::_warnings.size() << " warnings were found during parsing.";
if(Error::_warnings.size() == 0 && Error::_errors.size() == 0){
cerr << " info" << endl;
}
else if(Error::_errors.size() == 0){
cerr << " warning" << endl;
}
else{
cerr << " error" << endl;
}
}
void Error::flush_in_file(const string &filename){
cout << "flush in file : " << filename << endl;
void Error::flush(const string &filename){
if(_errors.empty() && _warnings.empty()) {
return;
}
else {
const int number_of_errors = Error::_errors.size();
const int number_of_warnings = Error::_warnings.size();
// Print the errors
while(!_errors.empty()) {
_errors.pop();
}
while(!_warnings.empty()) {
_warnings.pop();
}
cerr << endl << "Your trace has " << number_of_errors << " errors and " << number_of_warnings << " warnings." << endl;
}
}
......@@ -7,9 +7,9 @@
**/
#include <string>
#include <queue>
#include <iostream>
#include <fstream>
#include <queue>
/*! \class Error
* \brief Define errors and warnings used in the parser.
......@@ -19,8 +19,6 @@ private:
Error();
static int _line_error;
static int _priority_printable_min;
static std::queue<std::string> _errors;
static std::queue<std::string> _warnings;
static std::string _content;
......@@ -33,22 +31,46 @@ public:
/*!
* \brief Define the priority _ERROR.
*/
const static int _EVERYTHING = 0;
const static int _EVERYTHING;
/*!
* \brief Define the priority _WARNING.
*/
const static int _WARNING = 1;
const static int _WARNING;
/*!
* \brief Define the priority _ERROR.
*/
const static int _ERROR = 2;
const static int _ERROR;
/*
* Kind of errors known
*/
/*!
* \brief Define the error when expected the character " (before the end of the file).
*/
const static std::string _PARSE;
/*!
* \brief Define the error when the mmap function fails.
*/
const static std::string _MMAP;
/*!
* \brief Define the error when the file is empty.
*/
const static std::string _EMPTY_FILE;
/*!
* \brief Define the error when the fstat function fails.
*/
const static std::string _FSTAT;
/*!
* \brief Define the error when the open function fails.
*/
const static std::string _OPEN;
/*!
* \brief Define the error when the munmap function fails.
*/
const static std::string _MUNMAP;
/*!
* \brief Define the error when missing the end of a definition.
*/
......@@ -66,9 +88,13 @@ public:
*/
const static std::string _EXPECT_ID_DEF;
/*!
* \brief Define the error when some extra characters are ignored at the end of a line in a definition.
* \brief Define the error when the identity of a definition doesn't match with any definition defined.
*/
const static std::string _UNKNOWN_ID_DEF;
/*!
* \brief Define the error when some extra tokens are ignored at the end of a line.
*/
const static std::string _EXTRA_TOKEN_IN_DEF;
const static std::string _EXTRA_TOKEN;
/*!
* \brief Define the error when an event doesn't match with the event with the same name know by the parser.
*/
......@@ -78,7 +104,7 @@ public:
*/
const static std::string _FIELD_TYPE_MISSING;
/*!
* \brief Define the error when the type of a field in a definition is not recognized by the parser.
* \brief Define the error when the type of a field in not recognized by the parser.
*/
const static std::string _FIELD_TYPE_UNKNOWN;
/*!
......@@ -89,42 +115,53 @@ public:
* \brief Define the error when a value don't match with its type.
*/
const static std::string _INCOMPATIBLE_VALUE_IN_EVENT;
/*!
* \brief Define the error when a type is not reconized by the parser.
*/
const static std::string _UNKNOWN_TYPE_IN_EVENT;
/*!
* \brief Define the error when an event is not reconized by the parser.
*/
const static std::string _UNKNOWN_EVENT_IN_PARSER_DEF_NOT_FOUND;
/*!
* \brief Define the error when the parser can't parse a line.
*/
const static std::string _UNKNOWN_LINE;
/*!
* \brief Define the error when the file which has to be parse doesn't have the right extension.
*/
const static std::string _BAD_FILE_EXTENSION;
/*!
* \brief Define the error when some extra characters are ignored at the end of the line event.
* \brief Define the error when some field values are missing for an event.
*/
const static std::string _LINE_TOO_LONG_EVENT;
const static std::string _LINE_TOO_SHORT_EVENT;
//////
/// Errors from undefined entities
//////
/*!
* \brief Define the error when a container type does not exist.
*/
const static std::string _UNKNOWN_CONTAINER_TYPE;
/*!
* \brief Define the error when a containere does not exist.
*/
const static std::string _UNKNOWN_CONTAINER;
/*!
* \brief Define the error when an event type does not exist.
*/
const static std::string _UNKNOWN_EVENT_TYPE;
const static std::string _UNKNOWN_EVENT;
/*!
* \brief Define the error when a state type does not exist.
*/
const static std::string _UNKNOWN_STATE_TYPE;
/*!
* \brief Define the error when a variable type does not exist.
*/
const static std::string _UNKNOWN_VARIABLE_TYPE;
/*!
* \brief Define the error when a link type does not exist.
*/
const static std::string _UNKNOWN_LINK_TYPE;
/*!
* \brief Define the error when a entity type does not exist.
*/
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
* \param kind_of_error : content of error
......@@ -132,7 +169,9 @@ public:
*/
static void set(const std::string kind_of_error, const int priority);
/*!
static void set(const std::string kind_of_error, const unsigned int line_number, const int priority);
/*!
* \fn set_and_print(const std::string kind_of_error, const int priority) static void
* \brief raise and throw to the interface an error or a warning
* \param kind_of_error : content of error
......@@ -140,7 +179,7 @@ public:
*/
static void set_and_print(const std::string kind_of_error, const int priority);
/*!
/*!
* \fn set_and_print(const std::string kind_of_error, const unsigned int line_number, const int priority) static void
* \brief raise and throw to the interface an error or a warning and the line when it occurs
* \param kind_of_error : content of error
......@@ -149,14 +188,22 @@ public:
*/
static void set_and_print(const std::string kind_of_error, const unsigned int line_number, const int priority);
/*!
/*!
* \fn print(const int priority) static void
* \brief print the current error
* \param priority : _ERROR or _WARNING
*/
static void print(const int priority);
/*!
/*!
* \fn print(const std::string content, const int priority) static void
* \brief print the current error
* \param content : the string we want to print
* \param priority : _ERROR or _WARNING
*/
static void print(const std::string content, const int priority);
/*!
* \fn set_if(bool condition, const std::string kind_of_error, const unsigned int line_number, const int priority) static bool
* \brief raise an error or a warning and the line when it occurs if the condition is satisfied
* \param condition : a condition
......@@ -167,18 +214,19 @@ public:
*/
static bool set_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
*/
static void print_numbers();
/*!
* \fn flush_in_file(const std::string &filename) static void
/*!
* \fn flush(const std::string &filename) static void
* \brief print all the errors and warnings saved in a file and empty the queues _errors and _warnings
* \param filename : a file path
*/
static void flush_in_file(const std::string &filename);
static void flush(const std::string &filename);
};
#endif // ERRORS_HPP
......@@ -323,23 +323,28 @@ void Trace::end_link(Date &time, LinkType *type, Container *ancestor, Container
Container *Trace::search_container_type(String name){
string *res = new string("search(" + name.to_string() + ")");
Container *Trace::search_container_type(String name) const{
string *res = new string((string)"search(" + name.to_string() + ")");
to_freed.push_back(res);
return res;
}
Container *Trace::search_container(String name){
string* res = new string("search(" + name + ")");
Container *Trace::search_container(String name) const{
string* res = new string((string)"search(" + name.to_string() + ")");
to_freed.push_back(res);
return res;
}
Container *Trace::search_container(string name) const{
string* res = new string((string)"search(" + name + ")");
to_freed.push_back(res);
return res;
}
Container *Trace::search_event_type(String name){
string* res = new string("search(" + name.to_string() + ")");
string* res = new string((string)"search(" + name.to_string() + ")");
to_freed.push_back(res);
return res;
}
......@@ -363,21 +368,25 @@ VariableType *Trace::search_variable_type(String name){
LinkType *Trace::search_link_type(String name){
string* res = new string("search(" + name.to_string() + ")");
string* res = new string((string)"search(" + name.to_string() + ")");
to_freed.push_back(res);
return res;
}
EntityValue *Trace::search_entity_value(String name){
string* res = new string("search(" + name.to_string() + ")");
EntityValue *Trace::search_entity_value(String name, EntityType *entity_type) const{
string* res = new string((string)"search(" + name.to_string() + ")");
to_freed.push_back(res);
return res;
}
EntityType *Trace::search_entity_type(String name){
string* res = new string("search(" + name.to_string() + ")");
EntityType *Trace::search_entity_type(String name) const{
string* res = new string((string)"search(" + name.to_string() + ")");
to_freed.push_back(res);
return res;
}
void Trace::finish(){
cout << "finish" << endl;
}
......@@ -36,8 +36,8 @@ typedef std::string LinkType;
class Trace{
private:
std::vector<std::string*> to_freed;
void free_str();
mutable std::vector<std::string*> to_freed;
void free_str();
public :
......@@ -286,7 +286,7 @@ public :
* \brief search a container type by his name or alias
*
*/
Container *search_container_type(String name) ;
Container *search_container_type(String name) const;
/*!
*
......@@ -294,7 +294,14 @@ public :
* \brief search a container by his name or alias
*
*/
Container *search_container(String name) ;
Container *search_container(String name) const;
/*!
*
* \fn search_container
* \brief search a container by his name or alias
*
*/
Container *search_container(std::string name) const;
/*!
*
......@@ -335,8 +342,10 @@ public :
* \brief search a container by his name or alias
*
*/
EntityValue *search_entity_value(String name) ;
EntityType *search_entity_type(String name) ;
EntityValue *search_entity_value(String name, EntityType *entity_type) const;
EntityType *search_entity_type(String name) const;
void finish();
};//end class
......
Supports Markdown
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