aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/SourceReferenceFormatter.h
blob: 7dea5254e1b1497fd9801029a6693273c7e77d85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
    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 <http://www.gnu.org/licenses/>.
*/
/**
 * @author Christian <c@ethdev.com>
 * @date 2014
 * Formatting functions for errors referencing positions and locations in the source.
 */

#pragma once

#include <ostream>
#include <sstream>
#include <functional>

namespace langutil
{
struct SourceLocation;
class Scanner;
}

namespace dev
{

struct Exception; // forward

namespace solidity
{

class CompilerStack; // forward

class SourceReferenceFormatter
{
public:
    using ScannerFromSourceNameFun = std::function<langutil::Scanner const&(std::string const&)>;

    explicit SourceReferenceFormatter(
        std::ostream& _stream,
        ScannerFromSourceNameFun _scannerFromSourceName
    ):
        m_stream(_stream),
        m_scannerFromSourceName(std::move(_scannerFromSourceName))
    {}

    /// Prints source location if it is given.
    void printSourceLocation(langutil::SourceLocation const* _location);
    void printExceptionInformation(Exception const& _exception, std::string const& _name);

    static std::string formatExceptionInformation(
        Exception const& _exception,
        std::string const& _name,
        ScannerFromSourceNameFun const& _scannerFromSourceName
    )
    {
        std::ostringstream errorOutput;

        SourceReferenceFormatter formatter(errorOutput, _scannerFromSourceName);
        formatter.printExceptionInformation(_exception, _name);
        return errorOutput.str();
    }
private:
    /// Prints source name if location is given.
    void printSourceName(langutil::SourceLocation const* _location);

    std::ostream& m_stream;
    ScannerFromSourceNameFun m_scannerFromSourceName;
};

}
}
nsertions'>+1 * - Welcome X.org 7.2 \o/.flz2007-05-201-0/+1 * Update to 4.4.1.marcus2007-04-091-1/+1 * Presenting GNOME 2.18 for FreeBSD. GNOME 2.18 is a departure from recent GNOMEmarcus2007-03-191-2/+3 * Update to 4.2.2.marcus2006-11-211-1/+1 * Presenting GNOME 2.16.1 for FreeBSD. This release represents a massivemarcus2006-10-141-5/+5 * Update to 4.0.4.marcus2006-08-011-1/+1 * Update to 4.0.3.marcus2006-07-311-1/+1 * Presenting GNOME 2.14.1 for FreeBSD! Checkoutmarcus2006-04-301-8/+6 * Conversion to a single libtool environment.ade2006-02-231-10/+1 * - Bump $PORTREVISION for libexpat shlib bump.kuriyama2006-02-061-0/+2 * Switch to <target>:: convention for both patch-autotools and run-autotools,ade2005-11-191-1/+1 * Mass-conversion to the USE_AUTOTOOLS New World Order. The code presentade2005-11-151-1/+1 * Presenting GNOME 2.12 for FreeBSD. The release is chock full of bug fixesmarcus2005-11-051-2/+2 * Revert previous commit since 3.2.18 requires the newer GTK+. It wouldmarcus2005-09-061-1/+2 * Update to 3.2.18.kwm2005-09-061-1/+1