Gyoji Compiler
Loading...
Searching...
No Matches
errors.hpp
1/* Copyright 2025 Jonathan S. Arney
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://github.com/jarney/gyoji/blob/master/LICENSE
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#pragma once
16
17#include <string>
18#include <vector>
19#include <memory>
20
21#include <gyoji-misc/pointers.hpp>
22#include <gyoji-context/source-reference.hpp>
23
24namespace Gyoji::context {
25
26 class Errors;
27 class Error;
28 class ErrorMessage;
29
39 public:
41 const SourceReference & _src_ref,
42 std::string _errormsg
43 );
49 void print();
54 const SourceReference & get_source_ref() const;
58 const std::string & get_message() const;
68 size_t get_line() const;
69 private:
71 SourceReference src_ref;
72 std::string errormsg;
73 };
74
90 class Error {
91 public:
97 Error(std::string _error_title);
101 ~Error();
106 void add_message(const SourceReference & _src_ref,
107 std::string _errormsg);
114 void print();
119 size_t size() const;
123 const ErrorMessage & get(size_t n) const;
128 private:
130 std::string error_title;
131 };
132
133 class TokenStream;
134
145 class Errors {
146 public:
153 Errors(TokenStream & _token_stream);
157 ~Errors();
161 void add_error(Gyoji::owned<Error> error);
169 void add_simple_error(
170 const SourceReference & src_ref,
171 std::string _error_title,
172 std::string _error_message
173 );
179 void print() const;
183 size_t size() const;
187 const Error & get(size_t n) const;
188 private:
190 const TokenStream & token_stream;
191 };
192
193};
Message about a specific location in the code.
Definition errors.hpp:38
size_t get_line() const
Definition errors.cpp:145
void add_context(const std::vector< std::pair< size_t, std::string > > &_context)
Definition errors.cpp:133
const SourceReference & get_source_ref() const
Definition errors.cpp:137
void print()
Definition errors.cpp:225
const std::string & get_message() const
Definition errors.cpp:141
An error reported during compilation.
Definition errors.hpp:90
void add_message(const SourceReference &_src_ref, std::string _errormsg)
Definition errors.cpp:83
~Error()
Definition errors.cpp:70
size_t size() const
Definition errors.cpp:112
const ErrorMessage & get(size_t n) const
Definition errors.cpp:116
const std::vector< Gyoji::owned< ErrorMessage > > & get_messages() const
Definition errors.cpp:108
void print()
Definition errors.cpp:73
Container for errors reported.
Definition errors.hpp:145
size_t size() const
Definition errors.cpp:55
void add_simple_error(const SourceReference &src_ref, std::string _error_title, std::string _error_message)
Definition errors.cpp:96
void add_error(Gyoji::owned< Error > error)
Definition errors.cpp:39
void print() const
Definition errors.cpp:28
const Error & get(size_t n) const
Definition errors.cpp:61
~Errors()
Definition errors.cpp:24
References a location in the source-file.
Definition source-reference.hpp:30
Stream of tokens read by the parser to provide context for errors.
Definition token-stream.hpp:120
The context namespace deals with objects that should last the entire scope of compilation.
Definition gyoji-context.hpp:30