1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

New API to custom parse #define lines from GCC during scanning

Option to override the matching of macro defines for the Core Build
GCC toolchain. This may be needed for custom compilers.

Also-by: Jonah Graham <jonah@kichwacoders.com>
This commit is contained in:
Erwin Waterlander 2023-02-15 12:23:17 +00:00 committed by Jonah Graham
parent 590906a005
commit 920f7d85a5
3 changed files with 26 additions and 7 deletions

View file

@ -12,6 +12,9 @@ This is the New & Noteworthy page for CDT 11.1 which is part of Eclipse 2023-03
Please see [CHANGELOG-API](CHANGELOG-API.md) for details on the breaking API changes in this release as well as future planned API changes.
## GCCToolchain allows custom parsing of `#define` lines
See new method `matchDefines` introduced in `GCCToolChain`.
# Noteworthy Issues and Pull Requests
See [Noteworthy issues and PRs](https://github.com/eclipse-cdt/cdt/issues?q=is%3Aclosed+label%3Anoteworthy+milestone%3A11.1.0) for this release in the issue/PR tracker.

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.build.gcc.core;singleton:=true
Bundle-Version: 2.0.100.qualifier
Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.eclipse.cdt.build.gcc.core.internal.Activator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime,

View file

@ -56,6 +56,8 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
public static final String TYPE_ID = "org.eclipse.cdt.build.gcc"; //$NON-NLS-1$
private static Pattern definePattern = Pattern.compile("#define ([^\\s]*)\\s(.*)"); //$NON-NLS-1$
private final IToolChainProvider provider;
private final String id;
private final Path path;
@ -471,7 +473,6 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
// Scan for the scanner info
Map<String, String> symbols = new HashMap<>();
List<String> includePath = new ArrayList<>();
Pattern definePattern = Pattern.compile("#define ([^\\s]*)\\s(.*)"); //$NON-NLS-1$
// First the include path off the error stream
Thread includePathReaderThread = new Thread("Include Path Reader") {
@ -509,11 +510,9 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
// Now the defines off the output stream
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
if (line.startsWith("#define ")) { //$NON-NLS-1$
Matcher matcher = definePattern.matcher(line);
if (matcher.matches()) {
symbols.put(matcher.group(1), matcher.group(2));
}
Map<String, String> matchDefines = matchDefines(line);
if (matchDefines != null) {
symbols.putAll(matchDefines);
}
}
} catch (IOException e) {
@ -535,6 +534,23 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()]));
}
/**
* Find any macro defines on the given input line and return a map of all such defines.
*
* @param line single line of output from the compiler
* @return map of macro defines
* @since 2.1
*/
protected Map<String, String> matchDefines(String line) {
if (line.startsWith("#define ")) { //$NON-NLS-1$
Matcher matcher = definePattern.matcher(line);
if (matcher.matches()) {
return Map.of(matcher.group(1), matcher.group(2));
}
}
return Map.of();
}
@Override
public String[] getErrorParserIds() {
return new String[] { "org.eclipse.cdt.core.GCCErrorParser", //$NON-NLS-1$