1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 559674: Migrating from a ILanguageSettingsProvider implementation to IIndexerInfoConsumer (1)

Change-Id: I0903f75c7cb4fbd4f3119ae22500b66b2f15794d
Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
This commit is contained in:
Martin Weber 2020-03-26 21:19:37 +01:00 committed by Alexander Fedorov
parent d374b71c94
commit fc7e62940f
10 changed files with 274 additions and 269 deletions

View file

@ -1,12 +1,10 @@
# Debugging options for the org.eclipse.cdt.cmake.is.core plugin. # Debugging options for the org.eclipse.cdt.cmake.is.core plugin.
# Trace CMAKE_EXPORT_COMPILE_COMMANDS Parser tool detection participant lookup # Trace total time for parsing compile_commands.json files
org.eclipse.cdt.cmake.is.core/CECC/participant=false org.eclipse.cdt.cmake.is.core/debug/performance=false
# Trace CMAKE_EXPORT_COMPILE_COMMANDS Parser command-line argument parser lookup # Trace compile_commands.json Parser tool detection participant lookup
org.eclipse.cdt.cmake.is.core/CECC/arglets=false org.eclipse.cdt.cmake.is.core/debug/participant=false
# Trace detected language setting entries # Trace how compiler command-line arguments are detected and parsed
org.eclipse.cdt.cmake.is.core/CECC/entries=false org.eclipse.cdt.cmake.is.core/debug/arglets=false
# Trace language setting entries as passed to the indexer # Trace detected preprocessor symbols and include path entries as passed to the indexer
org.eclipse.cdt.cmake.is.core/CECC/indexer-entries=false org.eclipse.cdt.cmake.is.core/debug/detected.entries=false
# Trace CMAKE_EXPORT_COMPILE_COMMANDS Compiler Built-ins detected language setting entries
org.eclipse.cdt.cmake.is.core/CECC/builtins/entries=false

View file

