coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
if_control.h
Go to the documentation of this file.
1 #ifndef IF_CONTROL_H
2 #define IF_CONTROL_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2004, 2006 Symbian Software Ltd. *
6  * All rights reserved. *
7  * Copyright (C) 2002, 2003 Tony Finch <dot@dotat.at>. *
8  * All rights reserved. *
9  * Copyright (C) 1985, 1993 The Regents of the University of California. *
10  * All rights reserved. *
11  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
12  * All rights reserved. *
13  * *
14  * Contributed by Mike Kinghan, imk@burroingroingjoing.com, *
15  * derived from the code of Tony Finch *
16  * *
17  * Redistribution and use in source and binary forms, with or without *
18  * modification, are permitted provided that the following conditions *
19  * are met: *
20  * *
21  * Redistributions of source code must retain the above copyright *
22  * notice, this list of conditions and the following disclaimer. *
23  * *
24  * Redistributions in binary form must reproduce the above copyright *
25  * notice, this list of conditions and the following disclaimer in the *
26  * documentation and/or other materials provided with the distribution. *
27  * *
28  * Neither the name of Symbian Software Ltd. nor the names of its *
29  * contributors may be used to endorse or promote products derived from *
30  * this software without specific prior written permission. *
31  * *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
35  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
36  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
37  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
38  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
39  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
40  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
41  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
42  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
43  * DAMAGE. *
44  * *
45  **************************************************************************/
46 #include "line_type.h"
47 #include <cstddef>
48 
59 struct if_control {
60 
62  enum if_state {
85  };
86 
97  static void transition(line_type linetype);
98 
100  static bool dead_line();
101 
103  static bool was_unconditional_line() {
104  return ifstate[if_depth()] == IF_STATE_OUTSIDE;
105  }
106 
110  static bool is_unconditional_line();
111 
113  static size_t if_start_line() {
114  return if_start_lines[if_depth()];
115  }
116 
118  static size_t if_depth() {
119  return depth;
120  }
121 
123  static if_state state() {
124  return ifstate[if_depth()];
125  }
126 
128  static void top() {
129  depth = 0;
130  }
131 
132 private:
133 
138  static const unsigned MAXDEPTH = 64;
139 
141  using transition_t = void();
142 
148 
150  static void nest();
151 
153  static void set_state(if_state is) {
154  size_t deep = if_depth();
155  ifstate[deep] = is;
156  }
157 
159  static void Strue();
160 
162  static void Sfalse();
163 
165  static void Selse();
166 
168  static void Pelif();
169 
171  static void Pelse();
172 
174  static void Pendif();
175 
177  static void Dfalse();
178 
180  static void Delif();
181 
183  static void Delse();
184 
186  static void Dendif();
187 
189  static void Fdrop() {
190  nest();
191  Dfalse();
192  }
193 
195  static void Fpass() {
196  nest();
197  Pelif();
198  }
199 
201  static void Ftrue() {
202  nest();
203  Strue();
204  }
205 
207  static void Ffalse() {
208  nest();
209  Sfalse();
210  }
211 
213  static void Mpass();
214 
216  static void Mtrue();
217 
219  static void Melif();
220 
222  static void Melse();
223 
225  static void orphan_elif();
226 
228  static void orphan_else();
229 
231  static void orphan_endif();
232 
234  static void early_eof();
235 
238 
240  static size_t depth;
241 
243  static size_t if_start_lines[MAXDEPTH];
244 
245 };
246 
247 #endif // EOF
static void orphan_else()
Diagnose an input orphan #else on cerr
Definition: if_control.cpp:150
We have an else after a true state.
Definition: if_control.h:78
static void Fdrop()
State transition.
Definition: if_control.h:189
Maintains state with respect to #if logic.
Definition: if_control.h:59
static transition_t *const transition_table[IF_STATE_COUNT][LT_SENTINEL]
The #if-state transition table.
Definition: if_control.h:147
static void Pendif()
State transition.
Definition: if_control.cpp:87
static void Selse()
State transition.
Definition: if_control.cpp:69
We have a false elif after a pass state.
Definition: if_control.h:72
static void Melse()
State transition.
Definition: if_control.cpp:138
static bool was_unconditional_line()
Is the current line outside any #if scope?
Definition: if_control.h:103
static void early_eof()
Diagnose unexpected end of input on cerr
Definition: if_control.cpp:160
static bool is_unconditional_line()
Is the current line outside any #if scope or in the scope of a satisfied #if?
Definition: if_control.cpp:326
static void Dfalse()
State transition.
Definition: if_control.cpp:93
static bool dead_line()
Is the current line rejected?
Definition: if_control.cpp:316
static void Delse()
State transition.
Definition: if_control.cpp:105
static void set_state(if_state is)
Set the #if-state at the current nesting depth.
Definition: if_control.h:153
static size_t if_start_lines[MAXDEPTH]
Array of start lines of nested #if-directives.
Definition: if_control.h:243
static size_t if_depth()
Get the current depth of #if-nesting.
Definition: if_control.h:118
All elifs after a true are false.
Definition: if_control.h:82
static void Melif()
State transition.
Definition: if_control.cpp:131
static void Fpass()
State transition.
Definition: if_control.h:195
The first non-false (el)if is true.
Definition: if_control.h:68
Count of if-control states.
Definition: if_control.h:84
static if_state state()
Get the current #if-state.
Definition: if_control.h:123
We have a true elif after a pass state.
Definition: if_control.h:74
We have an else after only false states.
Definition: if_control.h:80
static size_t if_start_line()
Get the starting line number of the current #if sequence.
Definition: if_control.h:113
static void Delif()
State transition.
Definition: if_control.cpp:99
static void Pelif()
State transition.
Definition: if_control.cpp:75
void( transition_t)
Type of #if-state transition functions.
Definition: if_control.h:141
static void orphan_endif()
Diagnose an input orphan #endif on cerr
Definition: if_control.cpp:155
static void Strue()
State transition.
Definition: if_control.cpp:57
static void Ffalse()
State transition.
Definition: if_control.h:207
static void top()
Reset the depth of #if-nesting to 0.
Definition: if_control.h:128
static void Mtrue()
State transition.
Definition: if_control.cpp:124
The first non-false (el)if is insoluble.
Definition: if_control.h:70
if_state
symbolic constants denoting the if-control states.
Definition: if_control.h:62
static void Ftrue()
State transition.
Definition: if_control.h:201
static if_state ifstate[MAXDEPTH]
Array of states of nested #if-directives.
Definition: if_control.h:237
static void Mpass()
State transition.
Definition: if_control.cpp:117
static void Dendif()
State transition.
Definition: if_control.cpp:111
static size_t depth
Current depth of #if-nesting.
Definition: if_control.h:240
static void Sfalse()
State transition.
Definition: if_control.cpp:63
Sentinel.
Definition: line_type.h:78
line_type
Enumeration of types of input lines.
Definition: line_type.h:52
static void Pelse()
State transition.
Definition: if_control.cpp:81
static void orphan_elif()
Diagnose an input orphan #elif on cerr
Definition: if_control.cpp:145
We are outside any if
Definition: if_control.h:64
We have a false if followed by false elif
Definition: if_control.h:66
static const unsigned MAXDEPTH
Maximum depth of hash-if nesting.
Definition: if_control.h:138
We have an else after a pass state.
Definition: if_control.h:76
static void transition(line_type linetype)
Transition the if-control state given an evaluated line type.
Definition: if_control.cpp:310
static void nest()
Increment the #if-nesting depth.
Definition: if_control.cpp:301