OpenASIP  2.0
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  */
69 public:
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 
96 private:
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
AssemblyParserDiagnostic::codeErrors_
std::set< CompilerMessage > codeErrors_
Error messages with line number.
Definition: AssemblyParserDiagnostic.hh:102
ParserStructs.hh
CompilerMessage::message
std::string message
Message.
Definition: AssemblyParserDiagnostic.hh:47
CompilerMessage::assemblerLine
std::string assemblerLine
Assembly code line number.
Definition: AssemblyParserDiagnostic.hh:48
AssemblyParserDiagnostic
Definition: AssemblyParserDiagnostic.hh:68
AssemblyParserDiagnostic::anyErrors
bool anyErrors() const
Definition: AssemblyParserDiagnostic.hh:82
CompilerMessage::lineNumber
UValue lineNumber
Message generation line number.
Definition: AssemblyParserDiagnostic.hh:49
AssemblyParserDiagnostic::otherErrors_
std::set< CompilerMessage > otherErrors_
For positionless and internal errors.
Definition: AssemblyParserDiagnostic.hh:105
UValue
unsigned long UValue
Definition: ParserStructs.hh:44
CompilerMessage
Definition: AssemblyParserDiagnostic.hh:46
AssemblyParserDiagnostic::clear
void clear()
Definition: AssemblyParserDiagnostic.cc:89
AssemblyParserDiagnostic::addError
void addError(UValue lineNumber, const std::string &message)
Definition: AssemblyParserDiagnostic.cc:68
AssemblyParserDiagnostic::otherErrors
const std::set< CompilerMessage > & otherErrors() const
Definition: AssemblyParserDiagnostic.hh:90
AssemblyParserDiagnostic::errors
const std::set< CompilerMessage > & errors() const
Definition: AssemblyParserDiagnostic.hh:86
AssemblyParserDiagnostic::codeLine
std::string codeLine(UValue lineNumber) const
Definition: AssemblyParserDiagnostic.cc:96
AssemblyParserDiagnostic::lineStarts_
std::vector< UValue > lineStarts_
New line start positions in assembly listing.
Definition: AssemblyParserDiagnostic.hh:111
AssemblyParserDiagnostic::warnings_
std::set< CompilerMessage > warnings_
Warning messages.
Definition: AssemblyParserDiagnostic.hh:99
CompilerMessage::operator<
bool operator<(const CompilerMessage &other) const
Definition: AssemblyParserDiagnostic.hh:57
AssemblyParserDiagnostic::addWarning
void addWarning(UValue lineNumber, const std::string &message)
Definition: AssemblyParserDiagnostic.cc:56
AssemblyParserDiagnostic::listing_
std::shared_ptr< const std::string > listing_
The current assembly listing.
Definition: AssemblyParserDiagnostic.hh:108
AssemblyParserDiagnostic::reset
void reset(std::shared_ptr< const std::string > assemblyText)
Definition: AssemblyParserDiagnostic.cc:40
CompilerMessage::toString
std::string toString() const
Definition: AssemblyParserDiagnostic.hh:51
AssemblyParserDiagnostic::warnings
const std::set< CompilerMessage > & warnings() const
Definition: AssemblyParserDiagnostic.hh:78