libqasm
library for handling cQASM files
cqasm-error.hpp
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <string>
8 #include <sstream>
9 #include <vector>
10 #include "cqasm-tree.hpp"
11 #include "cqasm-annotations.hpp"
12 
13 namespace cqasm {
14 
18 namespace error {
19 
27 class AnalysisError : public std::runtime_error {
28 private:
29 
33  mutable std::string msg;
34 
35 public:
36 
41  std::ostringstream message;
42 
46  std::unique_ptr<annotations::SourceLocation> location;
47 
52  explicit AnalysisError(std::string &&message = "", const tree::Annotatable *node = nullptr);
53 
59  void context(const tree::Annotatable &node);
60 
64  const std::string &get_message() const;
65 
69  const char *what() const noexcept override;
70 
71 };
72 
76 #define CQASM_ANALYSIS_ERROR(Name) \
77  class Name : public ::cqasm::error::AnalysisError { \
78  public: \
79  explicit Name( \
80  std::string &&message = "", \
81  const tree::Annotatable *node = nullptr \
82  ) : \
83  ::cqasm::error::AnalysisError(std::move(message), node) \
84  {} \
85  }
86 
87 } // namespace error
88 } // namespace cqasm
const std::string & get_message() const
Constructs the message string.
Definition: cqasm-error.cpp:40
std::ostringstream message
The stringstream used to construct the message.
Definition: cqasm-error.hpp:41
AnalysisError(std::string &&message="", const tree::Annotatable *node=nullptr)
Constructs a new error.
Definition: cqasm-error.cpp:14
Contains annotation objects used within the trees by libqasm.
Toplevel namespace with entry points for the new API.
std::unique_ptr< annotations::SourceLocation > location
Attached location in the source file, if any.
Definition: cqasm-error.hpp:46
Wrapper for pulling parts of tree-gen&#39;s support library into libqasm.
const char * what() const noexcept override
Returns the message exception-style.
Definition: cqasm-error.cpp:54
void context(const tree::Annotatable &node)
Sets the context of this error to the SourceLocation annotation of the given node, if the error doesn&#39;t already have such a context.
Definition: cqasm-error.cpp:29
::tree::annotatable::Annotatable Annotatable
Definition: cqasm-tree.hpp:19
Exception used for analysis errors.
Definition: cqasm-error.hpp:27