Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: LLVM
Standard: c++17
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: Empty
ColumnLimit: 100
PointerAlignment: Left
NamespaceIndentation: All
SortIncludes: Never
ReflowComments: false
22 changes: 22 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: clang-format

on:
push:
branches: [main, master]
pull_request:

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install clang-format 17
run: |
sudo apt-get update
sudo apt-get install -y clang-format-17
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-17 100

- name: Run format-check
run: ./scripts/format-check.sh
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,16 @@ endif()
include(${CMAKE_SOURCE_DIR}/cmake/tscancode.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/flawfinder.cmake)
# include(${CMAKE_SOURCE_DIR}/cmake/ikos.cmake)

# ============
# FORMATTING
# ============
add_custom_target(format
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/format.sh"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Run clang-format on source files")

add_custom_target(format-check
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/format-check.sh"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Verify clang-format compliance")
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ cmake .. \
make -j4
```

### CODE STYLE (clang-format)

- Version cible : `clang-format` 17 (utilisée dans la CI).
- Formater localement : `./scripts/format.sh`
- Vérifier sans modifier : `./scripts/format-check.sh`
- CMake : `cmake --build build --target format` ou `--target format-check`
- CI : le job GitHub Actions `clang-format` échoue si un fichier n’est pas formaté.

### DEBUG

You can pass arguments to CMake and invoke ASan.
Expand Down
2 changes: 1 addition & 1 deletion include/App/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ctrace
{
CT_NODISCARD ProgramConfig buildConfig(int argc, char *argv[]);
CT_NODISCARD ProgramConfig buildConfig(int argc, char* argv[]);
}

#endif // APP_CONFIG_HPP
2 changes: 1 addition & 1 deletion include/App/Runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace ctrace
{
CT_NODISCARD int run_server(const ProgramConfig& config);
CT_NODISCARD int run_cli_analysis(const ProgramConfig& config);
}
} // namespace ctrace

#endif // APP_RUNNER_HPP
36 changes: 18 additions & 18 deletions include/ArgumentParser/ArgumentManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,67 @@
*/
class ArgumentManager
{
public:
/**
public:
/**
* @brief Constructs an `ArgumentManager` with a given argument parser.
*
* @param parser A `std::unique_ptr` to an `IArgumentParser` implementation.
*/
explicit ArgumentManager(std::unique_ptr<IArgumentParser> parser);
explicit ArgumentManager(std::unique_ptr<IArgumentParser> parser);

/**
/**
* @brief Adds an option to the argument parser.
*
* @param name The name of the option (e.g., "--option").
* @param hasArgument Indicates whether the option requires an argument.
* @param shortName A single-character shorthand for the option (e.g., '-o').
*/
void addOption(const std::string& name, bool hasArgument, char shortName);
void addOption(const std::string& name, bool hasArgument, char shortName);

/**
/**
* @brief Adds a flag to the argument parser.
*
* Flags are options that do not require arguments (e.g., "--verbose").
*
* @param name The name of the flag (e.g., "--flag").
* @param shortName A single-character shorthand for the flag (e.g., '-f').
*/
void addFlag(const std::string& name, char shortName);
void addFlag(const std::string& name, char shortName);

/**
/**
* @brief Parses the command-line arguments.
*
* @param argc The number of arguments.
* @param argv The array of argument strings.
*/
void parse(int argc, char* argv[]);
void parse(int argc, char* argv[]);

/**
/**
* @brief Checks if a specific option was provided.
*
* @param name The name of the option to check.
* @return `true` if the option was provided, `false` otherwise.
*/
[[nodiscard]] bool hasOption(const std::string& name) const;
[[nodiscard]] bool hasOption(const std::string& name) const;

/**
/**
* @brief Checks if no options were provided.
*
* @return `true` if no options were provided, `false` otherwise.
*/
[[nodiscard]] bool hasNoOption() const;
[[nodiscard]] bool hasNoOption() const;

/**
/**
* @brief Retrieves the value of a specific option.
*
* @param name The name of the option.
* @return The value of the option as a `std::string`.
*/
[[nodiscard]] std::string getOptionValue(const std::string& name) const;
[[nodiscard]] std::string getOptionValue(const std::string& name) const;

private:
std::unique_ptr<IArgumentParser> _parser; ///< The underlying argument parser implementation.
bool _hasNoOption = false; ///< Flag indicating if no options were provided.
private:
std::unique_ptr<IArgumentParser> _parser; ///< The underlying argument parser implementation.
bool _hasNoOption = false; ///< Flag indicating if no options were provided.
};

#endif // ARGUMENTMANAGER_HPP
24 changes: 12 additions & 12 deletions include/ArgumentParser/BaseArgumentParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
*/
class BaseArgumentParser : public IArgumentParser
{
protected:
ErrorCode _lastError; ///< Stores the last error code encountered.
std::string _errorMessage; ///< Stores the last error message encountered.
protected:
ErrorCode _lastError; ///< Stores the last error code encountered.
std::string _errorMessage; ///< Stores the last error message encountered.

/**
/**
* @brief Sets the last error code and message.
*
* This method updates the internal error state with the provided
Expand All @@ -26,30 +26,30 @@ class BaseArgumentParser : public IArgumentParser
* @param code The error code to set.
* @param message The error message to set (default is an empty string).
*/
void setError(ErrorCode code, const std::string& message = "");
void setError(ErrorCode code, const std::string& message = "");

public:
/**
public:
/**
* @brief Default constructor for `BaseArgumentParser`.
*
* Initializes the error state to `ErrorCode::SUCCESS` and clears
* the error message.
*/
BaseArgumentParser();
BaseArgumentParser();

/**
/**
* @brief Retrieves the last error code.
*
* @return An `ErrorCode` representing the last error encountered.
*/
ErrorCode getLastError() const override;
ErrorCode getLastError() const override;

/**
/**
* @brief Retrieves the last error message.
*
* @return A `std::string` containing the last error message.
*/
std::string getErrorMessage() const override;
std::string getErrorMessage() const override;
};

#endif // BASE_ARGUMENT_PARSER_HPP
56 changes: 30 additions & 26 deletions include/ArgumentParser/CLI11/CLI11ArgumentParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
class CLI11ArgumentParser : public BaseArgumentParser
{
private:
CLI::App app{"CLI11 Argument Parser"}; ///< CLI11 application instance.
std::vector<OptionInfo> _options; ///< List of registered options.
std::vector<std::pair<std::string, bool*>> _flags; ///< List of flag options (no arguments).
std::vector<std::pair<std::string, std::string*>> _values; ///< List of options with arguments.
private:
CLI::App app{"CLI11 Argument Parser"}; ///< CLI11 application instance.
std::vector<OptionInfo> _options; ///< List of registered options.
std::vector<std::pair<std::string, bool*>> _flags; ///< List of flag options (no arguments).
std::vector<std::pair<std::string, std::string*>> _values; ///< List of options with arguments.

/**
/**
* @brief Checks if an option already exists.
*
* This method verifies whether an option with the given name or short name
Expand All @@ -31,19 +31,19 @@ class CLI11ArgumentParser : public BaseArgumentParser
* @param shortName The short name of the option.
* @return `true` if the option exists, `false` otherwise.
*/
[[nodiscard]] bool optionExists(const std::string& name, char shortName) const
[[nodiscard]] bool optionExists(const std::string& name, char shortName) const
{
for (const auto& opt : _options)
{
for (const auto& opt : _options)
if (opt.name == name || (shortName != '\0' && opt.shortName == shortName))
{
if (opt.name == name || (shortName != '\0' && opt.shortName == shortName))
{
return true;
}
return true;
}
return false;
}
return false;
}

/**
/**
* @brief Removes leading dashes from an option name.
*
* This helper function strips leading dashes (`-` or `--`) from an option name
Expand All @@ -52,17 +52,17 @@ class CLI11ArgumentParser : public BaseArgumentParser
* @param name The option name to process.
* @return A string without leading dashes.
*/
static std::string stripDashes(const std::string& name)
static std::string stripDashes(const std::string& name)
{
std::string stripped = name;
while (!stripped.empty() && stripped[0] == '-')
{
std::string stripped = name;
while (!stripped.empty() && stripped[0] == '-')
{
stripped.erase(0, 1);
}
return stripped;
stripped.erase(0, 1);
}
return stripped;
}

public:
public:
/**
* @brief Constructs a `CLI11ArgumentParser` instance.
*
Expand Down Expand Up @@ -104,7 +104,8 @@ class CLI11ArgumentParser : public BaseArgumentParser
{
auto* value = new std::string();
_values.emplace_back(longOpt, value);
auto* cliOption = app.add_option("-" + shortOpt + "," + name, *value, "Option with argument");
auto* cliOption =
app.add_option("-" + shortOpt + "," + name, *value, "Option with argument");
if (!cliOption)
{
setError(ErrorCode::INVALID_OPTION, "Failed to add option: " + name);
Expand Down Expand Up @@ -166,7 +167,8 @@ class CLI11ArgumentParser : public BaseArgumentParser
for (auto& opt : _options)
{
std::string longOpt = stripDashes(opt.name);
if (opt.hasArgument) {
if (opt.hasArgument)
{
for (const auto& [name, value] : _values)
{
if (name == longOpt && !value->empty())
Expand Down Expand Up @@ -203,7 +205,8 @@ class CLI11ArgumentParser : public BaseArgumentParser
{
for (const auto& opt : _options)
{
if (opt.name == name || (opt.shortName != '\0' && std::string(1, opt.shortName) == name))
if (opt.name == name ||
(opt.shortName != '\0' && std::string(1, opt.shortName) == name))
{
return opt.isSet;
}
Expand All @@ -222,7 +225,8 @@ class CLI11ArgumentParser : public BaseArgumentParser
{
for (const auto& opt : _options)
{
if (opt.name == name || (opt.shortName != '\0' && std::string(1, opt.shortName) == name))
if (opt.name == name ||
(opt.shortName != '\0' && std::string(1, opt.shortName) == name))
{
return opt.value;
}
Expand Down
Loading
Loading