@ -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". * 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. * 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.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.cdt.cmake.is.core.IArglet.IParseContext; import org.eclipse.cdt.cmake.is.core.IArglet.IArgumentCollector;
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.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -23,7 +20,7 @@ import org.eclipse.core.runtime.Path;
* *
* @author Martin Weber * @author Martin Weber
*/ */
public class Arglets { public final class Arglets {
private static final String EMPTY_STR = ""; //$NON-NLS-1$ private static final String EMPTY_STR = ""; //$NON-NLS-1$
/** matches a macro name, with optional macro parameter list */ /** matches a macro name, with optional macro parameter list */
@ -134,7 +131,7 @@ public class Arglets {
*/ */
public static abstract class MacroDefineGeneric { public static abstract class MacroDefineGeneric {
protected final int processArgument(IParseContext parseContext, String args, protected final int processArgument(IArgumentCollector resultCollector, String args,
NameValueOptionMatcher[] optionMatchers) { NameValueOptionMatcher[] optionMatchers) {
for (NameValueOptionMatcher oMatcher : optionMatchers) { for (NameValueOptionMatcher oMatcher : optionMatchers) {
final Matcher matcher = oMatcher.matcher; final Matcher matcher = oMatcher.matcher;
@ -143,9 +140,7 @@ public class Arglets {
if (matcher.lookingAt()) { if (matcher.lookingAt()) {
final String name = matcher.group(oMatcher.nameGroup); final String name = matcher.group(oMatcher.nameGroup);
final String value = oMatcher.valueGroup == -1 ? null : matcher.group(oMatcher.valueGroup); final String value = oMatcher.valueGroup == -1 ? null : matcher.group(oMatcher.valueGroup);
final ICLanguageSettingEntry entry = CDataUtil.createCMacroEntry(name, value, resultCollector.addDefine(name, value);
ICSettingEntry.READONLY);
parseContext.addSettingEntry(entry);
final int end = matcher.end(); final int end = matcher.end();
return end; return end;
} }
@ -162,16 +157,14 @@ public class Arglets {
/*- /*-
* @see org.eclipse.cdt.cmake.is.IArglet#processArgument(java.util.List, java.lang.String) * @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) { NameOptionMatcher optionMatcher) {
final Matcher oMatcher = optionMatcher.matcher; final Matcher oMatcher = optionMatcher.matcher;
oMatcher.reset(argsLine); oMatcher.reset(argsLine);
if (oMatcher.lookingAt()) { if (oMatcher.lookingAt()) {
final String name = oMatcher.group(1); final String name = oMatcher.group(1);
final ICLanguageSettingEntry entry = CDataUtil.createCMacroEntry(name, null, resultCollector.addUndefine(name);
ICSettingEntry.UNDEFINED | ICSettingEntry.READONLY);
parseContext.addSettingEntry(entry);
final int end = oMatcher.end(); final int end = oMatcher.end();
return end; return end;
} }
@ -184,12 +177,13 @@ public class Arglets {
*/ */
public static abstract class IncludePathGeneric { public static abstract class IncludePathGeneric {
/** /**
* @param isSystemIncludePath <code>true</code> if the include path is a system include path otherwise <code>false</code>
* @param cwd the current working directory of the compiler at its invocation * @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) * IPath, String)
*/ */
protected final int processArgument(IParseContext parseContext, IPath cwd, String argsLine, protected final int processArgument(boolean isSystemIncludePath, IArgumentCollector resultCollector, IPath cwd,
NameOptionMatcher[] optionMatchers) { String argsLine, NameOptionMatcher[] optionMatchers) {
for (NameOptionMatcher oMatcher : optionMatchers) { for (NameOptionMatcher oMatcher : optionMatchers) {
final Matcher matcher = oMatcher.matcher; final Matcher matcher = oMatcher.matcher;
@ -203,10 +197,11 @@ public class Arglets {
// prepend CWD // prepend CWD
name = cwd.append(path).toOSString(); name = cwd.append(path).toOSString();
} }
if (isSystemIncludePath) {
final ICLanguageSettingEntry entry = CDataUtil.createCIncludePathEntry(name, resultCollector.addSystemIncludePath(name);
ICSettingEntry.READONLY); } else {
parseContext.addSettingEntry(entry); resultCollector.addIncludePath(name);
}
final int end = matcher.end(); final int end = matcher.end();
return end; return end;
} }
@ -249,8 +244,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String) * @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatchers); 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) * @see org.eclipse.cdt.cmake.is.IArglet#processArgument(java.util.List, java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatcher); return processArgument(resultCollector, argsLine, optionMatcher);
} }
} }
@ -292,8 +287,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String) * @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, cwd, argsLine, optionMatchers); 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) * @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, cwd, argsLine, optionMatchers); 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 * A tool argument parser capable to parse a armcc-compiler system include path
* argument: {@code -Jdir}. * argument: {@code -Jdir}.
*/ */
// TODO move this to the arm plugin
public static class SystemIncludePath_armcc extends IncludePathGeneric implements IArglet { public static class SystemIncludePath_armcc extends IncludePathGeneric implements IArglet {
@SuppressWarnings("nls") @SuppressWarnings("nls")
static final NameOptionMatcher[] optionMatchers = { static final NameOptionMatcher[] optionMatchers = {
@ -336,8 +332,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String) * @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, cwd, argsLine, optionMatchers); return processArgument(true, resultCollector, cwd, argsLine, optionMatchers);
} }
} }
@ -355,14 +351,15 @@ public class Arglets {
*/ */
public static abstract class BuiltinDetctionArgsGeneric { 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) * 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) { for (Matcher matcher : optionMatchers) {
matcher.reset(argsLine); matcher.reset(argsLine);
if (matcher.lookingAt()) { if (matcher.lookingAt()) {
parseContext.addBuiltinDetectionArgument(matcher.group()); resultCollector.addBuiltinDetectionArgument(matcher.group());
return matcher.end(); return matcher.end();
} }
} }
@ -393,8 +390,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String) * @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatchers); return processArgument(resultCollector, argsLine, optionMatchers);
} }
} }
@ -412,8 +409,8 @@ public class Arglets {
* @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String) * @see org.eclipse.cdt.cmake.is.IArglet#processArgs(java.lang.String)
*/ */
@Override @Override
public int processArgument(IParseContext parseContext, IPath cwd, String argsLine) { public int processArgument(IArgumentCollector resultCollector, IPath cwd, String argsLine) {
return processArgument(parseContext, argsLine, optionMatchers); return processArgument(resultCollector, argsLine, optionMatchers);
} }
} }

View file

