diff --git a/cmake/org.eclipse.cdt.cmake.is.core/.options b/cmake/org.eclipse.cdt.cmake.is.core/.options
index 63f54a86c06..1ba287d7b04 100644
--- a/cmake/org.eclipse.cdt.cmake.is.core/.options
+++ b/cmake/org.eclipse.cdt.cmake.is.core/.options
@@ -1,12 +1,10 @@
# Debugging options for the org.eclipse.cdt.cmake.is.core plugin.
-# Trace CMAKE_EXPORT_COMPILE_COMMANDS Parser tool detection participant lookup
-org.eclipse.cdt.cmake.is.core/CECC/participant=false
-# Trace CMAKE_EXPORT_COMPILE_COMMANDS Parser command-line argument parser lookup
-org.eclipse.cdt.cmake.is.core/CECC/arglets=false
-# Trace detected language setting entries
-org.eclipse.cdt.cmake.is.core/CECC/entries=false
-# Trace language setting entries as passed to the indexer
-org.eclipse.cdt.cmake.is.core/CECC/indexer-entries=false
-# Trace CMAKE_EXPORT_COMPILE_COMMANDS Compiler Built-ins detected language setting entries
-org.eclipse.cdt.cmake.is.core/CECC/builtins/entries=false
+# Trace total time for parsing compile_commands.json files
+org.eclipse.cdt.cmake.is.core/debug/performance=false
+# Trace compile_commands.json Parser tool detection participant lookup
+org.eclipse.cdt.cmake.is.core/debug/participant=false
+# Trace how compiler command-line arguments are detected and parsed
+org.eclipse.cdt.cmake.is.core/debug/arglets=false
+# Trace detected preprocessor symbols and include path entries as passed to the indexer
+org.eclipse.cdt.cmake.is.core/debug/detected.entries=false
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/Arglets.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/Arglets.java
index c64c8a95290..269e76ad939 100644
--- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/Arglets.java
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/Arglets.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015-2019 Martin Weber.
+ * Copyright (c) 2015-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.
@@ -11,10 +11,7 @@ package org.eclipse.cdt.cmake.is.core;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.cdt.cmake.is.core.IArglet.IParseContext;
-import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
-import org.eclipse.cdt.core.settings.model.ICSettingEntry;
-import org.eclipse.cdt.core.settings.model.util.CDataUtil;
+import org.eclipse.cdt.cmake.is.core.IArglet.IArgumentCollector;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -23,7 +20,7 @@ import org.eclipse.core.runtime.Path;
*
* @author Martin Weber
*/
-public class Arglets {
+public final class Arglets {
private static final String EMPTY_STR = ""; //$NON-NLS-1$
/** matches a macro name, with optional macro parameter list */
@@ -134,7 +131,7 @@ public class Arglets {
*/
public static abstract class MacroDefineGeneric {
- protected final int processArgument(IParseContext parseContext, String args,
+ protected final int processArgument(IArgumentCollector resultCollector, String args,
NameValueOptionMatcher[] optionMatchers) {
for (NameValueOptionMatcher oMatcher : optionMatchers) {
final Matcher matcher = oMatcher.matcher;
@@ -143,9 +140,7 @@ public class Arglets {
if (matcher.lookingAt()) {
final String name = matcher.group(oMatcher.nameGroup);
final String value = oMatcher.valueGroup == -1 ? null : matcher.group(oMatcher.valueGroup);
- final ICLanguageSettingEntry entry = CDataUtil.createCMacroEntry(name, value,
- ICSettingEntry.READONLY);
- parseContext.addSettingEntry(entry);
+ resultCollector.addDefine(name, value);
final int end = matcher.end();
return end;
}
@@ -162,16 +157,14 @@ public class Arglets {
/*-
* @see org.eclipse.cdt.cmake.is.IArglet#processArgument(java.util.List, java.lang.String)
*/
- protected final int processArgument(IParseContext parseContext, String argsLine,
+ protected final int processArgument(IArgumentCollector resultCollector, String argsLine,
NameOptionMatcher optionMatcher) {
final Matcher oMatcher = optionMatcher.matcher;
oMatcher.reset(argsLine);
if (oMatcher.lookingAt()) {
final String name = oMatcher.group(1);
- final ICLanguageSettingEntry entry = CDataUtil.createCMacroEntry(name, null,
- ICSettingEntry.UNDEFINED | ICSettingEntry.READONLY);
- parseContext.addSettingEntry(entry);
+ resultCollector.addUndefine(name);
final int end = oMatcher.end();
return end;
}
@@ -184,12 +177,13 @@ public class Arglets {
*/
public static abstract class IncludePathGeneric {
/**
+ * @param isSystemIncludePath true
if the include path is a system include path otherwise false
* @param cwd the current working directory of the compiler at its invocation
- * @see org.eclipse.cdt.cmake.is.core.IArglet#processArgument(IParseContext,
+ * @see org.eclipse.cdt.cmake.is.core.IArglet#processArgument(IArgumentCollector,
* IPath, String)
*/
- protected final int processArgument(IParseContext parseContext, IPath cwd, String argsLine,
- NameOptionMatcher[] optionMatchers) {
+ protected final int processArgument(boolean isSystemIncludePath, IArgumentCollector resultCollector, IPath cwd,
+ String argsLine, NameOptionMatcher[] optionMatchers) {
for (NameOptionMatcher oMatcher : optionMatchers) {
final Matcher matcher = oMatcher.matcher;
@@ -203,10 +197,11 @@ public class Arglets {
// prepend CWD
name = cwd.append(path).toOSString();
}
-
- final ICLanguageSettingEntry entry = CDataUtil.createCIncludePathEntry(name,
- ICSettingEntry.READONLY);
- parseContext.addSettingEntry(entry);
+ if (isSystemIncludePath) {
+ resultCollector.addSystemIncludePath(name);
+ } else {
+ resultCollector.addIncludePath(name);
+ }
final int end = matcher.end();
return end;
}
@@ -249,8 +244,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, argsLine, optionMatchers);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(resultCollector, argsLine, optionMatchers);
}
}
@@ -270,8 +265,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgument(java.util.List, java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, argsLine, optionMatcher);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(resultCollector, argsLine, optionMatcher);
}
}
@@ -292,8 +287,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, cwd, argsLine, optionMatchers);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(false, resultCollector, cwd, argsLine, optionMatchers);
}
}
@@ -314,8 +309,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, cwd, argsLine, optionMatchers);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(true, resultCollector, cwd, argsLine, optionMatchers);
}
}
@@ -324,6 +319,7 @@ public class Arglets {
* A tool argument parser capable to parse a armcc-compiler system include path
* argument: {@code -Jdir}.
*/
+ // TODO move this to the arm plugin
public static class SystemIncludePath_armcc extends IncludePathGeneric implements IArglet {
@SuppressWarnings("nls")
static final NameOptionMatcher[] optionMatchers = {
@@ -336,8 +332,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, cwd, argsLine, optionMatchers);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(true, resultCollector, cwd, argsLine, optionMatchers);
}
}
@@ -355,14 +351,15 @@ public class Arglets {
*/
public static abstract class BuiltinDetctionArgsGeneric {
/**
- * @see org.eclipse.cdt.cmake.is.core.IArglet#processArgument(IParseContext,
+ * @see org.eclipse.cdt.cmake.is.core.IArglet#processArgument(IArgumentCollector,
* IPath, String)
*/
- protected final int processArgument(IParseContext parseContext, String argsLine, Matcher[] optionMatchers) {
+ protected final int processArgument(IArgumentCollector resultCollector, String argsLine,
+ Matcher[] optionMatchers) {
for (Matcher matcher : optionMatchers) {
matcher.reset(argsLine);
if (matcher.lookingAt()) {
- parseContext.addBuiltinDetectionArgument(matcher.group());
+ resultCollector.addBuiltinDetectionArgument(matcher.group());
return matcher.end();
}
}
@@ -393,8 +390,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, argsLine, optionMatchers);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(resultCollector, argsLine, optionMatchers);
}
}
@@ -412,8 +409,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/
@Override
- public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) {
- return processArgument(parseContext, argsLine, optionMatchers);
+ public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
+ return processArgument(resultCollector, argsLine, optionMatchers);
}
}
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/DefaultToolCommandlineParser.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/DefaultToolCommandlineParser.java
index 0ed6d9b47ae..141670d036c 100644
--- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/DefaultToolCommandlineParser.java
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/DefaultToolCommandlineParser.java
@@ -9,10 +9,8 @@
package org.eclipse.cdt.cmake.is.core;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Objects;
import java.util.Optional;
-import java.util.Set;
import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsDetectionBehavior;
import org.eclipse.cdt.cmake.is.core.internal.ParseContext;
@@ -28,19 +26,13 @@ import org.eclipse.core.runtime.Platform;
* @author Martin Weber
*/
public class DefaultToolCommandlineParser implements IToolCommandlineParser {
- @SuppressWarnings("nls")
- private static final boolean DEBUG = Boolean.parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/CECC/args"));
+ private static final boolean DEBUG = Boolean
+ .parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/debug/arglets")); //$NON-NLS-1$
private final IArglet[] argumentParsers;
- private final String languageID;
private final IResponseFileArglet responseFileArglet;
private final IBuiltinsDetectionBehavior builtinsDetection;
- /** gathers the result */
- private ParseContext result;
-
- private IPath cwd;
-
/**
* Constructs a new object with the given values.
*
@@ -51,10 +43,6 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
* "com.nvidia.cuda.toolchain.language.cuda.cu"
*
*
- * @param languageID the language ID of the language that the
- * tool compiles or {@code null} if the
- * language ID should be derived from the
- * source file-name extension
* @param responseFileArglet the parsers for the response-file
* command-line argument for the tool or
* {@code null} if the tool does not recognize
@@ -67,6 +55,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
* detection.
* @param argumentParsers the parsers for the command line arguments
* of of interest for the tool
+ *
* @throws NullPointerException if the {@code argumentParsers} arguments is
* {@code null}
* @see Arglets various IArglet implementations you may want to use
@@ -74,9 +63,8 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
* you may want to use
*/
@SuppressWarnings("nls")
- public DefaultToolCommandlineParser(String languageID, IResponseFileArglet responseFileArglet,
+ public DefaultToolCommandlineParser(IResponseFileArglet responseFileArglet,
IBuiltinsDetectionBehavior builtinsDetectionBehavior, IArglet... argumentParsers) {
- this.languageID = languageID;
this.builtinsDetection = builtinsDetectionBehavior;
this.argumentParsers = Objects.requireNonNull(argumentParsers, "argumentParsers");
this.responseFileArglet = responseFileArglet;
@@ -84,60 +72,8 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
@Override
public IResult processArgs(IPath cwd, String args) {
- this.result = new ParseContext();
- this.cwd = Objects.requireNonNull(cwd, "cwd"); //$NON-NLS-1$
-
- ParserHandler ph = new ParserHandler();
- ph.parseArguments(responseFileArglet, args);
- return result;
- }
-
- /**
- * Implemented to determine the language ID from the source file name extension,
- * if the language ID of this object is {@code null}.
- */
- @Override
- public String getLanguageId(String sourceFileExtension) {
- if (languageID != null) {
- return languageID;
- }
- return determineLanguageId(sourceFileExtension).orElse(null);
- }
-
- /**
- * Default implementation.
- *
- * @return always an empty set
- */
- @Override
- public Set getCustomLanguageIds() {
- return Collections.emptySet();
- }
-
- /**
- * Gets the languageID of the specified file name extension. This is a
- * convenience method for subclasses.
- *
- * @param sourceFileExtension The file name extension to examine
- * @return an {@code Optional} holding the language ID or {@code Optional.empty()} if the file name extension is
- * unknown.
- */
- @SuppressWarnings("nls")
- protected Optional determineLanguageId(String sourceFileExtension) {
- switch (sourceFileExtension) {
- case "c":
- return Optional.of("org.eclipse.cdt.core.gcc");
- case "C":
- case "cc":
- case "cpp":
- case "CPP":
- case "cp":
- case "cxx":
- case "c++":
- return Optional.of("org.eclipse.cdt.core.g++");
- default:
- return Optional.empty();
- }
+ ParserHandler ph = new ParserHandler(cwd);
+ return ph.parseArguments(responseFileArglet, args);
}
@Override
@@ -148,7 +84,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
@SuppressWarnings("nls")
@Override
public String toString() {
- return "[languageID=" + this.languageID + ", argumentParsers=" + Arrays.toString(this.argumentParsers) + "]";
+ return "[" + getClass().getName() + ", argumentParsers=" + Arrays.toString(this.argumentParsers) + "]";
}
/**
@@ -175,12 +111,25 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
*/
private class ParserHandler implements IParserHandler {
+ private final IPath cwd;
+
+ /**
+ * @param cwd the current working directory of the compiler at the time of its
+ * invocation
+ *
+ * @throws NullPointerException if any of the arguments is {@code null}
+ */
+ public ParserHandler(IPath cwd) {
+ this.cwd = Objects.requireNonNull(cwd, "cwd"); //$NON-NLS-1$
+ }
+
/**
* @param responseFileArglet
* @param args the command line arguments to process
*/
@SuppressWarnings("nls")
- private void parseArguments(IResponseFileArglet responseFileArglet, String args) {
+ private IResult parseArguments(IResponseFileArglet responseFileArglet, String args) {
+ ParseContext result = new ParseContext();
// eat buildOutput string argument by argument..
while (!(args = StringUtil.trimLeadingWS(args)).isEmpty()) {
boolean argParsed = false;
@@ -227,6 +176,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
}
}
}
+ return result;
}
/**
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IArglet.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IArglet.java
index c88f4c9cf26..02b72097d48 100644
--- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IArglet.java
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IArglet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015-2019 Martin Weber.
+ * Copyright (c) 2015-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.
@@ -8,7 +8,6 @@
*******************************************************************************/
package org.eclipse.cdt.cmake.is.core;
-import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.core.runtime.IPath;
/**
@@ -23,37 +22,30 @@ public interface IArglet {
* Parses the next command-line argument and extracts all detected
* LanguageSettings objects.
*
- * @param parseContext the buffer that receives the new {@code LanguageSetting}
- * entries
- * @param cwd the current working directory of the compiler at its
- * invocation
- * @param argsLine the arguments passed to the tool, as they appear in the
- * build output. Implementers may safely assume that the
- * specified value does not contain leading whitespace
- * characters, but trailing WS may occur.
+ * @param resultCollector the buffer that receives the parsed command-line
+ * arguments
+ * @param cwd the current working directory of the compiler at its
+ * invocation
+ * @param argsLine the arguments passed to the tool, as they appear in
+ * the build output. Implementers may safely assume that
+ * the specified value does not contain leading
+ * whitespace characters, but trailing WS may occur.
* @return the number of characters from {@code argsLine} that has been
* processed. Return a value of {@code zero} or less, if this tool
* argument parser cannot process the first argument from the input.
*/
- int processArgument(IParseContext parseContext, IPath cwd, String argsLine);
+ int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine);
/**
* Gathers the results of argument parsing.
*
* @author Martin Weber
*/
- interface IParseContext {
+ interface IArgumentCollector extends IRawIndexerInfoCollector {
/**
- * Adds a language setting to the result.
- *
- * @param entry
- */
- void addSettingEntry(ICLanguageSettingEntry entry);
-
- /**
- * Adds a compiler argument that affects built-in detection to the result. For
- * the GNU compilers, these are options like {@code --sysroot} and options that
- * specify the language's standard ({@code -std=c++17}.
+ * Adds a compiler argument that affects built-in detection. For the GNU
+ * compilers, these are options like {@code --sysroot} and options that specify
+ * the language's standard ({@code -std=c++17}.
*/
void addBuiltinDetectionArgument(String argument);
}
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IRawIndexerInfo.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IRawIndexerInfo.java
new file mode 100644
index 00000000000..641d72ef8e0
--- /dev/null
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IRawIndexerInfo.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Martin Weber.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+
+package org.eclipse.cdt.cmake.is.core;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Information about C preprocessor symbols and include paths collected from a
+ * compiler command-line or by performing compiler built-ins detection.
+ *
+ * @author weber
+ */
+public interface IRawIndexerInfo {
+ /**
+ * Gets the preprocessor symbols (macro definition)s.
+ */
+ Map getDefines();
+
+ /**
+ * Gets the preprocessor symbol cancellations (macro undefine) collected from
+ * the command-line.
+ */
+ List getUndefines();
+
+ /**
+ * Gets the preprocessor include paths collected from the command-line.
+ */
+ List getIncludePaths();
+
+ /**
+ * Gets the preprocessor system include paths collected from the command-line.
+ */
+ List getSystemIncludePaths();
+}
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IRawIndexerInfoCollector.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IRawIndexerInfoCollector.java
new file mode 100644
index 00000000000..c7dae77314b
--- /dev/null
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IRawIndexerInfoCollector.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Martin Weber.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+
+package org.eclipse.cdt.cmake.is.core;
+
+/**
+ * Gathers information about C preprocessor symbols and include paths collected
+ * from a compiler command-line or by performing compiler built-ins detection.
+ *
+ * @author weber
+ */
+public interface IRawIndexerInfoCollector {
+
+ /**
+ * Adds a preprocessor symbol (macro definition).
+ *
+ * @param name the name of the preprocessor symbol
+ * @param value the symbol value or {@code null} or the empty string if the
+ * symbol has no value
+ */
+ void addDefine(String name, String value);
+
+ /**
+ * Adds a preprocessor symbol cancellation (macro undefine) and cancels any
+ * previous definition of {@code name} that was added through
+ * {@link #addDefine(String, String)}.
+ *
+ * @param name the name of the preprocessor symbol to cancel
+ */
+ void addUndefine(String name);
+
+ /**
+ * Adds a preprocessor include path.
+ *
+ * @param path the name of the include directory
+ */
+ void addIncludePath(String path);
+
+ /**
+ * Adds a preprocessor system include path.
+ *
+ * @param path the name of the include directory
+ */
+ void addSystemIncludePath(String path);
+
+}
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IToolCommandlineParser.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IToolCommandlineParser.java
index 9424e387704..32d3646e6be 100644
--- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IToolCommandlineParser.java
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/IToolCommandlineParser.java
@@ -10,10 +10,8 @@ package org.eclipse.cdt.cmake.is.core;
import java.util.List;
import java.util.Optional;
-import java.util.Set;
import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsDetectionBehavior;
-import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.core.runtime.IPath;
/**
@@ -34,45 +32,13 @@ public interface IToolCommandlineParser {
*/
public IResult processArgs(IPath cwd, String args);
- /**
- * Gets the language ID of the language that the tool compiles. If the tool is
- * able to compile for multiple programming languages, the specified
- * {@code sourceFileExtension} may be used to compute the Language ID.
- *
- * NOTE: CDT expects "org.eclipse.cdt.core.gcc" for the C language and
- * "org.eclipse.cdt.core.g++" for the C++ language, so one of that IDs should be
- * returned here. (Some extension to CDT may recognize different language IDs,
- * such as "com.nvidia.cuda.toolchain.language.cuda.cu".)
- *
- *
- * @param sourceFileExtension the extension of the source file name
- *
- * @return a valid language ID, or {@code null}. If {@code null} or an invalid
- * language ID, the results of argument processing will be ignored by
- * CDT.
- */
- public String getLanguageId(String sourceFileExtension);
-
- /**
- * Gets the custom language IDs that the tool compiles. Some CDT based IDEs use
- * language IDs of their own, for example
- * "com.nvidia.cuda.toolchain.language.cuda.cu" for CUDA. A custom language ID
- * is an ID other than CDT's default IDs for the C language
- * ("org.eclipse.cdt.core.gcc") and the C++ ("org.eclipse.cdt.core.g++")
- * language,
- *
- * @return the custom language IDs or an empty set if the tool does not compile
- * for languages other than C and C++
- */
- public Set getCustomLanguageIds();
-
/**
* Gets the {@code IBuiltinsDetectionBehavior} which specifies how built-in
* compiler macros and include path detection is handled for a specific
* compiler.
*
- * @return the {@code IBuiltinsDetectionBehavior} or an empty {@code Oprional} if the
- * compiler does not support built-in detection
+ * @return the {@code IBuiltinsDetectionBehavior} or an empty {@code Optional}
+ * if the compiler does not support built-in detection
*/
public Optional getIBuiltinsDetectionBehavior();
@@ -83,14 +49,7 @@ public interface IToolCommandlineParser {
*
* @see IToolCommandlineParser#processArgs(IPath, String)
*/
- interface IResult {
- /**
- * Gets the language setting entries produced during processing.
- *
- * @return the language setting entries
- */
- List getSettingEntries();
-
+ interface IResult extends IRawIndexerInfo {
/**
* Gets the compiler arguments from the command-line that affect built-in
* detection. For the GNU compilers, these are options like {@code --sysroot}
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParseContext.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParseContext.java
index c3c1a7e2aa9..0dd73f68b06 100644
--- a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParseContext.java
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/internal/ParseContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2019 Martin Weber.
+ * Copyright (c) 2019-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.
@@ -14,41 +14,24 @@ import java.util.List;
import org.eclipse.cdt.cmake.is.core.IArglet;
import org.eclipse.cdt.cmake.is.core.IToolCommandlineParser;
-import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.cdt.cmake.is.core.internal.builtins.RawIndexerInfo;
/**
- * Default implementation of IParseContext.
+ * Default implementation of IArgumentCollector.
*
* @author Martin Weber
*/
-public class ParseContext implements IArglet.IParseContext, IToolCommandlineParser.IResult {
- @SuppressWarnings("nls")
- private static final boolean DEBUG = Boolean
- .parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/CECC/entries"));
- private final List entries = new ArrayList<>();
+public final class ParseContext extends RawIndexerInfo
+ implements IArglet.IArgumentCollector, IToolCommandlineParser.IResult {
private final List args = new ArrayList<>();
- @Override
- public void addSettingEntry(ICLanguageSettingEntry entry) {
- if (DEBUG)
- System.out.printf(" Added entry: %s%n", entry); //$NON-NLS-1$
- entries.add(entry);
- }
-
@Override
public void addBuiltinDetectionArgument(String argument) {
args.add(argument);
}
- @Override
- public List getSettingEntries() {
- return entries;
- }
-
@Override
public List getBuiltinDetectionArgs() {
return args;
}
-
}
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 2635efb3ba0..5a630ecc526 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
@@ -15,9 +15,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Set;
import java.util.function.Consumer;
-import java.util.stream.Collectors;
import org.eclipse.cdt.cmake.is.core.Arglets;
import org.eclipse.cdt.cmake.is.core.DefaultToolCommandlineParser;
@@ -45,68 +43,72 @@ import org.eclipse.core.runtime.Status;
*
*/
@SuppressWarnings("nls")
-public class ParserDetection {
+public final class ParserDetection {
private static final ILog log = Plugin.getDefault().getLog();
private static final boolean DEBUG_PARTCIPANT_DETECTION = Boolean
- .parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/CECC/participant"));
+ .parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/debug/participant"));
/**
* tool detectors and their tool option parsers for each tool of interest that
* takes part in the current build. The Matcher detects whether a command line
* is an invocation of the tool.
*/
- private static final List parserDetectors = new ArrayList<>(22);
+ private static List parserDetectors;
- static {
- /** Names of known tools along with their command line argument parsers */
- 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() };
+ static void init() {
+ if (parserDetectors == null) {
+ parserDetectors = new ArrayList<>(22);
- IBuiltinsDetectionBehavior btbGccMaybee = new MaybeGccBuiltinDetectionBehavior();
- IBuiltinsDetectionBehavior btbGcc = new GccBuiltinDetectionBehavior();
+ /** Names of known tools along with their command line argument parsers */
+ 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() };
- // POSIX compatible C compilers =================================
- {
- final IToolCommandlineParser cc = new DefaultToolCommandlineParser("org.eclipse.cdt.core.gcc",
- new ResponseFileArglets.At(), btbGccMaybee, gcc_args);
- parserDetectors.add(new DefaultToolDetectionParticipant("cc", true, "exe", cc));
- }
- // POSIX compatible C++ compilers ===============================
- {
- final IToolCommandlineParser cxx = new DefaultToolCommandlineParser("org.eclipse.cdt.core.g++",
- new ResponseFileArglets.At(), btbGccMaybee, gcc_args);
- parserDetectors.add(new DefaultToolDetectionParticipant("c\\+\\+", true, "exe", cxx));
- }
+ IBuiltinsDetectionBehavior btbGccMaybee = new MaybeGccBuiltinDetectionBehavior();
+ IBuiltinsDetectionBehavior btbGcc = new GccBuiltinDetectionBehavior();
- // GNU C compatible compilers ====
- {
- final IToolCommandlineParser gcc = new DefaultToolCommandlineParser("org.eclipse.cdt.core.gcc",
- new ResponseFileArglets.At(), btbGcc, gcc_args);
- parserDetectors.add(new DefaultToolDetectionParticipant("gcc", true, "exe", gcc));
- parserDetectors.add(new DefaultToolDetectionParticipant("clang", true, "exe", gcc));
- // cross compilers, e.g. arm-none-eabi-gcc ====
- parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-gcc", true, "exe", gcc));
- }
- // GNU C++ compatible compilers ====
- {
- final IToolCommandlineParser gxx = new DefaultToolCommandlineParser("org.eclipse.cdt.core.g++",
- new ResponseFileArglets.At(), btbGcc, gcc_args);
- parserDetectors.add(new DefaultToolDetectionParticipant("g\\+\\+", true, "exe", gxx));
- parserDetectors.add(new DefaultToolDetectionParticipant("clang\\+\\+", true, "exe", gxx));
- // cross compilers, e.g. arm-none-eabi-g++ ====
- parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-g\\+\\+", true, "exe", gxx));
- }
- {
- // cross compilers, e.g. arm-none-eabi-c++ ====
- final IToolCommandlineParser cxx = new DefaultToolCommandlineParser("org.eclipse.cdt.core.g++",
- new ResponseFileArglets.At(), btbGccMaybee, gcc_args);
- parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-c\\+\\+", true, "exe", cxx));
- }
+ // POSIX compatible C compilers =================================
+ {
+ final IToolCommandlineParser cc = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
+ btbGccMaybee, gcc_args);
+ parserDetectors.add(new DefaultToolDetectionParticipant("cc", true, "exe", cc));
+ }
+ // POSIX compatible C++ compilers ===============================
+ {
+ final IToolCommandlineParser cxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
+ btbGccMaybee, gcc_args);
+ parserDetectors.add(new DefaultToolDetectionParticipant("c\\+\\+", true, "exe", cxx));
+ }
- // compilers from extension points
- loadExtentionsSorted(parserDetectors::add);
+ // GNU C compatible compilers ====
+ {
+ final IToolCommandlineParser gcc = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
+ btbGcc, gcc_args);
+ parserDetectors.add(new DefaultToolDetectionParticipant("gcc", true, "exe", gcc));
+ parserDetectors.add(new DefaultToolDetectionParticipant("clang", true, "exe", gcc));
+ // cross compilers, e.g. arm-none-eabi-gcc ====
+ parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-gcc", true, "exe", gcc));
+ }
+ // GNU C++ compatible compilers ====
+ {
+ final IToolCommandlineParser gxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
+ btbGcc, gcc_args);
+ parserDetectors.add(new DefaultToolDetectionParticipant("g\\+\\+", true, "exe", gxx));
+ parserDetectors.add(new DefaultToolDetectionParticipant("clang\\+\\+", true, "exe", gxx));
+ // cross compilers, e.g. arm-none-eabi-g++ ====
+ parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-g\\+\\+", true, "exe", gxx));
+ }
+ {
+ // cross compilers, e.g. arm-none-eabi-c++ ====
+ final IToolCommandlineParser cxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
+ btbGccMaybee, gcc_args);
+ parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-c\\+\\+", true, "exe", cxx));
+ }
+
+ // compilers from extension points
+ loadExtentionsSorted(parserDetectors::add);
+ }
}
/**
@@ -141,16 +143,6 @@ public class ParserDetection {
private ParserDetection() {
}
- /**
- * Gets the custom language IDs of each of the IToolDetectionParticipants.
- *
- * @see IToolCommandlineParser#getCustomLanguageIds()
- */
- public static Set getCustomLanguages() {
- return parserDetectors.stream().map(d -> d.getParser().getCustomLanguageIds()).flatMap(l -> l.stream())
- .collect(Collectors.toSet());
- }
-
/**
* Determines the parser detector that can parse the specified command-line.
*
@@ -217,6 +209,8 @@ public class ParserDetection {
*/
private static ParserDetectionResult determineDetector0(String commandLine, String versionSuffixRegex,
boolean matchBackslash) {
+ init();
+
Optional cmdline;
// try basenames
for (IToolDetectionParticipant pd : parserDetectors) {
diff --git a/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/language/settings/providers/IIndexerInfoConsumer.java b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/language/settings/providers/IIndexerInfoConsumer.java
new file mode 100644
index 00000000000..76761668327
--- /dev/null
+++ b/cmake/org.eclipse.cdt.cmake.is.core/src/main/java/org/eclipse/cdt/cmake/is/core/language/settings/providers/IIndexerInfoConsumer.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Martin Weber.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+
+package org.eclipse.cdt.cmake.is.core.language.settings.providers;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Receives the indexer relevant information for each source file.
+ *
+ * @author weber
+ */
+public interface IIndexerInfoConsumer {
+ // TODO Docs
+ // Yes. Docs are currently intentionally missing here, since ATM it is not clear how to properly handle the sourceFileName argument.
+ //
+ // Cmake writes filenames with forward slashes (/) even if it runs on windows.
+ // OTOH, IScannerInfoProvider requests info for IResourceS.
+ // Somewhere in the calling sequence, the filenames have to be converted/mapped to IResource.Conversion*could*
+ // be done in CompileCommandsJsonParser, but when I think of builds running
+ // in a Linux-Docker-Container under windows, it might be better to do the conversion
+ //on the IIndexerInfoConsumer side which has more information on the build setup.
+ void acceptSourceFileInfo(String sourceFileName, List systemIncludePaths,
+ Map definedSymbols, List includePaths);
+}