OpenASIP 2.2
Loading...
Searching...
No Matches
AssemblyParserDiagnostic.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002-2017 Tampere University.
3 *
4 * This file is part of TTA-Based Codesign Environment (TCE).
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file AssemblyParserDiagnostic.hh
26 *
27 * Declaration of assembly parser diagnostics.
28 *
29 * @author Henry Linjamäki 2017 (henry.linjamaki-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#ifndef ASSEMBLY_PARSER_DIAGNOSTIC_HH
34#define ASSEMBLY_PARSER_DIAGNOSTIC_HH
35
36#include <string>
37#include <memory>
38#include <set>
39#include <tuple>
40
41#include "ParserStructs.hh"
42
43/**
44 * Struct for parser reports.
45 */
47 std::string message = ""; ///< Message.
48 std::string assemblerLine = ""; ///< Assembly code line number.
49 UValue lineNumber = 0; ///< Message generation line number.
50
51 std::string toString() const {
52 return std::string("Warning in line ") + std::to_string(lineNumber)
53 + ": " + assemblerLine + "\n"
54 + "reason: " + message;
55 }
56
57 bool operator<(const CompilerMessage& other) const {
58 auto mine = std::tie(lineNumber, assemblerLine, message);
59 auto theirs = std::tie(
60 other.lineNumber, other.assemblerLine, other.message);
61 return mine < theirs;
62 }
63};
64
65/**
66 * The class for storing and query assembly parser reports.
67 */
69public:
70 void reset(std::shared_ptr<const std::string> assemblyText);
71
72 void addWarning(UValue lineNumber, const std::string& message);
73 void addError(UValue lineNumber, const std::string& message);
74 void addError(const std::string& message);
75
76 void clear();
77
78 const std::set<CompilerMessage>& warnings() const {
79 return warnings_;
80 }
81
82 bool anyErrors() const {
83 return errors().size() && otherErrors().size();
84 }
85
86 const std::set<CompilerMessage>& errors() const {
87 return codeErrors_;
88 }
89
90 const std::set<CompilerMessage>& otherErrors() const {
91 return otherErrors_;
92 }
93
94 std::string codeLine(UValue lineNumber) const;
95
96private:
97
98 /// Warning messages.
99 std::set<CompilerMessage> warnings_;
100
101 /// Error messages with line number.
102 std::set<CompilerMessage> codeErrors_;
103
104 /// For positionless and internal errors.
105 std::set<CompilerMessage> otherErrors_;
106
107 /// The current assembly listing.
108 std::shared_ptr<const std::string> listing_ = nullptr;
109
110 /// New line start positions in assembly listing.
111 std::vector<UValue> lineStarts_;
112};
113
114#endif // ASSEMBLY_PARSER_DIAGNOSTIC_HH
unsigned long UValue
std::string codeLine(UValue lineNumber) const
std::shared_ptr< const std::string > listing_
The current assembly listing.
std::set< CompilerMessage > otherErrors_
For positionless and internal errors.
std::vector< UValue > lineStarts_
New line start positions in assembly listing.
std::set< CompilerMessage > codeErrors_
Error messages with line number.
const std::set< CompilerMessage > & warnings() const
const std::set< CompilerMessage > & errors() const
void reset(std::shared_ptr< const std::string > assemblyText)
void addWarning(UValue lineNumber, const std::string &message)
const std::set< CompilerMessage > & otherErrors() const
std::set< CompilerMessage > warnings_
Warning messages.
void addError(UValue lineNumber, const std::string &message)
std::string message
Message.
bool operator<(const CompilerMessage &other) const
std::string assemblerLine
Assembly code line number.
UValue lineNumber
Message generation line number.
std::string toString() const