From 073b03d90c8f0648ba135f0b30d8e72fd871478f Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Fri, 30 Nov 2018 14:34:08 +0100 Subject: liblangutil: refactor SourceReferenceFormatter, splitting out retrieval and making use of new SourceLocation's CharStream knowledge --- liblangutil/SourceReferenceExtractor.h | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 liblangutil/SourceReferenceExtractor.h (limited to 'liblangutil/SourceReferenceExtractor.h') diff --git a/liblangutil/SourceReferenceExtractor.h b/liblangutil/SourceReferenceExtractor.h new file mode 100644 index 00000000..0be7e9d8 --- /dev/null +++ b/liblangutil/SourceReferenceExtractor.h @@ -0,0 +1,74 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +#pragma once + +#include +#include +#include +#include + +namespace dev +{ +struct Exception; +} + +namespace langutil +{ + +struct LineColumn +{ + int line; + int column; + + LineColumn(std::tuple const& _t): line{std::get<0>(_t)}, column{std::get<1>(_t)} {} + LineColumn(int _line, int _column): line{_line}, column{_column} {} + LineColumn(): line{-1}, column{-1} {} +}; + +struct SourceReference +{ + std::string message; ///< A message that relates to this source reference (such as a warning or an error message). + std::string sourceName; ///< Underlying source name (for example the filename). + LineColumn position; ///< Actual (error) position this source reference is surrounding. + bool multiline; ///< Indicates whether the actual SourceReference is truncated to one line. + std::string text; ///< Extracted source code text (potentially truncated if multiline or too long). + int startColumn; ///< Highlighting range-start of text field. + int endColumn; ///< Highlighting range-end of text field. + + /// Constructs a SourceReference containing a message only. + static SourceReference MessageOnly(std::string _msg) + { + return SourceReference{std::move(_msg), "", LineColumn{-1, -1}, false, "", -1, -1}; + } +}; + +struct SourceLocation; + +namespace SourceReferenceExtractor +{ + struct Message + { + SourceReference primary; + std::string category; // "Error", "Warning", ... + std::vector secondary; + }; + + Message extract(dev::Exception const& _exception, std::string _category); + SourceReference extract(SourceLocation const* _location, std::string message = ""); +} + +} -- cgit v1.2.3 From 62fe57479e7d8949e4ed2e0efb31238d5d8d6d0a Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 12 Dec 2018 14:51:22 +0100 Subject: make use of C++ `= default` constructor declarations as well as more non-static member initialization syntax. --- liblangutil/SourceReferenceExtractor.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'liblangutil/SourceReferenceExtractor.h') diff --git a/liblangutil/SourceReferenceExtractor.h b/liblangutil/SourceReferenceExtractor.h index 0be7e9d8..bcbc50bc 100644 --- a/liblangutil/SourceReferenceExtractor.h +++ b/liblangutil/SourceReferenceExtractor.h @@ -31,28 +31,29 @@ namespace langutil struct LineColumn { - int line; - int column; + int line = {-1}; + int column = {-1}; + LineColumn() = default; LineColumn(std::tuple const& _t): line{std::get<0>(_t)}, column{std::get<1>(_t)} {} - LineColumn(int _line, int _column): line{_line}, column{_column} {} - LineColumn(): line{-1}, column{-1} {} }; struct SourceReference { - std::string message; ///< A message that relates to this source reference (such as a warning or an error message). - std::string sourceName; ///< Underlying source name (for example the filename). - LineColumn position; ///< Actual (error) position this source reference is surrounding. - bool multiline; ///< Indicates whether the actual SourceReference is truncated to one line. - std::string text; ///< Extracted source code text (potentially truncated if multiline or too long). - int startColumn; ///< Highlighting range-start of text field. - int endColumn; ///< Highlighting range-end of text field. + std::string message; ///< A message that relates to this source reference (such as a warning or an error message). + std::string sourceName; ///< Underlying source name (for example the filename). + LineColumn position; ///< Actual (error) position this source reference is surrounding. + bool multiline = {false}; ///< Indicates whether the actual SourceReference is truncated to one line. + std::string text; ///< Extracted source code text (potentially truncated if multiline or too long). + int startColumn = {-1}; ///< Highlighting range-start of text field. + int endColumn = {-1}; ///< Highlighting range-end of text field. /// Constructs a SourceReference containing a message only. static SourceReference MessageOnly(std::string _msg) { - return SourceReference{std::move(_msg), "", LineColumn{-1, -1}, false, "", -1, -1}; + SourceReference sref; + sref.message = std::move(_msg); + return sref; } }; -- cgit v1.2.3