Skip to content

Commit

Permalink
Issue #54: file-parser: Pass File object in onFile
Browse files Browse the repository at this point in the history
Makes it easier to extend with other information.
  • Loading branch information
SimonKagstrom committed Jan 29, 2015
1 parent 53e254c commit d00367e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/engines/bash-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class BashEngine : public ScriptEngineBase
for (FileListenerList_t::const_iterator it = m_fileListeners.begin();
it != m_fileListeners.end();
++it)
(*it)->onFile(filename, IFileParser::FLG_NONE);
(*it)->onFile(File(filename, IFileParser::FLG_NONE));

parseFile(filename);
}
Expand Down
6 changes: 3 additions & 3 deletions src/engines/gcov-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ class GcovEngine : public IEngine, IFileParser::IFileListener
}

// From IFileParser::IFileListener
void onFile(const std::string &file, enum IFileParser::FileFlags flags)
void onFile(const IFileParser::File &file)
{
if (!(flags & IFileParser::FLG_TYPE_COVERAGE_DATA))
if (!(file.m_flags & IFileParser::FLG_TYPE_COVERAGE_DATA))
return;

m_gcdaFiles.push_back(file);
m_gcdaFiles.push_back(file.m_filename);
}

FileList_t m_gcdaFiles;
Expand Down
2 changes: 1 addition & 1 deletion src/engines/python-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class PythonEngine : public ScriptEngineBase
for (FileListenerList_t::const_iterator it = m_fileListeners.begin();
it != m_fileListeners.end();
++it)
(*it)->onFile(p->filename, IFileParser::FLG_NONE);
(*it)->onFile(File(p->filename, IFileParser::FLG_NONE));

parseFile(p->filename);
}
Expand Down
17 changes: 16 additions & 1 deletion src/include/file-parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ namespace kcov
HITS_UNLIMITED, //< Accumulated (Python/bash)
};

/**
* Holder class for files (e.g., ELF binaries)
*/
class File
{
public:
File(const std::string &filename, const enum FileFlags flags = FLG_NONE) :
m_filename(filename), m_flags(flags)
{
}

const std::string m_filename;
const enum FileFlags m_flags;
};

virtual ~IFileParser() {}

/**
Expand All @@ -50,7 +65,7 @@ namespace kcov
class IFileListener
{
public:
virtual void onFile(const std::string &file, enum FileFlags flags) = 0;
virtual void onFile(const File &file) = 0;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/merge-file-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class MergeParser :
}

// From IFileParser::IFileListener
void onFile(const std::string &file, enum FileFlags flags)
void onFile(const IFileParser::File &file)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/output-handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ namespace kcov
}

// From IElf::IFileListener
void onFile(const std::string &file, enum IFileParser::FileFlags flags)
void onFile(const IFileParser::File &file)
{
// Only unmarshal the main file
if (flags & IFileParser::FLG_TYPE_SOLIB)
if (file.m_flags & IFileParser::FLG_TYPE_SOLIB)
return;

if (!m_unmarshalData) {
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/elf-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ElfInstance : public IFileParser
for (FileListenerList_t::const_iterator it = m_fileListeners.begin();
it != m_fileListeners.end();
++it)
(*it)->onFile(m_filename, m_isMainFile ? IFileParser::FLG_NONE : IFileParser::FLG_TYPE_SOLIB);
(*it)->onFile(File(m_filename, m_isMainFile ? IFileParser::FLG_NONE : IFileParser::FLG_TYPE_SOLIB));

// After the first, all other are solibs
m_isMainFile = false;
Expand Down Expand Up @@ -481,7 +481,7 @@ class ElfInstance : public IFileParser
for (FileListenerList_t::const_iterator it = m_fileListeners.begin();
it != m_fileListeners.end();
++it)
(*it)->onFile(file, IFileParser::FLG_TYPE_COVERAGE_DATA);
(*it)->onFile(File(file, IFileParser::FLG_TYPE_COVERAGE_DATA));
}
}

Expand Down

0 comments on commit d00367e

Please sign in to comment.