coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
options.h
Go to the documentation of this file.
1 #ifndef OPTIONS_H
2 #define OPTIONS_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2004 - 2006 Symbian Software Ltd. *
6  * All rights reserved. *
7  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
8  * All rights reserved. *
9  * *
10  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
11  * *
12  * Redistribution and use in source and binary forms, with or without *
13  * modification, are permitted provided that the following conditions *
14  * are met: *
15  * *
16  * Redistributions of source code must retain the above copyright *
17  * notice, this list of conditions and the following disclaimer. *
18  * *
19  * Redistributions in binary form must reproduce the above copyright *
20  * notice, this list of conditions and the following disclaimer in the *
21  * documentation and/or other materials provided with the distribution. *
22  * *
23  * Neither the name of Symbian Software Ltd. nor the names of its *
24  * contributors may be used to endorse or promote products derived from *
25  * this software without specific prior written permission. *
26  * *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
30  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
31  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
35  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
36  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
37  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
38  * DAMAGE. *
39  * *
40  **************************************************************************/
41 
42 #include <string>
43 #include <vector>
44 
49 enum discard_policy {
54 };
55 
69 };
70 
73  CMD_HELP = 1,
84 };
85 
87 struct options {
88 
90  static command_code get_command();
91 
93  static std::string const & exec_path() {
94  return _exec_path_;
95  }
97  static std::string const & prog_name() {
98  return _prog_name_;
99  }
101  static std::string const & backup_suffix() {
102  return _backup_suffix_;
103  }
105  static bool got_opts() {
106  return _got_opts_;
107  }
109  static bool replace() {
110  return _replace_;
111  }
113  static bool list_location() {
114  return _list_locate_;
115  }
117  static bool list_only_once() {
118  return _list_only_once_;
119  }
121  static bool list_once_per_file() {
122  return _list_once_per_file_;
123  }
125  static bool list_only_active() {
126  return _list_only_active_;
127  }
129  static bool list_only_inactive() {
130  return _list_only_inactive_;
131  }
133  static bool list_symbols_in_ifs() {
134  return _list_symbols_in_ifs_;
135  }
137  static bool list_symbols_in_defs() {
138  return _list_symbols_in_defs_;
139  }
141  static bool list_symbols_in_undefs() {
143  }
145  static bool list_symbols_in_includes() {
147  }
149  static bool list_symbols_in_lines() {
151  }
153  static bool list_system_includes() {
154  return _list_system_includes_;
155  }
157  static bool list_local_includes() {
158  return _list_local_includes_;
159  }
161  static bool complement() {
162  return _complement_;
163  }
167  static bool eval_wip() {
168  return _eval_wip_;
169  }
171  static bool expand_references() {
172  return _expand_references_;
173  }
176  return _discard_policy_;
177  }
179  static bool line_directives() {
180  return _line_directives_;
181  }
183  static bool plaintext() {
184  return _plaintext_;
185  }
187  static bool recurse() {
188  return _recurse_;
189  }
191  static bool keep_going() {
192  return _keepgoing_;
193  }
195  static bool implicit() {
196  return _implicit_;
197  }
201  static bool no_transients() {
202  return _no_transients_;
203  }
205  static bool explain_references() {
206  return _explain_references_;
207  }
209  static bool selected_symbols() {
210  return _selected_symbols_;
211  }
213  static unsigned & max_expansion() {
214  return _max_expansion_;
215  }
216 
218  static bool have_source_output() {
219  static bool yes =
221  return yes;
222  }
223 
226  static bool yes =
228  return yes;
229  }
230 
238  static void parse_executable(char **argv);
239 
245  static void parse(int argc, char *argv[]);
246 
248  static bool diagnostic_gagged(unsigned reason);
249 
254  static void finish();
255 
256 private:
257 
260  OPT_FILE = 'f',
261  OPT_REPLACE = 'r',
262  OPT_BACKUP = 'b',
263  OPT_DEF = 'D',
264  OPT_UNDEF = 'U',
265  OPT_CONFLICT = 'x',
266  OPT_GAG = 'g',
267  OPT_VERBOSE = 'V',
269  OPT_EVALWIP = 'E',
270  OPT_DISCARD = 'k',
271  OPT_LINE = 1,
272  OPT_POD = 'P',
273  OPT_RECURSE = 'R',
274  OPT_FILTER = 'F',
276  OPT_IFS = 'i',
277  OPT_DEFS = 'd',
278  OPT_UNDEFS = 'u',
280  OPT_LOCATE = 'L',
281  OPT_ONCE = 'o',
282  OPT_SYSTEM = 's',
283  OPT_LOCAL = 'l',
284  OPT_ACTIVE = 'A',
285  OPT_INACTIVE = 'I',
287  OPT_IMPLICIT = 'm',
288  OPT_DIR = 4,
289  OPT_PREFIX = 'p',
293  OPT_LNS = 8,
296  };
297 
301  static struct option long_options [];
302 
309  static char opts [];
310 
312  static struct cmd_option commands [];
313 
315  static int const source_cmd_exclusions [];
316 
318  static int const symbols_cmd_exclusions [];
319 
321  static int const includes_cmd_exclusions[];
322 
324  static int const directives_cmd_exclusions [];
325 
327  static int const defs_cmd_exclusions [];
328 
330  static int const pragmas_cmd_exclusions [];
331 
333  static int const errors_cmd_exclusions[];
334 
336  static int const lines_cmd_exclusions[];
337 
339  static int const spin_cmd_exclusions[];
340 
344  static struct exclusion_list const cmd_exclusion_lists [];
345 
352  static void make_opts_list();
353 
361  static void
362  config_diagnostics(std::string const & arg);
363 
369  static void finalise_diagnostics();
370 
377  static void
378  error_invalid_opt(struct cmd_option const *cmd, int bad_opt);
379 
380 
396  static void add_files(std::string const & path);
397 
407  static void parse_file(std::string const & argsfile);
408 
414  static void parse_command_args(int argc, char *argv[]);
415 
417  static bool progress_gagged();
418 
420  static struct cmd_option * _command_;
422  static std::string _exec_path_;
424  static std::string _prog_name_;
426  static std::string _backup_suffix_;
428  static bool _got_opts_;
430  static bool _replace_;
432  static bool _list_locate_;
434  static bool _list_only_once_;
436  static bool _list_once_per_file_;
438  static bool _list_only_active_;
440  static bool _list_only_inactive_;
456  static bool _complement_;
460  static bool _eval_wip_;
462  static bool _expand_references_;
466  static bool _line_directives_;
468  static bool _plaintext_;
470  static bool _recurse_;
472  static bool _keepgoing_;
474  static bool _implicit_;
478  static bool _no_transients_;
480  static bool _explain_references_;
482  static bool _selected_symbols_;
484  static unsigned _max_expansion_;
487 
489  static std::vector<std::string > _argfile_argv_;
491  static std::string _memfile_;
493  static int _cmd_line_files_;
494 
496  static bool _parsing_file_;
497 };
498 
499 #endif // EOF
The --conflict option.
Definition: options.h:265
The directives command.
Definition: options.h:82
static bool plaintext()
Are we to omit parsing for C/C++ comments?
Definition: options.h:183
static bool implicit()
Do we implicitly --undef all unconfigured symbols?
Definition: options.h:195
static bool _list_only_once_
Do we report only the first occurrence of listed items?
Definition: options.h:434
The version command.
Definition: options.h:74
static bool list_only_once()
Do we report only the first occurrence of listed items?
Definition: options.h:117
static discard_policy & get_discard_policy()
Get the policy for discarding lines.
Definition: options.h:175
static int const includes_cmd_exclusions[]
Excluded options for the includes command.
Definition: options.h:321
static int const errors_cmd_exclusions[]
Excluded options for the errors command.
Definition: options.h:333
The --no-transients option.
Definition: options.h:290
The --pod option.
Definition: options.h:272
static bool list_only_active()
Do we list items only from operative directives?
Definition: options.h:125
static bool eval_wip()
Do we evaluate constants in truth-functional contexts or treat them as unknowns.
Definition: options.h:167
static bool selected_symbols()
Is symbol reporting restricted to a selected set?
Definition: options.h:209
static bool line_directives()
Do we output #line directives?
Definition: options.h:179
static bool list_symbols_in_includes()
Do we list symbols in #include directives?
Definition: options.h:145
static std::string _backup_suffix_
Suffix for backup files.
Definition: options.h:426
The symbols command.
Definition: options.h:76
static bool _list_only_inactive_
Do list items only from dropped lines?
Definition: options.h:440
Blank discarded lines.
Definition: options.h:52
static bool _list_local_includes_
Do we list local #include directives?
Definition: options.h:454
discard_policy
Symbolic constants denoting policies for discarding lines.
Definition: options.h:50
The line command.
Definition: options.h:81
Manages coan's commandline arguments.
Definition: options.cpp:98
static bool list_only_inactive()
Do we list items only from inoperative directives?
Definition: options.h:129
The --complement option.
Definition: options.h:268
static bool _list_only_active_
Do we list items only from kept lines?
Definition: options.h:438
static void parse(int argc, char *argv[])
Parse the commandline.
Definition: options.cpp:705
static bool list_local_includes()
Do we list local #include directives?
Definition: options.h:157
static bool _selected_symbols_
Is symbol reporting restricted to a selected set?
Definition: options.h:482
static void error_invalid_opt(struct cmd_option const *cmd, int bad_opt)
Raise a usage error when an option is invalid for the active command.
Definition: options.cpp:340
static int const lines_cmd_exclusions[]
Excluded options for the lines command.
Definition: options.h:336
The --line option.
Definition: options.h:271
static int const source_cmd_exclusions[]
Excluded options for the source command.
Definition: options.h:315
static int _cmd_line_files_
The number of input files/dirs specified on the commandline.
Definition: options.h:493
The --active option.
Definition: options.h:284
static unsigned _max_expansion_
Limit size for reported macro expansions.
Definition: options.h:484
The --dir option.
Definition: options.h:288
The help command.
Definition: options.h:73
static command_code get_command()
Get the operative coan command code.
Definition: options.cpp:247
static bool _recurse_
Recurse into directories?
Definition: options.h:470
The defs command.
Definition: options.h:78
static std::string _memfile_
Read whole ARGFILE into this storage.
Definition: options.h:491
static int const spin_cmd_exclusions[]
Excluded options for the spin command.
Definition: options.h:339
Comment out a contradicted directive.
Definition: options.h:66
The --inactive option.
Definition: options.h:285
static int const pragmas_cmd_exclusions[]
Excluded options for the pragmas command.
Definition: options.h:330
static int const symbols_cmd_exclusions[]
Excluded options for the symbols command.
Definition: options.h:318
static bool _got_opts_
Have we got all commandline options?
Definition: options.h:428
static bool complement()
Are we to output lines instead of dropping them and vice versa?
Definition: options.h:161
The --replace option.
Definition: options.h:261
The --filter option.
Definition: options.h:274
The --discard option.
Definition: options.h:270
static void parse_file(std::string const &argsfile)
Parse commandline options from a file.
Definition: options.cpp:669
The --implicit option.
Definition: options.h:287
The --undefine option.
Definition: options.h:264
static bool explain_references()
Do we report the progressive expansion of symbol references?
Definition: options.h:205
static struct cmd_option commands[]
Array of structures specifying the valid coan commands.
Definition: options.h:312
option_codes
Symbolic constants for the options of all coan commands.
Definition: options.h:259
The --expand option.
Definition: options.h:286
The --recurse option.
Definition: options.h:273
static void parse_command_args(int argc, char *argv[])
Parse the options to the active coan command.
Definition: options.cpp:382
static bool list_system_includes()
Do we list system #include directives?
Definition: options.h:153
static void finish()
Analyse the class global state after parsing the commandline.
Definition: options.cpp:731
The --defs option.
Definition: options.h:277
static bool _implicit_
Do we implicitly --undef all unconfigured symbols?
Definition: options.h:474
The --locate option.
Definition: options.h:280
Info structure for an option for getopt_long().
Definition: get_options.h:57
static bool got_opts()
Have we got all the options?
Definition: options.h:105
The --includes option.
Definition: options.h:279
The --once-only option.
Definition: options.h:281
static bool list_at_most_once_per_file()
Say whether items are reportable at most once per file.
Definition: options.h:225
The errors command.
Definition: options.h:80
The --local option.
Definition: options.h:283
static void finalise_diagnostics()
Configure the final state of diagnostic output filtering.
Definition: options.cpp:326
static bool _expand_references_
Do we report the expansions of symbol references?
Definition: options.h:462
static bool _no_transients_
Definition: options.h:478
static struct option long_options[]
Array of structures specifying the valid options for all coan commands.
Definition: options.h:301
static char opts[]
Array in which we will assemble the shortopts arguments for getopts_long()
Definition: options.h:309
static bool list_once_per_file()
Do we report the listed items just once per input file?
Definition: options.h:121
static bool expand_references()
Do we report the expansions reported symbols?
Definition: options.h:171
static bool _eval_wip_
Do we evaluate constants in truth-functional contexts or treat them as unknowns?
Definition: options.h:460
Delete a contradicted directive.
Definition: options.h:64
The --eval-wip option.
Definition: options.h:269
The pragmas command.
Definition: options.h:79
The --max-expansion option.
Definition: options.h:294
Drop discarded lines.
Definition: options.h:51
static bool _keepgoing_
Continue to process input files after errors.
Definition: options.h:472
The --system option.
Definition: options.h:282
contradiction_policy
Symbolic constants denoting policies for handling contradictions.
Definition: options.h:62
static void config_diagnostics(std::string const &arg)
Configure diagnostic output.
Definition: options.cpp:275
The --undefs option.
Definition: options.h:278
The --keepgoing option.
Definition: options.h:275
The --file option.
Definition: options.h:260
static bool _list_system_includes_
Do we list system #include directives?
Definition: options.h:452
static bool progress_gagged()
Say whether progress messages are suppressed.
Definition: options.cpp:791
static bool list_location()
Do we report file and line numbers for listed items?
Definition: options.h:113
static bool _list_locate_
Do we report file and line numbers for listed items?
Definition: options.h:432
static bool recurse()
Do we recurse into directories?
Definition: options.h:187
static int const defs_cmd_exclusions[]
Excluded options for the defs command.
Definition: options.h:327
static bool _explain_references_
Do we report the derivation of symbol resolutions?
Definition: options.h:480
The --prefix option.
Definition: options.h:289
Comment discarded lines.
Definition: options.h:53
static std::vector< std::string > _argfile_argv_
Array of options read from --file ARGFILE
Definition: options.h:489
static discard_policy _discard_policy_
Policy for discarding lines.
Definition: options.h:464
static bool keep_going()
Shall we continue to process input files after errors?
Definition: options.h:191
The includes command.
Definition: options.h:77
static bool list_symbols_in_defs()
Do we list symbols in #define directives?
Definition: options.h:137
Info structure for a command option for get_command()
Definition: get_options.h:94
static bool diagnostic_gagged(unsigned reason)
Say whether a diagnostic reason code is gagged.
Definition: options.cpp:796
static bool no_transients()
Definition: options.h:201
static std::string _exec_path_
argv[0]
Definition: options.h:422
static bool replace()
Do we replace input files with output files?
Definition: options.h:109
static bool _list_symbols_in_lines_
Do we list symbols in #line directives?
Definition: options.h:450
Encapsulates a filesystem path.
Definition: path.h:59
static bool _plaintext_
Are we to omit parsing for comments?
Definition: options.h:468
static unsigned & max_expansion()
Is symbol reporting restricted to a selected set?
Definition: options.h:213
static bool _complement_
Are to output lines instead of dropping tem and vice versa?
Definition: options.h:456
static struct exclusion_list const cmd_exclusion_lists[]
Array of exclusion lists for the coan commands, indexed by command code.
Definition: options.h:344
static std::string const & exec_path()
Get our executable's full pathname, argv[0]
Definition: options.h:93
The --select option.
Definition: options.h:292
Replace a contradicted directive with an #error
Definition: options.h:68
static bool have_source_output()
Say whether the current comment generates source code.
Definition: options.h:218
The --gag option.
Definition: options.h:266
the spin command
Definition: options.h:83
The --verbose option.
Definition: options.h:267
static bool list_symbols_in_ifs()
Do we list items only from inoperative directives?
Definition: options.h:133
The --define option.
Definition: options.h:263
command_code
Sequential symbolic constants for coan commands.
Definition: options.h:72
The --lns option.
Definition: options.h:293
static void parse_executable(char **argv)
Parse the full and short names of the executable.
Definition: options.cpp:694
static bool list_symbols_in_lines()
Do we list symbols in #line directives?
Definition: options.h:149
static std::string const & backup_suffix()
Get the file backup name suffix.
Definition: options.h:101
The --explain option.
Definition: options.h:291
static bool _list_symbols_in_ifs_
Do we list symbols in `#if/else/endif directives?
Definition: options.h:442
static std::string const & prog_name()
Get the program's name.
Definition: options.h:97
static bool _list_symbols_in_undefs_
Do we list symbols in #undef directives?
Definition: options.h:446
static void add_files(std::string const &path)
Add files to the input dataset.
Definition: options.cpp:350
The --once-per-file option.
Definition: options.h:295
static int _diagnostic_filter_
Bitmask of diagnostic filters.
Definition: options.h:486
static void make_opts_list()
Assemble the shortopts arguments for getopts_long().
Definition: options.cpp:252
static bool _list_symbols_in_defs_
Do we list symbols in #define directives?
Definition: options.h:444
static struct cmd_option * _command_
Pointer to the details of the operative coan command.
Definition: options.h:420
Structure representing a set of options that are excluded by another option.
Definition: get_options.h:104
static bool _parsing_file_
Are we parsing an argsfile ?
Definition: options.h:496
static bool _list_once_per_file_
Do we report only the first occurrence per file of listed items?
Definition: options.h:436
static bool _line_directives_
Do we output #line directives?
Definition: options.h:466
The --backup option.
Definition: options.h:262
static std::string _prog_name_
Filename element of exec_path
Definition: options.h:424
static int const directives_cmd_exclusions[]
Excluded options for the directives command.
Definition: options.h:324
The --ifs option.
Definition: options.h:276
static bool list_symbols_in_undefs()
Do we list symbols in #undef directives?
Definition: options.h:141
The source command.
Definition: options.h:75
static bool _replace_
Do we replace input files with output files?
Definition: options.h:430
static bool _list_symbols_in_includes_
Do we list symbols in #include directives?
Definition: options.h:448