From b7969ba527fa236487748f800d74f0d94266faea Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 30 May 2013 21:44:37 -0700 Subject: [PATCH] Bug 401621 - CDT formatter hangs with 100% cpu load --- .../eclipse/cdt/internal/formatter/CodeFormatterVisitor.java | 5 ++++- .../src/org/eclipse/cdt/internal/formatter/Scribe.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 4c309d72524..b3ee92ac944 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -529,6 +529,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, // declarations, with a possible exception for the trailing semicolon // of the last one. In both cases formatting is driven by the text of // parameters of the macro, not by the expanded code. + scribe.setTailFormatter( + new TrailingTokenFormatter(Token.tSEMI, macroEndOffset, + preferences.insert_space_before_semicolon, false)); formatFunctionStyleMacroExpansion(macroExpansion); } } @@ -596,7 +599,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, localScanner.getNextToken(); // Skip the opening parenthesis. int parenLevel = 0; int token; - while ((token = localScanner.getNextToken()) != Token.tBADCHAR) { + while ((token = localScanner.getNextToken()) != -1) { int tokenOffset = localScanner.getCurrentTokenStartPosition(); if (parenLevel == 0 && (token == Token.tCOMMA || token == Token.tRPAREN)) { if (currentArgument != null) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index e70cc0c9191..959a9255654 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -1289,6 +1289,7 @@ public class Scribe { return hasWhitespace; } } + scanner.resetTo(currentTokenStartPosition, scannerEndPosition); return hasWhitespace; } @@ -2058,7 +2059,8 @@ public class Scribe { } final int currentPosition= scanner.getCurrentPosition(); if (offset > currentPosition) { - printRaw(currentPosition, currentPosition - offset); + fSkipStartOffset = Integer.MAX_VALUE; + printRaw(currentPosition, offset - currentPosition); } fSkipStartOffset= offset; fSkipEndOffset= endOffset;