@ -9,10 +9,8 @@
package org.eclipse.cdt.cmake.is.core; package org.eclipse.cdt.cmake.is.core;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsDetectionBehavior; import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsDetectionBehavior;
import org.eclipse.cdt.cmake.is.core.internal.ParseContext; import org.eclipse.cdt.cmake.is.core.internal.ParseContext;
@ -28,19 +26,13 @@ import org.eclipse.core.runtime.Platform;
* @author Martin Weber * @author Martin Weber
*/ */
public class DefaultToolCommandlineParser implements IToolCommandlineParser { public class DefaultToolCommandlineParser implements IToolCommandlineParser {
@SuppressWarnings("nls") private static final boolean DEBUG = Boolean
private static final boolean DEBUG = Boolean.parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/CECC/args")); .parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/debug/arglets")); //$NON-NLS-1$
private final IArglet[] argumentParsers; private final IArglet[] argumentParsers;
private final String languageID;
private final IResponseFileArglet responseFileArglet; private final IResponseFileArglet responseFileArglet;
private final IBuiltinsDetectionBehavior builtinsDetection; private final IBuiltinsDetectionBehavior builtinsDetection;
/** gathers the result */
private ParseContext result;
private IPath cwd;
/** /**
* Constructs a new object with the given values. * Constructs a new object with the given values.
* <p> * <p>
@ -51,10 +43,6 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
* "com.nvidia.cuda.toolchain.language.cuda.cu" * "com.nvidia.cuda.toolchain.language.cuda.cu"
* </p> * </p>
* *
* @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 * @param responseFileArglet the parsers for the response-file
* command-line argument for the tool or * command-line argument for the tool or
* {@code null} if the tool does not recognize * {@code null} if the tool does not recognize
@ -67,6 +55,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
* detection. * detection.
* @param argumentParsers the parsers for the command line arguments * @param argumentParsers the parsers for the command line arguments
* of of interest for the tool * of of interest for the tool
*
* @throws NullPointerException if the {@code argumentParsers} arguments is * @throws NullPointerException if the {@code argumentParsers} arguments is
* {@code null} * {@code null}
* @see Arglets various IArglet implementations you may want to use * @see Arglets various IArglet implementations you may want to use
@ -74,9 +63,8 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
* you may want to use * you may want to use
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public DefaultToolCommandlineParser(String languageID, IResponseFileArglet responseFileArglet, public DefaultToolCommandlineParser(IResponseFileArglet responseFileArglet,
IBuiltinsDetectionBehavior builtinsDetectionBehavior, IArglet... argumentParsers) { IBuiltinsDetectionBehavior builtinsDetectionBehavior, IArglet... argumentParsers) {
this.languageID = languageID;
this.builtinsDetection = builtinsDetectionBehavior; this.builtinsDetection = builtinsDetectionBehavior;
this.argumentParsers = Objects.requireNonNull(argumentParsers, "argumentParsers"); this.argumentParsers = Objects.requireNonNull(argumentParsers, "argumentParsers");
this.responseFileArglet = responseFileArglet; this.responseFileArglet = responseFileArglet;
@ -84,60 +72,8 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
@Override @Override
public IResult processArgs(IPath cwd, String args) { public IResult processArgs(IPath cwd, String args) {
this.result = new ParseContext(); ParserHandler ph = new ParserHandler(cwd);
this.cwd = Objects.requireNonNull(cwd, "cwd"); //$NON-NLS-1$ return ph.parseArguments(responseFileArglet, args);
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<String> 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<String>} holding the language ID or {@code Optional.empty()} if the file name extension is
* unknown.
*/
@SuppressWarnings("nls")
protected Optional<String> 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();
}
} }
@Override @Override
@ -148,7 +84,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { 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 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 responseFileArglet
* @param args the command line arguments to process * @param args the command line arguments to process
*/ */
@SuppressWarnings("nls") @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.. // eat buildOutput string argument by argument..
while (!(args = StringUtil.trimLeadingWS(args)).isEmpty()) { while (!(args = StringUtil.trimLeadingWS(args)).isEmpty()) {
boolean argParsed = false; boolean argParsed = false;
@ -227,6 +176,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
} }
} }
} }
return result;
} }
/** /**

View file

@ -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". * 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. * 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; package org.eclipse.cdt.cmake.is.core;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
/** /**
@ -23,37 +22,30 @@ public interface IArglet {
* Parses the next command-line argument and extracts all detected * Parses the next command-line argument and extracts all detected
* LanguageSettings objects. * LanguageSettings objects.
* *
* @param parseContext the buffer that receives the new {@code LanguageSetting} * @param resultCollector the buffer that receives the parsed command-line
* entries * arguments
* @param cwd the current working directory of the compiler at its * @param cwd the current working directory of the compiler at its
* invocation * invocation
* @param argsLine the arguments passed to the tool, as they appear in the * @param argsLine the arguments passed to the tool, as they appear in
* build output. Implementers may safely assume that the * the build output. Implementers may safely assume that
* specified value does not contain leading whitespace * the specified value does not contain leading
* characters, but trailing WS may occur. * whitespace characters, but trailing WS may occur.
* @return the number of characters from {@code argsLine} that has been * @return the number of characters from {@code argsLine} that has been
* processed. Return a value of {@code zero} or less, if this tool * processed. Return a value of {@code zero} or less, if this tool
* argument parser cannot process the first argument from the input. * 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. * Gathers the results of argument parsing.
* *
* @author Martin Weber * @author Martin Weber
*/ */
interface IParseContext { interface IArgumentCollector extends IRawIndexerInfoCollector {
/** /**
* Adds a language setting to the result. * Adds a compiler argument that affects built-in detection. For the GNU
* * compilers, these are options like {@code --sysroot} and options that specify
* @param entry * the language's standard ({@code -std=c++17}.
*/
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}.
*/ */
void addBuiltinDetectionArgument(String argument); void addBuiltinDetectionArgument(String argument);
} }

