diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java index 7bdd914d8b2..f651963efab 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java @@ -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); + } + } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index c73ab8fb4a5..0285de6f199 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -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) + // #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(); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index e53ee231e15..aac62c4d8f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -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) {