coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
contradiction Struct Reference

Class contradiction handles contradictions between commandline options and directives. More...

#include <contradiction.h>

Public Types

enum  cause { cause::DIFFERENTLY_REDEFING_D, cause::UNDEFING_D, cause::DEFINING_U }
 Reasons for reporting a contadiction. More...
 

Static Public Member Functions

static void set_contradiction_policy (contradiction_policy p)
 Set the operative contradiction policy. More...
 
static void forget ()
 Forget about an apparent contradiction. More...
 
static void flush ()
 Discharge any pending contradiction. More...
 
static void insert (cause why, std::string const &symname)
 Insert an error diagnostic into the output as a error directive or comment. More...
 
static void save (cause why, std::string const &symname)
 Save diagnostic details of a potential contradiction. More...
 
static std::string const & last_conflicted_symbol_id ()
 Get the name of the latest #undef-ed symbol. More...
 

Static Private Member Functions

static void insert_pending ()
 Insert a stored error diagnostic into output. More...
 

Static Private Attributes

static contradiction_policy _policy_ = CONTRADICTION_COMMENT
 The operative contradiction policy.
 
static unsigned _policy_code_
 The reason-code of diagnostics associated with the operative contradiction policy.
 
static std::string _subst_text_
 Text for substitution in output. More...
 
static std::string _last_conflicted_symbol_
 The name of the latest #undef-ed symbol. More...
 
static unsigned _errored_lines_
 The number of lines converted to error directives.
 
static unsigned _unconditional_errored_lines_
 The number of lines converted to unconditional error directives.
 

Detailed Description

Class contradiction handles contradictions between commandline options and directives.

The contradiction class manages contradictions detected between commandline -D or -U options and in-source \#define or #undef directives.

If, for example, a commandline -DFOO option is given and an #undef FOO directive is parsed in-source, a contradiction arises. It will be handled in accordance with the specified or default --conflict option.

Definition at line 60 of file contradiction.h.

Member Enumeration Documentation

enum contradiction::cause
strong

Reasons for reporting a contadiction.

Enumerator
DIFFERENTLY_REDEFING_D 

An in-souce #define differently redefines a -D option.

UNDEFING_D 

An in-souce #undef contradicts a -D option.

DEFINING_U 

An in-souce #define contradicts a -U option.

Definition at line 63 of file contradiction.h.

Member Function Documentation

void contradiction::flush ( )
static

Discharge any pending contradiction.

When an apparent contradiction transpires to be genuine in the light of the following input we have a pending diagnostic action to discharge. It will consist of writing a warning to cerr, unless warnings are suppressed, and inserting a diagnostic comment or error in the output, unless the operative --conflict policy is delete. This function discharges any such the pending action and otherwise is a no-op.

Definition at line 80 of file contradiction.cpp.

void contradiction::forget ( )
static

Forget about an apparent contradiction.

The function causes the program to forget about a contradiction that would be governed by the --conflict policy when later input shows it to be innocuous. Its purpose is to cope with the complication created by the common precautionary idioms:

#undef FOO #define FOO

and:

#undef FOO #define FOO XYZ

These idioms may be encountered when FOO is the subject of a --define option. In this case the precautionary #undef FOO will at first appear to conflict with that --define, but the ensuing #define will show that the conflict is only apparent.

To cater for these cases, we defer diagnostic action on the #undef until we see what follows. If a #define follows that agrees with the --define options, with only whitespace and comments intervening, then we forget about the pending contradiction. This function clears the pending diagnostic action.

Note
An #undef that is prima facie conflicting will always be be dropped, whether or not it is anulled by a following #define. If is not anulled by a following #define, then it will dropped because any of the 3 possible --conflict policies will require it either to be simply dropped, or else dropped and replaced with a diagnostic insertion. If the #undef is anulled by a following #define, then both will be dropped because the #define in isolation would be dropped.

Definition at line 87 of file contradiction.cpp.

void contradiction::insert ( cause  why,
std::string const &  symname 
)
static

Insert an error diagnostic into the output as a error directive or comment.

Parameters
whyThe reason for the potential contradiction.
symnameThe name of symbol in the conflicting #define or #undef.

The functions inserts a diagnostic as a error directive or comment (depending on the operative --conflict policy) to replace a #undef or #define directive that conflicts with a --define or --undef option. The diagnostic is also written as a warning to cerr.

Definition at line 74 of file contradiction.cpp.

void contradiction::insert_pending ( )
staticprivate

Insert a stored error diagnostic into output.

Insert a stored error diagnostic into the output as a error directive or a comment (depending on the --conflict policy) to replace a #undef or #define directive that conflicts with a --define option. Reiterate the diagnostic as a warning on cerr.

If the --conflict delete is in force, there will be no diagnostic to insert in output, but the diagnostic is still written to cerr.

Definition at line 57 of file contradiction.cpp.

static std::string const& contradiction::last_conflicted_symbol_id ( )
inlinestatic

Get the name of the latest #undef-ed symbol.

Return the symbol name that was undefined by the last #undef directive that conflicts with a -define option, if any.

Returns
The relevant symbol name, or an empty string if none.

Definition at line 168 of file contradiction.h.

void contradiction::save ( cause  why,
std::string const &  symname 
)
static

Save diagnostic details of a potential contradiction.

Parameters
whyThe reason for the potential contradiction.
symnameThe name of symbol in the conflicting #define or #undef.

A potential contradiction can require confirmation after parsing further input. When an #undef directive is read that conflicts with a --define option, we will diagnose a conflict only if the #undef is not followed by a #define that agrees with the conflicting --define. This function stores the relevant diagnostics for writing if the contradiction is confirmed. Otherwise the contradiction is forgotten.

Definition at line 93 of file contradiction.cpp.

static void contradiction::set_contradiction_policy ( contradiction_policy  p)
inlinestatic

Set the operative contradiction policy.

Parameters
pThe contradiction policy to be applied.

Definition at line 76 of file contradiction.h.

Member Data Documentation

string contradiction::_last_conflicted_symbol_
staticprivate

The name of the latest #undef-ed symbol.

The symbol name that was undefined by the last #undef directive that conflicts with a --define option, if any.

Definition at line 208 of file contradiction.h.

string contradiction::_subst_text_
staticprivate

Text for substitution in output.

The substitute text that will be inserted in output is placed of a contradicted directive.

Definition at line 200 of file contradiction.h.


The documentation for this struct was generated from the following files: