Skip to content

Commit

Permalink
New API to custom parse #define lines from GCC during scanning
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ewaterlander authored and jonahgraham committed Feb 15, 2023
1 parent 590906a commit 920f7d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NewAndNoteworthy/CDT-11.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -471,7 +473,6 @@ private IExtendedScannerInfo getScannerInfo(IBuildConfiguration buildConfig, Lis
// 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") {
Expand Down Expand Up @@ -509,11 +510,9 @@ public void run() {
// 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) {
Expand All @@ -535,6 +534,23 @@ public void run() {
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$
Expand Down

0 comments on commit 920f7d8

Please sign in to comment.