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