From 26872220ccda70ec844e63bb792294bf3549319f Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 22 Sep 2025 22:41:33 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=AD=D1=82=D0=B0=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B0=20=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B1=D0=BE=D0=B9=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B0=20Clang.=20=D0=95=D0=B5=20=D0=BE=D1=81?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BD=D0=B0=D1=8F=20=D0=B7=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=20=E2=80=94=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D1=82=D1=8C=20=D0=B0=D1=82=D1=80=D0=B8?= =?UTF-8?q?=D0=B1=D1=83=D1=82=20[[maybe=5Funused]]=20=D0=BA=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=D0=BC=20unused=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BC=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B8=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=BC=20=D0=B2=20=D0=BA=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clang/tools/clang-format-vs/ClangFormat.sln | 12 +- .../ClangFormat/ClangFormat.csproj | 18 +- .../ClangFormat/Resources.Designer.cs | 26 +- .../clang-format-vs/IvashchukVA_n_ast.cpp | 108 +++++++ clang/tools/clang-format-vs/UpgradeLog.htm | 273 ++++++++++++++++++ 5 files changed, 419 insertions(+), 18 deletions(-) create mode 100644 clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp create mode 100644 clang/tools/clang-format-vs/UpgradeLog.htm diff --git a/clang/tools/clang-format-vs/ClangFormat.sln b/clang/tools/clang-format-vs/ClangFormat.sln index 46d742bce3f0b..b2e25f92a2f25 100644 --- a/clang/tools/clang-format-vs/ClangFormat.sln +++ b/clang/tools/clang-format-vs/ClangFormat.sln @@ -1,10 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.12 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 d17.13 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClangFormat", "ClangFormat\ClangFormat.csproj", "{7FD1783E-2D31-4D05-BF23-6EBE1B42B608}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{754FC069-D67B-A9D7-50A1-8D1CA196D8F1}" + ProjectSection(SolutionItems) = preProject + IvashchukVA_n_ast.cpp = IvashchukVA_n_ast.cpp + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,4 +24,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {08B1E269-8481-4341-AAE4-42A6FD7FCD7D} + EndGlobalSection EndGlobal diff --git a/clang/tools/clang-format-vs/ClangFormat/ClangFormat.csproj b/clang/tools/clang-format-vs/ClangFormat/ClangFormat.csproj index e5b7ec008a1ac..07d8e62553973 100644 --- a/clang/tools/clang-format-vs/ClangFormat/ClangFormat.csproj +++ b/clang/tools/clang-format-vs/ClangFormat/ClangFormat.csproj @@ -1,5 +1,5 @@  - + Debug @@ -13,7 +13,7 @@ ClangFormat true Key.snk - v4.0 + v4.8 15.0 @@ -245,6 +245,18 @@ 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + false + + + false + + + false + + + false + @@ -258,4 +270,4 @@ --> - + \ No newline at end of file diff --git a/clang/tools/clang-format-vs/ClangFormat/Resources.Designer.cs b/clang/tools/clang-format-vs/ClangFormat/Resources.Designer.cs index e3129b3db83ae..3239cae022a71 100644 --- a/clang/tools/clang-format-vs/ClangFormat/Resources.Designer.cs +++ b/clang/tools/clang-format-vs/ClangFormat/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. // //------------------------------------------------------------------------------ @@ -13,13 +13,13 @@ namespace LLVM.ClangFormat { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -33,7 +33,7 @@ internal Resources() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp b/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp new file mode 100644 index 0000000000000..b9398c78fc133 --- /dev/null +++ b/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp @@ -0,0 +1,108 @@ +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/Attr.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendPluginRegistry.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; + +namespace { +class MaybeUnusedVisitor final + : public clang::RecursiveASTVisitor { +public: + explicit MaybeUnusedVisitor(clang::ASTContext *context, Rewriter &Rewrite) + : m_context(context), TheRewriter(Rewrite) {} + + bool VisitFunctionDecl(FunctionDecl *FunctionDeclaration) { + if (!FunctionDeclaration->hasBody() || FunctionDeclaration->isImplicit()) + return true; + + for (unsigned i = 0, NumParams = FunctionDeclaration->getNumParams(); + i < NumParams; ++i) { + ParmVarDecl *ParamDecl = FunctionDeclaration->getParamDecl(i); + if (ParamDecl && ParamDecl->getName() == "unused" && + !ParamDecl->hasAttr()) { + SourceLocation Loc = ParamDecl->getBeginLoc(); + if (Loc.isValid()) + TheRewriter.InsertText(Loc, "[[maybe_unused]] ", true); + } + } + + Stmt *FunctionBody = FunctionDeclaration->getBody(); + if (FunctionBody) + processLocalVars(FunctionBody); + + return true; + } + +private: + void processLocalVars(Stmt *Statement) { + if (!Statement) + return; + + if (auto *DeclStatement = dyn_cast(Statement)) { + for (auto *Declaration : DeclStatement->decls()) { + if (auto *VarDecl = dyn_cast(Declaration)) { + if (VarDecl->isLocalVarDecl() && !VarDecl->isImplicit() && + VarDecl->getName() == "unused" && + !VarDecl->hasAttr()) { + SourceLocation Loc = VarDecl->getBeginLoc(); + if (Loc.isValid()) + TheRewriter.InsertText(Loc, "[[maybe_unused]] ", true); + } + } + } + } else { + for (Stmt *ChildStatement : Statement->children()) { + processLocalVars(ChildStatement); + } + } + } + + clang::ASTContext *m_context; + clang::Rewriter &TheRewriter; +}; + +class MaybeUnusedConsumer final : public clang::ASTConsumer { +public: + explicit MaybeUnusedConsumer(clang::ASTContext *context, Rewriter &Rewrite) + : Visitor(context, Rewrite) {} + + void HandleTranslationUnit(clang::ASTContext &Context) override { + Visitor.TraverseDecl(Context.getTranslationUnitDecl()); + } + +private: + MaybeUnusedVisitor Visitor; +}; + +class MaybeUnusedAction final : public clang::PluginASTAction { +public: + std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef) override { + TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); + return std::make_unique(&CI.getASTContext(), + TheRewriter); + } + + bool ParseArgs(const clang::CompilerInstance &CI, + const std::vector &Args) override { + return true; + } + + void EndSourceFileAction() override { + auto &SM = TheRewriter.getSourceMgr(); + TheRewriter.getEditBuffer(SM.getMainFileID()).write(llvm::outs()); + } + +private: + Rewriter TheRewriter; +}; + +} // namespace + +static clang::FrontendPluginRegistry::Add + X("IvashchukVA_n_ast", + "Marks unused parameters/variables with [[maybe_unused]] attribute"); \ No newline at end of file diff --git a/clang/tools/clang-format-vs/UpgradeLog.htm b/clang/tools/clang-format-vs/UpgradeLog.htm new file mode 100644 index 0000000000000..72d60595c45a7 --- /dev/null +++ b/clang/tools/clang-format-vs/UpgradeLog.htm @@ -0,0 +1,273 @@ + + + + Отчет о переносе +

