From 67ba1ab281d6ce7972792eadbe4af4365c2dc1dc Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Tue, 23 Jan 2024 15:54:19 +0100 Subject: [PATCH 1/9] Renamed cpp to c and cpp2 to cpp --- README.md | 2 +- cli/pom.xml | 4 +- docs/1.-How-to-Use-JPlag.md | 2 +- languages/c/pom.xml | 35 ++++++ .../src/main/java/de/jplag/c/CLanguage.java} | 13 ++- .../src/main/java/de/jplag/c/CTokenType.java | 77 +++++++++++++ .../main/java/de/jplag/c}/NewlineStream.java | 2 +- .../src/main/java/de/jplag/c}/Scanner.java | 4 +- .../c}/experimental/GCCSourceAnalysis.java | 4 +- .../jplag/c}/experimental/SourceAnalysis.java | 4 +- .../experimental/UnreachableCodeFilter.java | 4 +- languages/{cpp => c}/src/main/javacc/CPP.jj | 4 +- languages/{cpp2 => cpp}/README.md | 0 languages/cpp/pom.xml | 27 +++-- .../de/jplag/cpp}/grammar/CPP14Lexer.g4 | 0 .../de/jplag/cpp}/grammar/CPP14Parser.g4 | 0 .../main/java/de/jplag/cpp}/CPPLanguage.java | 6 +- .../main/java/de/jplag/cpp}/CPPListener.java | 8 +- .../java/de/jplag/cpp}/CPPParserAdapter.java | 6 +- .../main/java/de/jplag/cpp/CPPTokenType.java | 105 ++++++++---------- .../java/de/jplag/cpp}/CppLanguageTest.java | 2 +- .../jplag/cpp}/CallOutsideMethodInClass.cpp | 0 .../resources/de/jplag/cpp}/FunctionCall.cpp | 0 .../test/resources/de/jplag/cpp}/IfElse.cpp | 0 .../test/resources/de/jplag/cpp}/IntArray.cpp | 0 .../src/test/resources/de/jplag/cpp}/Loop.cpp | 0 .../test/resources/de/jplag/cpp}/Union.cpp | 0 .../test/resources/de/jplag/cpp}/bc6h_enc.h | 0 languages/cpp2/pom.xml | 38 ------- .../main/java/de/jplag/cpp2/CPPTokenType.java | 62 ----------- languages/pom.xml | 2 +- 31 files changed, 206 insertions(+), 205 deletions(-) create mode 100644 languages/c/pom.xml rename languages/{cpp/src/main/java/de/jplag/cpp/Language.java => c/src/main/java/de/jplag/c/CLanguage.java} (73%) create mode 100644 languages/c/src/main/java/de/jplag/c/CTokenType.java rename languages/{cpp/src/main/java/de/jplag/cpp => c/src/main/java/de/jplag/c}/NewlineStream.java (97%) rename languages/{cpp/src/main/java/de/jplag/cpp => c/src/main/java/de/jplag/c}/Scanner.java (91%) rename languages/{cpp/src/main/java/de/jplag/cpp => c/src/main/java/de/jplag/c}/experimental/GCCSourceAnalysis.java (95%) rename languages/{cpp/src/main/java/de/jplag/cpp => c/src/main/java/de/jplag/c}/experimental/SourceAnalysis.java (90%) rename languages/{cpp/src/main/java/de/jplag/cpp => c/src/main/java/de/jplag/c}/experimental/UnreachableCodeFilter.java (98%) rename languages/{cpp => c}/src/main/javacc/CPP.jj (99%) rename languages/{cpp2 => cpp}/README.md (100%) rename languages/{cpp2/src/main/antlr4/de/jplag/cpp2 => cpp/src/main/antlr4/de/jplag/cpp}/grammar/CPP14Lexer.g4 (100%) rename languages/{cpp2/src/main/antlr4/de/jplag/cpp2 => cpp/src/main/antlr4/de/jplag/cpp}/grammar/CPP14Parser.g4 (100%) rename languages/{cpp2/src/main/java/de/jplag/cpp2 => cpp/src/main/java/de/jplag/cpp}/CPPLanguage.java (88%) rename languages/{cpp2/src/main/java/de/jplag/cpp2 => cpp/src/main/java/de/jplag/cpp}/CPPListener.java (98%) rename languages/{cpp2/src/main/java/de/jplag/cpp2 => cpp/src/main/java/de/jplag/cpp}/CPPParserAdapter.java (91%) rename languages/{cpp2/src/test/java/de/jplag/cpp2 => cpp/src/test/java/de/jplag/cpp}/CppLanguageTest.java (99%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/CallOutsideMethodInClass.cpp (100%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/FunctionCall.cpp (100%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/IfElse.cpp (100%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/IntArray.cpp (100%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/Loop.cpp (100%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/Union.cpp (100%) rename languages/{cpp2/src/test/resources/de/jplag/cpp2 => cpp/src/test/resources/de/jplag/cpp}/bc6h_enc.h (100%) delete mode 100644 languages/cpp2/pom.xml delete mode 100644 languages/cpp2/src/main/java/de/jplag/cpp2/CPPTokenType.java diff --git a/README.md b/README.md index 2a124620a..89779e41b 100644 --- a/README.md +++ b/README.md @@ -145,8 +145,8 @@ Clustering --cluster-skip Skips the clustering (default: false) Commands: + c cpp - cpp2 csharp emf emf-model diff --git a/cli/pom.xml b/cli/pom.xml index b6812a3eb..b20db5877 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -44,12 +44,12 @@ de.jplag - cpp + c ${revision} de.jplag - cpp2 + cpp ${revision} diff --git a/docs/1.-How-to-Use-JPlag.md b/docs/1.-How-to-Use-JPlag.md index 42f5b76e8..089e2bca9 100644 --- a/docs/1.-How-to-Use-JPlag.md +++ b/docs/1.-How-to-Use-JPlag.md @@ -84,8 +84,8 @@ Clustering --cluster-skip Skips the clustering (default: false) Commands: + c cpp - cpp2 csharp emf emf-model diff --git a/languages/c/pom.xml b/languages/c/pom.xml new file mode 100644 index 000000000..71d9cdb8e --- /dev/null +++ b/languages/c/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + de.jplag + languages + ${revision} + + c + + + + + com.helger.maven + ph-javacc-maven-plugin + + + javacc-gen + + javacc + + generate-sources + + 21 + true + de.jplag.c + src/main/javacc + ${project.build.directory}/generated-sources/javacc + + + + + + + diff --git a/languages/cpp/src/main/java/de/jplag/cpp/Language.java b/languages/c/src/main/java/de/jplag/c/CLanguage.java similarity index 73% rename from languages/cpp/src/main/java/de/jplag/cpp/Language.java rename to languages/c/src/main/java/de/jplag/c/CLanguage.java index dcc69edd7..3e487b89d 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/Language.java +++ b/languages/c/src/main/java/de/jplag/c/CLanguage.java @@ -1,4 +1,4 @@ -package de.jplag.cpp; +package de.jplag.c; import java.io.File; import java.util.List; @@ -6,16 +6,17 @@ 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(); } @@ -26,7 +27,7 @@ public String[] suffixes() { @Override public String getName() { - return "C/C++ Scanner [basic markup]"; + return "C(C++) Scanner [basic markup]"; } @Override diff --git a/languages/c/src/main/java/de/jplag/c/CTokenType.java b/languages/c/src/main/java/de/jplag/c/CTokenType.java new file mode 100644 index 000000000..185daa3e1 --- /dev/null +++ b/languages/c/src/main/java/de/jplag/c/CTokenType.java @@ -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; + } +} diff --git a/languages/cpp/src/main/java/de/jplag/cpp/NewlineStream.java b/languages/c/src/main/java/de/jplag/c/NewlineStream.java similarity index 97% rename from languages/cpp/src/main/java/de/jplag/cpp/NewlineStream.java rename to languages/c/src/main/java/de/jplag/c/NewlineStream.java index 9cc21a3d8..f45c9af61 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/NewlineStream.java +++ b/languages/c/src/main/java/de/jplag/c/NewlineStream.java @@ -1,4 +1,4 @@ -package de.jplag.cpp; +package de.jplag.c; import java.io.IOException; import java.io.InputStream; diff --git a/languages/cpp/src/main/java/de/jplag/cpp/Scanner.java b/languages/c/src/main/java/de/jplag/c/Scanner.java similarity index 91% rename from languages/cpp/src/main/java/de/jplag/cpp/Scanner.java rename to languages/c/src/main/java/de/jplag/c/Scanner.java index e7f25476d..c3292814e 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/Scanner.java +++ b/languages/c/src/main/java/de/jplag/c/Scanner.java @@ -1,4 +1,4 @@ -package de.jplag.cpp; +package de.jplag.c; import java.io.File; import java.util.ArrayList; @@ -32,7 +32,7 @@ public List scan(Set 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)); } diff --git a/languages/cpp/src/main/java/de/jplag/cpp/experimental/GCCSourceAnalysis.java b/languages/c/src/main/java/de/jplag/c/experimental/GCCSourceAnalysis.java similarity index 95% rename from languages/cpp/src/main/java/de/jplag/cpp/experimental/GCCSourceAnalysis.java rename to languages/c/src/main/java/de/jplag/c/experimental/GCCSourceAnalysis.java index 52b7bdfcd..85d94d514 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/experimental/GCCSourceAnalysis.java +++ b/languages/c/src/main/java/de/jplag/c/experimental/GCCSourceAnalysis.java @@ -1,4 +1,4 @@ -package de.jplag.cpp.experimental; +package de.jplag.c.experimental; import java.io.BufferedReader; import java.io.File; @@ -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); diff --git a/languages/cpp/src/main/java/de/jplag/cpp/experimental/SourceAnalysis.java b/languages/c/src/main/java/de/jplag/c/experimental/SourceAnalysis.java similarity index 90% rename from languages/cpp/src/main/java/de/jplag/cpp/experimental/SourceAnalysis.java rename to languages/c/src/main/java/de/jplag/c/experimental/SourceAnalysis.java index 0d846370e..f92986d1d 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/experimental/SourceAnalysis.java +++ b/languages/c/src/main/java/de/jplag/c/experimental/SourceAnalysis.java @@ -1,4 +1,4 @@ -package de.jplag.cpp.experimental; +package de.jplag.c.experimental; import java.io.File; import java.util.Set; @@ -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. diff --git a/languages/cpp/src/main/java/de/jplag/cpp/experimental/UnreachableCodeFilter.java b/languages/c/src/main/java/de/jplag/c/experimental/UnreachableCodeFilter.java similarity index 98% rename from languages/cpp/src/main/java/de/jplag/cpp/experimental/UnreachableCodeFilter.java rename to languages/c/src/main/java/de/jplag/c/experimental/UnreachableCodeFilter.java index e795c6976..59b8df85b 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/experimental/UnreachableCodeFilter.java +++ b/languages/c/src/main/java/de/jplag/c/experimental/UnreachableCodeFilter.java @@ -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; diff --git a/languages/cpp/src/main/javacc/CPP.jj b/languages/c/src/main/javacc/CPP.jj similarity index 99% rename from languages/cpp/src/main/javacc/CPP.jj rename to languages/c/src/main/javacc/CPP.jj index cc1689fbe..ee4ca34d8 100644 --- a/languages/cpp/src/main/javacc/CPP.jj +++ b/languages/c/src/main/javacc/CPP.jj @@ -14,7 +14,7 @@ options } PARSER_BEGIN(CPPScanner) -package de.jplag.cpp; +package de.jplag.c; import java.io.File; import java.io.FileInputStream; @@ -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; diff --git a/languages/cpp2/README.md b/languages/cpp/README.md similarity index 100% rename from languages/cpp2/README.md rename to languages/cpp/README.md diff --git a/languages/cpp/pom.xml b/languages/cpp/pom.xml index 734f52d92..d3cfb4881 100644 --- a/languages/cpp/pom.xml +++ b/languages/cpp/pom.xml @@ -8,25 +8,28 @@ cpp + + + org.antlr + antlr4-runtime + + + de.jplag + language-antlr-utils + ${revision} + + + - com.helger.maven - ph-javacc-maven-plugin + org.antlr + antlr4-maven-plugin - javacc-gen - javacc + antlr4 - generate-sources - - 21 - true - de.jplag.cpp - src/main/javacc - ${project.build.directory}/generated-sources/javacc - diff --git a/languages/cpp2/src/main/antlr4/de/jplag/cpp2/grammar/CPP14Lexer.g4 b/languages/cpp/src/main/antlr4/de/jplag/cpp/grammar/CPP14Lexer.g4 similarity index 100% rename from languages/cpp2/src/main/antlr4/de/jplag/cpp2/grammar/CPP14Lexer.g4 rename to languages/cpp/src/main/antlr4/de/jplag/cpp/grammar/CPP14Lexer.g4 diff --git a/languages/cpp2/src/main/antlr4/de/jplag/cpp2/grammar/CPP14Parser.g4 b/languages/cpp/src/main/antlr4/de/jplag/cpp/grammar/CPP14Parser.g4 similarity index 100% rename from languages/cpp2/src/main/antlr4/de/jplag/cpp2/grammar/CPP14Parser.g4 rename to languages/cpp/src/main/antlr4/de/jplag/cpp/grammar/CPP14Parser.g4 diff --git a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPLanguage.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java similarity index 88% rename from languages/cpp2/src/main/java/de/jplag/cpp2/CPPLanguage.java rename to languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java index 990ab8c9f..c2f4d79a8 100644 --- a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPLanguage.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java @@ -1,4 +1,4 @@ -package de.jplag.cpp2; +package de.jplag.cpp; import org.kohsuke.MetaInfServices; @@ -10,7 +10,7 @@ */ @MetaInfServices(Language.class) public class CPPLanguage extends AbstractAntlrLanguage { - private static final String IDENTIFIER = "cpp2"; + private static final String IDENTIFIER = "cpp"; public CPPLanguage() { super(new CPPParserAdapter()); @@ -23,7 +23,7 @@ public String[] suffixes() { @Override public String getName() { - return "C/C++ Parser"; + return "C++(C) Parser"; } @Override diff --git a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPListener.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java similarity index 98% rename from languages/cpp2/src/main/java/de/jplag/cpp2/CPPListener.java rename to languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java index 115ec54de..7da0c24c7 100644 --- a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPListener.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java @@ -1,6 +1,6 @@ -package de.jplag.cpp2; +package de.jplag.cpp; -import static de.jplag.cpp2.CPPTokenType.*; +import static de.jplag.cpp.CPPTokenType.*; import java.util.function.Function; @@ -10,8 +10,8 @@ import de.jplag.TokenType; import de.jplag.antlr.AbstractAntlrListener; import de.jplag.antlr.ContextVisitor; -import de.jplag.cpp2.grammar.CPP14Parser; -import de.jplag.cpp2.grammar.CPP14Parser.*; +import de.jplag.cpp.grammar.CPP14Parser; +import de.jplag.cpp.grammar.CPP14Parser.*; import de.jplag.semantics.CodeSemantics; import de.jplag.semantics.VariableAccessType; import de.jplag.semantics.VariableRegistry; diff --git a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPParserAdapter.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPParserAdapter.java similarity index 91% rename from languages/cpp2/src/main/java/de/jplag/cpp2/CPPParserAdapter.java rename to languages/cpp/src/main/java/de/jplag/cpp/CPPParserAdapter.java index 925406360..d1bc12a6b 100644 --- a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPParserAdapter.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPParserAdapter.java @@ -1,4 +1,4 @@ -package de.jplag.cpp2; +package de.jplag.cpp; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CommonTokenStream; @@ -8,8 +8,8 @@ import de.jplag.AbstractParser; import de.jplag.antlr.AbstractAntlrListener; import de.jplag.antlr.AbstractAntlrParserAdapter; -import de.jplag.cpp2.grammar.CPP14Lexer; -import de.jplag.cpp2.grammar.CPP14Parser; +import de.jplag.cpp.grammar.CPP14Lexer; +import de.jplag.cpp.grammar.CPP14Parser; /** * The adapter between {@link AbstractParser} and the ANTLR based parser of this language module. diff --git a/languages/cpp/src/main/java/de/jplag/cpp/CPPTokenType.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPTokenType.java index e8143b98f..0bf830cd6 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/CPPTokenType.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPTokenType.java @@ -2,67 +2,52 @@ import de.jplag.TokenType; +/** + * C++ token types extracted by this language module. + */ public enum CPPTokenType 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"); + CLASS_BEGIN("CLASS{"), + CLASS_END("}CLASS"), + STRUCT_BEGIN("STRUCT{"), + STRUCT_END("}STRUCT"), + ENUM_BEGIN("ENUM{"), + ENUM_END("}ENUM"), + UNION_BEGIN("UNION{"), + UNION_END("}UNION"), + FUNCTION_BEGIN("FUNCTION{"), + FUNCTION_END("}FUNCTION"), + DO_BEGIN("DO{"), + DO_END("}DO"), + WHILE_BEGIN("WHILE{"), + WHILE_END("}WHILE"), + FOR_BEGIN("FOR{"), + FOR_END("}FOR"), + SWITCH_BEGIN("SWITCH{"), + SWITCH_END("}SWITCH"), + CASE("CASE"), + TRY_BEGIN("TRY{"), + TRY_END("}TRY"), + CATCH_BEGIN("CATCH{"), + CATCH_END("}CATCH"), + IF_BEGIN("IF{"), + IF_END("}IF"), + ELSE("ELSE"), + BREAK("BREAK"), + CONTINUE("CONTINUE"), + GOTO("GOTO"), + RETURN("RETURN"), + THROW("THROW"), + NEWCLASS("NEWCLASS"), + GENERIC("GENERIC"), + NEWARRAY("NEWARRAY"), + BRACED_INIT_BEGIN("BRACED_INIT{"), + BRACED_INIT_END("}BRACED_INIT"), + ASSIGN("ASSIGN"), + STATIC_ASSERT("STATIC_ASSERT"), + VARDEF("VARDEF"), + QUESTIONMARK("COND"), + DEFAULT("DEFAULT"), + APPLY("APPLY"); private final String description; diff --git a/languages/cpp2/src/test/java/de/jplag/cpp2/CppLanguageTest.java b/languages/cpp/src/test/java/de/jplag/cpp/CppLanguageTest.java similarity index 99% rename from languages/cpp2/src/test/java/de/jplag/cpp2/CppLanguageTest.java rename to languages/cpp/src/test/java/de/jplag/cpp/CppLanguageTest.java index 52d4342d9..c885c4562 100644 --- a/languages/cpp2/src/test/java/de/jplag/cpp2/CppLanguageTest.java +++ b/languages/cpp/src/test/java/de/jplag/cpp/CppLanguageTest.java @@ -1,4 +1,4 @@ -package de.jplag.cpp2; +package de.jplag.cpp; import java.util.Arrays; diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/CallOutsideMethodInClass.cpp b/languages/cpp/src/test/resources/de/jplag/cpp/CallOutsideMethodInClass.cpp similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/CallOutsideMethodInClass.cpp rename to languages/cpp/src/test/resources/de/jplag/cpp/CallOutsideMethodInClass.cpp diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/FunctionCall.cpp b/languages/cpp/src/test/resources/de/jplag/cpp/FunctionCall.cpp similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/FunctionCall.cpp rename to languages/cpp/src/test/resources/de/jplag/cpp/FunctionCall.cpp diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/IfElse.cpp b/languages/cpp/src/test/resources/de/jplag/cpp/IfElse.cpp similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/IfElse.cpp rename to languages/cpp/src/test/resources/de/jplag/cpp/IfElse.cpp diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/IntArray.cpp b/languages/cpp/src/test/resources/de/jplag/cpp/IntArray.cpp similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/IntArray.cpp rename to languages/cpp/src/test/resources/de/jplag/cpp/IntArray.cpp diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/Loop.cpp b/languages/cpp/src/test/resources/de/jplag/cpp/Loop.cpp similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/Loop.cpp rename to languages/cpp/src/test/resources/de/jplag/cpp/Loop.cpp diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/Union.cpp b/languages/cpp/src/test/resources/de/jplag/cpp/Union.cpp similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/Union.cpp rename to languages/cpp/src/test/resources/de/jplag/cpp/Union.cpp diff --git a/languages/cpp2/src/test/resources/de/jplag/cpp2/bc6h_enc.h b/languages/cpp/src/test/resources/de/jplag/cpp/bc6h_enc.h similarity index 100% rename from languages/cpp2/src/test/resources/de/jplag/cpp2/bc6h_enc.h rename to languages/cpp/src/test/resources/de/jplag/cpp/bc6h_enc.h diff --git a/languages/cpp2/pom.xml b/languages/cpp2/pom.xml deleted file mode 100644 index cfd8366cc..000000000 --- a/languages/cpp2/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - - de.jplag - languages - ${revision} - - cpp2 - - - - org.antlr - antlr4-runtime - - - de.jplag - language-antlr-utils - ${revision} - - - - - - - org.antlr - antlr4-maven-plugin - - - - antlr4 - - - - - - - diff --git a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPTokenType.java b/languages/cpp2/src/main/java/de/jplag/cpp2/CPPTokenType.java deleted file mode 100644 index a87a43630..000000000 --- a/languages/cpp2/src/main/java/de/jplag/cpp2/CPPTokenType.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.jplag.cpp2; - -import de.jplag.TokenType; - -/** - * C++ token types extracted by this language module. - */ -public enum CPPTokenType implements TokenType { - CLASS_BEGIN("CLASS{"), - CLASS_END("}CLASS"), - STRUCT_BEGIN("STRUCT{"), - STRUCT_END("}STRUCT"), - ENUM_BEGIN("ENUM{"), - ENUM_END("}ENUM"), - UNION_BEGIN("UNION{"), - UNION_END("}UNION"), - FUNCTION_BEGIN("FUNCTION{"), - FUNCTION_END("}FUNCTION"), - DO_BEGIN("DO{"), - DO_END("}DO"), - WHILE_BEGIN("WHILE{"), - WHILE_END("}WHILE"), - FOR_BEGIN("FOR{"), - FOR_END("}FOR"), - SWITCH_BEGIN("SWITCH{"), - SWITCH_END("}SWITCH"), - CASE("CASE"), - TRY_BEGIN("TRY{"), - TRY_END("}TRY"), - CATCH_BEGIN("CATCH{"), - CATCH_END("}CATCH"), - IF_BEGIN("IF{"), - IF_END("}IF"), - ELSE("ELSE"), - BREAK("BREAK"), - CONTINUE("CONTINUE"), - GOTO("GOTO"), - RETURN("RETURN"), - THROW("THROW"), - NEWCLASS("NEWCLASS"), - GENERIC("GENERIC"), - NEWARRAY("NEWARRAY"), - BRACED_INIT_BEGIN("BRACED_INIT{"), - BRACED_INIT_END("}BRACED_INIT"), - ASSIGN("ASSIGN"), - STATIC_ASSERT("STATIC_ASSERT"), - VARDEF("VARDEF"), - QUESTIONMARK("COND"), - DEFAULT("DEFAULT"), - APPLY("APPLY"); - - private final String description; - - @Override - public String getDescription() { - return this.description; - } - - CPPTokenType(String description) { - this.description = description; - } -} diff --git a/languages/pom.xml b/languages/pom.xml index 203275f10..16367daf6 100644 --- a/languages/pom.xml +++ b/languages/pom.xml @@ -9,8 +9,8 @@ languages pom + c cpp - cpp2 csharp emf-metamodel emf-metamodel-dynamic From 3c7c9d38fd7932c4a4ab529b8ea897ccfc48c70f Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Tue, 30 Jan 2024 15:10:24 +0100 Subject: [PATCH 2/9] add c/cpp rename to report viewer --- report-viewer/src/model/Language.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/report-viewer/src/model/Language.ts b/report-viewer/src/model/Language.ts index a9b9b91f8..344fbc691 100644 --- a/report-viewer/src/model/Language.ts +++ b/report-viewer/src/model/Language.ts @@ -4,8 +4,8 @@ enum ParserLanguage { JAVA = 'Javac based AST plugin', PYTHON = 'Python3 Parser', - CPP = 'C/C++ Scanner [basic markup]', - CPP2 = 'C/C++ Parser', + C = 'C(C++) Scanner [basic markup]', + CPP = 'C++(C) Parser', C_SHARP = 'C# 6 Parser', EMF_METAMODEL_DYNAMIC = 'emf-dynamic', EMF_METAMODEL = 'EMF metamodel', @@ -66,8 +66,8 @@ function getHighlightLanguage(language: ParserLanguage | undefined): HighlightLa switch (language) { case ParserLanguage.PYTHON: return HighlightLanguage.PYTHON + case ParserLanguage.C: case ParserLanguage.CPP: - case ParserLanguage.CPP2: return HighlightLanguage.CPP case ParserLanguage.C_SHARP: return HighlightLanguage.C_SHARP From a0ed87be3af4d50d428328c1b0cf602d2ebadf91 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Tue, 30 Jan 2024 15:23:33 +0100 Subject: [PATCH 3/9] Fixed compiler error due to renaming of cpp modules. --- coverage-report/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage-report/pom.xml b/coverage-report/pom.xml index 3d918dd10..71f01179a 100644 --- a/coverage-report/pom.xml +++ b/coverage-report/pom.xml @@ -63,12 +63,12 @@ de.jplag - cpp + c ${revision} de.jplag - cpp2 + cpp ${revision} From faf05caf83cc774dab76eed90e29952cfbe2f975 Mon Sep 17 00:00:00 2001 From: TwoOfTwelve Date: Fri, 2 Feb 2024 11:01:47 +0100 Subject: [PATCH 4/9] Simplified C / CPP names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timur Sağlam --- report-viewer/src/model/Language.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report-viewer/src/model/Language.ts b/report-viewer/src/model/Language.ts index 344fbc691..8e88f7b1a 100644 --- a/report-viewer/src/model/Language.ts +++ b/report-viewer/src/model/Language.ts @@ -4,8 +4,8 @@ enum ParserLanguage { JAVA = 'Javac based AST plugin', PYTHON = 'Python3 Parser', - C = 'C(C++) Scanner [basic markup]', - CPP = 'C++(C) Parser', + C = 'C Scanner', + CPP = 'C++ Parser', C_SHARP = 'C# 6 Parser', EMF_METAMODEL_DYNAMIC = 'emf-dynamic', EMF_METAMODEL = 'EMF metamodel', From 0e6a23af877fd95f7b05252c478abbce37195526 Mon Sep 17 00:00:00 2001 From: TwoOfTwelve Date: Fri, 2 Feb 2024 11:01:54 +0100 Subject: [PATCH 5/9] Simplified C / CPP names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timur Sağlam --- languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java index c2f4d79a8..8a04708f0 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPLanguage.java @@ -23,7 +23,7 @@ public String[] suffixes() { @Override public String getName() { - return "C++(C) Parser"; + return "C++ Parser"; } @Override From 34e34e8e0cc02f88e22ae9617236b6d60ed1d84a Mon Sep 17 00:00:00 2001 From: TwoOfTwelve Date: Fri, 2 Feb 2024 11:02:05 +0100 Subject: [PATCH 6/9] Simplified C / CPP names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timur Sağlam --- languages/c/src/main/java/de/jplag/c/CLanguage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/c/src/main/java/de/jplag/c/CLanguage.java b/languages/c/src/main/java/de/jplag/c/CLanguage.java index 3e487b89d..fbfdbde36 100644 --- a/languages/c/src/main/java/de/jplag/c/CLanguage.java +++ b/languages/c/src/main/java/de/jplag/c/CLanguage.java @@ -27,7 +27,7 @@ public String[] suffixes() { @Override public String getName() { - return "C(C++) Scanner [basic markup]"; + return "C Scanner"; } @Override From 9e1c76d91f4b8a9fe554a3b460c2f39879aeec03 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 9 Feb 2024 12:57:29 +0100 Subject: [PATCH 7/9] Improved c++ readability. --- README.md | 4 +- docs/2.-Supported-Languages.md | 2 +- .../main/java/de/jplag/cpp/CPPListener.java | 58 +++++++++++++------ 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 89779e41b..cbdbe47ab 100644 --- a/README.md +++ b/README.md @@ -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 | cpp | legacy | JavaCC | +| [C++](https://isocpp.org) | 14 | cpp2 | 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 | diff --git a/docs/2.-Supported-Languages.md b/docs/2.-Supported-Languages.md index b3b54345a..c89bb8ee3 100644 --- a/docs/2.-Supported-Languages.md +++ b/docs/2.-Supported-Languages.md @@ -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: diff --git a/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java index 7da0c24c7..eead87d83 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java @@ -33,29 +33,11 @@ class CPPListener extends AbstractAntlrListener { visit(FunctionDefinitionContext.class).map(FUNCTION_BEGIN, FUNCTION_END).addLocalScope().withSemantics(CodeSemantics::createControl); - visit(IterationStatementContext.class, rule -> rule.Do() != null).map(DO_BEGIN, DO_END).addLocalScope().withLoopSemantics(); - visit(IterationStatementContext.class, rule -> rule.For() != null).map(FOR_BEGIN, FOR_END).addLocalScope().withLoopSemantics(); - visit(IterationStatementContext.class, rule -> rule.While() != null && rule.Do() == null).map(WHILE_BEGIN, WHILE_END).addLocalScope() - .withLoopSemantics(); - - visit(SelectionStatementContext.class, rule -> rule.Switch() != null).map(SWITCH_BEGIN, SWITCH_END).addLocalScope() - .withSemantics(CodeSemantics::createControl); - visit(SelectionStatementContext.class, rule -> rule.If() != null).map(IF_BEGIN, IF_END).addLocalScope() - .withSemantics(CodeSemantics::createControl); - // possible problem: variable from if visible in else, but in reality is not -- doesn't really matter - visit(CPP14Parser.Else).map(ELSE).withSemantics(CodeSemantics::createControl); - - visit(LabeledStatementContext.class, rule -> rule.Case() != null).map(CASE).withSemantics(CodeSemantics::createControl); - visit(LabeledStatementContext.class, rule -> rule.Default() != null).map(DEFAULT).withSemantics(CodeSemantics::createControl); + statementRules(); visit(TryBlockContext.class).map(TRY_BEGIN, TRY_END).addLocalScope().withSemantics(CodeSemantics::createControl); visit(HandlerContext.class).map(CATCH_BEGIN, CATCH_END).addLocalScope().withSemantics(CodeSemantics::createControl); - visit(JumpStatementContext.class, rule -> rule.Break() != null).map(BREAK).withSemantics(CodeSemantics::createControl); - visit(JumpStatementContext.class, rule -> rule.Continue() != null).map(CONTINUE).withSemantics(CodeSemantics::createControl); - visit(JumpStatementContext.class, rule -> rule.Goto() != null).map(GOTO).withSemantics(CodeSemantics::createControl); - visit(JumpStatementContext.class, rule -> rule.Return() != null).map(RETURN).withSemantics(CodeSemantics::createControl); - visit(ThrowExpressionContext.class).map(THROW).withSemantics(CodeSemantics::createControl); visit(NewExpressionContext.class, rule -> rule.newInitializer() != null).map(NEWCLASS).withSemantics(CodeSemantics::new); @@ -73,6 +55,35 @@ class CPPListener extends AbstractAntlrListener { .onEnter((rule, varReg) -> varReg.setNextVariableAccessType(VariableAccessType.WRITE)); visit(BracedInitListContext.class).map(BRACED_INIT_BEGIN, BRACED_INIT_END).withSemantics(CodeSemantics::new); + typeSpecifierRule(); + declarationRules(); + expressionRules(); + idRules(); + } + + private void statementRules() { + visit(IterationStatementContext.class, rule -> rule.Do() != null).map(DO_BEGIN, DO_END).addLocalScope().withLoopSemantics(); + visit(IterationStatementContext.class, rule -> rule.For() != null).map(FOR_BEGIN, FOR_END).addLocalScope().withLoopSemantics(); + visit(IterationStatementContext.class, rule -> rule.While() != null && rule.Do() == null).map(WHILE_BEGIN, WHILE_END).addLocalScope() + .withLoopSemantics(); + + visit(SelectionStatementContext.class, rule -> rule.Switch() != null).map(SWITCH_BEGIN, SWITCH_END).addLocalScope() + .withSemantics(CodeSemantics::createControl); + visit(SelectionStatementContext.class, rule -> rule.If() != null).map(IF_BEGIN, IF_END).addLocalScope() + .withSemantics(CodeSemantics::createControl); + // possible problem: variable from if visible in else, but in reality is not -- doesn't really matter + visit(CPP14Parser.Else).map(ELSE).withSemantics(CodeSemantics::createControl); + + visit(LabeledStatementContext.class, rule -> rule.Case() != null).map(CASE).withSemantics(CodeSemantics::createControl); + visit(LabeledStatementContext.class, rule -> rule.Default() != null).map(DEFAULT).withSemantics(CodeSemantics::createControl); + + visit(JumpStatementContext.class, rule -> rule.Break() != null).map(BREAK).withSemantics(CodeSemantics::createControl); + visit(JumpStatementContext.class, rule -> rule.Continue() != null).map(CONTINUE).withSemantics(CodeSemantics::createControl); + visit(JumpStatementContext.class, rule -> rule.Goto() != null).map(GOTO).withSemantics(CodeSemantics::createControl); + visit(JumpStatementContext.class, rule -> rule.Return() != null).map(RETURN).withSemantics(CodeSemantics::createControl); + } + + private void typeSpecifierRule() { visit(SimpleTypeSpecifierContext.class, rule -> { if (hasAncestor(rule, MemberdeclarationContext.class, FunctionDefinitionContext.class)) { return true; @@ -99,7 +110,9 @@ class CPPListener extends AbstractAntlrListener { variableRegistry.registerVariable(name, scope, true); } }); + } + private void declarationRules() { mapApply(visit(SimpleDeclarationContext.class, rule -> { if (!hasAncestor(rule, FunctionBodyContext.class)) { return false; @@ -125,12 +138,17 @@ class CPPListener extends AbstractAntlrListener { varReg.setNextVariableAccessType(VariableAccessType.WRITE); } }); + } + + private void expressionRules() { visit(ConditionalExpressionContext.class, rule -> rule.Question() != null).map(QUESTIONMARK).withSemantics(CodeSemantics::new); mapApply(visit(PostfixExpressionContext.class, rule -> rule.LeftParen() != null)); visit(PostfixExpressionContext.class, rule -> rule.PlusPlus() != null || rule.MinusMinus() != null).map(ASSIGN) .withSemantics(CodeSemantics::new).onEnter((rule, varReg) -> varReg.setNextVariableAccessType(VariableAccessType.READ_WRITE)); + } + private void idRules() { visit(UnqualifiedIdContext.class).onEnter((ctx, varReg) -> { ParserRuleContext parentCtx = ctx.getParent().getParent(); if (!parentCtx.getParent().getParent().getText().contains("(")) { @@ -141,6 +159,8 @@ class CPPListener extends AbstractAntlrListener { }); } + + private void mapApply(ContextVisitor visitor) { visitor.onExit((ctx, varReg) -> varReg.setMutableWrite(false)).onEnter((ctx, varReg) -> { varReg.addAllNonLocalVariablesAsReads(); From 9f0387286d83f50c65fd25b8c003485ca410874c Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Tue, 13 Feb 2024 14:14:39 +0100 Subject: [PATCH 8/9] spotless. --- languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java b/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java index eead87d83..19db6dea7 100644 --- a/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java +++ b/languages/cpp/src/main/java/de/jplag/cpp/CPPListener.java @@ -159,8 +159,6 @@ private void idRules() { }); } - - private void mapApply(ContextVisitor visitor) { visitor.onExit((ctx, varReg) -> varReg.setMutableWrite(false)).onEnter((ctx, varReg) -> { varReg.addAllNonLocalVariablesAsReads(); From ce39f2ca601222a71e83b9a7f85d8693592a96f7 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Tue, 13 Feb 2024 15:22:02 +0100 Subject: [PATCH 9/9] Updated c/cpp readmes. --- README.md | 1 + languages/c/README.md | 12 ++++++++++++ languages/cpp/README.md | 11 ++++------- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 languages/c/README.md diff --git a/README.md b/README.md index 68ae01481..fc2296b12 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Commands: emf-model go java + javascript kotlin llvmir python3 diff --git a/languages/c/README.md b/languages/c/README.md new file mode 100644 index 000000000..735466e44 --- /dev/null +++ b/languages/c/README.md @@ -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: ` 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. \ No newline at end of file diff --git a/languages/cpp/README.md b/languages/cpp/README.md index a8046b20f..9eb9b09aa 100644 --- a/languages/cpp/README.md +++ b/languages/cpp/README.md @@ -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++.
+The JPlag C++ frontend allows the use of JPlag with submissions in C++.
It is based on the [C++ ANTLR4 grammar](https://github.com/antlr/grammars-v4/tree/master/cpp), licensed under MIT. ### C++ specification compatibility @@ -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