Merge pull request #1924 from joakim-hove/keyword-location
Keyword location
This commit is contained in:
commit
60f6c26456
@ -516,7 +516,7 @@ list( APPEND PUBLIC_HEADER_FILES
|
||||
opm/common/OpmLog/LogUtil.hpp
|
||||
opm/common/OpmLog/MessageFormatter.hpp
|
||||
opm/common/OpmLog/MessageLimiter.hpp
|
||||
opm/common/OpmLog/Location.hpp
|
||||
opm/common/OpmLog/KeywordLocation.hpp
|
||||
opm/common/OpmLog/OpmLog.hpp
|
||||
opm/common/OpmLog/StreamLog.hpp
|
||||
opm/common/OpmLog/TimerLog.hpp
|
||||
|
@ -17,39 +17,48 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_HPP
|
||||
#define LOCATION_HPP
|
||||
#ifndef KEYWORD_LOCATION_HPP
|
||||
#define KEYWORD_LOCATION_HPP
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class Location {
|
||||
class KeywordLocation {
|
||||
public:
|
||||
std::string keyword;
|
||||
std::string filename = "<memory string>";
|
||||
std::size_t lineno = 0;
|
||||
|
||||
Location() = default;
|
||||
Location(std::string fname, std::size_t lno) :
|
||||
KeywordLocation() = default;
|
||||
KeywordLocation(std::string kw, std::string fname, std::size_t lno) :
|
||||
keyword(std::move(kw)),
|
||||
filename(std::move(fname)),
|
||||
lineno(lno)
|
||||
{}
|
||||
|
||||
static Location serializeObject()
|
||||
std::string message() const {
|
||||
return this->keyword + " in " + this->filename + " at line " + std::to_string(this->lineno);
|
||||
}
|
||||
|
||||
static KeywordLocation serializeObject()
|
||||
{
|
||||
Location result;
|
||||
KeywordLocation result;
|
||||
result.keyword = "KW";
|
||||
result.filename = "test";
|
||||
result.lineno = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool operator==(const Location& data) const {
|
||||
return filename == data.filename &&
|
||||
bool operator==(const KeywordLocation& data) const {
|
||||
return keyword == data.keyword &&
|
||||
filename == data.filename &&
|
||||
lineno == data.lineno;
|
||||
}
|
||||
|
||||
template<class Serializer>
|
||||
void serializeOp(Serializer& serializer)
|
||||
{
|
||||
serializer(keyword);
|
||||
serializer(filename);
|
||||
serializer(lineno);
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -59,8 +59,8 @@ namespace Log {
|
||||
|
||||
|
||||
bool isPower2(int64_t x);
|
||||
std::string fileMessage(const Location& location, const std::string& msg);
|
||||
std::string fileMessage(int64_t messageType , const Location& location , const std::string& msg);
|
||||
std::string fileMessage(const KeywordLocation& location, const std::string& msg);
|
||||
std::string fileMessage(int64_t messageType , const KeywordLocation& location , const std::string& msg);
|
||||
std::string prefixMessage(int64_t messageType , const std::string& msg);
|
||||
std::string colorCodeMessage(int64_t messageType , const std::string& msg);
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <opm/parser/eclipse/Deck/DeckValue.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||
#include <opm/parser/eclipse/Deck/value_status.hpp>
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
namespace Opm {
|
||||
class DeckOutput;
|
||||
@ -43,7 +43,7 @@ namespace Opm {
|
||||
|
||||
DeckKeyword();
|
||||
explicit DeckKeyword(const ParserKeyword& parserKeyword);
|
||||
DeckKeyword(const Location& location, const std::string& keywordName);
|
||||
DeckKeyword(const KeywordLocation& location, const std::string& keywordName);
|
||||
DeckKeyword(const ParserKeyword& parserKeyword, const std::vector<std::vector<DeckValue>>& record_list, UnitSystem& system_active, UnitSystem& system_default);
|
||||
DeckKeyword(const ParserKeyword& parserKeyword, const std::vector<int>& data);
|
||||
DeckKeyword(const ParserKeyword& parserKeyword, const std::vector<double>& data, UnitSystem& system_active, UnitSystem& system_default);
|
||||
@ -52,7 +52,7 @@ namespace Opm {
|
||||
|
||||
const std::string& name() const;
|
||||
void setFixedSize();
|
||||
const Location& location() const;
|
||||
const KeywordLocation& location() const;
|
||||
|
||||
|
||||
size_t size() const;
|
||||
@ -105,7 +105,7 @@ namespace Opm {
|
||||
|
||||
private:
|
||||
std::string m_keywordName;
|
||||
Location m_location;
|
||||
KeywordLocation m_location;
|
||||
|
||||
std::vector< DeckRecord > m_recordList;
|
||||
bool m_isDataKeyword;
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -77,7 +77,7 @@ enum class Comparator {
|
||||
|
||||
|
||||
Condition() = default;
|
||||
Condition(const std::vector<std::string>& tokens, const Location& location);
|
||||
Condition(const std::vector<std::string>& tokens, const KeywordLocation& location);
|
||||
|
||||
|
||||
Quantity lhs;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <opm/io/eclipse/SummaryNode.hpp>
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -43,7 +43,7 @@ namespace Opm {
|
||||
using Type = Opm::EclIO::SummaryNode::Type;
|
||||
|
||||
SummaryConfigNode() = default;
|
||||
explicit SummaryConfigNode(std::string keyword, const Category cat, Location loc_arg);
|
||||
explicit SummaryConfigNode(std::string keyword, const Category cat, KeywordLocation loc_arg);
|
||||
|
||||
static SummaryConfigNode serializeObject();
|
||||
|
||||
@ -62,7 +62,7 @@ namespace Opm {
|
||||
const std::string& fip_region() const { return this->fip_region_; }
|
||||
|
||||
std::string uniqueNodeKey() const;
|
||||
const Location& location( ) const { return this->loc; }
|
||||
const KeywordLocation& location( ) const { return this->loc; }
|
||||
|
||||
operator Opm::EclIO::SummaryNode() const {
|
||||
return { keyword_, category_, type_, name_, number_, fip_region_ };
|
||||
@ -84,7 +84,7 @@ namespace Opm {
|
||||
private:
|
||||
std::string keyword_;
|
||||
Category category_;
|
||||
Location loc;
|
||||
KeywordLocation loc;
|
||||
Type type_{ Type::Undefined };
|
||||
std::string name_{};
|
||||
int number_{std::numeric_limits<int>::min()};
|
||||
|
@ -32,7 +32,7 @@ namespace Log {
|
||||
|
||||
|
||||
|
||||
std::string fileMessage(const Location& location, const std::string& message) {
|
||||
std::string fileMessage(const KeywordLocation& location, const std::string& message) {
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << message << "\n" << "In file " << location.filename << ", line " << location.lineno << "\n";
|
||||
@ -40,7 +40,7 @@ namespace Log {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string fileMessage(int64_t messageType , const Location& location, const std::string& message) {
|
||||
std::string fileMessage(int64_t messageType , const KeywordLocation& location, const std::string& message) {
|
||||
return fileMessage( location , prefixMessage( messageType , message ));
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <opm/output/eclipse/Summary.hpp>
|
||||
|
||||
#include <opm/common/OpmLog/OpmLog.hpp>
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
|
||||
|
@ -38,7 +38,7 @@ namespace Opm {
|
||||
{
|
||||
}
|
||||
|
||||
DeckKeyword::DeckKeyword(const Location& location, const std::string& keywordName) :
|
||||
DeckKeyword::DeckKeyword(const KeywordLocation& location, const std::string& keywordName) :
|
||||
m_keywordName(keywordName),
|
||||
m_location(location),
|
||||
m_isDataKeyword(false),
|
||||
@ -56,7 +56,7 @@ namespace Opm {
|
||||
{
|
||||
DeckKeyword result;
|
||||
result.m_keywordName = "test";
|
||||
result.m_location = Location::serializeObject();
|
||||
result.m_location = KeywordLocation::serializeObject();
|
||||
result.m_recordList = {DeckRecord::serializeObject()};
|
||||
result.m_isDataKeyword = true;
|
||||
result.m_slashTerminated = true;
|
||||
@ -153,7 +153,7 @@ namespace Opm {
|
||||
setDataKeyword();
|
||||
if (parser_item.dataType() != type_tag::integer)
|
||||
throw std::invalid_argument("Input to DeckKeyword '" + name() + "': cannot be std::vector<int>.");
|
||||
|
||||
|
||||
DeckItem item(parser_item.name(), int() );
|
||||
for (int val : data)
|
||||
item.push_back(val);
|
||||
@ -199,7 +199,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
const Location& DeckKeyword::location() const {
|
||||
const KeywordLocation& DeckKeyword::location() const {
|
||||
return this->m_location;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ void Quantity::add_arg(const std::string& arg) {
|
||||
this->args.push_back(strip_quotes(arg));
|
||||
}
|
||||
|
||||
Condition::Condition(const std::vector<std::string>& tokens, const Location& location) {
|
||||
Condition::Condition(const std::vector<std::string>& tokens, const KeywordLocation& location) {
|
||||
this->lhs = Quantity(tokens[0]);
|
||||
std::size_t token_index = 1;
|
||||
|
||||
|
@ -297,7 +297,7 @@ inline void keywordW( SummaryConfig::keyword_list& list,
|
||||
|
||||
inline void keywordW( SummaryConfig::keyword_list& list,
|
||||
const std::string& keyword,
|
||||
Location loc,
|
||||
KeywordLocation loc,
|
||||
const Schedule& schedule) {
|
||||
auto param = SummaryConfigNode {
|
||||
keyword, SummaryConfigNode::Category::Well , std::move(loc)
|
||||
@ -354,7 +354,7 @@ inline void keywordW( SummaryConfig::keyword_list& list,
|
||||
|
||||
inline void keywordG( SummaryConfig::keyword_list& list,
|
||||
const std::string& keyword,
|
||||
Location loc,
|
||||
KeywordLocation loc,
|
||||
const Schedule& schedule ) {
|
||||
auto param = SummaryConfigNode {
|
||||
keyword, SummaryConfigNode::Category::Group, std::move(loc)
|
||||
@ -405,7 +405,7 @@ inline void keywordG( SummaryConfig::keyword_list& list,
|
||||
|
||||
inline void keywordF( SummaryConfig::keyword_list& list,
|
||||
const std::string& keyword,
|
||||
Location loc) {
|
||||
KeywordLocation loc) {
|
||||
auto param = SummaryConfigNode {
|
||||
keyword, SummaryConfigNode::Category::Field, std::move(loc)
|
||||
}
|
||||
@ -505,7 +505,7 @@ inline void keywordR( SummaryConfig::keyword_list& list,
|
||||
|
||||
inline void keywordMISC( SummaryConfig::keyword_list& list,
|
||||
const std::string& keyword,
|
||||
Location loc)
|
||||
KeywordLocation loc)
|
||||
{
|
||||
if (meta_keywords.find(keyword) == meta_keywords.end())
|
||||
list.emplace_back( keyword, SummaryConfigNode::Category::Miscellaneous , std::move(loc));
|
||||
@ -798,7 +798,7 @@ inline void keywordMISC( SummaryConfig::keyword_list& list,
|
||||
|
||||
inline void handleKW( SummaryConfig::keyword_list& list,
|
||||
const std::string& keyword,
|
||||
Location loc,
|
||||
KeywordLocation loc,
|
||||
const Schedule& schedule,
|
||||
const ParseContext& parseContext,
|
||||
ErrorGuard& errors) {
|
||||
@ -858,7 +858,7 @@ SummaryConfigNode::Category parseKeywordCategory(const std::string& keyword) {
|
||||
}
|
||||
|
||||
|
||||
SummaryConfigNode::SummaryConfigNode(std::string keyword, const Category cat, Location loc_arg) :
|
||||
SummaryConfigNode::SummaryConfigNode(std::string keyword, const Category cat, KeywordLocation loc_arg) :
|
||||
keyword_(std::move(keyword)),
|
||||
category_(cat),
|
||||
loc(std::move(loc_arg))
|
||||
@ -869,7 +869,7 @@ SummaryConfigNode SummaryConfigNode::serializeObject()
|
||||
SummaryConfigNode result;
|
||||
result.keyword_ = "test1";
|
||||
result.category_ = Category::Region;
|
||||
result.loc = Location::serializeObject();
|
||||
result.loc = KeywordLocation::serializeObject();
|
||||
result.type_ = Type::Pressure;
|
||||
result.name_ = "test2";
|
||||
result.number_ = 2;
|
||||
|
@ -936,7 +936,7 @@ bool parseState( ParserState& parserState, const Parser& parser ) {
|
||||
}
|
||||
} else {
|
||||
const std::string msg = "The keyword " + rawKeyword->getKeywordName() + " is not recognized - ignored";
|
||||
Location location(parserState.current_path().string(), parserState.line());
|
||||
KeywordLocation location(rawKeyword->getKeywordName(), parserState.current_path().string(), parserState.line());
|
||||
OpmLog::warning(Log::fileMessage(location, msg));
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace {
|
||||
|
||||
RawKeyword::RawKeyword(const std::string& name, const std::string& filename, std::size_t lineNR, bool raw_string, Raw::KeywordSizeEnum sizeType, std::size_t size_arg) :
|
||||
m_name(keyword_name(name)),
|
||||
m_location(filename, lineNR),
|
||||
m_location(name, filename, lineNR),
|
||||
raw_string_keyword(raw_string),
|
||||
m_sizeType(sizeType)
|
||||
{
|
||||
@ -136,7 +136,7 @@ namespace {
|
||||
return m_isFinished;
|
||||
}
|
||||
|
||||
const Location& RawKeyword::location() const {
|
||||
const KeywordLocation& RawKeyword::location() const {
|
||||
return this->m_location;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
#include "RawEnums.hpp"
|
||||
#include "RawConsts.hpp"
|
||||
@ -51,7 +51,7 @@ namespace Opm {
|
||||
bool isFinished() const;
|
||||
bool unKnownSize() const;
|
||||
bool rawStringKeyword() const;
|
||||
const Location& location() const;
|
||||
const KeywordLocation& location() const;
|
||||
|
||||
using const_iterator = std::vector< RawRecord >::const_iterator;
|
||||
using iterator = std::vector< RawRecord >::iterator;
|
||||
@ -63,7 +63,7 @@ namespace Opm {
|
||||
std::size_t size() const;
|
||||
private:
|
||||
std::string m_name;
|
||||
Location m_location;
|
||||
KeywordLocation m_location;
|
||||
bool raw_string_keyword;
|
||||
Raw::KeywordSizeEnum m_sizeType;
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <opm/common/utility/TimeService.hpp>
|
||||
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
|
||||
@ -674,7 +674,7 @@ BOOST_AUTO_TEST_CASE(TestFieldAND) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Conditions) {
|
||||
auto location = Location("File", 100);
|
||||
auto location = KeywordLocation("Keyword", "File", 100);
|
||||
|
||||
// Missing comparator
|
||||
BOOST_CHECK_THROW(Action::Condition cond({"WWCT", "OPX"}, location), std::invalid_argument);
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <opm/common/OpmLog/TimerLog.hpp>
|
||||
#include <opm/common/OpmLog/StreamLog.hpp>
|
||||
#include <opm/common/OpmLog/LogUtil.hpp>
|
||||
#include <opm/common/OpmLog/Location.hpp>
|
||||
#include <opm/common/OpmLog/KeywordLocation.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(DoLogging) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Test_Format) {
|
||||
BOOST_CHECK_EQUAL( "There is an error here?\nIn file /path/to/file, line 100\n" , Log::fileMessage(Location("/path/to/file" , 100) , "There is an error here?"));
|
||||
BOOST_CHECK_EQUAL( "There is an error here?\nIn file /path/to/file, line 100\n" , Log::fileMessage(KeywordLocation("Keyword", "/path/to/file" , 100) , "There is an error here?"));
|
||||
|
||||
BOOST_CHECK_EQUAL( "\nError: This is the error" , Log::prefixMessage(Log::MessageType::Error , "This is the error"));
|
||||
BOOST_CHECK_EQUAL( "\nWarning: This is the warning" , Log::prefixMessage(Log::MessageType::Warning , "This is the warning"));
|
||||
@ -252,8 +252,8 @@ BOOST_AUTO_TEST_CASE(TestHelperFunctions)
|
||||
BOOST_CHECK(isPower2(1ul << 62));
|
||||
|
||||
// fileMessage
|
||||
BOOST_CHECK_EQUAL(fileMessage(Location("foo/bar", 1), "message"), "message\nIn file foo/bar, line 1\n");
|
||||
BOOST_CHECK_EQUAL(fileMessage(MessageType::Error, Location("foo/bar", 1), "message"), "\nError: message\nIn file foo/bar, line 1\n");
|
||||
BOOST_CHECK_EQUAL(fileMessage(KeywordLocation("Keyword", "foo/bar", 1), "message"), "message\nIn file foo/bar, line 1\n");
|
||||
BOOST_CHECK_EQUAL(fileMessage(MessageType::Error, KeywordLocation("Keyword", "foo/bar", 1), "message"), "\nError: message\nIn file foo/bar, line 1\n");
|
||||
|
||||
// prefixMessage
|
||||
BOOST_CHECK_EQUAL(prefixMessage(MessageType::Error, "message"), "\nError: message");
|
||||
|
Loading…
Reference in New Issue
Block a user