Commit 97f45323 authored by Johnny Jazeix's avatar Johnny Jazeix

Merge of the new_parser branch.

parent 96f4fa39
......@@ -80,6 +80,8 @@ OTFLIB_DIR = ./src/general/otf
all:
make -C \$(OTFLIB_DIR)
rm -rf \$(OTFLIB_DIR)/otflib/.libs/*so*
rm -rf \$(OTFLIB_DIR)/otflib/.libs/*dylib* # For mac
EOF
if "$WHICH" qmake-qt4 >/dev/null 2>&1 ; then
......
......@@ -162,6 +162,9 @@ bool Interface_console::draw_trace(const string & filename, const int format){
else if(filename.substr(position_of_dot) == ".otf") {
parser = new ParserOTF();
}
else if(filename.substr(position_of_dot) == ".ept") {
parser = new ParserVite();
}
else {
Error::set(Error::_BAD_FILE_EXTENSION, Error::_WARNING);
parser = new ParserPaje();
......@@ -254,8 +257,6 @@ bool Interface_console::draw_trace(const string & filename, const int format){
}
}
parser->reinit_cursor();
Error::print_numbers();
Error::flush("log.txt");
......
......@@ -68,6 +68,7 @@ class Interface_console;
#include "../trace/DrawTrace.hpp"
#include "../parser/ParserPaje.hpp"
#include "../parser/ParserOTF.hpp"
#include "../parser/ParserVite.hpp"
#include "resource.hpp"
......
......@@ -41,6 +41,7 @@
**
*/
#include "Definition.hpp"
#include <QObject>
using namespace std;
......@@ -55,7 +56,6 @@ Definition::Definition(string& eventname){
_event_name = eventname;
}
void Definition::store(string name, string type){
Field e;
......
......@@ -54,7 +54,6 @@
#include <string>
#include <set>
#include <map>
#include <QObject>
/*! \struct Field Definition.hpp "../parser/Definition.hpp"
* \brief Contains the name and the type of a definition element.
......@@ -107,7 +106,7 @@ public:
/*!
* \fn Definition(std::string &eventname)
* \brief constructor
* \param eventname : the name of the new Definition
* \param eventname : the name of the new Definition
*/
Definition(std::string &eventname);
......
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
**
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
**
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
**
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
** - JAZEIX Johnny
** - LAGRASSE Olivier
** - MARCOUEILLE Jule
** - NOISETTE Pascal
** - REDONDY Arthur
** - VUCHENER Clément
**
*/
#include <QFile>
#include "File.hpp"
#include "Line.hpp"
#include <QFileInfo>
using namespace std;
File::File() {
_current_line = 0;
_filesize = 0.;
_filename = "";
_buffer = "";
_cursor = 0;
_count = 0;
}
void File::open(string filename) {
_filename = filename;
close();
_file.open(filename.c_str(), ios::in);
_file.seekg (0, ios::end);
_filesize = _file.tellg();
_file.seekg (0, ios::beg);
}
File::~File() {
close();
}
void File::get_line(Line &line) {
string content = "";
_current_line ++;
if(_cursor == 0) {
fill_buffer();
}
_cursor = _buffer.find_first_of('\n');
if(_cursor == string::npos || _cursor >= _count) {
// We have to refill the buffer
content = _buffer;
fill_buffer();
}
_cursor = _buffer.find_first_of('\n')+1;
content += _buffer.substr(0, _cursor);
_buffer = _buffer.substr(_cursor);
try {
line = content;
}
catch(char *e) {
return;
}
line.set_line_number(_current_line);
}
void File::fill_buffer() {
_buffer.clear();
_file.read(_buffer_char, _BUFFER_SIZE-1);
_count = _file.gcount();
_buffer_char[_count] = '\0';
_buffer = _buffer_char;
}
bool File::is_eof() const {
return (_file.eof() && _cursor >= _count && _buffer == "\0");
}
void File::close() {
if(_file.is_open()) {
_file.close();
}
}
bool File::is_opened() {
return _file.is_open();
}
bool File::is_a_file() {
return QFileInfo(QString::fromStdString(_filename)).isFile();
}
float File::get_size_loaded() const {
if(_filesize != 0) {
return (float)_file.tellg() / (float)_filesize;
}
else {
return 0.;
}
}
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
**
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
**
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
**
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
** - JAZEIX Johnny
** - LAGRASSE Olivier
** - MARCOUEILLE Jule
** - NOISETTE Pascal
** - REDONDY Arthur
** - VUCHENER Clément
**
*/
/*!
*\file File.hpp
*/
#ifndef FILE_HPP
#define FILE_HPP
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
class Line;
/*! \class File File.hpp "../source/src/parser/File.hpp"
* \brief File object stand for paje format syntax unit .
*/
class File{
private:
mutable std::ifstream _file; // mutable to get the size
std::string _filename;
unsigned int _current_line;
int _filesize;
static const int _BUFFER_SIZE = 2048;
char _buffer_char[_BUFFER_SIZE];
std::string _buffer;
unsigned int _cursor;
unsigned int _count;
void fill_buffer();
public:
/*!
* \brief Constructor for the file
*/
File();
/*!
* \brief Constructor for the file
* \param filename : a filename
*/
File(std::string &filename);
/*!
* \brief Destructor
* Destroy the file
*/
~File();
/*!
* \fn open()
* \brief Open the file
* \param filename the file name
*/
void open(std::string filename);
/*!
* \fn close()
* \brief Close the file if already opened
*/
void close();
/*!
* \fn get_line()
* \brief Get the next line.
* \return the next line
*/
void get_line(Line &);
/*!
* \fn is_eof() const
* \brief test if file ended
* \return true if more files are available
*/
bool is_eof() const;
/*!
* \fn is_opened()
* \brief test if file is opened
* \return true if the file is opened
*/
bool is_opened();
/*!
* \fn is_a_file()
* \brief test if file is a file
* \return true if the file is a file
*/
bool is_a_file();
/*!
* \fn get_size_loaded() const;
* \return the scale of the size already loaded of the file by the parser. (between 0 and 1)
*/
float get_size_loaded() const;
};
#endif // FILE_HPP
......@@ -44,81 +44,130 @@
using namespace std;
Line::Line(){
Line::Line() {
_line_count = 0;
}
Line::Line(Line &){
Line::Line(const Line &l) {
_tokens = l._tokens;
_line_count = l._line_count;
}
Line::Line(string &filename){
open(filename.c_str());
Line::Line(string &string_line) {
fill_line(string_line);
}
Line::~Line(){
if(!_tokens.empty()){
_tokens.clear();
}
}
void Line::open(const char *filename){
_line_count = 0;
_source.open(filename);
_is_eof = false;
}
void Line::fill_line(const std::string &string_line) {
// We split the string_line in tokens
string current_token = "\0";
void Line::print() const{
const unsigned int token_size = _tokens.size();
cout << "-" ;
for(unsigned int i = 0 ; i < token_size ; i ++)
cout << _tokens[i] << " " ;
cout << "-" << endl;
char char_read = '\0';
for(int i = 0 ; char_read != '\n' ; i ++) {
char_read = string_line[i];
if(char_read == '\n') {
continue;
}
if(char_read == '%') {
_tokens.push_back("%");
current_token = "\0"; // Reinitialisation
continue;
}
if(char_read == '\'' || char_read == '"') {
int a = build_composite_token(string_line, i);
i += a;
current_token = "\0"; // Reinitialisation
continue;
}
if((char_read == ' ' || char_read == '\t')) {
// We store the token
if(current_token != "\0") {
_tokens.push_back(current_token);
current_token = "\0"; // Reinitialisation
}
continue;
}
current_token += char_read;
}
if(current_token != "\0") {
_tokens.push_back(current_token);
current_token = "\0"; // Reinitialisation
}
}
bool Line::starts_with(const string &s) const{
bool Line::starts_with(const string &s) const {
if(!_tokens.empty())
return _tokens[0] == s;
else // tokens is empty
return false;
}
bool Line::item(unsigned int i, string &e) const{
bool Line::item(unsigned int i, string &e) const {
if (i >= _tokens.size())
return false;
e = _tokens[i];
return true;
}
unsigned int Line::length() const{
unsigned int Line::length() const {
return _tokens.size();
}
void Line::set_line_number(const unsigned int n) {
_line_count = n;
}
void Line::clear(){
_tokens.clear();
}
bool Line::is_eof() const{
return _is_eof;
void Line::print() const {
const unsigned int token_size = _tokens.size();
cout << "-" ;
for(unsigned int i = 0 ; i < token_size ; i ++)
cout << _tokens[i] << " " ;
cout << "-" << endl;
}
void Line::newline(){
if(!_tokens.empty()){
clear();
}
string *tok;
_line_count++;
while ((tok = _source.read_token()) != NULL){
unsigned int Line::get_line_count() const {
return _line_count;
}
int Line::build_composite_token(string line, int index) {
string token;
int i = index+1;
char current_char = line[i];
int position = 0;
if (*tok == "\n"){
return;
do {
current_char = line[i];
if(current_char == '\"' || current_char == '\'') {
continue;
}
_tokens.push_back(*tok);
}
_is_eof = true;
}
unsigned int Line::get_line_count() const{
return _line_count;
if(current_char == '\0') {
throw "overflow in buffer";
}
token += current_char;
i ++;
position ++;
} while(current_char != '\"' && current_char != '\'' && current_char != '\n');
_tokens.push_back(token);
return i-index;
}
......@@ -53,10 +53,6 @@
#include <iostream>
#include <fstream>
#include "TokenSource.hpp"
/*! \class Line Line.hpp "../source/src/parser/Line.hpp"
* \brief Line object stand for paje format syntax unit .
*/
......@@ -66,9 +62,6 @@ class Line{
private:
std::vector<std::string> _tokens;
TokenSource::TokenSource _source; // TokenSource namespaced for windows support
bool _is_eof;
unsigned int _line_count;
void clear();
......@@ -83,13 +76,13 @@ public:
* \brief Constructor for the line
* \param l A reference of the line to be copied
*/
Line(Line &l);
Line(const Line &l);
/*!
* \brief Constructor for the line
* \param filename : a filename
* \param string_line : a filename
*/
Line(std::string &filename);
Line(std::string &string_line);
/*!
* \brief Destructor
......@@ -97,6 +90,13 @@ public:
*/
~Line();
/*!
* \fn fill_line(const std::string &string_line)
* \brief Split the string into tokens
* \param s string to be splitted
*/
void fill_line(const std::string &string_line);
/*!
* \fn starts_with(const std::string &s) const
* \param s : a string
......@@ -104,30 +104,6 @@ public:
*/
bool starts_with(const std::string &s) const;
/*!
* \fn is_eof() const
* \brief test if file ended
* \return true if more lines are available
*/
bool is_eof() const;
/*!
* \fn newline()
* \brief step to the next line of the file, a call to eof is required before newline()
*
*/
void newline();
/*!
* \fn operator==(const Line &l) const
* \brief true if the lines contains the same items
* \param l the line we want to check if it is equal to this
* \return true if the lines are equals
*
*/
bool operator==(const Line &l) const;
/*!
* \fn item(unsigned int i, std::string &e) const
* \brief the ith token in the line
......@@ -137,14 +113,6 @@ public:
*/
bool item(unsigned int i, std::string &e) const;
/*!
* \fn print() const
* \brief print the line
* Useful for debug.
*
*/
void print() const;
/*!
* \fn length() const
* \brief number of token
......@@ -156,17 +124,31 @@ public:
* \fn get_line_count() const
* \brief read line amount
* \return the number of lines already read.
*
*/
unsigned int get_line_count() const;
/*!
* \fn open(const char *filename)
* \brief open a file
* \param filename valid filename
* \fn set_line_number(const unsigned int n)
* \brief set the number of the line
* \param n the number of the line
*/
void open(const char *filename);
void set_line_number(const unsigned int n);
/*!
* \fn build_composite_token(std::string line, int index)
* \brief create a token within "" or ''
* \param line the line containing the token
* \param index from where we start to read the line
* \return the number of char read
*/
int build_composite_token(std::string line, int index);
/*!
* \fn print() const
* \brief print the line
* Useful for debug.
*/
void print() const;
};
#endif // LINE_HPP
......@@ -70,13 +70,14 @@ public:
* \fn parse(std::string filename, Trace &trace) = 0
* \param filename the name of the file to parse
* \param trace the structure of data to fill
* \param finish_trace_after_parse boolean set if we do not have to finish the trace after parsing
*/
virtual void parse(std::string filename, Trace &trace) = 0;
virtual void parse(std::string filename, Trace &trace, bool finish_trace_after_parse = true) = 0;
virtual ~Parser() {};
/*!
* \fn const int get_size_loaded() const = 0;
* \fn get_size_loaded() const = 0;
* \return the scale of the size already loaded of the file by the parser. (between 0 and 1)
*/
virtual float get_size_loaded() const = 0;
......@@ -101,13 +102,6 @@ public:
*/
virtual void set_file_to_parse(const std::string filename) = 0;
/*!
* \fn reinit_cursor()
* \brief reinitialize the cursor of TokenSource
* Useful for the thread of advancement.
*/
virtual void reinit_cursor() = 0;
/*!
* \fn finish()
* \brief set the end of the parsing
......
......@@ -42,6 +42,8 @@
*/
#include "ParserDefinitionOTF.hpp"
#include "../trace/Trace.hpp"
#include "../trace/values/Color.hpp"
using namespace std;
......
......@@ -51,10 +51,11 @@
#include <fstream>
#include <map>
#include <set>
#include "../trace/Trace.hpp"
#include "../trace/values/Color.hpp"
#include "otf.h"
class Trace;
class Color;
/*!
* \struct Process
* \brief Contains the definition of a process (equivalent in Paje : Container)
......
......@@ -41,6 +41,8 @@
**
*/
#include "ParserDefinitionPaje.hpp"
#include "Definition.hpp"
#include "Line.hpp"
using namespace std;
......
......@@ -51,9 +51,6 @@
#include <fstream>
#include <map>
#include "Definition.hpp"
#include "Line.hpp"
#ifndef VITE_DEBUG
#include "../message/Errors.hpp"
#else
......@@ -61,6 +58,9 @@