1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-15 12:15:47 +02:00

Formatting bug fixes.

This commit is contained in:
Sergey Prigogin 2011-03-28 00:14:20 +00:00
parent 56690dafd4
commit 32d0894ce1
4 changed files with 44 additions and 14 deletions

View file

@ -2668,14 +2668,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} while (isOverloadedLeftShift(binaryExpression)); } while (isOverloadedLeftShift(binaryExpression));
Collections.reverse(elements); Collections.reverse(elements);
Runnable tailFormatter = scribe.takeTailFormatter();
node.accept(this); node.accept(this);
scribe.printComment(); scribe.printComment();
if (preferences.insert_space_before_binary_operator) { if (preferences.insert_space_before_binary_operator) {
scribe.space(); scribe.space();
} }
Runnable tailFormatter = scribe.getTailFormatter();
Alignment wrapperAlignment = null; Alignment wrapperAlignment = null;
if ((preferences.alignment_for_overloaded_left_shift_chain & Alignment.M_INDENT_ON_COLUMN) != 0) { if ((preferences.alignment_for_overloaded_left_shift_chain & Alignment.M_INDENT_ON_COLUMN) != 0) {
wrapperAlignment = scribe.createAlignment( wrapperAlignment = scribe.createAlignment(
@ -2751,7 +2750,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(IASTLiteralExpression node) { private int visit(IASTLiteralExpression node) {
if (node.getKind() == IASTLiteralExpression.lk_string_literal) { if (node.getKind() == IASTLiteralExpression.lk_string_literal) {
// handle concatenation of string literals // Handle concatenation of string literals
int token; int token;
boolean needSpace= false; boolean needSpace= false;
final int line= scribe.line; final int line= scribe.line;

View file

@ -34,20 +34,23 @@ public class Location {
int editsIndex; int editsIndex;
OptimizedReplaceEdit textEdit; OptimizedReplaceEdit textEdit;
public Runnable tailFormatter;
public Location(Scribe scribe, int sourceRestart){ public Location(Scribe scribe, int sourceRestart){
update(scribe, sourceRestart); update(scribe, sourceRestart);
} }
public void update(Scribe scribe, int sourceRestart){ public void update(Scribe scribe, int sourceRestart){
this.outputColumn = scribe.column;
this.outputLine = scribe.line;
this.inputOffset = sourceRestart; this.inputOffset = sourceRestart;
this.outputLine = scribe.line;
this.outputColumn = scribe.column;
this.outputIndentationLevel = scribe.indentationLevel; this.outputIndentationLevel = scribe.indentationLevel;
this.lastNumberOfNewLines = scribe.lastNumberOfNewLines;
this.needSpace = scribe.needSpace; this.needSpace = scribe.needSpace;
this.pendingSpace = scribe.pendingSpace; this.pendingSpace = scribe.pendingSpace;
this.editsIndex = scribe.editsIndex;
this.numberOfIndentations = scribe.numberOfIndentations; this.numberOfIndentations = scribe.numberOfIndentations;
textEdit = scribe.getLastEdit(); this.lastNumberOfNewLines = scribe.lastNumberOfNewLines;
this.editsIndex = scribe.editsIndex;
this.textEdit = scribe.getLastEdit();
this.tailFormatter = scribe.getTailFormatter();
} }
} }

View file

@ -1686,19 +1686,19 @@ public class Scribe {
currentAlignment= currentAlignment.enclosing; // pop currentLocation currentAlignment= currentAlignment.enclosing; // pop currentLocation
throw e; // rethrow throw e; // rethrow
} }
// reset scribe/scanner to restart at this given location // Reset scribe/scanner to restart at this given location
resetAt(currentAlignment.location); resetAt(currentAlignment.location);
scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1); scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1);
// clean alignment chunkKind so it will think it is a new chunk again // Clean alignment chunkKind so it will think it is a new chunk again
currentAlignment.chunkKind= 0; currentAlignment.chunkKind= 0;
currentAlignmentException= null; currentAlignmentException= null;
} }
void redoMemberAlignment(AlignmentException e) { void redoMemberAlignment(AlignmentException e) {
// reset scribe/scanner to restart at this given location // Reset scribe/scanner to restart at this given location
resetAt(memberAlignment.location); resetAt(memberAlignment.location);
scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1); scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1);
// clean alignment chunkKind so it will think it is a new chunk again // Clean alignment chunkKind so it will think it is a new chunk again
memberAlignment.chunkKind= 0; memberAlignment.chunkKind= 0;
currentAlignmentException= null; currentAlignmentException= null;
} }
@ -1714,14 +1714,15 @@ public class Scribe {
line= location.outputLine; line= location.outputLine;
column= location.outputColumn; column= location.outputColumn;
indentationLevel= location.outputIndentationLevel; indentationLevel= location.outputIndentationLevel;
numberOfIndentations= location.numberOfIndentations;
lastNumberOfNewLines= location.lastNumberOfNewLines;
needSpace= location.needSpace; needSpace= location.needSpace;
pendingSpace= location.pendingSpace; pendingSpace= location.pendingSpace;
numberOfIndentations= location.numberOfIndentations;
lastNumberOfNewLines= location.lastNumberOfNewLines;
editsIndex= location.editsIndex; editsIndex= location.editsIndex;
if (editsIndex > 0) { if (editsIndex > 0) {
edits[editsIndex - 1]= location.textEdit; edits[editsIndex - 1]= location.textEdit;
} }
setTailFormatter(location.tailFormatter);
} }
private void resize() { private void resize() {

View file

@ -2129,6 +2129,33 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult(); assertFormatterResult();
} }
//class Stream {
//Stream& operator<<(const char* s);
//};
//const char* function();
//
//void text() {
//Stream() << "0123456789012345678" << function() << "0123456789012345678" << "0123";
//int i;
//}
//class Stream {
// Stream& operator<<(const char* s);
//};
//const char* function();
//
//void text() {
// Stream() << "0123456789012345678" << function() << "0123456789012345678"
// << "0123";
// int i;
//}
public void testOverloadedLeftShiftChain_3() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_OVERLOADED_LEFT_SHIFT_CHAIN,
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
assertFormatterResult();
}
//int main() { //int main() {
// std::vector<std::vector<int>> test; // std::vector<std::vector<int>> test;
// // some comment // // some comment