View file

@ -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<String, String> getDefines();
/**
* Gets the preprocessor symbol cancellations (macro undefine) collected from
* the command-line.
*/
List<String> getUndefines();
/**
* Gets the preprocessor include paths collected from the command-line.
*/
List<String> getIncludePaths();
/**
* Gets the preprocessor system include paths collected from the command-line.
*/
List<String> getSystemIncludePaths();
}

View file

@ -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);
}

View file

@ -10,10 +10,8 @@ package org.eclipse.cdt.cmake.is.core;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsDetectionBehavior; import org.eclipse.cdt.cmake.is.core.builtins.IBuiltinsDetectionBehavior;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
/** /**
@ -34,45 +32,13 @@ public interface IToolCommandlineParser {
*/ */
public IResult processArgs(IPath cwd, String args); 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.
* <p>
* 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".)
* </p>
*
* @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<String> getCustomLanguageIds();
/** /**
* Gets the {@code IBuiltinsDetectionBehavior} which specifies how built-in * Gets the {@code IBuiltinsDetectionBehavior} which specifies how built-in
* compiler macros and include path detection is handled for a specific * compiler macros and include path detection is handled for a specific
* compiler. * compiler.
* *
* @return the {@code IBuiltinsDetectionBehavior} or an empty {@code Oprional} if the * @return the {@code IBuiltinsDetectionBehavior} or an empty {@code Optional}
* compiler does not support built-in detection * if the compiler does not support built-in detection
*/ */
public Optional<IBuiltinsDetectionBehavior> getIBuiltinsDetectionBehavior(); public Optional<IBuiltinsDetectionBehavior> getIBuiltinsDetectionBehavior();
@ -83,14 +49,7 @@ public interface IToolCommandlineParser {
* *
* @see IToolCommandlineParser#processArgs(IPath, String) * @see IToolCommandlineParser#processArgs(IPath, String)
*/ */
interface IResult { interface IResult extends IRawIndexerInfo {
/**
* Gets the language setting entries produced during processing.
*
* @return the language setting entries
*/
List<ICLanguageSettingEntry> getSettingEntries();
/** /**
* Gets the compiler arguments from the command-line that affect built-in * Gets the compiler arguments from the command-line that affect built-in
* detection. For the GNU compilers, these are options like {@code --sysroot} * detection. For the GNU compilers, these are options like {@code --sysroot}

View file

@ -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". * 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. * 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.IArglet;
import org.eclipse.cdt.cmake.is.core.IToolCommandlineParser; import org.eclipse.cdt.cmake.is.core.IToolCommandlineParser;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.cmake.is.core.internal.builtins.RawIndexerInfo;
import org.eclipse.core.runtime.Platform;
/** /**
* Default implementation of IParseContext. * Default implementation of IArgumentCollector.
* *
* @author Martin Weber * @author Martin Weber
*/ */
public class ParseContext implements IArglet.IParseContext, IToolCommandlineParser.IResult { public final class ParseContext extends RawIndexerInfo
@SuppressWarnings("nls") implements IArglet.IArgumentCollector, IToolCommandlineParser.IResult {
private static final boolean DEBUG = Boolean
.parseBoolean(Platform.getDebugOption(Plugin.PLUGIN_ID + "/CECC/entries"));
private final List<ICLanguageSettingEntry> entries = new ArrayList<>();
private final List<String> args = new ArrayList<>(); private final List<String> 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 @Override
public void addBuiltinDetectionArgument(String argument) { public void addBuiltinDetectionArgument(String argument) {
args.add(argument); args.add(argument);
} }
@Override
public List<ICLanguageSettingEntry> getSettingEntries() {
return entries;
}
@Override @Override
public List<String> getBuiltinDetectionArgs() { public List<String> getBuiltinDetectionArgs() {
return args; return args;
} }
} }

View file

@ -15,9 +15,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer; 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.Arglets;
import org.eclipse.cdt.cmake.is.core.DefaultToolCommandlineParser; import org.eclipse.cdt.cmake.is.core.DefaultToolCommandlineParser;
@ -45,68 +43,72 @@ import org.eclipse.core.runtime.Status;
* *
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ParserDetection { public final class ParserDetection {
private static final ILog log = Plugin.getDefault().getLog(); private static final ILog log = Plugin.getDefault().getLog();
private static final boolean DEBUG_PARTCIPANT_DETECTION = Boolean 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 * 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 * takes part in the current build. The Matcher detects whether a command line
* is an invocation of the tool. * is an invocation of the tool.
*/ */
private static final List<IToolDetectionParticipant> parserDetectors = new ArrayList<>(22); private static List<IToolDetectionParticipant> parserDetectors;
static { static void init() {
/** Names of known tools along with their command line argument parsers */ if (parserDetectors == null) {
final IArglet[] gcc_args = { new Arglets.IncludePath_C_POSIX(), new Arglets.MacroDefine_C_POSIX(), parserDetectors = new ArrayList<>(22);
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() };
IBuiltinsDetectionBehavior btbGccMaybee = new MaybeGccBuiltinDetectionBehavior(); /** Names of known tools along with their command line argument parsers */
IBuiltinsDetectionBehavior btbGcc = new GccBuiltinDetectionBehavior(); 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 ================================= IBuiltinsDetectionBehavior btbGccMaybee = new MaybeGccBuiltinDetectionBehavior();
{ IBuiltinsDetectionBehavior btbGcc = new GccBuiltinDetectionBehavior();
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));
}
// GNU C compatible compilers ==== // POSIX compatible C compilers =================================
{ {
final IToolCommandlineParser gcc = new DefaultToolCommandlineParser("org.eclipse.cdt.core.gcc", final IToolCommandlineParser cc = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
new ResponseFileArglets.At(), btbGcc, gcc_args); btbGccMaybee, gcc_args);
parserDetectors.add(new DefaultToolDetectionParticipant("gcc", true, "exe", gcc)); parserDetectors.add(new DefaultToolDetectionParticipant("cc", true, "exe", cc));
parserDetectors.add(new DefaultToolDetectionParticipant("clang", true, "exe", gcc)); }
// cross compilers, e.g. arm-none-eabi-gcc ==== // POSIX compatible C++ compilers ===============================
parserDetectors.add(new DefaultToolDetectionParticipant("\\S+?-gcc", true, "exe", gcc)); {
} final IToolCommandlineParser cxx = new DefaultToolCommandlineParser(new ResponseFileArglets.At(),
// GNU C++ compatible compilers ==== btbGccMaybee, gcc_args);
{ parserDetectors.add(new DefaultToolDetectionParticipant("c\\+\\+", true, "exe", cxx));
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));
}
// compilers from extension points // GNU C compatible compilers ====
loadExtentionsSorted(parserDetectors::add); {
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() { private ParserDetection() {
} }
/**
* Gets the custom language IDs of each of the IToolDetectionParticipants.
*
* @see IToolCommandlineParser#getCustomLanguageIds()
*/
public static Set<String> 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. * 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, private static ParserDetectionResult determineDetector0(String commandLine, String versionSuffixRegex,
boolean matchBackslash) { boolean matchBackslash) {
init();
Optional<DefaultToolDetectionParticipant.MatchResult> cmdline; Optional<DefaultToolDetectionParticipant.MatchResult> cmdline;
// try basenames // try basenames
for (IToolDetectionParticipant pd : parserDetectors) { for (IToolDetectionParticipant pd : parserDetectors) {

View file

@ -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<String> systemIncludePaths,
Map<String, String> definedSymbols, List<String> includePaths);
}