1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 22:05:44 +02:00

Don't call exitNode method in finally blocks since the method may throw.

This commit is contained in:
Sergey Prigogin 2013-03-18 20:39:06 -07:00
parent af6790ddc6
commit 741970beb4

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2013 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -645,11 +645,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (!enterNode(node)) { if (!enterNode(node)) {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
try { int result = formatDeclaration(node);
return formatDeclaration(node);
} finally {
exitNode(node); exitNode(node);
} return result;
} }
private int formatDeclaration(IASTDeclaration node) { private int formatDeclaration(IASTDeclaration node) {
@ -703,7 +701,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTName node) { public int visit(IASTName node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
if (node instanceof ICPPASTQualifiedName) { if (node instanceof ICPPASTQualifiedName) {
visit((ICPPASTQualifiedName) node); visit((ICPPASTQualifiedName) node);
} else if (node instanceof ICPPASTTemplateId) { } else if (node instanceof ICPPASTTemplateId) {
@ -711,9 +708,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else { } else {
formatRaw(node); formatRaw(node);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -734,7 +729,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
if (node instanceof IASTEqualsInitializer) { if (node instanceof IASTEqualsInitializer) {
visit((IASTEqualsInitializer) node); visit((IASTEqualsInitializer) node);
} else if (node instanceof IASTInitializerList) { } else if (node instanceof IASTInitializerList) {
@ -744,9 +738,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else { } else {
formatRaw(node); formatRaw(node);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -756,7 +748,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTParameterDeclaration node) { public int visit(IASTParameterDeclaration node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
// decl-specifier // decl-specifier
final IASTDeclSpecifier declSpec= node.getDeclSpecifier(); final IASTDeclSpecifier declSpec= node.getDeclSpecifier();
if (declSpec != null) { if (declSpec != null) {
@ -771,9 +762,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
declarator.accept(this); declarator.accept(this);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -784,7 +773,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
public int visit(IASTDeclarator node) { public int visit(IASTDeclarator node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
// Common to all declarators // Common to all declarators
final IASTPointerOperator[] pointerOperators= node.getPointerOperators(); final IASTPointerOperator[] pointerOperators= node.getPointerOperators();
formatPointers(pointerOperators); formatPointers(pointerOperators);
@ -833,9 +821,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (initializer != null) { if (initializer != null) {
initializer.accept(this); initializer.accept(this);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -860,7 +846,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTDeclSpecifier node) { public int visit(IASTDeclSpecifier node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
if (node instanceof ICPPASTCompositeTypeSpecifier) { if (node instanceof ICPPASTCompositeTypeSpecifier) {
visit((ICPPASTCompositeTypeSpecifier) node); visit((ICPPASTCompositeTypeSpecifier) node);
} else if (node instanceof ICASTCompositeTypeSpecifier) { } else if (node instanceof ICASTCompositeTypeSpecifier) {
@ -876,9 +861,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else { } else {
formatRaw(node); formatRaw(node);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -888,7 +871,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTExpression node) { public int visit(IASTExpression node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
if (node instanceof IASTArraySubscriptExpression) { if (node instanceof IASTArraySubscriptExpression) {
visit((IASTArraySubscriptExpression) node); visit((IASTArraySubscriptExpression) node);
} else if (node instanceof IASTConditionalExpression) { } else if (node instanceof IASTConditionalExpression) {
@ -924,9 +906,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else { } else {
formatRaw(node); formatRaw(node);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -982,6 +962,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else { } else {
formatRaw(node); formatRaw(node);
} }
exitNode(node);
} catch (ASTProblemException e) { } catch (ASTProblemException e) {
if (node instanceof IASTProblemStatement) { if (node instanceof IASTProblemStatement) {
throw e; throw e;
@ -991,7 +972,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.unIndent(); scribe.unIndent();
} }
} }
} finally {
exitNode(node); exitNode(node);
} }
return PROCESS_SKIP; return PROCESS_SKIP;
@ -1003,7 +983,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTTypeId node) { public int visit(IASTTypeId node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
if (node instanceof IASTProblemHolder) { if (node instanceof IASTProblemHolder) {
throw new ASTProblemException(((IASTProblemHolder) node).getProblem()); throw new ASTProblemException(((IASTProblemHolder) node).getProblem());
} }
@ -1021,9 +1000,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
declarator.accept(this); declarator.accept(this);
} }
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1033,7 +1010,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTEnumerator enumerator) { public int visit(IASTEnumerator enumerator) {
if (!enterNode(enumerator)) { return PROCESS_SKIP; } if (!enterNode(enumerator)) { return PROCESS_SKIP; }
try {
// name // name
enumerator.getName().accept(this); enumerator.getName().accept(this);
@ -1046,9 +1022,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
value.accept(this); value.accept(this);
} }
} finally {
exitNode(enumerator); exitNode(enumerator);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1058,7 +1032,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(ICPPASTBaseSpecifier specifier) { public int visit(ICPPASTBaseSpecifier specifier) {
if (!enterNode(specifier)) { return PROCESS_SKIP; } if (!enterNode(specifier)) { return PROCESS_SKIP; }
try {
boolean needSpace= false; boolean needSpace= false;
loop: while (true) { loop: while (true) {
int token= peekNextToken(); int token= peekNextToken();
@ -1078,9 +1051,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.space(); scribe.space();
} }
specifier.getName().accept(this); specifier.getName().accept(this);
} finally {
exitNode(specifier); exitNode(specifier);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1090,7 +1061,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(ICPPASTNamespaceDefinition node) { public int visit(ICPPASTNamespaceDefinition node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
final int line= scribe.line; final int line= scribe.line;
// namespace <name> // namespace <name>
scribe.printNextToken(Token.t_namespace, false); scribe.printNextToken(Token.t_namespace, false);
@ -1110,9 +1080,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.unIndent(); scribe.unIndent();
} }
formatClosingBrace(preferences.brace_position_for_namespace_declaration); formatClosingBrace(preferences.brace_position_for_namespace_declaration);
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1222,9 +1190,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else { } else {
visit((IASTParameterDeclaration) node); visit((IASTParameterDeclaration) node);
} }
exitNode(node);
} catch (ASTProblemException e) { } catch (ASTProblemException e) {
skipNode(node); skipNode(node);
} finally {
exitNode(node); exitNode(node);
} }
return PROCESS_SKIP; return PROCESS_SKIP;
@ -1292,12 +1260,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(ICPPASTConstructorInitializer node) { private int visit(ICPPASTConstructorInitializer node) {
if (!enterNode(node)) { return PROCESS_SKIP; } if (!enterNode(node)) { return PROCESS_SKIP; }
try {
// Format like a function call // Format like a function call
formatFunctionCallArguments(node.getArguments()); formatFunctionCallArguments(node.getArguments());
} finally {
exitNode(node); exitNode(node);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1399,7 +1364,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
// Body // Body
if (bodyStmt instanceof IASTCompoundStatement) { if (bodyStmt instanceof IASTCompoundStatement) {
if (enterNode(bodyStmt)) { if (enterNode(bodyStmt)) {
try {
if (getCurrentPosition() <= nodeOffset(bodyStmt)) { if (getCurrentPosition() <= nodeOffset(bodyStmt)) {
formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration); formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration);
} }
@ -1407,10 +1371,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
preferences.brace_position_for_method_declaration, preferences.brace_position_for_method_declaration,
preferences.insert_space_before_opening_brace_in_method_declaration, preferences.insert_space_before_opening_brace_in_method_declaration,
preferences.indent_statements_compare_to_body); preferences.indent_statements_compare_to_body);
} finally {
exitNode(bodyStmt); exitNode(bodyStmt);
} }
}
} else if (bodyStmt != null) { } else if (bodyStmt != null) {
bodyStmt.accept(this); bodyStmt.accept(this);
} }
@ -1934,23 +1896,17 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.unIndent(); scribe.unIndent();
} }
if (enterNode(declaration)) { if (enterNode(declaration)) {
try {
scribe.startNewLine(); scribe.startNewLine();
visit((ICPPASTVisibilityLabel) declaration); visit((ICPPASTVisibilityLabel) declaration);
scribe.startNewLine(); scribe.startNewLine();
} finally {
exitNode(declaration); exitNode(declaration);
} }
}
} else { } else {
if (enterNode(declaration)) { if (enterNode(declaration)) {
try {
if (getCurrentPosition() <= nodeOffset(declaration)) if (getCurrentPosition() <= nodeOffset(declaration))
scribe.startNewLine(); scribe.startNewLine();
formatDeclaration(declaration); formatDeclaration(declaration);
} finally {
exitNode(declaration); exitNode(declaration);
}
} else { } else {
skipNode(declaration); skipNode(declaration);
} }
@ -3262,7 +3218,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) { if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) {
if (enterNode(body)) { if (enterNode(body)) {
try {
if (getCurrentPosition() <= nodeOffset(body)) { if (getCurrentPosition() <= nodeOffset(body)) {
formatLeftCurlyBrace(line, preferences.brace_position_for_block); formatLeftCurlyBrace(line, preferences.brace_position_for_block);
} }
@ -3270,10 +3225,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
preferences.brace_position_for_block, preferences.brace_position_for_block,
preferences.insert_space_before_opening_brace_in_block, preferences.insert_space_before_opening_brace_in_block,
preferences.indent_statements_compare_to_block); preferences.indent_statements_compare_to_block);
} finally {
exitNode(body); exitNode(body);
} }
}
} else { } else {
formatAction(line, body, preferences.brace_position_for_block); formatAction(line, body, preferences.brace_position_for_block);
} }
@ -3618,7 +3571,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
statements= Collections.singletonList(bodyStmt); statements= Collections.singletonList(bodyStmt);
} }
if (!enterNode(bodyStmt)) { return PROCESS_SKIP; } if (!enterNode(bodyStmt)) { return PROCESS_SKIP; }
try {
final int statementsLength = statements.size(); final int statementsLength = statements.size();
if (statementsLength != 0) { if (statementsLength != 0) {
boolean wasACase = false; boolean wasACase = false;
@ -3678,12 +3630,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
formatBlock((IASTCompoundStatement) statement, bracePosition, formatBlock((IASTCompoundStatement) statement, bracePosition,
preferences.insert_space_after_colon_in_case, preferences.insert_space_after_colon_in_case,
preferences.indent_statements_compare_to_block); preferences.indent_statements_compare_to_block);
exitNode(statement);
} catch (ASTProblemException e) { } catch (ASTProblemException e) {
if (i < statementsLength - 1) { if (i < statementsLength - 1) {
final IASTStatement nextStatement= statements.get(i + 1); final IASTStatement nextStatement= statements.get(i + 1);
skipToNode(nextStatement); skipToNode(nextStatement);
} }
} finally {
exitNode(statement); exitNode(statement);
} }
if (preferences.indent_switchstatements_compare_to_cases) { if (preferences.indent_switchstatements_compare_to_cases) {
@ -3696,12 +3648,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
formatBlock((IASTCompoundStatement) statement, bracePosition, formatBlock((IASTCompoundStatement) statement, bracePosition,
preferences.insert_space_before_opening_brace_in_block, preferences.insert_space_before_opening_brace_in_block,
preferences.indent_statements_compare_to_block); preferences.indent_statements_compare_to_block);
exitNode(statement);
} catch (ASTProblemException e) { } catch (ASTProblemException e) {
if (i < statementsLength - 1) { if (i < statementsLength - 1) {
final IASTStatement nextStatement= statements.get(i + 1); final IASTStatement nextStatement= statements.get(i + 1);
skipToNode(nextStatement); skipToNode(nextStatement);
} }
} finally {
exitNode(statement); exitNode(statement);
} }
} }
@ -3741,9 +3693,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
formatClosingBrace(brace_position); formatClosingBrace(brace_position);
} }
} finally {
exitNode(bodyStmt); exitNode(bodyStmt);
}
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -3816,14 +3766,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return false; return false;
IASTNodeLocation[] locations= node.getNodeLocations(); IASTNodeLocation[] locations= node.getNodeLocations();
if (locations.length == 0) { if (locations.length == 0) {
return true;
} else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) { } else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) {
IASTMacroExpansionLocation location = (IASTMacroExpansionLocation) locations[0]; IASTMacroExpansionLocation location = (IASTMacroExpansionLocation) locations[0];
if (locations.length <= 2 && node instanceof IASTStatement) { if (locations.length <= 2 && node instanceof IASTStatement) {
IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion(); IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion();
IASTFileLocation macroLocation = macroExpansion.getFileLocation(); IASTFileLocation macroLocation = macroExpansion.getFileLocation();
if (macroLocation.getNodeOffset() >= currentPosition && int macroOffset = macroLocation.getNodeOffset();
!scribe.shouldSkip(macroLocation.getNodeOffset()) && if (macroOffset >= currentPosition &&
(nodeEndOffset == macroLocation.getNodeOffset() + macroLocation.getNodeLength() || !scribe.shouldSkip(macroOffset) &&
(nodeEndOffset == macroOffset + macroLocation.getNodeLength() ||
locations.length == 2 && isSemicolonLocation(locations[1])) && locations.length == 2 && isSemicolonLocation(locations[1])) &&
isFunctionStyleMacroExpansion(macroExpansion)) { isFunctionStyleMacroExpansion(macroExpansion)) {
if (locations.length == 2 && isSemicolonLocation(locations[1])) { if (locations.length == 2 && isSemicolonLocation(locations[1])) {
@ -3844,7 +3796,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
continueNode(node.getParent()); continueNode(node.getParent());
return false; return false;
} }
} else { } else if (nodeLocation != null) {
scribe.restartAtOffset(nodeLocation.getNodeOffset()); scribe.restartAtOffset(nodeLocation.getNodeOffset());
} }
return true; return true;
@ -3995,14 +3947,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (stmt instanceof IASTCompoundStatement && !startsWithMacroExpansion(stmt)) { if (stmt instanceof IASTCompoundStatement && !startsWithMacroExpansion(stmt)) {
formatLeftCurlyBrace(line, brace_position); formatLeftCurlyBrace(line, brace_position);
if (enterNode(stmt)) { if (enterNode(stmt)) {
try {
formatBlock((IASTCompoundStatement) stmt, brace_position, formatBlock((IASTCompoundStatement) stmt, brace_position,
preferences.insert_space_before_opening_brace_in_block, preferences.insert_space_before_opening_brace_in_block,
preferences.indent_statements_compare_to_block); preferences.indent_statements_compare_to_block);
} finally {
exitNode(stmt); exitNode(stmt);
} }
}
} else if (stmt instanceof IASTNullStatement) { } else if (stmt instanceof IASTNullStatement) {
scribe.indent(); scribe.indent();
if (preferences.put_empty_statement_on_new_line) { if (preferences.put_empty_statement_on_new_line) {