diff --git a/src/.clang-tidy b/src/.clang-tidy index 4ff95b6..3d118a2 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -1 +1 @@ -Checks: 'boost-*,clang-analyzer-*,cppcoreguidelines-*,google-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-clang-analyzer-cplusplus.NewDeleteLeaks,-modernize-use-trailing-return-type,-misc-non-private-member-variables-in-classes,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-non-private-member-variables-in-classes,-modernize-use-nodiscard,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-readability-implicit-bool-conversion,-clang-diagnostic-unknown-warning-option,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-vararg,-modernize-raw-string-literal,-google-readability-todo,-readability-identifier-length,-readability-function-cognitive-complexity,-misc-no-recursion' +Checks: 'boost-*,clang-analyzer-*,cppcoreguidelines-*,google-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-clang-analyzer-cplusplus.NewDeleteLeaks,-modernize-use-trailing-return-type,-misc-non-private-member-variables-in-classes,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-non-private-member-variables-in-classes,-modernize-use-nodiscard,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-readability-implicit-bool-conversion,-clang-diagnostic-unknown-warning-option,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-vararg,-modernize-raw-string-literal,-google-readability-todo,-readability-identifier-length,-readability-function-cognitive-complexity,-misc-no-recursion,-misc-include-cleaner,-misc-use-anonymous-namespace,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-const-or-ref-data-members,-readability-avoid-nested-conditional-operator,-performance-enum-size,-clang-analyzer-optin.core.EnumCastOutOfRange' diff --git a/src/buildDoc.cpp b/src/buildDoc.cpp index 54f4e8d..9ee33f4 100644 --- a/src/buildDoc.cpp +++ b/src/buildDoc.cpp @@ -22,7 +22,6 @@ using boost::trim_copy; using std::cerr; -using std::endl; using std::function; using std::istringstream; using std::make_unique; @@ -158,7 +157,7 @@ static string replaceRegex(const string& haystack, const string& pattern, const } static string replaceRegex(string haystack, const string& pattern, const function& replacementFunc) { - regex r(pattern); + regex const r(pattern); while (true) { smatch match; if (regex_search(haystack, match, r)) { @@ -330,7 +329,7 @@ static vector splitStringIntoLines(const string& input) { } static bool startsWith(const string& str, char ch) { - return str.length() > 0 && str[0] == ch; + return !str.empty() && str[0] == ch; } static string readProcedureBlock(const vector& lines, size_t* i) { @@ -370,12 +369,12 @@ static unique_ptr parseProcedure(const string& input) { overload = newOverload.get(); procedure->overloads.push_back(std::move(newOverload)); } else if (section == ".description") { - if (procedure->description.length() > 0) { + if (!procedure->description.empty()) { throw runtime_error(string("Duplicate description in procedure ") + procedure->name); } procedure->description = readProcedureBlock(lines, &i); } else if (section == ".blurb") { - if (procedure->blurb.length() > 0) { + if (!procedure->blurb.empty()) { throw runtime_error(string("Duplicate blurb in procedure ") + procedure->name); } procedure->blurb = rest; @@ -412,12 +411,12 @@ static unique_ptr parseProcedure(const string& input) { newExample->description = readProcedureBlock(lines, &i); overload->examples.push_back(std::move(newExample)); } else if (section == ".example-code") { - if (example->code.length() > 0) { + if (!example->code.empty()) { throw runtime_error(string("Duplicate example-code in procedure ") + procedure->name); } example->code = readProcedureBlock(lines, &i); } else if (section == ".example-output") { - if (example->output.length() > 0) { + if (!example->output.empty()) { throw runtime_error(string("Duplicate example-output in procedure ") + procedure->name); } example->output = readProcedureBlock(lines, &i); @@ -676,12 +675,12 @@ int main() { buildProcedureIndex(procedures, &outputTxt, htmlPageTemplate); writeFile("../obj/resources/help/help.txt", insertDiagrams(outputTxt.str())); } catch (const regex_error& ex) { - ostringstream s; - cerr << ex.what() << ": " << NAMEOF_ENUM(ex.code()) << endl; + ostringstream const s; + cerr << ex.what() << ": " << NAMEOF_ENUM(ex.code()) << '\n'; return -1; } catch (const runtime_error& ex) { - ostringstream s; - cerr << ex.what() << endl; + ostringstream const s; + cerr << ex.what() << '\n'; return -1; } diff --git a/src/common.h b/src/common.h index 024e0e4..b643032 100644 --- a/src/common.h +++ b/src/common.h @@ -131,16 +131,6 @@ intrusive_ptr make_intrusive_ptr(Args&&... args) { } } // namespace boost -#ifdef CLANG_TIDY -// clang-tidy gets upset about assert() -#undef assert -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define assert(expr) \ - if (!(expr)) { \ - throw std::runtime_error(#expr); \ - } -#endif - // clang-tidy likes to see gsl::owner to express ownership of raw pointers, but we don't care about any other part of // the C++ Guidelines Support Library. let's just define our own gsl::owner. namespace gsl { diff --git a/src/compiler/BuiltInRecordTypesList.cpp b/src/compiler/BuiltInRecordTypesList.cpp index 3cb9cf0..882a1ab 100644 --- a/src/compiler/BuiltInRecordTypesList.cpp +++ b/src/compiler/BuiltInRecordTypesList.cpp @@ -23,7 +23,7 @@ class BuiltInRecordTypesList { }; } - std::unordered_map types{}; + std::unordered_map types; private: static boost::local_shared_ptr ValueField( diff --git a/src/compiler/CompiledProgram.cpp b/src/compiler/CompiledProgram.cpp index eb8ee84..27717d6 100644 --- a/src/compiler/CompiledProgram.cpp +++ b/src/compiler/CompiledProgram.cpp @@ -105,7 +105,7 @@ void CompiledProgram::run() const { // If it was successful, then execution will never reach this point. // If we're here, then it failed. - std::cerr << "Failed to start the program: " << strerror(errno) << std::endl; + std::cerr << "Failed to start the program: " << strerror(errno) << '\n'; // ChatGPT says it's important to use _exit and not exit here. _exit(EXIT_FAILURE); @@ -114,7 +114,7 @@ void CompiledProgram::run() const { int status{}; waitpid(pid, &status, 0); } else { - std::cout << "Failed to fork a new process: " << strerror(errno) << std::endl; + std::cout << "Failed to fork a new process: " << strerror(errno) << '\n'; } #endif diff --git a/src/compiler/Publisher.cpp b/src/compiler/Publisher.cpp index 6861549..f2b8410 100644 --- a/src/compiler/Publisher.cpp +++ b/src/compiler/Publisher.cpp @@ -13,7 +13,7 @@ Publisher::Publisher(const CompiledProgram& compiledProgram, const std::string& _pcode(compiledProgram.serialize()) {} std::string Publisher::getPublishDir(const std::string& basFilePath) { - std::string basDir = shared::getDirectoryName(basFilePath); + std::string const basDir = shared::getDirectoryName(basFilePath); return shared::pathCombine(basDir, "publish"); } @@ -34,13 +34,13 @@ std::string Publisher::publish(TargetPlatform platform) { std::vector licData{}; licData.insert(licData.end(), licString.begin(), licString.end()); if (isZip) { - std::vector entries{ + std::vector const entries{ compiler::ZipEntry{ std::move(exeFilename), std::move(exeData) }, compiler::ZipEntry{ licFilename, std::move(licData) }, }; compiler::zip(archiveFilePath, entries); } else { - std::vector entries{ + std::vector const entries{ shared::TarEntry{ std::move(exeFilename), std::move(exeData), 0777 }, shared::TarEntry{ licFilename, std::move(licData), 0664 }, }; diff --git a/src/compiler/TargetPlatform.cpp b/src/compiler/TargetPlatform.cpp index a31b12c..28307d2 100644 --- a/src/compiler/TargetPlatform.cpp +++ b/src/compiler/TargetPlatform.cpp @@ -97,7 +97,7 @@ const char* getPlatformExeExtension(TargetPlatform platform) { } std::string getLicenseForPlatform(TargetPlatform platform) { - std::string_view sv{ kLicense, kLicense_len }; + std::string_view const sv{ kLicense, kLicense_len }; switch (platform) { case TargetPlatform::kWinX86: case TargetPlatform::kWinX64: { diff --git a/src/compiler/compileProcedures.cpp b/src/compiler/compileProcedures.cpp index b1de41e..6d41a04 100644 --- a/src/compiler/compileProcedures.cpp +++ b/src/compiler/compileProcedures.cpp @@ -142,17 +142,17 @@ void assignProcedureIndices(const SourceProgram& sourceProgram, CompiledProgram* } void compileProcedures(const SourceProgram& sourceProgram, CompiledProgram* compiledProgram) { - BuiltInConstantList builtInConstants{}; - BuiltInProcedureList builtInProcedures{}; + BuiltInConstantList const builtInConstants{}; + BuiltInProcedureList const builtInProcedures{}; SymbolScope globalSymbolScope{ *compiledProgram }; // add symbols to the global scope for built-in constants - for (auto& builtInConstant : builtInConstants.constants) { + for (const auto& builtInConstant : builtInConstants.constants) { globalSymbolScope.addSymbol(builtInConstant.second.get(), SymbolType::kVariable); } // add symbols to the global scope for built-in procedures - for (auto& builtInProcedureGroup : builtInProcedures.map) { + for (const auto& builtInProcedureGroup : builtInProcedures.map) { for (auto& builtInProcedure : *builtInProcedureGroup.second) { globalSymbolScope.addSymbol(builtInProcedure.get(), SymbolType::kProcedure); } diff --git a/src/compiler/emit.cpp b/src/compiler/emit.cpp index 4224399..fb86c49 100644 --- a/src/compiler/emit.cpp +++ b/src/compiler/emit.cpp @@ -1200,7 +1200,7 @@ static void emitAssignStatement(const AssignStatementNode& statementNode, Proced static void emitCallStatement(const CallStatementNode& statementNode, ProcedureState* state) { auto numValueArgs = 0; auto numObjectArgs = 0; - int maxArgs = std::numeric_limits::max(); + int const maxArgs = std::numeric_limits::max(); for (const auto& arg : statementNode.arguments) { assert(arg->evaluatedType != nullptr); arg->evaluatedType->isValueType() ? numValueArgs++ : numObjectArgs++; @@ -2163,7 +2163,7 @@ static void emitPrint(const TypeNode& type, const Token& token, ProcedureState* // ---- O: list [0] | V: [0] // Print the list. We'll have to construct the type List of T from our type Set of T. - TypeNode listType{ Kind::kList, type.token, type.setKeyType }; + TypeNode const listType{ Kind::kList, type.token, type.setKeyType }; emitPrint(listType, token, state); // ---- O: [0] | V: [0] break; @@ -2377,7 +2377,7 @@ vector emit( std::cerr << "--start of emit--"; #endif ProcedureState state; - int maxLocals = std::numeric_limits::max(); + int const maxLocals = std::numeric_limits::max(); if (numLocalValues > maxLocals || numLocalObjects > maxLocals) { throw CompilerException( CompilerErrorCode::kTooManyLocalVariables, "Too many local variables.", procedureNode.token); diff --git a/src/compiler/makeExeFile.cpp b/src/compiler/makeExeFile.cpp index 03dcfc9..1b7a551 100644 --- a/src/compiler/makeExeFile.cpp +++ b/src/compiler/makeExeFile.cpp @@ -117,7 +117,7 @@ static size_t findBytecodeIndex(const vector& runnerBinary) { vector readDebugRunnerFile() { auto filename = fmt::format("runner{}", getPlatformExeExtension(getNativeTargetPlatform())); - vector candidates{ filename, fmt::format("/code/bin/{}", filename) }; + vector const candidates{ filename, fmt::format("/code/bin/{}", filename) }; // Find the first candidate file that actually exists. for (const auto& candidate : candidates) { diff --git a/src/compiler/parse.cpp b/src/compiler/parse.cpp index 2321e1c..bd6e899 100644 --- a/src/compiler/parse.cpp +++ b/src/compiler/parse.cpp @@ -151,7 +151,7 @@ static Term zeroOrMore(std::initializer_list terms) { static Term capture(int captureId, Term&& subTerm) { auto t = Term(TermType::kCapture); t.captureId = captureId; - t.subTerms.push_back(subTerm); + t.subTerms.push_back(std::move(subTerm)); return t; } diff --git a/src/compiler/tokenize.cpp b/src/compiler/tokenize.cpp index 5c1aef3..054d92f 100644 --- a/src/compiler/tokenize.cpp +++ b/src/compiler/tokenize.cpp @@ -231,7 +231,7 @@ bool Scanner::isCurrentTokenTextEmpty() { } TokenKind Scanner::classifyToken(const std::string& text) { - assert(text.length() > 0); + assert(!text.empty()); switch (text[0]) { case '\n': return TokenKind::kEndOfLine; diff --git a/src/compiler/typeCheck.cpp b/src/compiler/typeCheck.cpp index 7f99d00..63a0258 100644 --- a/src/compiler/typeCheck.cpp +++ b/src/compiler/typeCheck.cpp @@ -1088,6 +1088,7 @@ static void typeCheckSelectCaseStatement(SelectCaseStatementNode* statementNode) static void typeCheckYieldStatement(YieldStatementNode* statementNode) { assert(statementNode->boundCollectionDeclaration != nullptr); + (void)statementNode; } static void typeCheckDimListStatement(DimListStatementNode* statementNode) { @@ -1425,7 +1426,7 @@ void typeCheck( CompiledProgram* compiledProgram, const BuiltInProcedureList& builtInProcedures) { TypeCheckState state{ *procedureNode, sourceProgram, compiledProgram, builtInProcedures }; - return typeCheckBody(procedureNode->body.get(), &state); + typeCheckBody(procedureNode->body.get(), &state); } }; // namespace compiler diff --git a/src/runner/main.cpp b/src/runner/main.cpp index e1449e8..0c20103 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -31,16 +31,16 @@ int main(int /*argc*/, const char* /*argv*/[]) { auto error = interpreter.getError(); if (error.has_value()) { - std::cerr << "Error " << error->code.getString() << ": " << error->message << std::endl; + std::cerr << "Error " << error->code.getString() << ": " << error->message << '\n'; return 1; } return 0; } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } catch (...) { - std::cerr << "Unknown fatal error." << std::endl; + std::cerr << "Unknown fatal error." << '\n'; return 1; } } diff --git a/src/shared/InputLine.cpp b/src/shared/InputLine.cpp index 3e491b8..dc6b81e 100644 --- a/src/shared/InputLine.cpp +++ b/src/shared/InputLine.cpp @@ -5,7 +5,7 @@ namespace shared { InputLine::InputLine(const std::string& text, int width, int aMaxLen) : TInputLine( TRect(0, 0, width + 1 /*why is +1 needed?*/, 1), - std::max(text.size() + 1, static_cast(aMaxLen) + 1)) { + std::max(static_cast(text.size()) + 1, aMaxLen + 1)) { memcpy(data, text.c_str(), text.size()); data[text.size()] = 0; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } diff --git a/src/shared/Label.cpp b/src/shared/Label.cpp index 5b58930..a3bec46 100644 --- a/src/shared/Label.cpp +++ b/src/shared/Label.cpp @@ -5,7 +5,7 @@ namespace shared { Label::Label(const TRect& r) : TLabel(r, "", nullptr) {} -Label::Label(TStringView text, TView* link) : TLabel(TRect(0, 0, static_cast(cstrlen(text) + 3), 1), text, link) {} +Label::Label(TStringView text, TView* link) : TLabel(TRect(0, 0, (cstrlen(text) + 3), 1), text, link) {} Label::Label(const TRect& r, TStringView text, TView* link) : TLabel(r, text, link) {} diff --git a/src/shared/PictureView.cpp b/src/shared/PictureView.cpp index 5b6de60..d173111 100644 --- a/src/shared/PictureView.cpp +++ b/src/shared/PictureView.cpp @@ -89,7 +89,7 @@ std::string Picture::exportToString() { uint32_t previousBg = 0; auto previousTransparent = false; std::string previousChar = " "; - std::function newlineOrSpace = [&s, &lineStart]() -> void { + std::function const newlineOrSpace = [&s, &lineStart]() -> void { if (s.tellp() - lineStart >= 110) { s << "\n"; lineStart = s.tellp(); @@ -109,7 +109,7 @@ std::string Picture::exportToString() { auto changesBitMask = (previousChar != cell.ch ? 0x01 : 0) | (previousTransparent != cell.transparent ? 0x02 : 0) | (previousFg != fg ? 0x04 : 0) | (previousBg != bg ? 0x08 : 0); - char command = static_cast('A' + changesBitMask); + char const command = static_cast('A' + changesBitMask); s << command; diff --git a/src/shared/StatusLine.cpp b/src/shared/StatusLine.cpp index 0ea1dd7..f442d93 100644 --- a/src/shared/StatusLine.cpp +++ b/src/shared/StatusLine.cpp @@ -8,8 +8,8 @@ void StatusLine::draw() { TDrawBuffer b; TAttrPair color{}; - TAttrPair cNormal = getColor(0x0301); - TAttrPair cNormDisabled = getColor(0x0202); + TAttrPair const cNormal = getColor(0x0301); + TAttrPair const cNormDisabled = getColor(0x0202); b.moveChar(0, ' ', cNormal, size.x); auto* t = items; ushort i = 0; @@ -22,7 +22,7 @@ void StatusLine::draw() { } if (t->text != nullptr) { - ushort l = cstrlen(t->text); + ushort const l = cstrlen(t->text); if (i + l < size.x) { if (commandEnabled(t->command)) { if (colors != nullptr && colors->colorPairNormal.has_value()) { @@ -47,7 +47,7 @@ void StatusLine::draw() { t = t->next; } if (i < size.x - 2) { - TStringView hintText = hint(helpCtx); + TStringView const hintText = hint(helpCtx); if (!hintText.empty()) { b.moveStr(i, "\xB3 ", cNormal); i += 2; diff --git a/src/shared/ThinButton.cpp b/src/shared/ThinButton.cpp index 53f9823..fcde2dc 100644 --- a/src/shared/ThinButton.cpp +++ b/src/shared/ThinButton.cpp @@ -69,7 +69,7 @@ void ThinButton::drawState(bool down) { cButton = { 0xA0, 0xA0 }; } - int s = size.x - 1; + int const s = size.x - 1; b.moveChar(0, ' ', cButton, size.x); if (title != nullptr) { @@ -99,7 +99,7 @@ void ThinButton::handleEvent(TEvent& event) { TView::handleEvent(event); } - char c = hotKey(title); + char const c = hotKey(title); switch (event.what) { case evMouseDown: if ((state & sfDisabled) == 0) { diff --git a/src/shared/decimal.cpp b/src/shared/decimal.cpp index 1d84a15..2af79ec 100644 --- a/src/shared/decimal.cpp +++ b/src/shared/decimal.cpp @@ -59,9 +59,9 @@ Decimal doubleToDecimal(double x) { // Decompose double using bit manipulation uint64_t bits = 0; std::memcpy(&bits, &x, sizeof(double)); - uint32_t negative = (bits >> 63) & 1U; - uint32_t exponent = (bits >> 52) & 0x7FFU; - uint64_t mantissa = bits & 0xFFFFFFFFFFFFFU; + uint32_t const negative = (bits >> 63) & 1U; + uint32_t const exponent = (bits >> 52) & 0x7FFU; + uint64_t const mantissa = bits & 0xFFFFFFFFFFFFFU; if (std::isinf(x)) { mpd_uint128_triple_t infTriple{}; @@ -73,7 +73,7 @@ Decimal doubleToDecimal(double x) { int64_t binaryExponent = exponent; binaryExponent -= 0x3ff; // IEEE 754 double bias - Decimal fraction = mantissa / kDecimalDoubleMantissaDenominator; + Decimal const fraction = mantissa / kDecimalDoubleMantissaDenominator; Decimal magnitude = 2; auto isSubnormal = exponent == 0U; @@ -83,7 +83,7 @@ Decimal doubleToDecimal(double x) { } magnitude = magnitude.pow(binaryExponent); - Decimal sign = negative == 0U ? 1 : -1; + Decimal const sign = negative == 0U ? 1 : -1; if (exponent == 0U && mantissa == 0U) { return kDecimalZero; diff --git a/src/shared/tar.cpp b/src/shared/tar.cpp index 682dbc3..3033b5d 100644 --- a/src/shared/tar.cpp +++ b/src/shared/tar.cpp @@ -8,7 +8,7 @@ TarEntry::TarEntry(std::string name, std::vector data, uint mode) class OutputTarArchive { public: - std::vector bytes{}; + std::vector bytes; size_t index{ 0 }; static int read(mtar_t* tar, void* data, unsigned size) { diff --git a/src/tmbasic/AboutDialog.cpp b/src/tmbasic/AboutDialog.cpp index 01c9294..fcc6c0a 100644 --- a/src/tmbasic/AboutDialog.cpp +++ b/src/tmbasic/AboutDialog.cpp @@ -33,7 +33,7 @@ static const std::string kLogoPicture = static Picture getLogoPicture() { Picture picture{ kLogoPicture }; // replace RGB #C0C0C0 with BIOS color 7 otherwise it won't exactly match the background of the dialog box - TColorRGB c0c0c0{ 0xC0C0C0 }; + TColorRGB const c0c0c0{ 0xC0C0C0 }; for (auto& cell : picture.cells) { if (getBack(cell.colorAttr) == c0c0c0) { cell.colorAttr = { getFore(cell.colorAttr), TColorBIOS{ 7 } }; diff --git a/src/tmbasic/App.cpp b/src/tmbasic/App.cpp index f826f5b..85bbf6a 100644 --- a/src/tmbasic/App.cpp +++ b/src/tmbasic/App.cpp @@ -51,7 +51,7 @@ class DeskTop : public TDeskTop { public: explicit DeskTop(const TRect& r) : TDeskTop(r), TDeskInit(initTmBackground) {} - static TBackground* initTmBackground(TRect r) { return new Background(r); } + static gsl::owner initTmBackground(TRect r) { return new Background(r); } }; class AppPrivate { @@ -63,7 +63,7 @@ class AppPrivate { PictureWindowStatusItems pictureWindowStatusItems{}; PictureWindow* pictureWindow = nullptr; - static TDeskTop* initDeskTop(TRect r) { + static gsl::owner initDeskTop(TRect r) { r.a.y++; r.b.y--; return new DeskTop(r); @@ -261,7 +261,7 @@ class AppPrivate { return true; case kCmdProgramAddItem: { - DialogPtr d{}; + DialogPtr const d{}; auto cmd = TApplication::deskTop->execView(d.get()); if (cmd != cmCancel) { TEvent addEvent{ evCommand }; @@ -452,7 +452,7 @@ class AppPrivate { return; } - std::string source = "picture Untitled\nend picture\n"; + std::string const source = "picture Untitled\nend picture\n"; auto sourceMember = std::make_unique(SourceMemberType::kPicture, source, 0, 0); auto* sourceMemberPtr = sourceMember.get(); programWindow->addNewSourceMember(std::move(sourceMember)); @@ -682,7 +682,7 @@ void App::idle() { TApplication::idle(); auto now = std::chrono::steady_clock::now(); - std::chrono::duration msec = now - _private->lastTimerTick; + std::chrono::duration const msec = now - _private->lastTimerTick; if (msec.count() >= 250) { _private->lastTimerTick = now; message(deskTop, evBroadcast, kCmdTimerTick, nullptr); diff --git a/src/tmbasic/CodeEditorWindow.cpp b/src/tmbasic/CodeEditorWindow.cpp index 0df0b9f..ed68ea1 100644 --- a/src/tmbasic/CodeEditorWindow.cpp +++ b/src/tmbasic/CodeEditorWindow.cpp @@ -102,7 +102,7 @@ class CodeEditorFrame : public turbo::BasicEditorFrame { } }; -static TFrame* initCodeEditorFrame(TRect r) { +static gsl::owner initCodeEditorFrame(TRect r) { return new CodeEditorFrame(r); } diff --git a/src/tmbasic/HelpWindow.cpp b/src/tmbasic/HelpWindow.cpp index 730e47c..3ba84c3 100644 --- a/src/tmbasic/HelpWindow.cpp +++ b/src/tmbasic/HelpWindow.cpp @@ -23,7 +23,7 @@ class HelpWindowFrame : public TFrame { return { fore, back }; } - static TFrame* init(TRect r) { return new HelpWindowFrame(r); } + static gsl::owner init(TRect r) { return new HelpWindowFrame(r); } }; class HelpViewer : public THelpViewer { diff --git a/src/tmbasic/InsertColorDialog.cpp b/src/tmbasic/InsertColorDialog.cpp index 0172517..c8409a4 100644 --- a/src/tmbasic/InsertColorDialog.cpp +++ b/src/tmbasic/InsertColorDialog.cpp @@ -312,7 +312,7 @@ class PaletteView : public TView { auto width = getWidth(); auto height = getHeight(); const std::vector& colors = getColors(); - TPoint spot = makeLocal(event.mouse.where); + TPoint const spot = makeLocal(event.mouse.where); auto x = spot.x; auto y = spot.y; if (x >= 0 && x < width && y >= 0 && y < height) { diff --git a/src/tmbasic/InsertSymbolDialog.cpp b/src/tmbasic/InsertSymbolDialog.cpp index 0a96a63..a489f1d 100644 --- a/src/tmbasic/InsertSymbolDialog.cpp +++ b/src/tmbasic/InsertSymbolDialog.cpp @@ -51,7 +51,7 @@ class Cp437Table : public TView { void draw() override { TDrawBuffer buf; - TColorAttr color{ 0x30 }; + TColorAttr const color{ 0x30 }; for (uint16_t y = 0; y <= size.y - 1; y++) { buf.moveChar(0, ' ', color, static_cast(size.x)); @@ -69,7 +69,7 @@ class Cp437Table : public TView { if (event.what == evMouseDown) { do { if (mouseInView(event.mouse.where)) { - TPoint spot = makeLocal(event.mouse.where); + TPoint const spot = makeLocal(event.mouse.where); auto i = spot.x + 32 * spot.y; if (i >= 1 && i <= 254) { setCharFunc(_cp437toUtf8.at(i)); @@ -100,12 +100,12 @@ class UnicodeTable : public TView { void draw() override { TDrawBuffer buf; - TColorAttr color{ 0x30 }; + TColorAttr const color{ 0x30 }; for (ushort y = 0; y <= size.y - 1; y++) { buf.moveChar(0, ' ', color, static_cast(size.x)); for (ushort x = 0; x <= size.x - 1; x++) { - size_t i = 32 * (y + _unicodeTableScrollTop) + x; + size_t const i = 32 * (y + _unicodeTableScrollTop) + x; if (i < getSymbolCount()) { buf.moveStr(x, getSymbol(i), color, static_cast(1)); } @@ -121,8 +121,8 @@ class UnicodeTable : public TView { if (event.what == evMouseDown) { do { if (mouseInView(event.mouse.where)) { - TPoint spot = makeLocal(event.mouse.where); - size_t i = spot.x + 32 * (_unicodeTableScrollTop + spot.y); + TPoint const spot = makeLocal(event.mouse.where); + size_t const i = spot.x + 32 * (_unicodeTableScrollTop + spot.y); if (i < getSymbolCount()) { setCharFunc(getSymbol(i)); } else { diff --git a/src/tmbasic/PictureWindow.cpp b/src/tmbasic/PictureWindow.cpp index f17f7f8..bf7205f 100644 --- a/src/tmbasic/PictureWindow.cpp +++ b/src/tmbasic/PictureWindow.cpp @@ -67,12 +67,12 @@ class CanvasView : public TView { bool flashingSelection = false; // select mode > paste and move operations - std::optional pastedPicture{}; - std::optional pastedPictureLocation{}; + std::optional pastedPicture; + std::optional pastedPictureLocation; // select mode > move operation - std::optional moveOriginalRect{}; // where the pastedPicture is being dragged from - std::optional moveOriginalColor{}; // the color to fill in the original area + std::optional moveOriginalRect; // where the pastedPicture is being dragged from + std::optional moveOriginalColor; // the color to fill in the original area // mask mode bool flashingMask = false; @@ -645,13 +645,13 @@ void PictureWindowPrivate::updateStatusItems() { delete[] statusItems.character->text; // NOLINT statusItems.character->text = newStr(chText.str()); - TAttrPair attrPair{ TColorAttr(fg, bg), TColorAttr(fg, bg) }; + TAttrPair const attrPair{ TColorAttr(fg, bg), TColorAttr(fg, bg) }; statusItems.fgColor->colorPairNormal = attrPair; statusItems.bgColor->colorPairNormal = attrPair; statusItems.characterColor->colorPairNormal = attrPair; - TAttrPair sel{ 0x20, 0x2E }; - TAttrPair unsel{ 0x70, 0x74 }; + TAttrPair const sel{ 0x20, 0x2E }; + TAttrPair const unsel{ 0x70, 0x74 }; statusItems.selectColor->colorPairNormal = mode == PictureWindowMode::kSelect ? sel : unsel; statusItems.drawColor->colorPairNormal = mode == PictureWindowMode::kDraw ? sel : unsel; @@ -736,7 +736,7 @@ void PictureWindowPrivate::updateStatusItems() { void PictureWindowPrivate::onClear() { checkpoint(); - PictureCell pictureCell{ false, { fg, bg }, " " }; + PictureCell const pictureCell{ false, { fg, bg }, " " }; auto& picture = canvasView->picture; const auto selection = @@ -920,16 +920,16 @@ void PictureWindowPrivate::onRedo() { } void PictureWindowPrivate::onMouse(int pictureX, int pictureY, const CanvasViewMouseEventArgs& e) { - TPoint pt{ pictureX, pictureY }; + TPoint const pt{ pictureX, pictureY }; auto& picture = canvasView->picture; auto leftMouseDown = e.down && (e.buttons & mbLeftButton) != 0; auto rightMouseDown = e.down && (e.buttons & mbRightButton) != 0; auto leftDragging = e.move && (e.buttons & mbLeftButton) != 0; auto rightDragging = e.move && (e.buttons & mbRightButton) != 0; - TPoint verticalGripper{ picture.width / 2, picture.height }; - TPoint horizontalGripper{ picture.width + 1, picture.height / 2 }; - TPoint diagonalGripper{ picture.width + 1, picture.height }; + TPoint const verticalGripper{ picture.width / 2, picture.height }; + TPoint const horizontalGripper{ picture.width + 1, picture.height / 2 }; + TPoint const diagonalGripper{ picture.width + 1, picture.height }; if (leftMouseDown && (pt == verticalGripper || pt == horizontalGripper || pt == diagonalGripper)) { // the user has started to drag the resize gripper checkpoint(); @@ -1045,7 +1045,7 @@ void PictureWindowPrivate::onMouse(int pictureX, int pictureY, const CanvasViewM } auto& cell = picture.cells.at(pictureY * picture.width + pictureX); - TColorAttr color{ fg, bg }; + TColorAttr const color{ fg, bg }; switch (mode) { case PictureWindowMode::kSelect: @@ -1324,7 +1324,7 @@ void PictureWindow::handleEvent(TEvent& event) { if (event.keyDown.controlKeyState & kbPaste) { std::string s; std::array buf{}; - TSpan bufSpan{ buf.data(), buf.size() }; + TSpan const bufSpan{ buf.data(), buf.size() }; size_t length = 0; while (textEvent(event, bufSpan, length)) { s.append(buf.data(), length); diff --git a/src/tmbasic/ProgramWindow.cpp b/src/tmbasic/ProgramWindow.cpp index 4f7b32a..fbcfd0d 100644 --- a/src/tmbasic/ProgramWindow.cpp +++ b/src/tmbasic/ProgramWindow.cpp @@ -25,7 +25,6 @@ using compiler::SourceMember; using compiler::SourceMemberType; using compiler::SourceProgram; -using compiler::TargetPlatform; using shared::DialogPtr; using shared::Label; using shared::ViewPtr; @@ -445,7 +444,7 @@ void ProgramWindow::publish() { return; } - WindowPtr statusWindow{}; + WindowPtr const statusWindow{}; statusWindow.get()->drawView(); TScreen::flushScreen(); @@ -490,7 +489,7 @@ void ProgramWindow::run() { TProgram::application->suspend(); program.run(); - std::cout << "\nPress Enter to return to TMBASIC." << std::endl; + std::cout << "\nPress Enter to return to TMBASIC." << '\n'; std::cin.get(); TProgram::application->resume(); diff --git a/src/tmbasic/main.cpp b/src/tmbasic/main.cpp index 6dd0491..15c6d41 100644 --- a/src/tmbasic/main.cpp +++ b/src/tmbasic/main.cpp @@ -43,7 +43,7 @@ static void publishProgram(const std::string& filename, const std::vectoridentifier << "\"\nLn " << ex.token.lineIndex + 1 << ", Col " << ex.token.columnIndex + 1 << "\n" - << ex.message << std::endl; + << ex.message << '\n'; return 1; } catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + std::cerr << "Error: " << e.what() << '\n'; return 1; } catch (...) { - std::cerr << "Unknown error." << std::endl; + std::cerr << "Unknown error." << '\n'; return 1; } diff --git a/src/vm/BasicApp.cpp b/src/vm/BasicApp.cpp index 46788df..db0acca 100644 --- a/src/vm/BasicApp.cpp +++ b/src/vm/BasicApp.cpp @@ -27,15 +27,15 @@ BasicApp::~BasicApp() { shutDown(); } -TStatusLine* BasicApp::initBasicStatusLine(TRect /*r*/) { +gsl::owner BasicApp::initBasicStatusLine(TRect /*r*/) { return nullptr; } -TMenuBar* BasicApp::initBasicMenuBar(TRect /*r*/) { +gsl::owner BasicApp::initBasicMenuBar(TRect /*r*/) { return nullptr; } -TDeskTop* BasicApp::initBasicDeskTop(TRect r) { +gsl::owner BasicApp::initBasicDeskTop(TRect r) { return new DeskTop(r); } diff --git a/src/vm/BasicApp.h b/src/vm/BasicApp.h index 7e2fedd..9955698 100644 --- a/src/vm/BasicApp.h +++ b/src/vm/BasicApp.h @@ -18,9 +18,9 @@ class BasicApp : public TApplication { void forceScreenUpdate(); private: - static TStatusLine* initBasicStatusLine(TRect r); - static TMenuBar* initBasicMenuBar(TRect r); - static TDeskTop* initBasicDeskTop(TRect r); + static gsl::owner initBasicStatusLine(TRect r); + static gsl::owner initBasicMenuBar(TRect r); + static gsl::owner initBasicDeskTop(TRect r); }; } // namespace vm diff --git a/src/vm/BasicConsoleView.cpp b/src/vm/BasicConsoleView.cpp index bf78905..71fea81 100644 --- a/src/vm/BasicConsoleView.cpp +++ b/src/vm/BasicConsoleView.cpp @@ -43,7 +43,7 @@ TScreenCell* BasicConsoleView::getCell(int16_t x, int16_t y) { auto newSize = row->size(); // Fill in the gap with the fill color. - TColorAttr fill{ fillColor, fillColor }; + TColorAttr const fill{ fillColor, fillColor }; for (auto i = oldSize; i < newSize; i++) { auto* cell = &row->at(i); cell->attr = fill; @@ -58,7 +58,7 @@ TScreenCell* BasicConsoleView::getCell(int16_t x, int16_t y) { void BasicConsoleView::print(const std::string& str) { const auto bounds = getBounds(); - std::string_view view{ str }; + std::string_view const view{ str }; size_t iPrev = 0; size_t i = 0; size_t width = 0; diff --git a/src/vm/Interpreter.cpp b/src/vm/Interpreter.cpp index dd4596e..daf9b3f 100644 --- a/src/vm/Interpreter.cpp +++ b/src/vm/Interpreter.cpp @@ -153,7 +153,7 @@ void Interpreter::init(size_t procedureIndex) { _private->valueStackIndex = 0; _private->objectStackIndex = 0; - _private->callStack.push({ nullptr, 0, 0, 0, 0, 0, false, false }); + _private->callStack.emplace(nullptr, 0, 0, 0, 0, 0, false, false); decimal::context = decimal::IEEEContext(decimal::DECIMAL128); } @@ -172,10 +172,10 @@ struct SetDottedExpressionState { const std::vector* instructions{}; size_t* instructionIndex{}; bool isAssigningValue{}; - Value sourceValue{}; - boost::intrusive_ptr sourceObject{}; + Value sourceValue; + boost::intrusive_ptr sourceObject; bool error{}; - std::string errorMessage{}; + std::string errorMessage; ErrorCode errorCode{}; }; @@ -383,9 +383,9 @@ static void setDottedExpression(SetDottedExpressionState* state) { assert(state->instructions != nullptr); assert(state->instructionIndex != nullptr); - int numSuffixes = readInt(state->instructions, state->instructionIndex); - int numKeyValues = readInt(state->instructions, state->instructionIndex); - int numKeyObjects = readInt(state->instructions, state->instructionIndex); + int const numSuffixes = readInt(state->instructions, state->instructionIndex); + int const numKeyValues = readInt(state->instructions, state->instructionIndex); + int const numKeyObjects = readInt(state->instructions, state->instructionIndex); // Let's get our bearings in the stack. // <--- lower indices higher indices ---> @@ -813,8 +813,8 @@ bool Interpreter::run(int maxCycles) { auto returnsValue = opcode == Opcode::kCallV; auto returnsObject = opcode == Opcode::kCallO; auto& callProcedure = *procedures.at(procIndex); - _private->callStack.push( - { procedure, instructionIndex, numVals, numObjs, vsi, osi, returnsValue, returnsObject }); + _private->callStack.emplace( + procedure, instructionIndex, numVals, numObjs, vsi, osi, returnsValue, returnsObject); procedure = &callProcedure; instructions = &callProcedure.instructions; assert(instructions != nullptr); @@ -831,17 +831,17 @@ bool Interpreter::run(int maxCycles) { auto numObjs = readInt(instructions, &instructionIndex); auto returnsValue = opcode == Opcode::kSystemCallV || opcode == Opcode::kSystemCallVO; auto returnsObject = opcode == Opcode::kSystemCallO || opcode == Opcode::kSystemCallVO; - SystemCallInput systemCallInput{ this, - valueStack, - objectStack, - vsi, - osi, - numVals, - numObjs, - _private->consoleInputStream, - _private->consoleOutputStream, - _private->errorCode, - _private->errorMessage }; + SystemCallInput const systemCallInput{ this, + valueStack, + objectStack, + vsi, + osi, + numVals, + numObjs, + _private->consoleInputStream, + _private->consoleOutputStream, + _private->errorCode, + _private->errorMessage }; auto result = systemCall(static_cast(syscallIndex), systemCallInput); popValues(&vsi, numVals); for (auto i = 0; i < numObjs; i++) { @@ -990,7 +990,7 @@ bool Interpreter::run(int maxCycles) { } case Opcode::kValueListNew: { - int numVals = readInt(instructions, &instructionIndex); + int const numVals = readInt(instructions, &instructionIndex); ValueListBuilder valueListBuilder{}; for (int i = numVals - 1; i >= 0; i--) { valueListBuilder.items.push_back(std::move(*valueAt(valueStack, vsi, -1 - i))); @@ -1003,7 +1003,7 @@ bool Interpreter::run(int maxCycles) { } case Opcode::kObjectListNew: { - int numObjs = readInt(instructions, &instructionIndex); + int const numObjs = readInt(instructions, &instructionIndex); ObjectListBuilder objectListBuilder{}; for (int i = numObjs - 1; i >= 0; i--) { objectListBuilder.items.push_back(std::move(*objectAt(objectStack, osi, -1 - i))); diff --git a/src/vm/Program.cpp b/src/vm/Program.cpp index c114839..df37326 100644 --- a/src/vm/Program.cpp +++ b/src/vm/Program.cpp @@ -35,9 +35,9 @@ class ProgramReader { } boost::intrusive_ptr readString() { - size_t length = readInt(); - std::string_view sv{ reinterpret_cast(&vec.at(offset)), length }; - std::string str{ sv }; + size_t const length = readInt(); + std::string_view const sv{ reinterpret_cast(&vec.at(offset)), length }; + std::string const str{ sv }; offset += length; return boost::make_intrusive_ptr(str); } diff --git a/src/vm/TimeZone.cpp b/src/vm/TimeZone.cpp index bb5fc5d..a3a6f3d 100644 --- a/src/vm/TimeZone.cpp +++ b/src/vm/TimeZone.cpp @@ -26,8 +26,8 @@ bool TimeZone::equals(const Object& other) const { } std::vector TimeZone::getUtcOffsets(const DateTimeParts& dateTimeParts) const { - absl::CivilSecond civilSecond{ dateTimeParts.year, dateTimeParts.month, dateTimeParts.day, - dateTimeParts.hour, dateTimeParts.minute, dateTimeParts.second }; + absl::CivilSecond const civilSecond{ dateTimeParts.year, dateTimeParts.month, dateTimeParts.day, + dateTimeParts.hour, dateTimeParts.minute, dateTimeParts.second }; auto timeInfo = zone->At(civilSecond); // If this is the DST fallback hour, there is both a pre and post time. "pre" is always at least filled. diff --git a/src/vm/date.cpp b/src/vm/date.cpp index 22b525e..dfe8b17 100644 --- a/src/vm/date.cpp +++ b/src/vm/date.cpp @@ -225,7 +225,7 @@ Value DateTimeOffsetParts::toValue() const { } Value DateTimeParts::toValue() const { - DateTimeOffsetParts offsetParts{ year, month, day, hour, minute, second, millisecond, 0 }; + DateTimeOffsetParts const offsetParts{ year, month, day, hour, minute, second, millisecond, 0 }; return offsetParts.toValue(); } @@ -265,7 +265,7 @@ DateTimeOffsetParts::DateTimeOffsetParts(const Value& value) { } DateTimeParts::DateTimeParts(const Value& value) { - DateTimeOffsetParts parts{ value }; + DateTimeOffsetParts const parts{ value }; year = parts.year; month = parts.month; day = parts.day; @@ -276,7 +276,7 @@ DateTimeParts::DateTimeParts(const Value& value) { } boost::intrusive_ptr dateToString(const Value& date) { - DateTimeParts parts{ date }; + DateTimeParts const parts{ date }; std::stringstream ss; ss << std::setfill('0') << std::setw(4) << parts.year << "-" << std::setw(2) << parts.month << "-" << std::setw(2) << parts.day; @@ -284,7 +284,7 @@ boost::intrusive_ptr dateToString(const Value& date) { } boost::intrusive_ptr dateTimeToString(const Value& date) { - DateTimeParts parts{ date }; + DateTimeParts const parts{ date }; std::stringstream ss; ss << std::setfill('0') << std::setw(4) << parts.year << "-" << std::setw(2) << parts.month << "-" << std::setw(2) << parts.day << " " << std::setw(2) << parts.hour << ":" << std::setw(2) << parts.minute << ":" << std::setw(2) @@ -293,7 +293,7 @@ boost::intrusive_ptr dateTimeToString(const Value& date) { } boost::intrusive_ptr dateTimeOffsetToString(const Value& date) { - DateTimeOffsetParts parts{ date }; + DateTimeOffsetParts const parts{ date }; std::stringstream ss; ss << std::setfill('0') << std::setw(4) << parts.year << "-" << std::setw(2) << parts.month << "-" << std::setw(2) << parts.day << " " << std::setw(2) << parts.hour << ":" << std::setw(2) << parts.minute << ":" << std::setw(2) @@ -328,12 +328,12 @@ boost::intrusive_ptr timeSpanToString(const Value& timeSpan) { } Value dateTimeToDate(const Value& dateTime) { - DateTimeParts parts{ dateTime }; + DateTimeParts const parts{ dateTime }; return DateTimeParts{ parts.year, parts.month, parts.day, 0, 0, 0, 0 }.toValue(); } Value dateTimeOffsetToDateTime(const Value& dateTimeOffset) { - DateTimeOffsetParts parts{ dateTimeOffset }; + DateTimeOffsetParts const parts{ dateTimeOffset }; return DateTimeParts{ parts.year, parts.month, parts.day, parts.hour, parts.minute, parts.second, parts.millisecond } @@ -341,7 +341,7 @@ Value dateTimeOffsetToDateTime(const Value& dateTimeOffset) { } Value dateTimeOffsetToDate(const Value& dateTimeOffset) { - DateTimeOffsetParts parts{ dateTimeOffset }; + DateTimeOffsetParts const parts{ dateTimeOffset }; return DateTimeParts{ parts.year, parts.month, parts.day, 0, 0, 0, 0 }.toValue(); } diff --git a/src/vm/systemCalls.console.cpp b/src/vm/systemCalls.console.cpp index 55a8011..f3f42c4 100644 --- a/src/vm/systemCalls.console.cpp +++ b/src/vm/systemCalls.console.cpp @@ -175,8 +175,8 @@ static void setConsoleColorComponents(const SystemCallInput& input) { auto blue = input.getValue(-1); validateAndFloorRgb(&red, &green, &blue); - TColorRGB colorRgb{ static_cast(red.getInt32()), static_cast(green.getInt32()), - static_cast(blue.getInt32()) }; + TColorRGB const colorRgb{ static_cast(red.getInt32()), static_cast(green.getInt32()), + static_cast(blue.getInt32()) }; setForeOrBack(app->console->currentColorAttr, colorRgb); } @@ -219,12 +219,12 @@ void systemCallMoveCursor(const SystemCallInput& input, SystemCallResult* /*resu throw Error(ErrorCode::kWrongScreenMode, "Must be in fullscreen mode."); } - auto x = input.getValue(-2); + const auto& x = input.getValue(-2); if (x.num < 0 || x.num >= 32768) { throw Error(ErrorCode::kInvalidArgument, "X must be between 0 and 32767."); } - auto y = input.getValue(-1); + const auto& y = input.getValue(-1); if (y.num < 0 || y.num >= 32768) { throw Error(ErrorCode::kInvalidArgument, "Y must be between 0 and 32767."); } diff --git a/src/vm/systemCalls.dates.cpp b/src/vm/systemCalls.dates.cpp index 27c426f..a46b420 100644 --- a/src/vm/systemCalls.dates.cpp +++ b/src/vm/systemCalls.dates.cpp @@ -64,7 +64,7 @@ void systemCallDateFromParts(const SystemCallInput& input, SystemCallResult* res auto day = input.getValue(-1).getInt64(); validateDay(day); - DateTimeParts parts{ + DateTimeParts const parts{ static_cast(year), static_cast(month), static_cast(day), 0, 0, 0, 0 }; result->returnedValue = parts.toValue(); @@ -93,10 +93,10 @@ void systemCallDateTimeFromParts(const SystemCallInput& input, SystemCallResult* auto millisecond = input.getValue(-1).getInt64(); validateMillisecond(millisecond); - DateTimeParts parts{ static_cast(year), static_cast(month), - static_cast(day), static_cast(hour), - static_cast(minute), static_cast(second), - static_cast(millisecond) }; + DateTimeParts const parts{ static_cast(year), static_cast(month), + static_cast(day), static_cast(hour), + static_cast(minute), static_cast(second), + static_cast(millisecond) }; result->returnedValue = parts.toValue(); } @@ -104,7 +104,7 @@ void systemCallDateTimeFromParts(const SystemCallInput& input, SystemCallResult* // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetDay(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.day }; } @@ -133,10 +133,10 @@ void systemCallDateTimeOffsetFromParts(const SystemCallInput& input, SystemCallR auto offsetMilliseconds = input.getValue(-1).getInt64(); - DateTimeOffsetParts parts{ static_cast(year), static_cast(month), - static_cast(day), static_cast(hour), - static_cast(minute), static_cast(second), - static_cast(millisecond), offsetMilliseconds }; + DateTimeOffsetParts const parts{ static_cast(year), static_cast(month), + static_cast(day), static_cast(hour), + static_cast(minute), static_cast(second), + static_cast(millisecond), offsetMilliseconds }; result->returnedValue = parts.toValue(); } @@ -144,35 +144,35 @@ void systemCallDateTimeOffsetFromParts(const SystemCallInput& input, SystemCallR // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetHour(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.hour }; } // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetMillisecond(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.millisecond }; } // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetMinute(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.minute }; } // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetMonth(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.month }; } // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetSecond(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.second }; } @@ -203,7 +203,7 @@ void systemCallDateTimeOffsetToString(const SystemCallInput& input, SystemCallRe // (dateTimeOffset as DateTimeOffset) as Number void systemCallDateTimeOffsetYear(const SystemCallInput& input, SystemCallResult* result) { const auto& dateValue = input.getValue(-1); - DateTimeOffsetParts parts{ dateValue }; + DateTimeOffsetParts const parts{ dateValue }; result->returnedValue = Value{ parts.year }; } @@ -245,7 +245,7 @@ void systemCallSeconds(const SystemCallInput& input, SystemCallResult* result) { } // () as DateTimeOffset -void systemCallNow(const SystemCallInput& input, SystemCallResult* result) { +void systemCallNow(const SystemCallInput& /*input*/, SystemCallResult* result) { absl::TimeZone tz; #ifdef _WIN32 // Ask Windows for the local time zone because Abseil doesn't know how to do it. @@ -287,10 +287,10 @@ void systemCallNow(const SystemCallInput& input, SystemCallResult* result) { auto utcOffsetMilliseconds = static_cast(civilInfo.offset) * 1000; // Construct DateTimeOffsetParts. - DateTimeOffsetParts parts{ static_cast(year), static_cast(month), - static_cast(day), static_cast(hour), - static_cast(minute), static_cast(second), - static_cast(milliseconds), utcOffsetMilliseconds }; + DateTimeOffsetParts const parts{ static_cast(year), static_cast(month), + static_cast(day), static_cast(hour), + static_cast(minute), static_cast(second), + static_cast(milliseconds), utcOffsetMilliseconds }; // Return it in Value format. result->returnedValue = parts.toValue(); @@ -349,7 +349,7 @@ void systemCallTotalSeconds(const SystemCallInput& input, SystemCallResult* resu void systemCallUtcOffsets(const SystemCallInput& input, SystemCallResult* result) { const auto& timeZone = *castTimeZone(input.getObject(-1)); const auto& dateTimeValue = input.getValue(-1); - DateTimeParts dateTimeParts{ dateTimeValue }; + DateTimeParts const dateTimeParts{ dateTimeValue }; auto offsets = timeZone.getUtcOffsets(dateTimeParts); ValueListBuilder builder{}; for (const auto& offset : offsets) { diff --git a/src/vm/systemCalls.files.cpp b/src/vm/systemCalls.files.cpp index 71eefc7..df34968 100644 --- a/src/vm/systemCalls.files.cpp +++ b/src/vm/systemCalls.files.cpp @@ -169,7 +169,7 @@ void systemCallReadFileLines(const SystemCallInput& input, SystemCallResult* res // (filePath as String) as String void systemCallReadFileText(const SystemCallInput& input, SystemCallResult* result) { auto filePath = castString(input.getObject(-1))->value; - std::ifstream stream{ filePath }; + std::ifstream const stream{ filePath }; if (stream.fail()) { throw Error::fromFileErrno(errno, filePath); } @@ -196,8 +196,8 @@ void systemCallWriteFileBytes(const SystemCallInput& input, SystemCallResult* /* } constexpr size_t kChunkSize = 16 * 1024; // 16KB for (size_t i = 0; i < bytes.size(); i += kChunkSize) { - size_t remainingBytes = bytes.size() - i; - size_t chunkBytes = std::min(kChunkSize, remainingBytes); + size_t const remainingBytes = bytes.size() - i; + size_t const chunkBytes = std::min(kChunkSize, remainingBytes); stream.write(&bytes.at(i), static_cast(chunkBytes)); if (stream.fail()) { throw Error::fromFileErrno(errno, filePath); diff --git a/src/vm/systemCalls.strings.cpp b/src/vm/systemCalls.strings.cpp index 155ccbd..a88eec5 100644 --- a/src/vm/systemCalls.strings.cpp +++ b/src/vm/systemCalls.strings.cpp @@ -26,7 +26,7 @@ void systemCallCharacters(const SystemCallInput& input, SystemCallResult* result // Fast path if the whole string is ASCII. auto fastPath = true; - for (char ch : str.value) { + for (char const ch : str.value) { if (ch != 9 && (ch < 32 || ch > 126)) { fastPath = false; break; @@ -35,7 +35,7 @@ void systemCallCharacters(const SystemCallInput& input, SystemCallResult* result if (fastPath) { ObjectListBuilder objectListBuilder{}; - for (char ch : str.value) { + for (char const ch : str.value) { objectListBuilder.items.push_back(boost::make_intrusive_ptr(std::string{ ch })); } result->returnedObject = boost::make_intrusive_ptr(&objectListBuilder); @@ -85,7 +85,7 @@ void systemCallChr(const SystemCallInput& input, SystemCallResult* result) { } // Convert the UTF-8 array to a std::string. - std::string s{ reinterpret_cast(utf8.data()), static_cast(length) }; + std::string const s{ reinterpret_cast(utf8.data()), static_cast(length) }; result->returnedObject = boost::make_intrusive_ptr(s); } @@ -119,7 +119,7 @@ void systemCallCodePoints(const SystemCallInput& input, SystemCallResult* result // (input as String) as Number void systemCallCodeUnit1(const SystemCallInput& input, SystemCallResult* result) { const auto& str = *castString(input.getObject(-1)); - if (str.value.length() == 0) { + if (str.value.empty()) { result->returnedValue.num = 0; return; } @@ -143,7 +143,7 @@ void systemCallCodeUnit2(const SystemCallInput& input, SystemCallResult* result) void systemCallCodeUnits(const SystemCallInput& input, SystemCallResult* result) { const auto& str = *castString(input.getObject(-1)); ValueListBuilder b{}; - size_t numCodeUnits = str.value.length(); + size_t const numCodeUnits = str.value.length(); for (size_t i = 0; i < numCodeUnits; i++) { b.items.push_back(Value{ static_cast(str.value.at(i)) }); } @@ -202,7 +202,7 @@ void systemCallInputString(const SystemCallInput& input, SystemCallResult* resul // (input as String) as Boolean void systemCallIsDigit(const SystemCallInput& input, SystemCallResult* result) { const auto& str = *castString(input.getObject(-1)); - result->returnedValue.setBoolean(str.value.length() >= 1 && std::isdigit(str.value.at(0))); + result->returnedValue.setBoolean(!str.value.empty() && std::isdigit(str.value.at(0))); } // () as String @@ -241,7 +241,7 @@ void systemCallStringFromCodePoints(const SystemCallInput& input, SystemCallResu } // Convert the UTF-8 array to a std::string_view. - std::string_view sv{ reinterpret_cast(utf8.data()), static_cast(length) }; + std::string_view const sv{ reinterpret_cast(utf8.data()), static_cast(length) }; ss << sv; } @@ -306,7 +306,7 @@ void systemCallStringReplace(const SystemCallInput& input, SystemCallResult* res const auto& needle = *castString(input.getObject(-2)); const auto& replacement = *castString(input.getObject(-1)); - if (needle.value.length() == 0) { + if (needle.value.empty()) { throw Error(ErrorCode::kInvalidArgument, "Needle cannot be empty."); } @@ -326,7 +326,7 @@ void systemCallStringSplit(const SystemCallInput& input, SystemCallResult* resul const auto& str = *castString(input.getObject(-2)); const auto& separator = *castString(input.getObject(-1)); - if (separator.value.length() == 0) { + if (separator.value.empty()) { throw Error(ErrorCode::kInvalidArgument, "Separator cannot be empty."); }