diff --git a/include/yaramod/parser/file_context.h b/include/yaramod/parser/file_context.h index 0d1ec8ab..5e51359c 100644 --- a/include/yaramod/parser/file_context.h +++ b/include/yaramod/parser/file_context.h @@ -8,7 +8,7 @@ #include -#include "yaramod/types/location.h" +#include "yaramod/parser/location.h" #include "yaramod/types/token_stream.h" namespace yaramod { diff --git a/include/yaramod/parser/location.h b/include/yaramod/parser/location.h index 669201a9..aaff7221 100644 --- a/include/yaramod/parser/location.h +++ b/include/yaramod/parser/location.h @@ -1,5 +1,5 @@ /** - * @file src/types/location.h + * @file src/parser/location.h * @brief Declaration and Implementation of class Location. * @copyright (c) 2017 Avast Software, licensed under the MIT license */ diff --git a/include/yaramod/types/location.h b/include/yaramod/types/location.h deleted file mode 100644 index 669201a9..00000000 --- a/include/yaramod/types/location.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file src/types/location.h - * @brief Declaration and Implementation of class Location. - * @copyright (c) 2017 Avast Software, licensed under the MIT license - */ - -#pragma once - -#include -#include -#include - -namespace yaramod { - -class Location -{ -public: - Location() : Location(std::string{}) {} - Location(const std::string& filePath) : Location(filePath, 1, 0) {} - Location(const std::string& filePath, std::size_t line, std::size_t column) - : _filePath(filePath), _begin(line, column), _end(line, column) {} - Location(const Location&) = default; - Location(Location&&) noexcept = default; - - Location& operator=(const Location&) = default; - Location& operator=(Location&&) noexcept = default; - - /// @name Modifying methods - /// @{ - void addLine(std::size_t count = 1) - { - std::swap(_begin, _end); - _end.first = _begin.first + count; // line - _end.second = 0; // column - } - - void addColumn(std::size_t count) - { - _begin.first = _end.first; - _begin.second = _end.second; - _end.second += count; - } - - void reset() - { - _begin = {1, 0}; - _end = {1, 0}; - } - /// @} - - /// @name Getters - /// @{ - bool isUnnamed() const { return _filePath == "[stream]"; } - const std::string& getFilePath() const { return _filePath; } - std::pair begin() const { return {_begin.first, _begin.second + 1}; } - const std::pair& end() const { return _end; } - /// @} - - friend std::ostream& operator<<(std::ostream& os, const Location& location) - { - if (!location.isUnnamed()) - os << location.getFilePath() << ':'; - os << location.begin().first << '.' << location.begin().second; - if (location.begin().second < location.end().second) - os << '-' << location.end().second; - return os; - } - -private: - std::string _filePath; - std::pair _begin; // (line, column) - std::pair _end; // (line, column) -}; - -} //namespace yaramod diff --git a/include/yaramod/types/token.h b/include/yaramod/types/token.h index 92d2cbe0..0f695a58 100644 --- a/include/yaramod/types/token.h +++ b/include/yaramod/types/token.h @@ -8,8 +8,8 @@ #include +#include "yaramod/parser/location.h" #include "yaramod/types/literal.h" -#include "yaramod/types/location.h" #include "yaramod/types/token_type.h" #include "yaramod/yaramod_error.h"