Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed cpp to c and cpp2 to cpp #1496

Merged
merged 12 commits into from
Feb 15, 2024
Merged
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ In the following, a list of all supported languages with their supported languag
| Language | Version | CLI Argument Name | [state](https://github.com/jplag/JPlag/wiki/2.-Supported-Languages) | parser |
|--------------------------------------------------------|---------------------------------------------------------------------------------------:|-------------------|:-------------------------------------------------------------------:|:---------:|
| [Java](https://www.java.com) | 21 | java | mature | JavaC |
| [C/C++](https://isocpp.org) | 11 | cpp | legacy | JavaCC |
| [C/C++](https://isocpp.org) | 14 | cpp2 | beta | ANTLR 4 |
| [C](https://isocpp.org) | 11 | c | legacy | JavaCC |
| [C++](https://isocpp.org) | 14 | cpp | beta | ANTLR 4 |
| [C#](https://docs.microsoft.com/en-us/dotnet/csharp/) | 6 | csharp | beta | ANTLR 4 |
| [Go](https://go.dev) | 1.17 | golang | beta | ANTLR 4 |
| [Kotlin](https://kotlinlang.org) | 1.3 | kotlin | beta | ANTLR 4 |
Expand Down Expand Up @@ -146,8 +146,8 @@ Clustering

--cluster-skip Skips the clustering (default: false)
Commands:
c
cpp
cpp2
csharp
emf
emf-model
Expand Down
4 changes: 2 additions & 2 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>cpp</artifactId>
<artifactId>c</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>cpp2</artifactId>
<artifactId>cpp</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions coverage-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>cpp</artifactId>
<artifactId>c</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>cpp2</artifactId>
<artifactId>cpp</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion docs/1.-How-to-Use-JPlag.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ Clustering

--cluster-skip Skips the clustering (default: false)
Commands:
c
cpp
cpp2
csharp
emf
emf-model
Expand Down
2 changes: 1 addition & 1 deletion docs/2.-Supported-Languages.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JPlag currently supports Java, C/C++, C#, Go, Kotlin, Python, R, Rust, Scala, Swift, and Scheme. Additionally, it has primitive support for text and prototypical support for EMF metamodels. A detailed list, including the supported language versions can be found in the [project readme](https://github.com/jplag/JPlag/blob/main/README.md#supported-languages).
JPlag currently supports Java, C, C++, C#, Go, Kotlin, Python, R, Rust, Scala, Swift, and Scheme. Additionally, it has primitive support for text and prototypical support for EMF metamodels. A detailed list, including the supported language versions can be found in the [project readme](https://github.com/jplag/JPlag/blob/main/README.md#supported-languages).

The language modules differ in their maturity due to their age and different usage frequencies.
Thus, each frontend has a state label:
Expand Down
12 changes: 12 additions & 0 deletions languages/c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# JPlag C language module

This module allows the use of JPlag with submissions in c.

## Usage

To parse C submissions run JPlag with: `<jplag> <options> c` or use the `-l c` options.
To use the module from the API configure your `JPlagOption` object with `new CLanguage()` as 'Language' as described in the usage information in the [readme](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).

## C++

This module might work with C++ submissions. However you should use the [cpp module](https://github.com/jplag/JPlag/tree/main/languages/cpp) for that.
35 changes: 35 additions & 0 deletions languages/c/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.jplag</groupId>
<artifactId>languages</artifactId>
<version>${revision}</version>
</parent>
<artifactId>c</artifactId>

<build>
<plugins>
<plugin>
<groupId>com.helger.maven</groupId>
<artifactId>ph-javacc-maven-plugin</artifactId>
<executions>
<execution>
<id>javacc-gen</id>
<goals>
<goal>javacc</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<jdkVersion>21</jdkVersion>
<javadocFriendlyComments>true</javadocFriendlyComments>
<packageName>de.jplag.c</packageName>
<sourceDirectory>src/main/javacc</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/javacc</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package de.jplag.cpp;
package de.jplag.c;

import java.io.File;
import java.util.List;
import java.util.Set;

import org.kohsuke.MetaInfServices;

import de.jplag.Language;
import de.jplag.ParsingException;
import de.jplag.Token;

@MetaInfServices(de.jplag.Language.class)
public class Language implements de.jplag.Language {
private static final String IDENTIFIER = "cpp";
public class CLanguage implements Language {
private static final String IDENTIFIER = "c";

private final Scanner scanner; // cpp code is scanned not parsed
private final Scanner scanner; // c code is scanned not parsed

public Language() {
public CLanguage() {
scanner = new Scanner();
}

Expand All @@ -26,7 +27,7 @@ public String[] suffixes() {

@Override
public String getName() {
return "C/C++ Scanner [basic markup]";
return "C Scanner";
}

@Override
Expand Down
77 changes: 77 additions & 0 deletions languages/c/src/main/java/de/jplag/c/CTokenType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package de.jplag.c;

import de.jplag.TokenType;

public enum CTokenType implements TokenType {
C_BLOCK_BEGIN("BLOCK{"),
C_BLOCK_END("}BLOCK"),
C_QUESTIONMARK("COND"),
C_ELLIPSIS("..."),
C_ASSIGN("ASSIGN"),
C_DOT("DOT"),
C_ARROW("ARROW"),
C_ARROWSTAR("ARROWSTAR"),
C_AUTO("AUTO"),
C_BREAK("BREAK"),
C_CASE("CASE"),
C_CATCH("CATCH"),
C_CHAR("CHAR"),
C_CONST("CONST"),
C_CONTINUE("CONTINUE"),
C_DEFAULT("DEFAULT"),
C_DELETE("DELETE"),
C_DO("DO"),
C_DOUBLE("DOUBLE"),
C_ELSE("ELSE"),
C_ENUM("ENUM"),
C_EXTERN("EXTERN"),
C_FLOAT("FLOAT"),
C_FOR("FOR"),
C_FRIEND("FRIEND"),
C_GOTO("GOTO"),
C_IF("IF"),
C_INLINE("INLINE"),
C_INT("INT"),
C_LONG("LONG"),
C_NEW("NEW"),
C_PRIVATE("PRIVATE"),
C_PROTECTED("PROTECTED"),
C_PUBLIC("PUBLIC"),
C_REDECLARED("REDECLARED"),
C_REGISTER("REGISTER"),
C_RETURN("RETURN"),
C_SHORT("SHORT"),
C_SIGNED("SIGNED"),
C_SIZEOF("SIZEOF"),
C_STATIC("STATIC"),
C_STRUCT("STRUCT"),
C_CLASS("CLASS"),
C_SWITCH("SWITCH"),
C_TEMPLATE("TEMPLATE"),
C_THIS("THIS"),
C_TRY("TRY"),
C_TYPEDEF("TYPEDEF"),
C_UNION("UNION"),
C_UNSIGNED("UNSIGNED"),
C_VIRTUAL("VIRTUAL"),
C_VOID("VOID"),
C_VOLATILE("VOLATILE"),
C_WHILE("WHILE"),
C_OPERATOR("OPERATOR"),
C_THROW("THROW"),
C_ID("ID"),
C_FUN("FUN"),
C_DOTSTAR("DOTSTAR"),
C_NULL("NULL");

private final String description;

@Override
public String getDescription() {
return this.description;
}

CTokenType(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.cpp;
package de.jplag.c;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.cpp;
package de.jplag.c;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -32,7 +32,7 @@ public List<Token> scan(Set<File> files) throws ParsingException {
return tokens;
}

public void add(CPPTokenType type, de.jplag.cpp.Token token) {
public void add(CTokenType type, de.jplag.c.Token token) {
int length = token.endColumn - token.beginColumn + 1;
tokens.add(new Token(type, currentFile, token.beginLine, token.beginColumn, length));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.cpp.experimental;
package de.jplag.c.experimental;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -25,7 +25,7 @@ public GCCSourceAnalysis() {
}

@Override
public boolean isTokenIgnored(de.jplag.cpp.Token token, File file) {
public boolean isTokenIgnored(de.jplag.c.Token token, File file) {
String fileName = file.getName();
if (linesToDelete.containsKey(fileName)) {
var ignoredLineNumbers = linesToDelete.get(fileName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.cpp.experimental;
package de.jplag.c.experimental;

import java.io.File;
import java.util.Set;
Expand All @@ -16,7 +16,7 @@ public interface SourceAnalysis {
* @param file The file the token was scanned in
* @return True, if the token should not be added to a TokenList, false if it should
*/
boolean isTokenIgnored(de.jplag.cpp.Token token, File file);
boolean isTokenIgnored(de.jplag.c.Token token, File file);

/**
* Executes the source analysis on the files of a submission.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.jplag.cpp.experimental;
package de.jplag.c.experimental;

import static de.jplag.SharedTokenType.FILE_END;
import static de.jplag.cpp.CPPTokenType.*;
import static de.jplag.c.CTokenType.*;

import java.util.List;
import java.util.ListIterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ options
}

PARSER_BEGIN(CPPScanner)
package de.jplag.cpp;
package de.jplag.c;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -23,7 +23,7 @@ import java.io.InputStream;

import de.jplag.ParsingException;

import static de.jplag.cpp.CPPTokenType.*;
import static de.jplag.c.CTokenType.*;

public class CPPScanner {
private Scanner delegatingScanner;
Expand Down
11 changes: 4 additions & 7 deletions languages/cpp2/README.md → languages/cpp/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# JPlag C++ language module

**Note**: This language module is meant to replace the existing C++ language module in the future.
While the old language module is based on lexer tokens, this language module uses a parse tree for token extraction.
The base package name of this language module and its identifier are `cpp2` currently, but this might change if the old
language module gets replaced.
**Note**: This replaces the old cpp module, which is now only meant for c, as it works better for c than this one.

The JPlag C++ frontend allows the use of JPlag with submissions in C/C++. <br>
The JPlag C++ frontend allows the use of JPlag with submissions in C++. <br>
It is based on the [C++ ANTLR4 grammar](https://github.com/antlr/grammars-v4/tree/master/cpp), licensed under MIT.

### C++ specification compatibility
Expand All @@ -21,11 +18,11 @@ While the Java language module is based on an AST, this language module uses a p
There are differences, including:
- `import` is extracted in Java, while `using` is not extracted due to the fact that it can be placed freely in the code.

More syntactic elements of C/C++ may turn out to be helpful to include in the future, especially those that are newly introduced.
More syntactic elements of C++ may turn out to be helpful to include in the future, especially those that are newly introduced.

### Usage

To use the C++ frontend, add the `-l cpp2` flag in the CLI, or use a `JPlagOption` object with `new de.jplag.cpp2.CPPLanguage()` as `Language` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).
To use the C++ frontend, add the `-l cpp` flag in the CLI, or use a `JPlagOption` object with `new de.jplag.cpp.CPPLanguage()` as `Language` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).

### Changes to the Grammar

Expand Down
27 changes: 15 additions & 12 deletions languages/cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@
</parent>
<artifactId>cpp</artifactId>

<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>language-antlr-utils</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.helger.maven</groupId>
<artifactId>ph-javacc-maven-plugin</artifactId>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<executions>
<execution>
<id>javacc-gen</id>
<goals>
<goal>javacc</goal>
<goal>antlr4</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<jdkVersion>21</jdkVersion>
<javadocFriendlyComments>true</javadocFriendlyComments>
<packageName>de.jplag.cpp</packageName>
<sourceDirectory>src/main/javacc</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/javacc</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Loading
Loading