cxx-indenter.hxx   cxx-indenter.hxx 
skipping to change at line 111 skipping to change at line 111
private: private:
code_stream<C>& out_; code_stream<C>& out_;
bool buffering_; // True if write() should buffer the char . bool buffering_; // True if write() should buffer the char .
std::size_t position_; // Current position on the line. std::size_t position_; // Current position on the line.
std::size_t paren_balance_; // ( ) balance. std::size_t paren_balance_; // ( ) balance.
std::stack<std::size_t> indentation_; std::stack<std::size_t> indentation_;
std::size_t spaces_; std::size_t spaces_;
bool suppress_nl_; bool suppress_nl_;
construct construct_; construct construct_;
// Special state stach for the do-while construct. The presence // Special state stack for the do-while construct. The presence
// of an element in the stack indicates that we are in a braced // of an element in the stack indicates that we are in a braced
// do-while construct. The value of the element is the brace // do-while construct. The value of the element is the brace
// balance. // balance.
std::stack<std::size_t> do_while_state_; std::stack<std::size_t> do_while_state_;
typedef std::deque<C> hold; typedef std::deque<C> hold;
hold hold_; hold hold_;
private: private:
string token_; // previously fully recognized token string token_; // previously fully recognized token
skipping to change at line 153 skipping to change at line 153
// //
// else if (...) // else if (...)
// foo (); // foo ();
// //
// else // else
// if (...) // if (...)
// foo (); // foo ();
// //
struct indent_block struct indent_block
{ {
indent_block (bool newline, bool indented) indent_block (bool newline, std::size_t indentation)
: newline_ (newline), indented_ (indented) : newline_ (newline), indentation_ (indentation)
{ {
} }
bool newline_; bool newline_;
bool indented_; std::size_t indentation_; // Size of the indentation_ stack
// corresponding to this block, or
// 0 if it is not indented.
}; };
std::stack<indent_block> indent_stack_; std::stack<indent_block> indent_stack_;
}; };
} }
} }
#include <cutl/compiler/cxx-indenter.ixx> #include <cutl/compiler/cxx-indenter.ixx>
#include <cutl/compiler/cxx-indenter.txx> #include <cutl/compiler/cxx-indenter.txx>
 End of changes. 3 change blocks. 
4 lines changed or deleted 6 lines changed or added


 cxx-indenter.txx   cxx-indenter.txx 
skipping to change at line 213 skipping to change at line 213
break; break;
} }
case '{': case '{':
{ {
if (construct_ == con_other) if (construct_ == con_other)
{ {
if (!indent_stack_.empty ()) if (!indent_stack_.empty ())
{ {
// Pop all the blocks until the one that was indented. // Pop all the blocks until the one that was indented.
// //
while (!indent_stack_.top ().indented_) while (indent_stack_.top ().indentation_ == 0)
indent_stack_.pop (); indent_stack_.pop ();
// Pop the indented block and one level of indentation.
//
if (indentation_.size () > 1) if (indentation_.size () > 1)
indentation_.pop (); indentation_.pop ();
indent_stack_.pop (); indent_stack_.pop ();
} }
ensure_new_line (); ensure_new_line ();
output_indentation (); output_indentation ();
write (c); write (c);
ensure_new_line (); ensure_new_line ();
skipping to change at line 264 skipping to change at line 266
output_indentation (); output_indentation ();
hold_.push_back (c); hold_.push_back (c);
// Add double newline after '}'. // Add double newline after '}'.
// //
hold_.push_back ('\n'); hold_.push_back ('\n');
hold_.push_back ('\n'); hold_.push_back ('\n');
position_ = 0; position_ = 0;
if (!indent_stack_.empty ())
{
// Pop all the blocks until the one that was indented.
//
while (indent_stack_.top ().indentation_ == 0)
indent_stack_.pop ();
// Now pop all the indented blocks while also popping the
// indentation stack. Do it only if the indentation match.
// If it doesn't then that means this inden_stack entry is
// for some other, outer block.
//
while (!indent_stack_.empty () &&
indent_stack_.top ().indentation_ ==
indentation_.size ())
{
if (indentation_.size () > 1)
indentation_.pop ();
indent_stack_.pop ();
}
}
buffering_ = true; buffering_ = true;
} }
else else
defaulting = true; defaulting = true;
break; break;
} }
case ';': case ';':
{ {
if (construct_ == con_other) if (construct_ == con_other)
{ {
// for (;;) // for (;;)
// //
if (!indent_stack_.empty () && paren_balance_ == 0) if (!indent_stack_.empty () && paren_balance_ == 0)
{ {
// Pop all the blocks until the one that was indented. // Pop all the blocks until the one that was indented.
// //
while (!indent_stack_.top ().indented_) while (indent_stack_.top ().indentation_ == 0)
indent_stack_.pop (); indent_stack_.pop ();
if (indentation_.size () > 1) // Now pop all the indented blocks while also popping the
indentation_.pop (); // indentation stack. Do it only if the indentation match.
// If they don't then it means we are inside a block and
// the stack should be popped after seeing '}', not ';'.
//
while (!indent_stack_.empty () &&
indent_stack_.top ().indentation_ ==
indentation_.size ())
{
if (indentation_.size () > 1)
indentation_.pop ();
indent_stack_.pop (); indent_stack_.pop ();
}
} }
if (paren_balance_ != 0) if (paren_balance_ != 0)
{ {
// We are inside for (;;) statement. Nothing to do here. // We are inside for (;;) statement. Nothing to do here.
// //
defaulting = true; defaulting = true;
} }
else else
{ {
skipping to change at line 484 skipping to change at line 519
{ {
// Handle one line indentation blocks (if, else, etc). // Handle one line indentation blocks (if, else, etc).
// //
if (single_line_blocks_.find (token_) != single_line_blocks_.end ()) if (single_line_blocks_.find (token_) != single_line_blocks_.end ())
{ {
// Only indent sub-blocks if we are on a new line. // Only indent sub-blocks if we are on a new line.
// //
bool indent (indent_stack_.empty () || bool indent (indent_stack_.empty () ||
indent_stack_.top ().newline_); indent_stack_.top ().newline_);
indent_stack_.push (indent_block (c == '\n', indent));
if (indent) if (indent)
indentation_.push (indentation_.top () + spaces_); indentation_.push (indentation_.top () + spaces_);
indent_stack_.push (
indent_block (c == '\n', (indent ? indentation_.size () : 0)));
} }
// Keep track of the do ... while construct in order to suppress // Keep track of the do ... while construct in order to suppress
// the newline after } and before while. // the newline after } and before while.
// //
if (old == do_ && token_ == lbrace_) if (old == do_ && token_ == lbrace_)
do_while_state_.push (0); do_while_state_.push (0);
if (!do_while_state_.empty ()) if (!do_while_state_.empty ())
{ {
skipping to change at line 544 skipping to change at line 580
break; break;
} }
} }
} }
} }
} }
// Stop buffering unless we have another closing brace. // Stop buffering unless we have another closing brace.
// //
if (token_ != rbrace_) if (token_ != rbrace_)
{
buffering_ = false; buffering_ = false;
}
} }
} }
template <typename C> template <typename C>
void cxx_indenter<C>:: void cxx_indenter<C>::
ensure_new_line () ensure_new_line ()
{ {
if (hold_.empty () || hold_.back () != '\n') if (hold_.empty () || hold_.back () != '\n')
{ {
hold_.push_back ('\n'); hold_.push_back ('\n');
 End of changes. 10 change blocks. 
9 lines changed or deleted 43 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/