mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Devin Steffler.
Bug 97301 flattenLocationsToFile returns null causing NPE in indexer
This commit is contained in:
parent
680530305f
commit
2b8a395550
1 changed files with 44 additions and 0 deletions
|
@ -15,13 +15,16 @@ import java.io.Writer;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
|
@ -1594,6 +1597,47 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
|
||||||
assertEquals(((ASTNode)node).getLength(), 1);
|
assertEquals(((ASTNode)node).getLength(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug97301() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
// test2.h:
|
||||||
|
buffer.append("#ifndef _WINGDI_H\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#define _WINGDI_H\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#define _WINGDI_\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#if __GNUC__ >= 3\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#pragma GCC system_header\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#endif\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#ifdef __cplusplus\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("extern \"C\" {\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#endif\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#define WINGDIAPI\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#ifdef __cplusplus\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#endif\r\n"); //$NON-NLS-1$
|
||||||
|
String test2_h = buffer.toString();
|
||||||
|
importFile("test2.h", test2_h); //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
|
// test1.h:
|
||||||
|
buffer = new StringBuffer();
|
||||||
|
buffer.append("#ifdef RC_INVOKED\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#else\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#if !(defined NOGDI || defined _WINGDI_H)\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#include \"test2.h\"\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#endif\r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#endif\r\n"); //$NON-NLS-1$
|
||||||
|
importFile("test1.h", buffer.toString()); //$NON-NLS-1$
|
||||||
|
|
||||||
|
// test.c:
|
||||||
|
IFile file = importFile("test.c", "#include \"test1.h\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(file, ParserLanguage.CPP, false, true);
|
||||||
|
IASTPreprocessorStatement[] stmts = tu.getAllPreprocessorStatements();
|
||||||
|
IASTFileLocation fileLoc = tu.flattenLocationsToFile(stmts[5].getNodeLocations());
|
||||||
|
int fileOffset = test2_h.indexOf("#ifndef _WINGDI_H");
|
||||||
|
int fileLocOffset = fileLoc.getNodeOffset();
|
||||||
|
assertEquals(fileOffset, fileLocOffset);
|
||||||
|
}
|
||||||
|
|
||||||
public void testBug86126() throws Exception {
|
public void testBug86126() throws Exception {
|
||||||
importFile("foo.h", "int x;\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
importFile("foo.h", "int x;\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
String code = "#include \"foo.h\"\r\n"; //$NON-NLS-1$
|
String code = "#include \"foo.h\"\r\n"; //$NON-NLS-1$
|
||||||
|
|
Loading…
Add table
Reference in a new issue