mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 575622 - Problems in jsoncdb parser for compilers that do not support built-in detection
Change-Id: I04ff6ed03c135d23d9b6ef7c83411a1fffbd9f8d Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
parent
083b7b1964
commit
139e82268b
2 changed files with 48 additions and 36 deletions
|
@ -37,7 +37,6 @@ import org.eclipse.cdt.jsoncdb.core.participant.IToolCommandlineParser;
|
||||||
import org.eclipse.cdt.jsoncdb.core.participant.IToolCommandlineParser.IResult;
|
import org.eclipse.cdt.jsoncdb.core.participant.IToolCommandlineParser.IResult;
|
||||||
import org.eclipse.cdt.jsoncdb.core.participant.IToolDetectionParticipant;
|
import org.eclipse.cdt.jsoncdb.core.participant.IToolDetectionParticipant;
|
||||||
import org.eclipse.cdt.jsoncdb.core.participant.builtins.IBuiltinsDetectionBehavior;
|
import org.eclipse.cdt.jsoncdb.core.participant.builtins.IBuiltinsDetectionBehavior;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
@ -200,8 +199,8 @@ public class CompileCommandsJsonParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes an entry from a {@code compile_commands.json} file and stores a
|
* Processes an entry from a {@code compile_commands.json} file and remembers a
|
||||||
* {@link ICLanguageSettingEntry} for the file given the specified map.
|
* {@link IRawSourceFileInfo} for the given sourceFileInfo.
|
||||||
*
|
*
|
||||||
* @param sourceFileInfo parsed command entry of a compile_commands.json file
|
* @param sourceFileInfo parsed command entry of a compile_commands.json file
|
||||||
* @param jsonFile the JSON file being parsed (for marker creation only)
|
* @param jsonFile the JSON file being parsed (for marker creation only)
|
||||||
|
@ -257,51 +256,64 @@ public class CompileCommandsJsonParser {
|
||||||
createMarker(jsonFile, msg);
|
createMarker(jsonFile, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Runs detection of compiler built-ins if supported and notifies the
|
||||||
|
* {@code ISourceFileInfoConsumer} that was specified in the constructor for each source file.
|
||||||
|
*
|
||||||
* @param monitor
|
* @param monitor
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
private void detectBuiltins(IProgressMonitor monitor) throws CoreException {
|
private void detectBuiltins(IProgressMonitor monitor) throws CoreException {
|
||||||
if (builtinDetectorsToRun.isEmpty())
|
if (builtinDetectorsToRun.isEmpty()) {
|
||||||
return;
|
// compiler does not support built-in detection:
|
||||||
monitor.setTaskName(Messages.CompileCommandsJsonParser_msg_detecting_builtins);
|
// just feed the paths and defines with the file name to the indexer..
|
||||||
|
for (Entry<String, IRawSourceFileInfo> fileResultPair : fileResults.entrySet()) {
|
||||||
|
String sourceFileName = fileResultPair.getKey();
|
||||||
|
IRawSourceFileInfo fileResult = fileResultPair.getValue();
|
||||||
|
parseRequest.getSourceFileInfoConsumer().acceptSourceFileInfo(sourceFileName,
|
||||||
|
fileResult.getSystemIncludePaths(), fileResult.getDefines(), fileResult.getIncludePaths(),
|
||||||
|
fileResult.getMacroFiles(), fileResult.getIncludeFiles());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// run detection of compiler built-ins...
|
||||||
|
monitor.setTaskName(Messages.CompileCommandsJsonParser_msg_detecting_builtins);
|
||||||
|
|
||||||
final IFile jsonFile = parseRequest.getFile();
|
final IFile jsonFile = parseRequest.getFile();
|
||||||
final IContainer buildRootFolder = jsonFile.getParent();
|
final IContainer buildRootFolder = jsonFile.getParent();
|
||||||
|
|
||||||
java.nio.file.Path buildDir = java.nio.file.Path.of(buildRootFolder.getLocationURI());
|
java.nio.file.Path buildDir = java.nio.file.Path.of(buildRootFolder.getLocationURI());
|
||||||
// run each built-in detector and collect the results..
|
// run each built-in detector and collect the results..
|
||||||
Map<String, IRawSourceFileInfo> builtinDetectorsResults = new HashMap<>();
|
Map<String, IRawSourceFileInfo> builtinDetectorsResults = new HashMap<>();
|
||||||
for (Entry<String, CompilerBuiltinsDetector> entry : builtinDetectorsToRun.entrySet()) {
|
for (Entry<String, CompilerBuiltinsDetector> entry : builtinDetectorsToRun.entrySet()) {
|
||||||
IRawSourceFileInfo result = entry.getValue().detectBuiltins(jsonFile.getProject(), buildDir,
|
IRawSourceFileInfo result = entry.getValue().detectBuiltins(jsonFile.getProject(), buildDir,
|
||||||
parseRequest.getLauncher(), parseRequest.getConsole(), monitor);
|
parseRequest.getLauncher(), parseRequest.getConsole(), monitor);
|
||||||
// store detector key with result
|
// store detector key with result
|
||||||
builtinDetectorsResults.put(entry.getKey(), result);
|
builtinDetectorsResults.put(entry.getKey(), result);
|
||||||
}
|
}
|
||||||
// all built-in detectors have been run at this point, reduce memory footprint
|
// all built-in detectors have been run at this point, reduce memory footprint
|
||||||
builtinDetectorsToRun.clear();
|
builtinDetectorsToRun.clear();
|
||||||
|
|
||||||
// most of the time we get different String objects for different source files
|
// most of the time we get different String objects for different source files
|
||||||
// that have the same sequence of characters. So reduce the number of String
|
// that have the same sequence of characters. So reduce the number of String
|
||||||
// objects by pooling them..
|
// objects by pooling them..
|
||||||
Map<String, String> strPool = new HashMap<>();
|
Map<String, String> strPool = new HashMap<>();
|
||||||
Function<String, String> stringPooler = v -> {
|
Function<String, String> stringPooler = v -> {
|
||||||
String old = strPool.putIfAbsent(v, v);
|
String old = strPool.putIfAbsent(v, v);
|
||||||
return old == null ? v : old;
|
return old == null ? v : old;
|
||||||
};
|
};
|
||||||
|
|
||||||
// merge built-in results with source file results
|
// merge built-in results with source file results
|
||||||
for (Entry<String, String> link : fileToBuiltinDetectorLinks.entrySet()) {
|
for (Entry<String, String> link : fileToBuiltinDetectorLinks.entrySet()) {
|
||||||
String sourceFileName = link.getKey();
|
String sourceFileName = link.getKey();
|
||||||
IRawSourceFileInfo fileResult = fileResults.get(sourceFileName);
|
IRawSourceFileInfo fileResult = fileResults.get(sourceFileName);
|
||||||
IRawSourceFileInfo builtinDetectorsResult = builtinDetectorsResults.get(link.getValue());
|
IRawSourceFileInfo builtinDetectorsResult = builtinDetectorsResults.get(link.getValue());
|
||||||
mergeResultsForFile(stringPooler, sourceFileName, fileResult, builtinDetectorsResult);
|
mergeResultsForFile(stringPooler, sourceFileName, fileResult, builtinDetectorsResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges preprocessor symbols and macros for a source file with compiler
|
* Merges preprocessor symbols and macros for a source file with compiler
|
||||||
* built-in preprocessor symbols and macros and passes the to the
|
* built-in preprocessor symbols and macros and passes them to the
|
||||||
* {@code ISourceFileInfoConsumer} that was specified in the constructor.
|
* {@code ISourceFileInfoConsumer} that was specified in the constructor.
|
||||||
*
|
*
|
||||||
* @param fileResult source file preprocessor symbols and macros
|
* @param fileResult source file preprocessor symbols and macros
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class DefaultToolCommandlineParser implements IToolCommandlineParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<IBuiltinsDetectionBehavior> getIBuiltinsDetectionBehavior() {
|
public Optional<IBuiltinsDetectionBehavior> getIBuiltinsDetectionBehavior() {
|
||||||
return Optional.of(builtinsDetection);
|
return Optional.ofNullable(builtinsDetection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
|
|
Loading…
Add table
Reference in a new issue