mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Testcase and fix for 164644, slash inside function style macro
This commit is contained in:
parent
10f16fe5d3
commit
3954755d03
3 changed files with 48 additions and 1 deletions
|
@ -15,6 +15,7 @@
|
|||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
@ -23,7 +24,9 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -136,4 +139,9 @@ public class AST2FileBasePluginTest extends TestCase {
|
|||
return file;
|
||||
}
|
||||
|
||||
protected StringBuffer[] getContents(int sections) throws IOException {
|
||||
return TestSourceReader.getContentsForTest(
|
||||
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
@ -609,4 +610,40 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
assertFileLocation(incName, filename, code.lastIndexOf("TARG"), "TARG".length());
|
||||
}
|
||||
}
|
||||
|
||||
// #define NAME test.h
|
||||
// #define MAKE_INCLUDE(path, header) <path/header>
|
||||
// #include MAKE_INCLUDE(test_bug164644, NAME)
|
||||
public void testBug164644() throws Exception {
|
||||
String tmpDir= System.getProperty("java.io.tmpdir");
|
||||
File tmpFile= new File(tmpDir + "/test_bug164644/test.h").getCanonicalFile();
|
||||
tmpFile.getParentFile().mkdirs();
|
||||
tmpFile.createNewFile();
|
||||
try {
|
||||
String code= getContents(1)[0].toString();
|
||||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(
|
||||
Collections.EMPTY_MAP, new String[] {tmpDir}, null, null);
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "main.cc" : "main.c";
|
||||
IFile sfile = importFile(filename, code);
|
||||
IASTTranslationUnit tu = parse(sfile, scannerInfo);
|
||||
|
||||
IASTPreprocessorIncludeStatement[] incs = tu.getIncludeDirectives();
|
||||
assertNotNull(incs);
|
||||
assertEquals(1, incs.length);
|
||||
|
||||
assertEquals(tmpFile.getAbsolutePath(), incs[0].getPath());
|
||||
assertFileLocation(incs[0], filename, code.indexOf("#include MAKE_INCLUDE(test_bug164644, NAME)"), "#include MAKE_INCLUDE(test_bug164644, NAME)".length());
|
||||
IASTPreprocessorIncludeStatement inc = incs[0];
|
||||
IASTName incName= inc.getName();
|
||||
assertEquals(true, inc.isSystemInclude());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
tmpFile.delete();
|
||||
tmpFile.getParentFile().delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4397,9 +4397,10 @@ abstract class BaseScanner implements IScanner {
|
|||
} else if (c == '/' && pos + 1 < limit) {
|
||||
|
||||
// less than obvious, comments are whitespace
|
||||
c = expansion[++pos];
|
||||
c = expansion[pos+1];
|
||||
if (c == '/') {
|
||||
// copy up to here or before the last whitespace
|
||||
++pos;
|
||||
++lastcopy;
|
||||
int n = wsstart < 0 ? pos - 1 - lastcopy : wsstart
|
||||
- lastcopy;
|
||||
|
@ -4412,6 +4413,7 @@ abstract class BaseScanner implements IScanner {
|
|||
// skip the rest
|
||||
lastcopy = expansion.length - 1;
|
||||
} else if (c == '*') {
|
||||
++pos;
|
||||
if (wsstart < 1)
|
||||
wsstart = pos - 1;
|
||||
while (++pos < limit) {
|
||||
|
|
Loading…
Add table
Reference in a new issue