mirror of
https://github.com/boostorg/wave.git
synced 2026-02-02 09:22:19 +00:00
Enforced that #if/#endif are balanced file wise.
[SVN r28084]
This commit is contained in:
@@ -157,7 +157,8 @@ public:
|
||||
integer_overflow,
|
||||
illegal_operator_redefinition,
|
||||
ill_formed_integer_literal,
|
||||
ill_formed_character_literal
|
||||
ill_formed_character_literal,
|
||||
unbalanced_if_endif
|
||||
};
|
||||
|
||||
preprocess_exception(char const *what_, error_code code, int line_,
|
||||
@@ -228,9 +229,10 @@ public:
|
||||
"this macro name cannot be used as a as it is an operator in C++", // illegal_operator_redefinition
|
||||
"ill formed integer literal or integer constant too large", // ill_formed_integer_literal
|
||||
"ill formed character literal", // ill_formed_character_literal
|
||||
"unbalanced #if/#endif in include file" // unbalanced_if_endif
|
||||
};
|
||||
BOOST_ASSERT(unexpected_error <= code &&
|
||||
code <= ill_formed_character_literal);
|
||||
code <= unbalanced_if_endif);
|
||||
return preprocess_exception_errors[code];
|
||||
}
|
||||
|
||||
@@ -271,10 +273,11 @@ public:
|
||||
util::severity_error, // integer_overflow
|
||||
util::severity_error, // illegal_operator_redefinition
|
||||
util::severity_error, // ill_formed_integer_literal
|
||||
util::severity_error // ill_formed_character_literal
|
||||
util::severity_error, // ill_formed_character_literal
|
||||
util::severity_warning // unbalanced_if_endif
|
||||
};
|
||||
BOOST_ASSERT(unexpected_error <= code &&
|
||||
code <= ill_formed_character_literal);
|
||||
code <= unbalanced_if_endif);
|
||||
return preprocess_exception_severity[code];
|
||||
}
|
||||
static char const *severity_text(int code)
|
||||
|
||||
@@ -45,11 +45,11 @@ namespace iteration_context_policies {
|
||||
// the beginning and the end of the loaded string.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct load_file_to_string {
|
||||
|
||||
struct load_file_to_string
|
||||
{
|
||||
template <typename IterContextT>
|
||||
class inner {
|
||||
|
||||
class inner
|
||||
{
|
||||
public:
|
||||
template <typename PositionT>
|
||||
static
|
||||
@@ -95,8 +95,8 @@ namespace iteration_context_policies {
|
||||
// istreambuf_iterators.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct load_file {
|
||||
|
||||
struct load_file
|
||||
{
|
||||
template <typename IterContextT>
|
||||
class inner {
|
||||
|
||||
@@ -136,25 +136,28 @@ namespace iteration_context_policies {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
template <typename IteratorT>
|
||||
struct base_iteration_context {
|
||||
|
||||
struct base_iteration_context
|
||||
{
|
||||
public:
|
||||
base_iteration_context(BOOST_WAVE_STRINGTYPE const &fname)
|
||||
: real_filename(fname), filename(fname), line(1), emitted_lines(1)
|
||||
base_iteration_context(
|
||||
BOOST_WAVE_STRINGTYPE const &fname, std::size_t if_block_depth = 0)
|
||||
: real_filename(fname), filename(fname), line(1), emitted_lines(1),
|
||||
if_block_depth(if_block_depth)
|
||||
{}
|
||||
base_iteration_context(IteratorT const &first_, IteratorT const &last_,
|
||||
BOOST_WAVE_STRINGTYPE const &fname)
|
||||
BOOST_WAVE_STRINGTYPE const &fname, std::size_t if_block_depth = 0)
|
||||
: first(first_), last(last_), real_filename(fname), filename(fname),
|
||||
line(1), emitted_lines(1)
|
||||
line(1), emitted_lines(1), if_block_depth(if_block_depth)
|
||||
{}
|
||||
|
||||
// the actual input stream
|
||||
IteratorT first; // actual input stream position
|
||||
IteratorT last; // end of input stream
|
||||
BOOST_WAVE_STRINGTYPE real_filename; // real name of the current file
|
||||
BOOST_WAVE_STRINGTYPE filename; // actual processed file
|
||||
BOOST_WAVE_STRINGTYPE filename; // actual processed file
|
||||
int line; // line counter of underlying stream
|
||||
int emitted_lines; // count of emitted newlines
|
||||
std::size_t if_block_depth; // depth of #if block recursion
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -224,7 +224,7 @@ private:
|
||||
typedef base_iteration_context<lexer_type> base_iteration_context_type;
|
||||
typedef
|
||||
iteration_context<lexer_type, typename ContextT::input_policy_type>
|
||||
iteration_context_t;
|
||||
iteration_context_type;
|
||||
|
||||
// parse tree related types
|
||||
typedef
|
||||
@@ -361,7 +361,16 @@ pp_iterator_functor<ContextT>::returned_from_include()
|
||||
|
||||
// restore the previous iteration context after finishing the preprocessing
|
||||
// of the included file
|
||||
BOOST_WAVE_STRINGTYPE oldfile = iter_ctx->real_filename;
|
||||
|
||||
iter_ctx = ctx.pop_iteration_context();
|
||||
|
||||
// ensure the itegrity of the #if/#endif stack
|
||||
if (iter_ctx->if_block_depth != ctx.get_if_block_depth()) {
|
||||
using boost::wave::util::impl::escape_lit;
|
||||
BOOST_WAVE_THROW(preprocess_exception, unbalanced_if_endif,
|
||||
escape_lit(oldfile).c_str(), act_pos);
|
||||
}
|
||||
|
||||
must_emit_line_directive = true;
|
||||
seen_newline = true;
|
||||
@@ -1009,7 +1018,7 @@ fs::path native_path(file_path, fs::native);
|
||||
|
||||
// preprocess the opened file
|
||||
boost::shared_ptr<base_iteration_context_type> new_iter_ctx (
|
||||
new iteration_context_t(native_path.native_file_string().c_str(),
|
||||
new iteration_context_type(native_path.native_file_string().c_str(),
|
||||
act_pos, ctx.get_language()));
|
||||
|
||||
// call the include policy trace function
|
||||
@@ -1019,6 +1028,7 @@ fs::path native_path(file_path, fs::native);
|
||||
// store current file position
|
||||
iter_ctx->filename = act_pos.get_file();
|
||||
iter_ctx->line = act_pos.get_line();
|
||||
iter_ctx->if_block_depth = ctx.get_if_block_depth();
|
||||
|
||||
// push the old iteration context onto the stack and continue with the new
|
||||
ctx.push_iteration_context(act_pos, iter_ctx);
|
||||
@@ -1721,7 +1731,7 @@ public:
|
||||
private:
|
||||
typedef
|
||||
boost::spirit::multi_pass<input_policy_type, boost::wave::util::functor_input>
|
||||
base_t;
|
||||
base_type;
|
||||
typedef pp_iterator<ContextT> self_type;
|
||||
typedef boost::wave::util::functor_input functor_input_type;
|
||||
|
||||
@@ -1733,7 +1743,7 @@ public:
|
||||
pp_iterator(ContextT &ctx, IteratorT const &first, IteratorT const &last,
|
||||
typename ContextT::position_type const &pos,
|
||||
boost::wave::language_support language)
|
||||
: base_t(input_policy_type(ctx, first, last, pos, language))
|
||||
: base_type(input_policy_type(ctx, first, last, pos, language))
|
||||
{}
|
||||
|
||||
void force_include(char const *path_, bool is_last)
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace util {
|
||||
template <typename IterationContextT>
|
||||
class iteration_context_stack
|
||||
{
|
||||
typedef std::stack<IterationContextT> base_t;
|
||||
typedef std::stack<IterationContextT> base_type;
|
||||
|
||||
public:
|
||||
typedef typename base_t::size_type size_type;
|
||||
typedef typename base_type::size_type size_type;
|
||||
|
||||
iteration_context_stack()
|
||||
: max_include_nesting_depth(BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH)
|
||||
@@ -40,12 +40,12 @@ public:
|
||||
size_type get_max_include_nesting_depth() const
|
||||
{ return max_include_nesting_depth; }
|
||||
|
||||
typename base_t::size_type size() const { return iter_ctx.size(); }
|
||||
typename base_t::value_type &top() { return iter_ctx.top(); }
|
||||
typename base_type::size_type size() const { return iter_ctx.size(); }
|
||||
typename base_type::value_type &top() { return iter_ctx.top(); }
|
||||
void pop() { iter_ctx.pop(); }
|
||||
|
||||
template <typename PositionT>
|
||||
void push(PositionT const &pos, typename base_t::value_type const &val)
|
||||
void push(PositionT const &pos, typename base_type::value_type const &val)
|
||||
{
|
||||
if (iter_ctx.size() == max_include_nesting_depth) {
|
||||
char buffer[22]; // 21 bytes holds all NUL-terminated unsigned 64-bit numbers
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
private:
|
||||
size_type max_include_nesting_depth;
|
||||
base_t iter_ctx;
|
||||
base_type iter_ctx;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user