Skip to content

Commit

Permalink
Add parser for CCES (CrossCore Embedded Studio from Analog Devices)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-devialet committed Jul 31, 2023
1 parent 533ac7e commit bb0f6f4
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SUPPORTED-FORMATS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--- DO NOT EDIT -- Generated at 2023-07-20T18:42:19.715720048 - Run the `main` method of `ParserRegistry` to regenerate after changing parsers -- DO NOT EDIT --->
<!--- DO NOT EDIT -- Generated at 2023-07-27T18:28:38.171216 - Run the `main` method of `ParserRegistry` to regenerate after changing parsers -- DO NOT EDIT --->
# Supported Report Formats

The static analysis model supports the following report formats.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package edu.hm.hafner.analysis.parser;


import java.io.UncheckedIOException;
import java.util.Iterator;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.util.LookaheadStream;

/**
* A parser for the CrossCoreEmbeddedStudio (CCES) log files.
*/
public class CrossCoreEmbeddedStudioParser extends LookaheadParser {
private static final long serialVersionUID = 5490211629355204910L;

/* Regex to match the CCES warnings.
*
* Details:
* - See below the MATCHER_* ids to ease their retrieval.
* - Potential columns are ignored
* - Assume warnings description are always spread over two lines (what was observed so far)
* - Errors are not parsed, only warnings
*/
private static final String CCES_WARNING_PATTERN =
"^\"(.+?)\", line (\\d+).*(cc\\d+).*warning:(.*)";

private static final Integer MATCHER_FILE = 1;
private static final Integer MATCHER_LINE = 2;
private static final Integer MATCHER_CATEGORY = 3;
private static final Integer MATCHER_MESSAGE_BEGIN = 4;

public CrossCoreEmbeddedStudioParser() {
super(CCES_WARNING_PATTERN);
}

CrossCoreEmbeddedStudioParser(final String pattern) {
super(pattern);
}

@Override
protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) {

StringBuilder message = new StringBuilder(matcher.group(MATCHER_MESSAGE_BEGIN).trim());

// always grab the second line
if (lookahead.hasNext()) {
message.append(" ");
message.append(lookahead.next().trim());
}

return builder.setFileName(matcher.group(MATCHER_FILE))
.setLineStart(matcher.group(MATCHER_LINE))
.setSeverity(Severity.WARNING_NORMAL)
.setCategory(matcher.group(MATCHER_CATEGORY))
.setMessage(message.toString())
.buildOptional();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.hm.hafner.analysis.registry;

import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.parser.CrossCoreEmbeddedStudioParser;

/**
* A descriptor for CrossCore Embedded Studio from Analog Devices
*/
public class CrossCoreEmbeddedStudioDescriptor extends ParserDescriptor {
private static final String ID = "crosscore-embedded-studio";
private static final String NAME = "CrossCore Embedded Studio (CCES)";

CrossCoreEmbeddedStudioDescriptor() {
super(ID, NAME);
}

@Override
public IssueParser createParser(final Option... options) {
return new CrossCoreEmbeddedStudioParser();
}

@Override
public String getUrl() {
return "https://www.analog.com/en/design-center/evaluation-hardware-and-software/software/adswt-cces.html";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ParserRegistry {
new CpdDescriptor(),
new CppCheckDescriptor(),
new CppLintDescriptor(),
new CrossCoreEmbeddedStudioDescriptor(),
new CssLintDescriptor(),
new DartAnalyzeDescriptor(),
new DetektDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package edu.hm.hafner.analysis.parser;

import edu.hm.hafner.analysis.AbstractParserTest;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.assertions.SoftAssertions;

/**
* Tests the class {@link CrossCoreEmbeddedStudioParser}.
*/
class CrossCoreEmbeddedStudioParserTest extends AbstractParserTest {
CrossCoreEmbeddedStudioParserTest() {
super("cces.log");
}

@Override
protected CrossCoreEmbeddedStudioParser createParser() {
return new CrossCoreEmbeddedStudioParser();
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
// check all warnings were caught
softly.assertThat(report).hasSize(6);


// test in details the first warning
softly.assertThat(report.get(0))
.hasFileName("src/dummy_1.c")
.hasLineStart(333)
.hasSeverity(Severity.WARNING_NORMAL)
.hasCategory("cc0188")
.hasMessage("enumerated type mixed with another type");

// test in details the last warning, that has column (but not parsed)
softly.assertThat(report.get(5))
.hasFileName("src/dummy_5.c")
.hasLineStart(125)
.hasSeverity(Severity.WARNING_NORMAL)
.hasCategory("cc1462")
.hasMessage("call to dummy_btc has not been inlined");

}
}
33 changes: 33 additions & 0 deletions src/test/resources/edu/hm/hafner/analysis/parser/cces.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Building libdummy for toolchain sharc_21565...
CC src/dummy_1.c
"src/dummy_1.c", line 333: cc0188: {D} warning:
enumerated type mixed with another type
dummy_get();
^

"src/dummy_2.c", line 36: cc0188: {D} warning: enumerated type
mixed with another type
dummy_get();
^

CC src/dummy_3.c
"src/dummy_3.c", line 149: cc0111: {D} warning: statement is
unreachable
break;
^

CC src/dummy_4.c
"src/dummy_4.c", line 85: cc0188: {D} warning: enumerated type
mixed with another type
dummy_get();
^

"src/dummy_4.c", line 295: cc0111: {D} warning: statement is
unreachable
break;
^

CC src/dummy_5.c
"src/dummy_5.c", line 125 (col. 22): cc1462: {D} warning: call to
dummy_btc has not been inlined

0 comments on commit bb0f6f4

Please sign in to comment.