From 17f52082495b84a36a9c4b617d14390f78fd9059 Mon Sep 17 00:00:00 2001 From: Chadlia Jerad Date: Mon, 2 Dec 2024 13:33:16 +0100 Subject: [PATCH] Attempt to fix redundant declaration error --- .../org/lflang/generator/c/CCompiler.java | 89 +++++++++++-------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 5d30d2d176..fb1871d113 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -49,7 +49,8 @@ import org.lflang.util.LFCommand; /** - * Responsible for creating and executing the necessary CMake command to compile code that is + * Responsible for creating and executing the necessary CMake command to compile + * code that is * generated by the CGenerator. This class uses CMake to compile. * * @author Soroush Bateni @@ -66,7 +67,8 @@ public class CCompiler { MessageReporter messageReporter; /** - * Indicate whether the compiler is in C++ mode. In C++ mode, the compiler produces .cpp files + * Indicate whether the compiler is in C++ mode. In C++ mode, the compiler + * produces .cpp files * instead of .c files and uses a C++ compiler to compiler the code. */ private final boolean cppMode; @@ -77,10 +79,11 @@ public class CCompiler { /** * Create an instance of CCompiler. * - * @param targetConfig The current target configuration. - * @param fileConfig The current file configuration. + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. * @param messageReporter Used to report errors. - * @param cppMode Whether the generated code should be compiled as if it were C++. + * @param cppMode Whether the generated code should be compiled as if it + * were C++. */ public CCompiler( TargetConfig targetConfig, @@ -97,8 +100,9 @@ public CCompiler( /** * Run the C compiler by invoking cmake and make. * - * @param generator An instance of GeneratorBase, only used to report error line numbers in the - * Eclipse IDE. + * @param generator An instance of GeneratorBase, only used to report error line + * numbers in the + * Eclipse IDE. * @return true if compilation succeeds, false otherwise. */ public boolean runCCompiler(GeneratorBase generator, LFGeneratorContext context) @@ -193,15 +197,15 @@ public boolean runCCompiler(GeneratorBase generator, LFGeneratorContext context) } /** - * Return a command to compile the specified C file using CMake. This produces a C-specific + * Return a command to compile the specified C file using CMake. This produces a + * C-specific * compile command. */ public LFCommand compileCmakeCommand() { // Set the build directory to be "build" Path buildPath = fileConfig.getSrcGenPath().resolve("build"); - LFCommand command = - commandFactory.createCommand("cmake", cmakeOptions(targetConfig, fileConfig), buildPath); + LFCommand command = commandFactory.createCommand("cmake", cmakeOptions(targetConfig, fileConfig), buildPath); if (command == null) { messageReporter .nowhere() @@ -247,7 +251,6 @@ private static List cmakeOptions(TargetConfig targetConfig, FileConfig f // Do not convert to Unix path arguments.add("-DLF_SOURCE_DIRECTORY='" + quote + srcPath + quote + "'"); arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'"); - arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'"); } else { arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'"); } @@ -273,29 +276,31 @@ private String buildTypeToCmakeConfig(BuildType type) { } /** - * Return a command to build the specified C file using CMake. This produces a C-specific build + * Return a command to build the specified C file using CMake. This produces a + * C-specific build * command. * - *

Note: It appears that configuration and build cannot happen in one command. Therefore, this + *

+ * Note: It appears that configuration and build cannot happen in one command. + * Therefore, this * is separated into a compile command and a build command. */ public LFCommand buildCmakeCommand() { // Set the build directory to be "build" Path buildPath = fileConfig.getSrcGenPath().resolve("build"); String cores = String.valueOf(Runtime.getRuntime().availableProcessors()); - LFCommand command = - commandFactory.createCommand( - "cmake", - List.of( - "--build", - ".", - "--target", - "install", - "--parallel", - cores, - "--config", - buildTypeToCmakeConfig(targetConfig.get(BuildTypeProperty.INSTANCE))), - buildPath); + LFCommand command = commandFactory.createCommand( + "cmake", + List.of( + "--build", + ".", + "--target", + "install", + "--parallel", + cores, + "--config", + buildTypeToCmakeConfig(targetConfig.get(BuildTypeProperty.INSTANCE))), + buildPath); if (command == null) { messageReporter .nowhere() @@ -308,8 +313,10 @@ public LFCommand buildCmakeCommand() { } /** - * Return a flash/emulate command using west. If board is null (defaults to qemu_cortex_m3) or - * qemu_* Return a flash command which runs the target as an emulation If ordinary target, return + * Return a flash/emulate command using west. If board is null (defaults to + * qemu_cortex_m3) or + * qemu_* Return a flash command which runs the target as an emulation If + * ordinary target, return * {@code west flash} */ public LFCommand buildWestFlashCommand(PlatformOptions options) { @@ -331,18 +338,23 @@ public LFCommand buildWestFlashCommand(PlatformOptions options) { } /** - * Check if the output produced by CMake has any known and common errors. If a known error is + * Check if the output produced by CMake has any known and common errors. If a + * known error is * detected, a specialized, more informative message is shown. * - *

Errors currently detected: + *

+ * Errors currently detected: * *

* * @param CMakeOutput The captured output from CMake. - * @return true if the provided 'CMakeOutput' contains a known error. false otherwise. + * @return true if the provided 'CMakeOutput' contains a known error. false + * otherwise. */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean outputContainsKnownCMakeErrors(String CMakeOutput) { @@ -372,8 +384,10 @@ private boolean outputContainsKnownCMakeErrors(String CMakeOutput) { * Produces the filename including the target-specific extension * * @param fileName The base name of the file without any extensions - * @param cppMode Indicate whether the compiler is in C++ mode In C++ mode, the compiler produces - * .cpp files instead of .c files and uses a C++ compiler to compiler the code. + * @param cppMode Indicate whether the compiler is in C++ mode In C++ mode, the + * compiler produces + * .cpp files instead of .c files and uses a C++ compiler to + * compiler the code. */ static String getTargetFileName(String fileName, boolean cppMode, TargetConfig targetConfig) { return fileName + getFileExtension(cppMode, targetConfig); @@ -382,8 +396,9 @@ static String getTargetFileName(String fileName, boolean cppMode, TargetConfig t /** * Return the file extension of the output source files. * - * @param cppMode Whether we are building C code using a C++ compiler. - * @param targetConfig The target configuration that parameterizes the build process. + * @param cppMode Whether we are building C code using a C++ compiler. + * @param targetConfig The target configuration that parameterizes the build + * process. */ static String getFileExtension(boolean cppMode, TargetConfig targetConfig) { if (targetConfig.getOrDefault(PlatformProperty.INSTANCE).platform() == Platform.ARDUINO) {