9 #ifndef ckcontext_hpp__
10 #define ckcontext_hpp__
14 #include <string_view>
25 template< std::
size_t N>
26 using err_string_array = std::array<const char*, N>;
28 template< std::
size_t N>
29 class err_object_base :
public err_string_array<N>
34 template<
typename ... AT>
35 err_object_base(
const char* name, AT && ... at)
36 : err_string_array<N>{std::forward<AT>(at) ...}, name(name)
45 err_object_s(
const char* n,
const char* e0,
const char* e1)
46 : err_object_base<2>{ n, e0, e1 }
56 : err_object_base<1>{ n, e0 }
64 using err_s = std::reference_wrapper<err_def_s>;
69 using err_n = std::reference_wrapper<err_def_n>;
82 extern err_def_s DUPLICATE_FUNCTION_DEFINITION;
83 extern err_def_s DUPLICATE_STRUCT_DEFINITION;
84 extern err_def_s DUPLICATE_ENUM_DEFINITION;
114 struct coverage_counter {
133 using map_t = std::map<std::string, coverage_counter>;
134 using map_element_t = std::pair<const std::string, coverage_counter>;
135 using map_element_obs =
const map_element_t*;
137 struct line_coverage_data {
139 void push(map_element_obs p)
144 template<
typename F>
145 void for_each(F && f)
const
153 std::vector< map_element_obs> v_;
156 using line_map_t = std::map<loc_t, line_coverage_data>;
158 struct coverage_data {
160 void inc(loc_t line, std::string n)
162 auto rv = map_.try_emplace(std::move(n));
163 rv.first->second.inc();
164 auto rvl = line_map_.try_emplace(line);
165 rvl.first->second.push(&*rv.first);
168 template<
typename F>
169 void for_each(F&& f)
const
171 for (
auto&& a : map_)
173 f(a.first, a.second);
177 template<
typename F>
178 void for_each_line(F&& f)
const
180 for (
auto&& a : line_map_)
182 f(a.first, a.second);
187 line_map_t line_map_;
196 context(CKTablesObs tables, std::ostream* outp, coverage::coverage_data * cd) :
CKContext(tables), line_(1), outp_(outp), cd_(cd) {}
198 std::ostream& out() {
return *outp_; }
215 static std::string escape(std::string_view s);
226 void cov(std::string n)
228 cd_->inc(
line(), std::move(n));
234 std::ostream * outp_;
236 coverage::coverage_data * cd_;
err_def_n BAD_NUMBER_OF_ARGUMENTS
Bad number of arguments.
std::reference_wrapper< err_def_n > err_n
Error message without parameters.
Definition: ckcontext.hpp:69
err_def_n NOT_NUMBER
Expression is not a number.
err_def_n INTERNAL
Internal error.
std::reference_wrapper< err_def_s > err_s
Error message with a string parameter.
Definition: ckcontext.hpp:64
err_def_s UNDEF_IDF
Undefined identifier of constant/variable/function.
err_def_n VOIDEXPR
Expression is of void type.
err_def_s SYNTAX
Syntax error.
err_def_n INVALID_SPECIFIERS
Conflicting declaration specifiers.
err_def_n UNTERMCHAR
Unterminated character literal.
err_def_n NOT_NUMBER_OR_POINTER
Expression is not a number or pointer.
err_def_n EOFINSTRCHR
End of file in string/character literal.
err_def_s INTOUTRANGE
Integer literal out of range.
err_def_n INVALID_FUNCTION_TYPE
Invalid function type constructed.
err_def_n UNEXPENDCMT
Unexpected end of comment.
err_def_n EOLINSTRCHR
End of line in string/character literal.
err_def_s BADINT
Malformed integer literal.
err_def_n NOT_POINTER
Expression is not a pointer.
err_def_n EMPTYCHAR
Empty character literal.
err_def_s BADESCAPE
Malformed escape sequence.
err_def_n INVALID_ARRAY_TYPE
Invalid array type constructed.
err_def_s UNCHAR
Invalid character.
err_def_n INCOMPATIBLE
Incompatible operands.
err_def_n EOFINCMT
End of file in comment.
unsigned loc_t
Line number in the compiled source file.
Definition: cktables.hpp:24
Lexical level of compiler context + error messaging.
Definition: ckcontext.hpp:193
void message(errors::err_n err, loc_t loc)
loc_t line() const
Get current line.
Definition: ckcontext.hpp:221
void message(errors::err_s err, loc_t loc, std::string_view msg)
loc_t incline()
Increment current line.
Definition: ckcontext.hpp:222
Error message without parameters.
Definition: ckcontext.hpp:52
Error message with a string parameter.
Definition: ckcontext.hpp:42
Semantic layer of compiler context.
Definition: cktables.hpp:1101