1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

207320: apply fix and add regression tests

This commit is contained in:
Andrew Ferguson 2007-10-26 10:41:25 +00:00
parent 672ce65667
commit 5b762b9f6b
3 changed files with 70 additions and 4 deletions

View file

@ -27,10 +27,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
@ -63,6 +65,30 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
setStrategy(new SinglePDOMTestStrategy(true)); setStrategy(new SinglePDOMTestStrategy(true));
} }
// template <class T>
// inline void testTemplate(T& aRef);
//
// class Temp {
// };
// #include <stdio.h>
// #include <stdlib.h>
// #include "test.h"
// int main(void) {
// puts("Hello World!!!");
//
// Temp testFile;
// testTemplate(testFile);
//
// return EXIT_SUCCESS;
// }
public void testBug207320() {
IBinding b0= getBindingFromASTName("testTemplate(", 12);
assertInstance(b0, ICPPFunction.class);
assertInstance(b0, ICPPTemplateInstance.class);
}
// class testdef{ // class testdef{
// //
// public: // public:

View file

@ -132,6 +132,40 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
assertEquals(9, ((ASTNode)node).getLength()); assertEquals(9, ((ASTNode)node).getLength());
} }
// template <class T>
// inline void testTemplate(T& aRef);
//
// class Temp {
// };
// #include <stdio.h>
// #include <stdlib.h>
// #include "test.h"
// int main(void) {
// puts("Hello World!!!");
//
// Temp testFile;
// testTemplate(testFile);
//
// return EXIT_SUCCESS;
// }
public void testBug207320() throws Exception {
StringBuffer[] buffers= getContents(2);
String hcode= buffers[0].toString();
String scode= buffers[1].toString();
IFile hfile = importFile("test.h", hcode);
IFile file = importFile("test.cpp", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
int hoffset= hcode.indexOf("testTemplate");
int soffset = scode.indexOf("testTemplate");
IASTNode def = testF3(file, soffset+2);
assertTrue(def instanceof IASTName);
assertEquals(((IASTName)def).toString(), "testTemplate"); //$NON-NLS-1$
assertEquals(((ASTNode)def).getOffset(), hoffset);
assertEquals(((ASTNode)def).getLength(), 12);
}
// // the header // // the header
// extern int MyInt; // MyInt is in another file // extern int MyInt; // MyInt is in another file
// extern const int MyConst; // MyConst is in another file // extern const int MyConst; // MyConst is in another file
@ -227,7 +261,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
// #include "testBasicTemplateInstance.h" // #include "testBasicTemplateInstance.h"
// N::AAA<int> a; // N::AAA<int> a;
public void _testBasicTemplateInstance() throws Exception{ public void testBasicTemplateInstance_207320() throws Exception{
StringBuffer[] buffers= getContents(2); StringBuffer[] buffers= getContents(2);
String hcode= buffers[0].toString(); String hcode= buffers[0].toString();
String scode= buffers[1].toString(); String scode= buffers[1].toString();
@ -235,7 +269,6 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
IFile file = importFile("testBasicTemplateInstance.cpp", scode); IFile file = importFile("testBasicTemplateInstance.cpp", scode);
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
int hoffset= hcode.indexOf("AAA"); int hoffset= hcode.indexOf("AAA");
int soffset = scode.indexOf("AAA<int>"); //$NON-NLS-1$ int soffset = scode.indexOf("AAA<int>"); //$NON-NLS-1$
IASTNode decl1 = testF3(file, soffset, 3); IASTNode decl1 = testF3(file, soffset, 3);

View file

@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
@ -130,8 +131,14 @@ public class OpenDeclarationsAction extends SelectionParseAction {
if (binding != null && !(binding instanceof IProblemBinding)) { if (binding != null && !(binding instanceof IProblemBinding)) {
IName[] declNames = findNames(fIndex, ast, isDefinition, binding); IName[] declNames = findNames(fIndex, ast, isDefinition, binding);
if (declNames.length == 0) { if (declNames.length == 0) {
// bug 86829, handle implicit methods. if(binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPMethod) { // bug 207320, handle template instances
IBinding definition= ((ICPPTemplateInstance)binding).getTemplateDefinition();
if(definition != null && !(definition instanceof IProblemBinding)) {
declNames = findNames(fIndex, ast, true, definition);
}
} else if (binding instanceof ICPPMethod) {
// bug 86829, handle implicit methods.
ICPPMethod method= (ICPPMethod) binding; ICPPMethod method= (ICPPMethod) binding;
if (method.isImplicit()) { if (method.isImplicit()) {
try { try {