From dbaa2242285261d7c953aea54eaafb3f20b2c229 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Thu, 17 Jun 2010 00:20:17 +0000 Subject: [PATCH] Bug 316154: support processing of inner functions --- .../cxx/model/AbstractAstFunctionChecker.java | 18 +--- .../internal/checkers/ReturnCheckerTest.java | 95 +++++++++++-------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractAstFunctionChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractAstFunctionChecker.java index 9941e15d4f1..3c8ee5b24ae 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractAstFunctionChecker.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractAstFunctionChecker.java @@ -12,12 +12,9 @@ package org.eclipse.cdt.codan.core.cxx.model; import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences; import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; -import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; /** * Abstract class for checkers that do all the work on function definition level @@ -33,18 +30,11 @@ public abstract class AbstractAstFunctionChecker extends public int visit(IASTDeclaration element) { if (element instanceof IASTFunctionDefinition) { - processFunction((IASTFunctionDefinition) element); - return PROCESS_CONTINUE; // this is to support gcc extension - // for enclosed functions + processFunction((IASTFunctionDefinition) element); } - if (element instanceof IASTSimpleDeclaration) { - IASTDeclSpecifier declSpecifier = ((IASTSimpleDeclaration) element) - .getDeclSpecifier(); - if (declSpecifier instanceof ICPPASTCompositeTypeSpecifier) { - return PROCESS_CONTINUE; // c++ methods - } - } - return PROCESS_SKIP; + // visit all nodes to support inner functions within class definitions + // and gcc extensions + return PROCESS_CONTINUE; } }); } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java index a944f2f9574..ce43f168cda 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java @@ -18,72 +18,91 @@ import org.eclipse.cdt.codan.core.test.CheckerTestCase; * */ public class ReturnCheckerTest extends CheckerTestCase { - - -// dummy() { -// return; // error here on line 2 -// } + // dummy() { + // return; // error here on line 2 + // } public void testDummyFunction() { loadCodeAndRun(getAboveComment()); checkNoErrors(); // because return type if not defined, usually people don't care } - -// void void_function(void) { -// return; // no error here -// } + // void void_function(void) { + // return; // no error here + // } public void testVoidFunction() { loadCodeAndRun(getAboveComment()); checkNoErrors(); } - -// int integer_return_function(void) { -// if (global) { -// if (global == 100) { -// return; // error here on line 4 -// } -// } -// } + // int integer_return_function(void) { + // if (global) { + // if (global == 100) { + // return; // error here on line 4 + // } + // } + // } public void testBasicTypeFunction() { loadCodeAndRun(getAboveComment()); checkErrorLine(4); } -// -// struct My_Struct { -// int a; -// }; -// -// struct My_Struct struct_return_function(void) { -// return; // error here on line 6 -// } + // + // struct My_Struct { + // int a; + // }; + // + // struct My_Struct struct_return_function(void) { + // return; // error here on line 6 + // } public void testUserDefinedFunction() { loadCodeAndRun(getAboveComment()); checkErrorLine(6); } - -// typedef unsigned int uint8_t; -// -// uint8_t return_typedef(void) { -// return; // error here on line 4 -// } + // typedef unsigned int uint8_t; + // + // uint8_t return_typedef(void) { + // return; // error here on line 4 + // } public void testTypedefReturnFunction() { loadCodeAndRun(getAboveComment()); checkErrorLine(4); } - -// typedef unsigned int uint8_t; -// -// uint8_t (*return_fp_no_typedef(void))(void) -// { -// return; // error here on line 5 -// } + // typedef unsigned int uint8_t; + // + // uint8_t (*return_fp_no_typedef(void))(void) + // { + // return; // error here on line 5 + // } public void testFunctionPointerReturnFunction() { loadCodeAndRun(getAboveComment()); checkErrorLine(5); } + // void test() { + // class A { + // public: + // void m() { + // return; // should not be an error here + // } + // }; + // } + public void testInnerFunction_Bug315525() { + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); + } + + // void test() { + // class A { + // public: + // int m() { + // return; // should be an error here + // } + // }; + // } + public void testInnerFunction_Bug316154() { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(5); + } } \ No newline at end of file