libcsdbg  1.28
C++ exception (and generic) stack trace debug library
void csdbg::parser::on_lib_load ( )
staticprotected

Library constructor.

Attention
If an exception occurs, its details are printed to the standard output and the process exits

Definition at line 26 of file parser.cpp.

References add_dictionary(), add_style(), csdbg::style::BOLD, csdbg::style::clone(), csdbg::string::cstr(), csdbg::util::dbg_info(), HLT_FILE_FG, HLT_FUNCTION_FG, HLT_KEYWORD_FG, HLT_NUMBER_FG, HLT_SCOPE_FG, HLT_TYPE_FG, m_default, m_fallback, parser(), csdbg::util::prefix(), csdbg::string::set(), csdbg::style::set_attr_enabled(), csdbg::style::set_fgcolor(), and csdbg::style::set_name().

27 {
28  try {
29  /* Create the default parser */
30  m_default = new parser;
31 
32  /*
33  * Equip the default parser with dictionaries for C++ keywords, intrinsic
34  * types and file extensions
35  */
36  string path("%s/etc/keywords.dict", util::prefix());
37  m_default->add_dictionary("keywords", path.cstr(), false);
38 
39  path.set("%s/etc/types.dict", util::prefix());
40  m_default->add_dictionary("types", path.cstr(), false);
41 
42  path.set("%s/etc/extensions.dict", util::prefix());
43  m_default->add_dictionary("extensions", path.cstr(), true);
44 
45  /*
46  * Create the default, fallback style. When a highlighter can't determine or
47  * create/obtain the correct style for a token, it uses the fallback
48  */
49  m_fallback = new style("fallback");
50 
51  /* Add styles for all kinds of trace tokens to the default parser */
52  style *s = m_fallback->clone();
53  s->set_name("delimiter");
54  m_default->add_style(s);
55 
56  s = m_fallback->clone();
57  s->set_name("number");
59  s->set_attr_enabled(style::BOLD, true);
60  m_default->add_style(s);
61 
62  s = m_fallback->clone();
63  s->set_name("keyword");
65  m_default->add_style(s);
66 
67  s = m_fallback->clone();
68  s->set_name("type");
70  s->set_attr_enabled(style::BOLD, true);
71  m_default->add_style(s);
72 
73  s = m_fallback->clone();
74  s->set_name("file");
76  m_default->add_style(s);
77 
78  s = m_fallback->clone();
79  s->set_name("scope");
81  m_default->add_style(s);
82 
83  s = m_fallback->clone();
84  s->set_name("function");
86  s->set_attr_enabled(style::BOLD, true);
87  m_default->add_style(s);
88 
89  util::dbg_info("default C++ stack trace parser/highlighter initialized");
90  return;
91  }
92 
93  catch (exception &x) {
94  std::cerr << x;
95  }
96 
97  catch (std::exception &x) {
98  std::cerr << x;
99  }
100 
101  exit(EXIT_FAILURE);
102 }
#define HLT_NUMBER_FG
Highlighter color for numbers (any base)
Definition: config.hpp:309
#define HLT_KEYWORD_FG
Highlighter color for C++ keywords.
Definition: config.hpp:314
virtual style & set_attr_enabled(attrset_t, bool)
Enable/disable a set of text formatting attributes.
Definition: style.cpp:237
virtual style * clone() const
Object virtual copy constructor.
Definition: style.cpp:74
virtual style & set_fgcolor(color_t)
Set the foreground color.
Definition: style.cpp:158
#define HLT_FILE_FG
Highlighter color for C++ files.
Definition: config.hpp:324
static parser * m_default
Default parser.
Definition: parser.hpp:35
#define HLT_TYPE_FG
Highlighter color for C++ intrinsic types.
Definition: config.hpp:319
virtual style & set_name(const i8 *)
Set the style name.
Definition: style.cpp:134
virtual style * add_style(const i8 *, color_t, color_t, attrset_t)
Add a style to the parser/highlighter.
Definition: parser.cpp:437
static const i8 * prefix()
Get the library installation prefix.
Definition: util.cpp:73
#define HLT_SCOPE_FG
Highlighter color for C++ ABI scopes.
Definition: config.hpp:329
#define HLT_FUNCTION_FG
Highlighter color for C++ function names.
Definition: config.hpp:334
virtual dictionary * add_dictionary(const i8 *, const i8 *, bool)
Add a dictionary to the parser.
Definition: parser.cpp:298
parser()
Object default constructor.
Definition: parser.cpp:157
static void dbg_info(const i8 *,...)
Print an informational debug message on the standard error stream.
Definition: util.cpp:680
static style * m_fallback
Shared fallback style.
Definition: parser.hpp:37

+ Here is the call graph for this function: