mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Fix for Bug 173837 - source formatters do not work in .cpp files
This commit is contained in:
parent
c3d550f539
commit
a6e6bc11d3
3 changed files with 32 additions and 5 deletions
|
@ -177,6 +177,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
public Scribe scribe;
|
||||
private String fTranslationUnitFile;
|
||||
|
||||
private boolean fInsideFor;
|
||||
|
||||
public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, int offset, int length) {
|
||||
localScanner = new Scanner() {
|
||||
public Token nextToken() {
|
||||
|
@ -740,6 +742,13 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
|
||||
private int visit(ICPPASTFunctionDeclarator node) {
|
||||
visit((IASTStandardFunctionDeclarator)node);
|
||||
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
|
||||
if (exceptionSpecification != null && exceptionSpecification.length > 0) {
|
||||
// TLETODO [formatter] need special alignment for exception specification
|
||||
scribe.printNextToken(Token.t_throw, true);
|
||||
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
||||
formatList(Arrays.asList(exceptionSpecification), align, true, false);
|
||||
}
|
||||
final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain();
|
||||
if (constructorChain != null && constructorChain.length > 0) {
|
||||
// TLETODO [formatter] need special constructor chain alignment
|
||||
|
@ -751,7 +760,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
formatList(Arrays.asList(constructorChain), align, false, false);
|
||||
scribe.unIndent();
|
||||
}
|
||||
// skip the rest (const, throw, etc.)
|
||||
// skip the rest (const, etc.)
|
||||
skipNode(node);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -855,7 +864,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
scribe.startNewLine();
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
@ -1339,9 +1347,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
|
||||
private int visit(IASTDeclarationStatement node) {
|
||||
node.getDeclaration().accept(this);
|
||||
// semicolon is already part of declaration
|
||||
// scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
// scribe.printTrailingComment();
|
||||
if (!fInsideFor) {
|
||||
scribe.startNewLine();
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
@ -1361,7 +1369,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.space();
|
||||
}
|
||||
IASTStatement initializerStmt= node.getInitializerStatement();
|
||||
fInsideFor= true;
|
||||
initializerStmt.accept(this);
|
||||
fInsideFor= false;
|
||||
final IASTExpression condition = node.getConditionExpression();
|
||||
if (condition != null) {
|
||||
if (preferences.insert_space_after_semicolon_in_for) {
|
||||
|
|
|
@ -5,3 +5,16 @@ struct x getX() {
|
|||
}
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171520
|
||||
int bug=sizeof(int);
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=173837
|
||||
class ABaseClass {
|
||||
protected:
|
||||
ABaseClass(int x);
|
||||
};
|
||||
class AClass : public ABaseClass {
|
||||
AClass(int x) throw(int);
|
||||
};
|
||||
AClass::AClass(int x) throw(int) :
|
||||
ABaseClass(x) {
|
||||
for (int i=0; i < 12;i++) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,3 +3,7 @@ struct x {};
|
|||
struct x getX() {}
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171520
|
||||
int bug=sizeof(int);
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=173837
|
||||
class ABaseClass {protected:ABaseClass(int x);};
|
||||
class AClass : public ABaseClass {AClass(int x) throw(int);};
|
||||
AClass::AClass(int x)throw(int):ABaseClass(x){for (int i=0;i < 12;i++) {}}
|
||||
|
|
Loading…
Add table
Reference in a new issue