mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Fixed Bug 87894 - [Offset] example from windows.h generates weird AST in DOM View
This commit is contained in:
parent
573d7a0dff
commit
e83f41c613
5 changed files with 40 additions and 56 deletions
|
@ -21,11 +21,15 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
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.IASTPreprocessorIncludeStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
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.IASTProblem;
|
||||||
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.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
|
@ -305,40 +309,8 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
||||||
assertSoleFileLocation(
|
assertSoleFileLocation(
|
||||||
macroDefinitions[5],
|
macroDefinitions[5],
|
||||||
"blarg.c", c_file_code.indexOf("#define POST_SECOND"), "#define POST_SECOND".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
"blarg.c", c_file_code.indexOf("#define POST_SECOND"), "#define POST_SECOND".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug87894() throws Exception {
|
|
||||||
StringBuffer fakeBuffer = new StringBuffer( "// windows_fake.h:\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "#ifdef RC_INVOKED\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "#define WIN32_LEAN_AND_MEAN\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "#endif\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "#ifndef WIN32_LEAN_AND_MEAN\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "#include \"rpc_fake.h\"\n" ); //$NON-NLS-1$
|
|
||||||
fakeBuffer.append( "#endif)\n" ); //$NON-NLS-1$
|
|
||||||
String windows_fake_h_code = fakeBuffer.toString();
|
|
||||||
importFile( "windows_fake.h", windows_fake_h_code ); //$NON-NLS-1$
|
|
||||||
StringBuffer rpcBuffer = new StringBuffer();
|
|
||||||
rpcBuffer.append( "// rpc_fake.h:\n" ); //$NON-NLS-1$
|
|
||||||
rpcBuffer.append( "#define RC_INVOKED\n" ); //$NON-NLS-1$
|
|
||||||
rpcBuffer.append( "\n" ); //$NON-NLS-1$
|
|
||||||
rpcBuffer.append( "#ifndef RPC_NO_WINDOWS_H\n" ); //$NON-NLS-1$
|
|
||||||
rpcBuffer.append( "#include \"windows_fake.h\"\n" ); //$NON-NLS-1$
|
|
||||||
rpcBuffer.append( "#endif\n" ); //$NON-NLS-1$
|
|
||||||
String rpc_fake_h_code = rpcBuffer.toString();
|
|
||||||
importFile( "rpc_fake.h", rpc_fake_h_code ); //$NON-NLS-1$
|
|
||||||
String test_c_code = "// test.c:\n#include \"windows_fake.h\"\n // endOffset is 64 but should be more like 266"; //$NON-NLS-1$
|
|
||||||
IFile f = importFile( "test.c", test_c_code ); //$NON-NLS-1$
|
|
||||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
|
||||||
: null) {
|
|
||||||
IASTTranslationUnit tu = parse(f, p); //$NON-NLS-1$
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
|
|
|
@ -1344,24 +1344,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
protected void pushContext(char[] buffer, Object data) {
|
protected void pushContext(char[] buffer, Object data) {
|
||||||
if (data instanceof InclusionData) {
|
if (data instanceof InclusionData) {
|
||||||
boolean isCircular = false;
|
if (isCircularInclusion( (InclusionData)data ))
|
||||||
for (int i = 0; i < bufferStackPos; ++i) {
|
|
||||||
if (bufferData[i] instanceof CodeReader
|
|
||||||
&& CharArrayUtils.equals(
|
|
||||||
((CodeReader) bufferData[i]).filename,
|
|
||||||
((InclusionData) data).reader.filename)) {
|
|
||||||
isCircular = true;
|
|
||||||
break;
|
|
||||||
} else if (bufferData[i] instanceof InclusionData
|
|
||||||
&& CharArrayUtils
|
|
||||||
.equals(
|
|
||||||
((InclusionData) bufferData[i]).reader.filename,
|
|
||||||
((InclusionData) data).reader.filename)) {
|
|
||||||
isCircular = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isCircular)
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pushContext(buffer);
|
pushContext(buffer);
|
||||||
|
@ -1369,6 +1352,24 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isCircularInclusion(InclusionData data) {
|
||||||
|
for (int i = 0; i < bufferStackPos; ++i) {
|
||||||
|
if (bufferData[i] instanceof CodeReader
|
||||||
|
&& CharArrayUtils.equals(
|
||||||
|
((CodeReader) bufferData[i]).filename,
|
||||||
|
data.reader.filename)) {
|
||||||
|
return true;
|
||||||
|
} else if (bufferData[i] instanceof InclusionData
|
||||||
|
&& CharArrayUtils
|
||||||
|
.equals(
|
||||||
|
((InclusionData) bufferData[i]).reader.filename,
|
||||||
|
data.reader.filename)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected Object popContext() {
|
protected Object popContext() {
|
||||||
//NOTE - do not set counters to 0 or -1 or something
|
//NOTE - do not set counters to 0 or -1 or something
|
||||||
//Subclasses may require those values in their popContext()
|
//Subclasses may require those values in their popContext()
|
||||||
|
|
|
@ -187,11 +187,13 @@ public class DOMScanner extends BaseScanner {
|
||||||
b.append(((InclusionData) data).reader.filename);
|
b.append(((InclusionData) data).reader.filename);
|
||||||
log.traceLog(b.toString());
|
log.traceLog(b.toString());
|
||||||
}
|
}
|
||||||
|
if( ! isCircularInclusion( (InclusionData) data ))
|
||||||
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
|
{
|
||||||
locationMap.startInclusion(((InclusionData) data).reader, inc.o,
|
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
|
||||||
resolveOffset(getCurrentOffset()));
|
locationMap.startInclusion(((InclusionData) data).reader, inc.o,
|
||||||
bufferDelta[bufferStackPos + 1] = 0;
|
resolveOffset(getCurrentOffset()));
|
||||||
|
bufferDelta[bufferStackPos + 1] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (data instanceof MacroData) {
|
else if (data instanceof MacroData) {
|
||||||
|
|
|
@ -37,4 +37,8 @@ public class InclusionNode implements IASTInclusionNode, IDependencyNodeHost {
|
||||||
incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node );
|
incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return stmt.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,6 +458,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
return new String(path);
|
return new String(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue