| 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 | |
|