Skip to content

Commit

Permalink
Emit line directives for includes with directive on first line (#223)
Browse files Browse the repository at this point in the history
* Emit line directives for includes with directive on first line
* Add nested include tests

Thanks to Nick Nobles for this bug report and fix
  • Loading branch information
njnobles authored Oct 3, 2024
1 parent f6ffdfe commit ffdc341
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/boost/wave/util/cpp_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,9 +1578,9 @@ pp_iterator_functor<ContextT>::on_include_helper(char const* f, char const* s,
char const* current_name = 0; // never try to match current file name
#endif

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

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

// call the include policy trace function
ctx.get_hooks().opened_include_file(ctx.derived(), dir_path, file_path,
Expand Down
74 changes: 74 additions & 0 deletions test/testwave/testfiles/t_5_040.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

// Line directives should be emitted for included files when they begin
// with a single #if/#ifdef/#define directive. Addresses github issue #222.
#include "t_5_040_001.hpp" // #if as first line should emit line directive
#include "t_5_040_002.hpp" // #define as first line should emit line directive
#include "t_5_040_003.hpp" // ensure nested includes emit line directive
#include "t_5_040_005.hpp" // ensure empty initial lines produce line directive

t_5_040_a
#if 1
t_5_040_b
#endif

//R #line 2 "t_5_040_001.hpp"
//R t_5_040_001a
//R #line 6 "t_5_040_001.hpp"
//R t_5_040_001b
//R
//R t_5_040_001c
//R #line 2 "t_5_040_002.hpp"
//R t_5_040_002
//R #line 2 "t_5_040_004.hpp"
//R t_5_040_004
//R #line 2 "t_5_040_003.hpp"
//R t_5_040_003
//R #line 15 "t_5_040_005.hpp"
//R t_5_040_005
//R #line 17 "t_5_040.cpp"
//R t_5_040_a
//R
//R t_5_040_b

//H 10: t_5_040.cpp(12): #include "t_5_040_001.hpp"
//H 04: "t_5_040_001.hpp"
//H 05: $S(t_5_040_001.hpp) ($B(t_5_040_001.hpp))
//H 10: t_5_040_001.hpp(1): #if
//H 11: t_5_040_001.hpp(1): #if 1: 1
//H 10: t_5_040_001.hpp(3): #endif
//H 10: t_5_040_001.hpp(7): #if
//H 11: t_5_040_001.hpp(7): #if 1: 1
//H 10: t_5_040_001.hpp(9): #endif
//H 06:
//H 10: t_5_040.cpp(13): #include "t_5_040_002.hpp"
//H 04: "t_5_040_002.hpp"
//H 05: t_5_040_002.hpp ($B(t_5_040_002.hpp))
//H 10: t_5_040_002.hpp(1): #define
//H 08: t_5_040_002.hpp(1): t_5_040_002_hpp=
//H 06:
//H 10: t_5_040.cpp(14): #include "t_5_040_003.hpp"
//H 04: "t_5_040_003.hpp"
//H 05: t_5_040_003.hpp ($B(t_5_040_003.hpp))
//H 10: t_5_040_003.hpp(1): #include "t_5_040_004.hpp"
//H 04: "t_5_040_004.hpp"
//H 05: t_5_040_004.hpp ($B(t_5_040_004.hpp))
//H 10: t_5_040_004.hpp(1): #if
//H 11: t_5_040_004.hpp(1): #if 1: 1
//H 10: t_5_040_004.hpp(3): #endif
//H 06:
//H 06:
//H 10: t_5_040.cpp(15): #include "t_5_040_005.hpp"
//H 04: "t_5_040_005.hpp"
//H 05: t_5_040_005.hpp ($B(t_5_040_005.hpp))
//H 06:
//H 10: t_5_040.cpp(18): #if
//H 11: t_5_040.cpp(18): #if 1: 1
//H 10: t_5_040.cpp(20): #endif
22 changes: 22 additions & 0 deletions test/testwave/testfiles/t_5_040_001.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if 1
t_5_040_001a
#endif

//Ensure line directive still properly gets replaced with empty line
t_5_040_001b
#if 1
t_5_040_001c
#endif

// Important: The #if must be the first line of this file to ensure proper testing
// of line directive emission. Do not move the copyright comment to the
// beginning of this file.

/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
15 changes: 15 additions & 0 deletions test/testwave/testfiles/t_5_040_002.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define t_5_040_002_hpp
t_5_040_002

// Important: The #define must be the first line of this file to ensure proper testing
// of line directive emission. Do not move the copyright comment to the
// beginning of this file.

/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
15 changes: 15 additions & 0 deletions test/testwave/testfiles/t_5_040_003.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "t_5_040_004.hpp"
t_5_040_003

// Important: The #include must be the first line of this file to ensure proper testing
// of line directive emission. Do not move the copyright comment to the
// beginning of this file.

/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
16 changes: 16 additions & 0 deletions test/testwave/testfiles/t_5_040_004.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#if 1
t_5_040_004
#endif

// Important: The #if must be the first line of this file to ensure proper testing
// of line directive emission. Do not move the copyright comment to the
// beginning of this file.

/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2024 Nick Nobles. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
15 changes: 15 additions & 0 deletions test/testwave/testfiles/t_5_040_005.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// Important: The first line of this file must be blank to ensure proper testing
// of line directive emission. Do not move the copyright comment to the
// beginning of this file.

/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2024 Jeff Trull. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

t_5_040_005
1 change: 1 addition & 0 deletions test/testwave/testfiles/test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ t_5_036.cpp
t_5_037.cpp
t_5_038.cpp
t_5_039.cpp
t_5_040.cpp

#
# unit tests from the mcpp preprocessor validation suite
Expand Down

0 comments on commit ffdc341

Please sign in to comment.