Skip to content

Commit

Permalink
Attempt to fix redundant declaration error
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadliaJerad committed Dec 2, 2024
1 parent 113d5f4 commit 17f5208
Showing 1 changed file with 52 additions and 37 deletions.
89 changes: 52 additions & 37 deletions core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -247,7 +251,6 @@ private static List<String> 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 + "'");
}
Expand All @@ -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.
*
* <p>Note: It appears that configuration and build cannot happen in one command. Therefore, this
* <p>
* 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()
Expand All @@ -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) {
Expand All @@ -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.
*
* <p>Errors currently detected:
* <p>
* Errors currently detected:
*
* <ul>
* <li>C++ compiler used to compile C files: This error shows up as &#39;#error &quot;The
* CMAKE_C_COMPILER is set to a C++ compiler&quot;&#39; in the &#39;CMakeOutput&#39; string.
* <li>C++ compiler used to compile C files: This error shows up as &#39;#error
* &quot;The
* CMAKE_C_COMPILER is set to a C++ compiler&quot;&#39; in the
* &#39;CMakeOutput&#39; string.
* </ul>
*
* @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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 17f5208

Please sign in to comment.