/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include "clang/AST/Comment.h" #include "plugin.hxx" // Remove dynamic exception specifications. See the mail thread starting at // // "Dynamic Exception Specifications" for details. namespace { bool isOverriding(FunctionDecl const * decl) { if (decl->hasAttr()) { return true; } auto m = dyn_cast(decl); return m != nullptr && m->begin_overridden_methods() != m->end_overridden_methods(); } bool isDtorOrDealloc(FunctionDecl const * decl) { if (isa(decl)) { return true; } switch (decl->getOverloadedOperator()) { case OO_Delete: case OO_Array_Delete: return true; default: return false; } } class DynExcSpec: public RecursiveASTVisitor, public loplugin::RewritePlugin { public: explicit DynExcSpec(loplugin::InstantiationData const & data): RewritePlugin(data) {} void run() override { if (compiler.getLangOpts().CPlusPlus) { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } } bool VisitFunctionDecl(FunctionDecl const * decl) { if (ignoreLocation(decl)) { return true; } auto proto = decl->getType()->getAs(); if (proto == nullptr || proto->getExceptionSpecType() != EST_Dynamic) { return true; } if (decl->isCanonicalDecl() && !isOverriding(decl) && !anyRedeclHasThrowsDocumentation(decl)) { report( DiagnosticsEngine::Warning, ("function declaration has dynamic exception specification but" " no corresponding documentation comment"), decl->getLocation()) << decl->getSourceRange(); } if (rewriter != nullptr) { if (!(decl->isDefined() || decl->isPure())) { return true; } if (auto m = dyn_cast(decl)) { for (auto i = m->begin_overridden_methods(); i != m->end_overridden_methods(); ++i) { auto proto2 = (*i)->getType()->getAs(); assert(proto2 != nullptr); if (proto2->getExceptionSpecType() == EST_Dynamic) { return true; } } } } bool dtorOrDealloc = isDtorOrDealloc(decl); SourceRange source; #if CLANG_VERSION >= 40000 source = decl->getExceptionSpecSourceRange(); #endif if (rewriter != nullptr && source.isValid()) { if (dtorOrDealloc) { if (replaceText(source, "noexcept(false)")) { return true; } } else { auto beg = source.getBegin(); if (beg.isFileID()) { for (;;) { auto prev = Lexer::GetBeginningOfToken( beg.getLocWithOffset(-1), compiler.getSourceManager(), compiler.getLangOpts()); auto n = Lexer::MeasureTokenLength( prev, compiler.getSourceManager(), compiler.getLangOpts()); auto s = StringRef( compiler.getSourceManager().getCharacterData(prev), n); while (s.startswith("\\\n")) { s = s.drop_front(2); while (!s.empty() && (s.front() == ' ' || s.front() == '\t' || s.front() == '\n' || s.front() == '\v' || s.front() == '\f')) { s = s.drop_front(1); } } if (!s.empty() && s != "\\") { if (s.startswith("//")) { beg = source.getBegin(); } break; } beg = prev; } } if (removeText(SourceRange(beg, source.getEnd()))) { return true; } } } report( DiagnosticsEngine::Warning, (dtorOrDealloc ? "replace dynamic exception specification with 'noexcept(false)'" : "remove dynamic exception specification"), source.isValid() ? source.getBegin() : decl->getLocation()) << (source.isValid() ? source : decl->getSourceRange()); return true; } private: bool hasThrowsDocumentation(FunctionDecl const * decl) { if (auto cmt = compiler.getASTContext().getCommentForDecl( decl, &compiler.getPreprocessor())) { for (auto i = cmt->child_begin(); i != cmt->child_end(); ++i) { if (auto bcc = dyn_cast(*i)) { if (compiler.getASTContext().getCommentCommandTraits() .getCommandInfo(bcc->getCommandID())->IsThrowsCommand) { return true; } } } } return false; } bool anyRedeclHasThrowsDocumentation(FunctionDecl const * decl) { return std::any_of( decl->redecls_begin(), decl->redecls_end(), [this](FunctionDecl * d) { return hasThrowsDocumentation(d); }); // std::bind( // &DynExcSpec::hasThrowsDocumentation, this, // std::placeholders::_1)); } }; loplugin::Plugin::Registration X("dynexcspec", true); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2024-05-11loplugin:ostr in svxNoel Grandin
2024-02-18ITEM: Rename for more control over SlotID usagesArmin Le Grand (allotropia)
2023-12-30tdf#146619 Recheck svx/ with IWYUGabor Kelemen
2023-10-02tdf#146619 Recheck include/s* with IWYUGabor Kelemen
2023-09-24tdf#157067: Fix missing background color in style previewKhaled Hosny
2023-04-25svx: rework the theme dialog to allow editing theme colorsTomaž Vajngerl
2023-03-16tdf#153704: Make sure the last script segment is also addedKhaled Hosny
2023-03-01create a default theme when SdrPage and SdrModel are createdTomaž Vajngerl
2023-01-27move Theme class to own file inside docmodelTomaž Vajngerl
2023-01-27move ColorSet class to own file inside docmodelTomaž Vajngerl
2023-01-27use ThemeColorChanger also in svx, when changing theme for SdrPageTomaž Vajngerl
2023-01-15Typo in "code"Andrea Gelmini
2023-01-14svx: add UX defined theme color setsTomaž Vajngerl
2023-01-14svx: add resolveColor that resolves the color for input themeTomaž Vajngerl
2023-01-14svx: change ColorSet add method to use ThemeColorTyp enumTomaž Vajngerl
2023-01-13introduce {Char,Fill}ColorThemeReference which uses XThemeColorTomaž Vajngerl
2023-01-12introduce docmodel comp., model::ThemeColor, use it in SvxColorItemTomaž Vajngerl
2023-01-05sw: add the ColorSet from SdrPage into ColorSets in ThemePanelTomaž Vajngerl
2022-12-30tdf#152737: Fix off-by-one errorsKhaled Hosny
2022-12-26svx: use array for colors in ColorSet, add consts, rename varsTomaž Vajngerl
2022-12-26svx: rename ThemeColorType enum values, use enum instead of indexTomaž Vajngerl
2022-12-16tdf#152460: Improve script handling in style previewsKhaled Hosny
2022-11-12cid#1516789 Division or modulo by float zeroCaolán McNamara
2022-10-01tdf#151114: Improve styles preview alignmentKhaled Hosny
2022-09-24tdf#151114: Fix swapped width and heightKhaled Hosny
2022-08-24cid#1510131 Uninitialized scalar fieldCaolán McNamara
2022-08-22tdf#87535: Preview styles using CTL/CJK fonts in the sidebarKhaled Hosny
2022-07-21clang-tidy modernize-pass-by-value in svxNoel Grandin
2022-06-20sd theme: consider accent1 color when inserting shape with solid fillMiklos Vajna
2022-06-05no need to allocate this separatelyNoel Grandin
2022-06-04tdf#149304 Stylist does not show upper/lower case font effectsNoel Grandin
2022-05-03Just use Any ctor instead of makeAny in svxStephan Bergmann
2022-04-22sd theme: add rendering for shape fill color effectsMiklos Vajna
2022-03-11loplugin:constparamsNoel Grandin
2022-03-03Recheck modules sv* with IWYUGabor Kelemen
2022-03-03sd theme: add rendering for shape fill colorMiklos Vajna
2022-01-10sd theme: fix applying new colors after theme change for group shapesMiklos Vajna