mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +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.codan.core.model.ICheckerWithPreferences;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
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.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
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.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for checkers that do all the work on function definition level
|
* 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) {
|
public int visit(IASTDeclaration element) {
|
||||||
if (element instanceof IASTFunctionDefinition) {
|
if (element instanceof IASTFunctionDefinition) {
|
||||||
processFunction((IASTFunctionDefinition) element);
|
processFunction((IASTFunctionDefinition) element);
|
||||||
return PROCESS_CONTINUE; // this is to support gcc extension
|
|
||||||
// for enclosed functions
|
|
||||||
}
|
}
|
||||||
if (element instanceof IASTSimpleDeclaration) {
|
// visit all nodes to support inner functions within class definitions
|
||||||
IASTDeclSpecifier declSpecifier = ((IASTSimpleDeclaration) element)
|
// and gcc extensions
|
||||||
.getDeclSpecifier();
|
return PROCESS_CONTINUE;
|
||||||
if (declSpecifier instanceof ICPPASTCompositeTypeSpecifier) {
|
|
||||||
return PROCESS_CONTINUE; // c++ methods
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_SKIP;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,72 +18,91 @@ import org.eclipse.cdt.codan.core.test.CheckerTestCase;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ReturnCheckerTest extends CheckerTestCase {
|
public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
|
// dummy() {
|
||||||
|
// return; // error here on line 2
|
||||||
// dummy() {
|
// }
|
||||||
// return; // error here on line 2
|
|
||||||
// }
|
|
||||||
public void testDummyFunction() {
|
public void testDummyFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors(); // because return type if not defined, usually people don't care
|
checkNoErrors(); // because return type if not defined, usually people don't care
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void void_function(void) {
|
||||||
// void void_function(void) {
|
// return; // no error here
|
||||||
// return; // no error here
|
// }
|
||||||
// }
|
|
||||||
public void testVoidFunction() {
|
public void testVoidFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int integer_return_function(void) {
|
||||||
// int integer_return_function(void) {
|
// if (global) {
|
||||||
// if (global) {
|
// if (global == 100) {
|
||||||
// if (global == 100) {
|
// return; // error here on line 4
|
||||||
// return; // error here on line 4
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
|
||||||
public void testBasicTypeFunction() {
|
public void testBasicTypeFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(4);
|
checkErrorLine(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// struct My_Struct {
|
// struct My_Struct {
|
||||||
// int a;
|
// int a;
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// struct My_Struct struct_return_function(void) {
|
// struct My_Struct struct_return_function(void) {
|
||||||
// return; // error here on line 6
|
// return; // error here on line 6
|
||||||
// }
|
// }
|
||||||
public void testUserDefinedFunction() {
|
public void testUserDefinedFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(6);
|
checkErrorLine(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef unsigned int uint8_t;
|
||||||
// typedef unsigned int uint8_t;
|
//
|
||||||
//
|
// uint8_t return_typedef(void) {
|
||||||
// uint8_t return_typedef(void) {
|
// return; // error here on line 4
|
||||||
// return; // error here on line 4
|
// }
|
||||||
// }
|
|
||||||
public void testTypedefReturnFunction() {
|
public void testTypedefReturnFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(4);
|
checkErrorLine(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef unsigned int uint8_t;
|
||||||
// typedef unsigned int uint8_t;
|
//
|
||||||
//
|
// uint8_t (*return_fp_no_typedef(void))(void)
|
||||||
// uint8_t (*return_fp_no_typedef(void))(void)
|
// {
|
||||||
// {
|
// return; // error here on line 5
|
||||||
// return; // error here on line 5
|
// }
|
||||||
// }
|
|
||||||
public void testFunctionPointerReturnFunction() {
|
public void testFunctionPointerReturnFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(5);
|
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