+ Отчет о миграции -

\ No newline at end of file From 84f62708ccf45f38a4931b8a226ce1bf7d0acd00 Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 22 Sep 2025 23:00:24 +0300 Subject: [PATCH 2/3] IvashchukVA lab1 var2 --- clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp b/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp index b9398c78fc133..b97f49e6965ba 100644 --- a/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp +++ b/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp @@ -104,5 +104,5 @@ class MaybeUnusedAction final : public clang::PluginASTAction { } // namespace static clang::FrontendPluginRegistry::Add - X("IvashchukVA_n_ast", + X("IvashchukVA_ast", "Marks unused parameters/variables with [[maybe_unused]] attribute"); \ No newline at end of file From 0b9bdb94e4530b7ce97d0c4dffd064b2d4429f8e Mon Sep 17 00:00:00 2001 From: Vadim Date: Tue, 23 Sep 2025 23:39:37 +0300 Subject: [PATCH 3/3] retest code --- .../clang-format-vs/IvashchukVA_n_ast.cpp | 103 ++++++++++-------- 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp b/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp index b97f49e6965ba..9bd9d182be5d9 100644 --- a/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp +++ b/clang/tools/clang-format-vs/IvashchukVA_n_ast.cpp @@ -9,68 +9,75 @@ using namespace clang; namespace { -class MaybeUnusedVisitor final - : public clang::RecursiveASTVisitor { + +class MaybeUnusedVisitor final : public RecursiveASTVisitor < +MaybeUnusedVisitor & gt; +{ public: - explicit MaybeUnusedVisitor(clang::ASTContext *context, Rewriter &Rewrite) - : m_context(context), TheRewriter(Rewrite) {} + explicit MaybeUnusedVisitor(ASTContext * Context, Rewriter & amp; R) + : Context(Context), TheRewriter(R) {} - bool VisitFunctionDecl(FunctionDecl *FunctionDeclaration) { - if (!FunctionDeclaration->hasBody() || FunctionDeclaration->isImplicit()) + bool VisitFunctionDecl(FunctionDecl * FuncDecl) { + if (!FuncDecl - > hasBody() || FuncDecl - > isImplicit()) return true; - for (unsigned i = 0, NumParams = FunctionDeclaration->getNumParams(); - i < NumParams; ++i) { - ParmVarDecl *ParamDecl = FunctionDeclaration->getParamDecl(i); - if (ParamDecl && ParamDecl->getName() == "unused" && - !ParamDecl->hasAttr()) { - SourceLocation Loc = ParamDecl->getBeginLoc(); - if (Loc.isValid()) - TheRewriter.InsertText(Loc, "[[maybe_unused]] ", true); + for (unsigned i = 0, e = FuncDecl - > getNumParams(); i & lt; e; ++i) { + ParmVarDecl *Param = FuncDecl - > + getParamDecl(i); + if (Param & amp; & Param - > getName() == "unused" & amp; & + !Param - > hasAttr & lt; UnusedAttr & gt; ()) { + const SourceLocation Loc = Param - > + getBeginLoc(); + if (Loc.isValid()) { + TheRewriter.InsertText(Loc, "[[maybe_unused]] ", + /*InsertBefore=*/true); + } } } - Stmt *FunctionBody = FunctionDeclaration->getBody(); - if (FunctionBody) - processLocalVars(FunctionBody); + if (Stmt *Body = FuncDecl - > getBody()) + ProcessLocalVariables(Body); return true; } private: - void processLocalVars(Stmt *Statement) { - if (!Statement) + void ProcessLocalVariables(Stmt * S) { + if (!S) return; - if (auto *DeclStatement = dyn_cast(Statement)) { - for (auto *Declaration : DeclStatement->decls()) { - if (auto *VarDecl = dyn_cast(Declaration)) { - if (VarDecl->isLocalVarDecl() && !VarDecl->isImplicit() && - VarDecl->getName() == "unused" && - !VarDecl->hasAttr()) { - SourceLocation Loc = VarDecl->getBeginLoc(); + if (auto *DS = dyn_cast & lt; DeclStmt & gt; (S)) { + for (auto *D : DS - > decls()) { + if (auto *VD = dyn_cast & lt; VarDecl & gt; (D)) { + if (VD - > isLocalVarDecl() & amp; & !VD - > + isImplicit() & amp; & VD - > getName() == "unused" & amp; + & !VD - > hasAttr & lt; UnusedAttr & gt; ()) { + const SourceLocation Loc = VD - > + getBeginLoc(); if (Loc.isValid()) - TheRewriter.InsertText(Loc, "[[maybe_unused]] ", true); + TheRewriter.InsertText(Loc, "[[maybe_unused]] ", + /*InsertBefore=*/true); } } } } else { - for (Stmt *ChildStatement : Statement->children()) { - processLocalVars(ChildStatement); + for (Stmt *Child : S - > children()) { + ProcessLocalVariables(Child); } } } - clang::ASTContext *m_context; - clang::Rewriter &TheRewriter; + ASTContext *const Context; + Rewriter & amp; + TheRewriter; }; -class MaybeUnusedConsumer final : public clang::ASTConsumer { +class MaybeUnusedConsumer : public ASTConsumer { public: - explicit MaybeUnusedConsumer(clang::ASTContext *context, Rewriter &Rewrite) - : Visitor(context, Rewrite) {} + explicit MaybeUnusedConsumer(ASTContext *Context, Rewriter & Rewrite) + : Visitor(Context, Rewrite) {} - void HandleTranslationUnit(clang::ASTContext &Context) override { + void HandleTranslationUnit(ASTContext & Context) override { Visitor.TraverseDecl(Context.getTranslationUnitDecl()); } @@ -78,22 +85,25 @@ class MaybeUnusedConsumer final : public clang::ASTConsumer { MaybeUnusedVisitor Visitor; }; -class MaybeUnusedAction final : public clang::PluginASTAction { +class MaybeUnusedAction : public PluginASTAction { public: - std::unique_ptr - CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef) override { + std::unique_ptr < + ASTConsumer > + CreateASTConsumer(CompilerInstance & CI, llvm::StringRef) override { TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); - return std::make_unique(&CI.getASTContext(), - TheRewriter); + return std::make_unique & lt; + MaybeUnusedConsumer & gt; + (& CI.getASTContext(), TheRewriter); } - bool ParseArgs(const clang::CompilerInstance &CI, - const std::vector &Args) override { + bool ParseArgs(const CompilerInstance & CI, const std::vector < + std::string & gt; & Args) override { return true; } void EndSourceFileAction() override { - auto &SM = TheRewriter.getSourceMgr(); + const auto & + SM = TheRewriter.getSourceMgr(); TheRewriter.getEditBuffer(SM.getMainFileID()).write(llvm::outs()); } @@ -103,6 +113,7 @@ class MaybeUnusedAction final : public clang::PluginASTAction { } // namespace -static clang::FrontendPluginRegistry::Add - X("IvashchukVA_ast", - "Marks unused parameters/variables with [[maybe_unused]] attribute"); \ No newline at end of file +static FrontendPluginRegistry::Add < +MaybeUnusedAction & gt; +X("IvashchukVA_lab1_2var", + "Marks unused parameters/variables with [[maybe_unused]] attribute"); \ No newline at end of file