Skip to content

Commit ffdc341

Browse files
authored
Emit line directives for includes with directive on first line (#223)
* Emit line directives for includes with directive on first line * Add nested include tests Thanks to Nick Nobles for this bug report and fix
1 parent f6ffdfe commit ffdc341

File tree

8 files changed

+161
-2
lines changed

8 files changed

+161
-2
lines changed

include/boost/wave/util/cpp_iterator.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,9 +1578,9 @@ pp_iterator_functor<ContextT>::on_include_helper(char const* f, char const* s,
15781578
char const* current_name = 0; // never try to match current file name
15791579
#endif
15801580

1581-
// call the 'found_include_directive' hook function
1581+
// call the 'found_include_directive' hook function
15821582
if (ctx.get_hooks().found_include_directive(ctx.derived(), f, include_next))
1583-
return true; // client returned false: skip file to include
1583+
return true; // client returned true: skip file to include
15841584

15851585
file_path = util::impl::unescape_lit(file_path);
15861586
std::string native_path_str;
@@ -1607,6 +1607,7 @@ pp_iterator_functor<ContextT>::on_include_helper(char const* f, char const* s,
16071607
boost::wave::enable_prefer_pp_numbers(ctx.get_language()),
16081608
is_system ? base_iteration_context_type::system_header :
16091609
base_iteration_context_type::user_header));
1610+
new_iter_ctx->emitted_lines = (unsigned int)(-1); // force #line directive
16101611

16111612
// call the include policy trace function
16121613
ctx.get_hooks().opened_include_file(ctx.derived(), dir_path, file_path,
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*=============================================================================
2+
Boost.Wave: A Standard compliant C++ preprocessor library
3+
http://www.boost.org/
4+
5+
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
6+
Software License, Version 1.0. (See accompanying file
7+
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8+
=============================================================================*/
9+
10+
// Line directives should be emitted for included files when they begin
11+
// with a single #if/#ifdef/#define directive. Addresses github issue #222.
12+
#include "t_5_040_001.hpp" // #if as first line should emit line directive
13+
#include "t_5_040_002.hpp" // #define as first line should emit line directive
14+
#include "t_5_040_003.hpp" // ensure nested includes emit line directive
15+
#include "t_5_040_005.hpp" // ensure empty initial lines produce line directive
16+
17+
t_5_040_a
18+
#if 1
19+
t_5_040_b
20+
#endif
21+
22+
//R #line 2 "t_5_040_001.hpp"
23+
//R t_5_040_001a
24+
//R #line 6 "t_5_040_001.hpp"
25+
//R t_5_040_001b
26+
//R
27+
//R t_5_040_001c
28+
//R #line 2 "t_5_040_002.hpp"
29+
//R t_5_040_002
30+
//R #line 2 "t_5_040_004.hpp"
31+
//R t_5_040_004
32+
//R #line 2 "t_5_040_003.hpp"
33+
//R t_5_040_003
34+
//R #line 15 "t_5_040_005.hpp"
35+
//R t_5_040_005
36+
//R #line 17 "t_5_040.cpp"
37+
//R t_5_040_a
38+
//R
39+
//R t_5_040_b
40+
41+
//H 10: t_5_040.cpp(12): #include "t_5_040_001.hpp"
42+
//H 04: "t_5_040_001.hpp"
43+
//H 05: $S(t_5_040_001.hpp) ($B(t_5_040_001.hpp))
44+
//H 10: t_5_040_001.hpp(1): #if
45+
//H 11: t_5_040_001.hpp(1): #if 1: 1
46+
//H 10: t_5_040_001.hpp(3): #endif
47+
//H 10: t_5_040_001.hpp(7): #if
48+
//H 11: t_5_040_001.hpp(7): #if 1: 1
49+
//H 10: t_5_040_001.hpp(9): #endif
50+
//H 06:
51+
//H 10: t_5_040.cpp(13): #include "t_5_040_002.hpp"
52+
//H 04: "t_5_040_002.hpp"
53+
//H 05: t_5_040_002.hpp ($B(t_5_040_002.hpp))
54+
//H 10: t_5_040_002.hpp(1): #define
55+
//H 08: t_5_040_002.hpp(1): t_5_040_002_hpp=
56+
//H 06:
57+
//H 10: t_5_040.cpp(14): #include "t_5_040_003.hpp"
58+
//H 04: "t_5_040_003.hpp"
59+
//H 05: t_5_040_003.hpp ($B(t_5_040_003.hpp))
60+
//H 10: t_5_040_003.hpp(1): #include "t_5_040_004.hpp"
61+
//H 04: "t_5_040_004.hpp"
62+
//H 05: t_5_040_004.hpp ($B(t_5_040_004.hpp))
63+
//H 10: t_5_040_004.hpp(1): #if
64+
//H 11: t_5_040_004.hpp(1): #if 1: 1
65+
//H 10: t_5_040_004.hpp(3): #endif
66+
//H 06:
67+
//H 06:
68+
//H 10: t_5_040.cpp(15): #include "t_5_040_005.hpp"
69+
//H 04: "t_5_040_005.hpp"
70+
//H 05: t_5_040_005.hpp ($B(t_5_040_005.hpp))
71+
//H 06:
72+
//H 10: t_5_040.cpp(18): #if
73+
//H 11: t_5_040.cpp(18): #if 1: 1
74+
//H 10: t_5_040.cpp(20): #endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#if 1
2+
t_5_040_001a
3+
#endif
4+
5+
//Ensure line directive still properly gets replaced with empty line
6+
t_5_040_001b
7+
#if 1
8+
t_5_040_001c
9+
#endif
10+
11+
// Important: The #if must be the first line of this file to ensure proper testing
12+
// of line directive emission. Do not move the copyright comment to the
13+
// beginning of this file.
14+
15+
/*=============================================================================
16+
Boost.Wave: A Standard compliant C++ preprocessor library
17+
http://www.boost.org/
18+
19+
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
20+
Software License, Version 1.0. (See accompanying file
21+
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
22+
=============================================================================*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define t_5_040_002_hpp
2+
t_5_040_002
3+
4+
// Important: The #define must be the first line of this file to ensure proper testing
5+
// of line directive emission. Do not move the copyright comment to the
6+
// beginning of this file.
7+
8+
/*=============================================================================
9+
Boost.Wave: A Standard compliant C++ preprocessor library
10+
http://www.boost.org/
11+
12+
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
13+
Software License, Version 1.0. (See accompanying file
14+
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15+
=============================================================================*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "t_5_040_004.hpp"
2+
t_5_040_003
3+
4+
// Important: The #include must be the first line of this file to ensure proper testing
5+
// of line directive emission. Do not move the copyright comment to the
6+
// beginning of this file.
7+
8+
/*=============================================================================
9+
Boost.Wave: A Standard compliant C++ preprocessor library
10+
http://www.boost.org/
11+
12+
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
13+
Software License, Version 1.0. (See accompanying file
14+
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15+
=============================================================================*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#if 1
2+
t_5_040_004
3+
#endif
4+
5+
// Important: The #if must be the first line of this file to ensure proper testing
6+
// of line directive emission. Do not move the copyright comment to the
7+
// beginning of this file.
8+
9+
/*=============================================================================
10+
Boost.Wave: A Standard compliant C++ preprocessor library
11+
http://www.boost.org/
12+
13+
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
14+
Software License, Version 1.0. (See accompanying file
15+
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
16+
=============================================================================*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// Important: The first line of this file must be blank to ensure proper testing
3+
// of line directive emission. Do not move the copyright comment to the
4+
// beginning of this file.
5+
6+
/*=============================================================================
7+
Boost.Wave: A Standard compliant C++ preprocessor library
8+
http://www.boost.org/
9+
10+
Copyright (c) 2024 Jeff Trull. Distributed under the Boost
11+
Software License, Version 1.0. (See accompanying file
12+
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13+
=============================================================================*/
14+
15+
t_5_040_005

test/testwave/testfiles/test.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ t_5_036.cpp
146146
t_5_037.cpp
147147
t_5_038.cpp
148148
t_5_039.cpp
149+
t_5_040.cpp
149150

150151
#
151152
# unit tests from the mcpp preprocessor validation suite

0 commit comments

Comments
 (0)