Initial skeleton

This commit is contained in:
Matteo Settenvini 2023-11-29 21:54:14 +01:00
commit 5d3e2d4e20
Signed by: matteo
GPG Key ID: 8576CC1AD97D42DF
6 changed files with 154 additions and 0 deletions

0
.clang-format Normal file
View File

28
.clang-tidy Normal file
View File

@ -0,0 +1,28 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: matteo
CheckOptions:
llvm-else-after-return.WarnOnConditionVariables: 'false'
modernize-loop-convert.MinConfidence: reasonable
modernize-replace-auto-ptr.IncludeStyle: llvm
cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
google-readability-namespace-comments.ShortNamespaceLines: '10'
cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
google-readability-braces-around-statements.ShortStatementLines: '1'
cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
google-readability-namespace-comments.SpacesBeforeComments: '2'
modernize-loop-convert.MaxCopySize: '16'
modernize-pass-by-value.IncludeStyle: llvm
modernize-use-nullptr.NullMacros: 'NULL'
llvm-qualified-auto.AddConstToQualified: 'false'
modernize-loop-convert.NamingStyle: CamelCase
llvm-else-after-return.WarnOnUnfixable: 'false'
google-readability-function-size.StatementThreshold: '800'
...

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/build
*.orig
*.rej
*~

16
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"format"
],
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
]
}

18
CMakeLists.txt Normal file
View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.22)
project(format-demo)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_custom_command(OUTPUT main-formatted.cc
DEPENDS main-unformatted.cc .clang-format .clang-tidy
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/main-unformatted.cc main-formatted.cc
COMMAND clang-format-16 -i main-formatted.cc
COMMAND clang-tidy-16 --fix --fix-notes -fix-errors
-fix-errors -p ${CMAKE_CURRENT_BINARY_DIR} main-formatted.cc
VERBATIM)
add_custom_target(format
DEPENDS main-formatted.cc
COMMENT "Formatting and linting sources"
SOURCES main-unformatted.cc ${CMAKE_CURRENT_BINARY_DIR}/main-formatted.cc
.clang-format .clang-tidy
VERBATIM)

88
main-unformatted.cc Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cstdint>
#define BIT_MASK 0xDEADBEAF
#define MULTILINE_DEF(a,b) if ((a)>2) { \
auto temp = (b)/2; \
(b)+=10; \
someFunctionCall((a),(b));\
}
namespace LevelOneNamespace {
extern auto someFunctionCall(int16_t, float *) -> int;
namespace LevelTwoNamespace {
template <typename T, int size> bool is_sorted(T(&array)[size]) {
return std::adjacent_find(array, array + size, std::greater<T>()) ==
array + size;
}
std::vector<uint32_t> returnVector( uint32_t* LongNameForParameter1,
double* LongNameForParameter2,
const float& LongNameForParameter3,
std::map<std::string,int32_t>& LongNameForParameter4) {
//TODO: This is a long comment that allows you to understand how long comments will be trimmed. Here should be deep thought but it's just not right time for this
for (auto& i: LongNameForParameter4) {
auto b = someFunctionCall(static_cast<int16_t>(*LongNameForParameter2),reinterpret_cast<float*>(LongNameForParameter2));
i.second++;
}
do {
auto a = 100;
if (a)
a--;
else
a++;
} while (false);
return {};
}
}
}
int main() {
std::srand(std::time(0));
int list[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
using LevelOneNamespace::LevelTwoNamespace::is_sorted;
do {
std::random_shuffle(list, list + 9);
} while (is_sorted(list));
int score = 0;
do {
std::cout << "Current list: ";
std::copy(list, list + 9, std::ostream_iterator<int>(std::cout, " "));
int rev;
while (true) {
std::cout << "\nDigits to reverse? ";
std::cin >> rev;
if (rev > 1 && rev < 10)
break;
std::cout << "Please enter a value between 2 and 9.";
}
++score;
std::reverse(list, list + rev);
} while (!is_sorted(list));
std::cout << "Congratulations, you sorted the list.\n"
<< "You needed " << score << " reversals." << std::endl;
return 0;
}