mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 316154: support processing of inner functions
This commit is contained in:
parent
d36946d206
commit
dbaa224228
2 changed files with 61 additions and 52 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue