mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed 90851 - [DOM AST] NPE in LocationMap.defineObjectStyleMacro
This commit is contained in:
parent
c35557f172
commit
26907961a3
3 changed files with 279 additions and 250 deletions
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
@ -21,16 +22,14 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -62,10 +61,10 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
|
||||
private static final IParserLogService NULL_LOG = new NullLogService();
|
||||
|
||||
private static final ICodeReaderFactory factory = CDOM
|
||||
.getInstance()
|
||||
.getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES);
|
||||
private static final ICodeReaderFactory factory = CDOM.getInstance()
|
||||
.getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES);
|
||||
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
@ -77,10 +76,15 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
|
||||
protected IASTTranslationUnit parse(IFile code, ParserLanguage language)
|
||||
throws Exception {
|
||||
return parse(code, language, SCANNER_INFO);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse(IFile code, ParserLanguage language,
|
||||
IScannerInfo s) throws Exception {
|
||||
InputStream stream = code.getContents();
|
||||
IScanner scanner = new DOMScanner(new CodeReader(code.getLocation()
|
||||
.toOSString(), stream), SCANNER_INFO, ParserMode.COMPLETE_PARSE,
|
||||
language, NULL_LOG, getScannerConfig(language), factory);
|
||||
.toOSString(), stream), s, ParserMode.COMPLETE_PARSE, language,
|
||||
NULL_LOG, getScannerConfig(language), factory);
|
||||
ISourceCodeParser parser = null;
|
||||
if (language == ParserLanguage.CPP) {
|
||||
parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE,
|
||||
|
@ -261,7 +265,7 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
"source.c", cpp_code.indexOf("int z;"), "int z;".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
IASTTranslationUnit.IDependencyTree tree = tu.getDependencyTree();
|
||||
assertEquals( tree.getInclusions().length, 2 );
|
||||
assertEquals(tree.getInclusions().length, 2);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -313,6 +317,19 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testBug90851() throws Exception {
|
||||
IFile imacro_file = importFile( "macro.h", "#define BEAST 666\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile include_file = importFile( "include.h", "int value = BEAST;\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String [] macros = { imacro_file.getLocation().toOSString() };
|
||||
String [] includes = { include_file.getLocation().toOSString() };
|
||||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, EMPTY_STRING_ARRAY, macros, includes );
|
||||
IFile code = importFile( "main.c", "int main() { return value; } "); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
parse(code, p, scannerInfo ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(DOMLocationInclusionTests.class);
|
||||
suite.addTest(new DOMLocationInclusionTests("cleanupProject")); //$NON-NLS-1$
|
||||
|
|
|
@ -1617,6 +1617,7 @@ abstract class BaseScanner implements IScanner {
|
|||
*
|
||||
*/
|
||||
protected void errorHandle() {
|
||||
if( bufferStackPos > 0 )
|
||||
++bufferPos[bufferStackPos];
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,12 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
|
|||
*/
|
||||
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||
|
||||
|
||||
public LocationMap() {
|
||||
tu = new _TranslationUnit();
|
||||
currentContext = tu;
|
||||
}
|
||||
|
||||
public class MacroExpansionLocation implements IASTMacroExpansion {
|
||||
|
||||
public MacroExpansionLocation(
|
||||
|
@ -1087,7 +1093,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
}
|
||||
|
||||
protected static class _CompositeFileContext extends _CompositeContext {
|
||||
public final CodeReader reader;
|
||||
public CodeReader reader;
|
||||
|
||||
public _CompositeFileContext(_CompositeContext parent, int startOffset,
|
||||
int endOffset, CodeReader reader) {
|
||||
|
@ -1095,6 +1101,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
this.reader = reader;
|
||||
}
|
||||
|
||||
public _CompositeFileContext(_CompositeContext parent, int startOffset,
|
||||
int endOffset ) {
|
||||
super(parent, startOffset, endOffset);
|
||||
}
|
||||
|
||||
|
||||
public int getLineNumber(int nodeOffset) {
|
||||
if( nodeOffset >= reader.buffer.length )
|
||||
return 1;
|
||||
|
@ -1124,8 +1136,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
* @param startOffset
|
||||
* @param endOffset
|
||||
*/
|
||||
public _TranslationUnit(CodeReader reader) {
|
||||
super(null, 0, 0, reader);
|
||||
public _TranslationUnit() {
|
||||
super(null, 0, 0 );
|
||||
}
|
||||
|
||||
IMacroDefinition [] builtins = new IMacroDefinition[2];
|
||||
|
@ -1773,8 +1785,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
||||
*/
|
||||
public void startTranslationUnit(CodeReader tu_reader) {
|
||||
tu = new _TranslationUnit(tu_reader);
|
||||
currentContext = tu;
|
||||
tu.reader = tu_reader;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue