diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java index 1686b778fbd..90baeba904e 100644 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java @@ -389,12 +389,13 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { @Override public void acceptSourceFileInfo(String sourceFileName, List systemIncludePaths, - Map definedSymbols, List includePaths) { + Map definedSymbols, List includePaths, List macroFiles, + List includeFiles) { IFile file = getFileForCMakePath(sourceFileName); if (file != null) { ExtendedScannerInfo info = new ExtendedScannerInfo(definedSymbols, - systemIncludePaths.stream().toArray(String[]::new), null, null, - includePaths.stream().toArray(String[]::new)); + systemIncludePaths.stream().toArray(String[]::new), macroFiles.stream().toArray(String[]::new), + includeFiles.stream().toArray(String[]::new), includePaths.stream().toArray(String[]::new)); infoPerResource.put(file, info); haveUpdates = true; } diff --git a/cmake/org.eclipse.cdt.cmake.is.core.doc/doc/html/supported-compilers.xhtml b/cmake/org.eclipse.cdt.cmake.is.core.doc/doc/html/supported-compilers.xhtml index edf7d563d9a..b1a8e93715e 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core.doc/doc/html/supported-compilers.xhtml +++ b/cmake/org.eclipse.cdt.cmake.is.core.doc/doc/html/supported-compilers.xhtml @@ -27,6 +27,8 @@ th, td { Macros Include directories System include
directories + Macros file + Include file Compiler executables @@ -38,6 +40,8 @@ th, td { Yes Yes Yes + Yes (-imacros) + Yes (-include) cc, cc.exe, gcc, gcc.exe, ".+-gcc", ".+-gcc.exe" @@ -47,6 +51,8 @@ th, td { Yes Yes Yes + Yes (-imacros) + Yes (-include) c++, c++.exe, g++, g++.exe, ".+-g\+\+", ".+-g\+\+.exe" , ".+-c\+\+", ".+-c\+\+.exe" @@ -57,6 +63,8 @@ th, td { Yes Yes Yes + N/A + Yes (-include) clang, clang.exe @@ -66,6 +74,8 @@ th, td { Yes Yes Yes + N/A + Yes (-include) clang++, clang++.exe @@ -75,6 +85,8 @@ th, td { Yes Yes No + No + No cc, cc.exe @@ -84,6 +96,8 @@ th, td { Yes Yes No + No + No c++, c++.exe diff --git a/cmake/org.eclipse.cdt.cmake.is.core.tests/src/main/java/org/eclipse/cdt/cmake/is/core/internal/IncludeFile_GCCTest.java b/cmake/org.eclipse.cdt.cmake.is.core.tests/src/main/java/org/eclipse/cdt/cmake/is/core/internal/IncludeFile_GCCTest.java new file mode 100644 index 00000000000..68a7557a39d --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.is.core.tests/src/main/java/org/eclipse/cdt/cmake/is/core/internal/IncludeFile_GCCTest.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL". + * A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.cmake.is.core.internal; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.cdt.cmake.is.core.participant.Arglets.IncludeFile_GCC; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Martin Weber + */ +public class IncludeFile_GCCTest { + private IncludeFile_GCC testee; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + testee = new IncludeFile_GCC(); + } + + /** + * Test method for {@link IncludeFile_GCC#processArgument(IParseContext, IPath, java.lang.String)} . + */ + @Test + public final void testProcessArgument() { + final String more = " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c"; + ParseContext result; + String parsed; + + String name = "/an/Include/file.inc"; + IPath cwd = new Path(""); + // -include/an/Include/file.inc + result = new ParseContext(); + assertEquals(8 + name.length(), testee.processArgument(result, cwd, "-include" + name + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + // -include'/an/Include/file.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 2, testee.processArgument(result, cwd, "-include" + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + // -include"/an/Include/file.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 2, + testee.processArgument(result, cwd, "-include" + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + + // -include /an/Include/file.inc + result = new ParseContext(); + assertEquals(8 + name.length() + 3, testee.processArgument(result, cwd, "-include " + name + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + // -include '/an/Include/file.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-include " + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + // -include "/an/Include/file.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-include " + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + + name = (new Path("A:an\\Include/file.inc")).toOSString(); + // -includeA:an\Include/file.inc + result = new ParseContext(); + assertEquals(8 + name.length(), testee.processArgument(result, cwd, "-include" + name + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + } + + /** + * Test method for {@link IncludeFile_GCC#processArgument(IParseContext, IPath, java.lang.String)} + */ + @Test + public final void testProcessArgument_WS() { + final String more = " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c"; + ParseContext result = new ParseContext(); + String parsed; + + String name = "/ye olde/In clu de/fi le.inc"; + IPath cwd = new Path(""); + // -include'/ye olde/In clu de/fi le.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 2, testee.processArgument(result, cwd, "-include" + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + // -include"/ye olde/In clu de/fi le.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 2, + testee.processArgument(result, cwd, "-include" + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + + // -include '/ye olde/In clu de/fi le.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-include " + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + // -include "/ye olde/In clu de/fi le.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-include " + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + + name = (new Path("A:an\\In CLU de/fi le.inc")).toOSString(); + // -include'A:an\In CLU de/fi le.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 2, + testee.processArgument(result, cwd, "-include" + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getIncludeFiles().size()); + parsed = result.getIncludeFiles().get(0); + assertEquals("name", name, parsed); + } +} diff --git a/cmake/org.eclipse.cdt.cmake.is.core.tests/src/main/java/org/eclipse/cdt/cmake/is/core/internal/MacrosFile_GCCTest.java b/cmake/org.eclipse.cdt.cmake.is.core.tests/src/main/java/org/eclipse/cdt/cmake/is/core/internal/MacrosFile_GCCTest.java new file mode 100644 index 00000000000..61e56c41210 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.is.core.tests/src/main/java/org/eclipse/cdt/cmake/is/core/internal/MacrosFile_GCCTest.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * Content is provided to you under the terms and conditions of the Eclipse Public License Version 2.0 "EPL". + * A copy of the EPL is available at http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.cmake.is.core.internal; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.cdt.cmake.is.core.participant.Arglets.MacrosFile_GCC; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Martin Weber + */ +public class MacrosFile_GCCTest { + private MacrosFile_GCC testee; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + testee = new MacrosFile_GCC(); + } + + /** + * Test method for {@link MacrosFile_GCC#processArgument(IParseContext, IPath, java.lang.String)} . + */ + @Test + public final void testProcessArgument() { + final String more = " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c"; + ParseContext result; + String parsed; + + String name = "/an/Macros/file.inc"; + IPath cwd = new Path(""); + // -imacros/an/Macros/file.inc + result = new ParseContext(); + assertEquals(8 + name.length(), testee.processArgument(result, cwd, "-imacros" + name + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + // -imacros'/an/Macros/file.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 2, testee.processArgument(result, cwd, "-imacros" + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + // -imacros"/an/Macros/file.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 2, + testee.processArgument(result, cwd, "-imacros" + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + + // -imacros /an/Macros/file.inc + result = new ParseContext(); + assertEquals(8 + name.length() + 3, testee.processArgument(result, cwd, "-imacros " + name + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + // -imacros '/an/Macros/file.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-imacros " + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + // -imacros "/an/Macros/file.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-imacros " + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + + name = (new Path("A:an\\Macros/file.inc")).toOSString(); + // -imacrosA:an\Macros/file.inc + result = new ParseContext(); + assertEquals(8 + name.length(), testee.processArgument(result, cwd, "-imacros" + name + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + } + + /** + * Test method for {@link MacrosFile_GCC#processArgument(IParseContext, IPath, java.lang.String)} + */ + @Test + public final void testProcessArgument_WS() { + final String more = " -o CMakeFiles/execut1.dir/util1.c.o -c /testprojects/C-subsrc/src/src-sub/main1.c"; + ParseContext result = new ParseContext(); + String parsed; + + String name = "/ye olde/Ma cr os/fi le.inc"; + IPath cwd = new Path(""); + // -imacros'/ye olde/Ma cr os/fi le.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 2, testee.processArgument(result, cwd, "-imacros" + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + // -imacros"/ye olde/Ma cr os/fi le.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 2, + testee.processArgument(result, cwd, "-imacros" + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + + // -imacros '/ye olde/Ma cr os/fi le.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-imacros " + "'" + name + "'" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + // -imacros "/ye olde/Ma cr os/fi le.inc" + result = new ParseContext(); + assertEquals(8 + name.length() + 3 + 2, + testee.processArgument(result, cwd, "-imacros " + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + + name = (new Path("A:an\\Ma cr os/fi le.inc")).toOSString(); + // -imacros'A:an\Ma cr os/fi le.inc' + result = new ParseContext(); + assertEquals(8 + name.length() + 2, + testee.processArgument(result, cwd, "-imacros" + "\"" + name + "\"" + more)); + assertEquals("#entries", 1, result.getMacroFiles().size()); + parsed = result.getMacroFiles().get(0); + assertEquals("name", name, parsed); + } +} diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/CompileCommandsJsonParser.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/CompileCommandsJsonParser.java index db50aafead2..ec1e9c9c632 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/CompileCommandsJsonParser.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/CompileCommandsJsonParser.java @@ -337,10 +337,12 @@ public class CompileCommandsJsonParser { .concat(fileResult.getSystemIncludePaths().stream(), builtinDetectorsResult.getSystemIncludePaths().stream()) .map(stringPooler).collect(Collectors.toList()); + List macroFiles = fileResult.getMacroFiles(); + List includeFiles = fileResult.getIncludeFiles(); // feed the paths and defines with the file name to the indexer.. parseRequest.getIndexerInfoConsumer().acceptSourceFileInfo(sourceFileName, systemIncludePaths, effectiveDefines, - includePaths); + includePaths, macroFiles, includeFiles); } private static void createMarker(IResource rc, String message) throws CoreException { diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java index a921dd1e4c5..bd2f300c141 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IIndexerInfoConsumer.java @@ -41,9 +41,16 @@ public interface IIndexerInfoConsumer { * the preprocessor macros used to compile the given source file * @param includePaths * the local include paths ({@code #include "..."}) used to compile the given source file + * @param macroFiles + * the names of files that will be pre-processed by the compiler before parsing the source-file in + * order to populate the preprocessor macro-dictionary + * @param includeFiles + * the names of files that will be pre-processed by the compiler as if + * an {@code #include "file"} directive appeared as the first line of the source file */ void acceptSourceFileInfo(String sourceFileName, List systemIncludePaths, - Map definedSymbols, List includePaths); + Map definedSymbols, List includePaths, List macroFiles, + List includeFiles); /** * Notifies this consumer that no further calls to {link {@link #acceptSourceFileInfo(String, List, Map, List)} will diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParserDetection.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParserDetection.java index 92647f5b249..5adb1cdf91c 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParserDetection.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParserDetection.java @@ -25,8 +25,8 @@ import org.eclipse.cdt.cmake.is.core.participant.DefaultToolDetectionParticipant import org.eclipse.cdt.cmake.is.core.participant.IArglet; import org.eclipse.cdt.cmake.is.core.participant.IToolCommandlineParser; import org.eclipse.cdt.cmake.is.core.participant.IToolDetectionParticipant; -import org.eclipse.cdt.cmake.is.core.participant.ResponseFileArglets; import org.eclipse.cdt.cmake.is.core.participant.IToolDetectionParticipant.MatchResult; +import org.eclipse.cdt.cmake.is.core.participant.ResponseFileArglets; import org.eclipse.cdt.cmake.is.core.participant.builtins.IBuiltinsDetectionBehavior; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -63,7 +63,8 @@ public final class ParserDetection { final IArglet[] gcc_args = { new Arglets.IncludePath_C_POSIX(), new Arglets.MacroDefine_C_POSIX(), new Arglets.MacroUndefine_C_POSIX(), // not defined by POSIX, but does not harm.. - new Arglets.SystemIncludePath_C(), new Arglets.LangStd_GCC(), new Arglets.Sysroot_GCC() }; + new Arglets.SystemIncludePath_C(), new Arglets.LangStd_GCC(), new Arglets.Sysroot_GCC(), + new Arglets.IncludeFile_GCC(), new Arglets.MacrosFile_GCC() }; IBuiltinsDetectionBehavior btbGccMaybee = new MaybeGccBuiltinDetectionBehavior(); IBuiltinsDetectionBehavior btbGcc = new GccBuiltinDetectionBehavior(); diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/RawIndexerInfo.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/RawIndexerInfo.java index 029e1bae87c..640a16d4419 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/RawIndexerInfo.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/builtins/RawIndexerInfo.java @@ -40,6 +40,8 @@ public class RawIndexerInfo implements IRawIndexerInfo, IRawIndexerInfoCollector private final List undefines = new ArrayList<>(); private final List includePaths = new ArrayList<>(); private final List systemIncludePaths = new ArrayList<>(); + private final List macroFiles = new ArrayList<>(0); + private final List includeFiles = new ArrayList<>(0); @Override public void addDefine(String name, String value) { @@ -87,6 +89,22 @@ public class RawIndexerInfo implements IRawIndexerInfo, IRawIndexerInfoCollector systemIncludePaths.add(path); } + @Override + public void addMacroFile(String path) { + Objects.requireNonNull(path); + if (DEBUG) + System.out.printf(" Added macro file: %s%n", path); //$NON-NLS-1$ + macroFiles.add(path); + } + + @Override + public void addIncludeFile(String path) { + Objects.requireNonNull(path); + if (DEBUG) + System.out.printf(" Added include file: %s%n", path); //$NON-NLS-1$ + includeFiles.add(path); + } + @Override public Map getDefines() { return Collections.unmodifiableMap(defines); @@ -106,4 +124,14 @@ public class RawIndexerInfo implements IRawIndexerInfo, IRawIndexerInfoCollector public List getSystemIncludePaths() { return Collections.unmodifiableList(systemIncludePaths); } + + @Override + public List getMacroFiles() { + return Collections.unmodifiableList(macroFiles); + } + + @Override + public List getIncludeFiles() { + return Collections.unmodifiableList(includeFiles); + } } diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/Arglets.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/Arglets.java index ad7fbd655b7..4233ade55c2 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/Arglets.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/Arglets.java @@ -210,6 +210,56 @@ public final class Arglets { } } + /** + * A tool argument parser capable to parse a C-compiler include file argument. + */ + public static abstract class IncludeFileGeneric { + /** + * @param cwd + * the current working directory of the compiler at its invocation + */ + protected final int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine, + NameOptionMatcher[] optionMatchers) { + for (NameOptionMatcher oMatcher : optionMatchers) { + final Matcher matcher = oMatcher.matcher; + + matcher.reset(argsLine); + if (matcher.lookingAt()) { + String name = matcher.group(oMatcher.nameGroup); + resultCollector.addIncludeFile(name); + final int end = matcher.end(); + return end; + } + } + return 0;// no input consumed + } + } + + /** + * A tool argument parser capable to parse a C-compiler macros file argument. + */ + public static abstract class MacrosFileGeneric { + /** + * @param cwd + * the current working directory of the compiler at its invocation + */ + protected final int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine, + NameOptionMatcher[] optionMatchers) { + for (NameOptionMatcher oMatcher : optionMatchers) { + final Matcher matcher = oMatcher.matcher; + + matcher.reset(argsLine); + if (matcher.lookingAt()) { + String name = matcher.group(oMatcher.nameGroup); + resultCollector.addMacroFile(name); + final int end = matcher.end(); + return end; + } + } + return 0;// no input consumed + } + } + //////////////////////////////////////////////////////////////////// // POSIX compatible option parsers //////////////////////////////////////////////////////////////////// @@ -367,6 +417,44 @@ public final class Arglets { } } + //////////////////////////////////////////////////////////////////// + /** + * A tool argument parser capable to parse a GCC include file argument {@code -include }. + */ + public static class IncludeFile_GCC extends IncludeFileGeneric implements IArglet { + @SuppressWarnings("nls") + private static final NameOptionMatcher[] optionMatchers = { + /* "-include=" quoted directory */ + new NameOptionMatcher("-include" + REGEX_INCLUDEPATH_QUOTED_DIR, 2), + /* "-include=" unquoted directory */ + new NameOptionMatcher("-include" + REGEX_INCLUDEPATH_UNQUOTED_DIR, 1), }; + + @Override + public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) { + return processArgument(resultCollector, cwd, argsLine, optionMatchers); + } + } + + /** + * A tool argument parser capable to parse a GCC macros file argument {@code -imacros }. + */ + public static class MacrosFile_GCC extends MacrosFileGeneric implements IArglet { + @SuppressWarnings("nls") + private static final NameOptionMatcher[] optionMatchers = { + /* "-include=" quoted directory */ + new NameOptionMatcher("-imacros" + REGEX_INCLUDEPATH_QUOTED_DIR, 2), + /* "-include=" unquoted directory */ + new NameOptionMatcher("-imacros" + REGEX_INCLUDEPATH_UNQUOTED_DIR, 1), }; + + /*- + * @see de.marw.cmake.cdt.lsp.IArglet#processArgs(java.lang.String) + */ + @Override + public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) { + return processArgument(resultCollector, cwd, argsLine, optionMatchers); + } + } + //////////////////////////////////////////////////////////////////// /** * A tool argument parser capable to parse a GCC option to specify paths diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfo.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfo.java index c5c2d3ec516..5c19172531c 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfo.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfo.java @@ -41,4 +41,16 @@ public interface IRawIndexerInfo { * Gets the preprocessor system include paths collected from the command-line. */ List getSystemIncludePaths(); + + /** + * Gets the names of files will be pre-processed by the compiler before parsing the source-file in + * order to populate the preprocessor macro-dictionary. + */ + List getMacroFiles(); + + /** + * Gets the names of files that will be pre-processed by the compiler as if + * an {@code #include "file"} directive appeared as the first line of the source file. + */ + List getIncludeFiles(); } diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfoCollector.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfoCollector.java index 55e5e596f07..6fc3f34ec21 100644 --- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfoCollector.java +++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/participant/IRawIndexerInfoCollector.java @@ -44,11 +44,26 @@ public interface IRawIndexerInfoCollector { */ void addIncludePath(String path); + /** + * Adds the name of a file that will be pre-processed by the compiler before parsing the source-file in + * order to populate the preprocessor macro-dictionary. + * + * @param path the name of the file + */ + void addSystemIncludePath(String path); + + /** + * Adds the name of a file that will be pre-processed by the compiler as if + * an {@code #include "file"} directive appeared as the first line of the source file. + * + * @param path the name of the file + */ + void addMacroFile(String path); + /** * Adds a preprocessor system include path. * * @param path the name of the include directory */ - void addSystemIncludePath(String path); - + void addIncludeFile(String path); } diff --git a/cmake/org.eclipse.cdt.cmake.is.nvidia.tests/src/main/java/org/eclipse/cdt/cmake/is/nvidia/builtins/NvccOutputProcessorTest.java b/cmake/org.eclipse.cdt.cmake.is.nvidia.tests/src/main/java/org/eclipse/cdt/cmake/is/nvidia/builtins/NvccOutputProcessorTest.java index f8be518945b..0d2c75e7542 100644 --- a/cmake/org.eclipse.cdt.cmake.is.nvidia.tests/src/main/java/org/eclipse/cdt/cmake/is/nvidia/builtins/NvccOutputProcessorTest.java +++ b/cmake/org.eclipse.cdt.cmake.is.nvidia.tests/src/main/java/org/eclipse/cdt/cmake/is/nvidia/builtins/NvccOutputProcessorTest.java @@ -93,5 +93,16 @@ public class NvccOutputProcessorTest { Objects.requireNonNull(path); systemIncludePaths.add(path); } + + @Override + public void addMacroFile(String path) { + // nvcc does not have a corresponding option + } + + @Override + public void addIncludeFile(String path) { + // nvcc does not have a corresponding option + + } } }