|
|
|||
File indexing completed on 2026-05-10 08:36:22
0001 //===--- BracesAroundStatement.h - clang-tidy ------- -----------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// 0009 /// \file 0010 /// This file provides utilities to put braces around a statement. 0011 /// 0012 //===----------------------------------------------------------------------===// 0013 0014 #include "clang/AST/Stmt.h" 0015 #include "clang/Basic/Diagnostic.h" 0016 #include "clang/Basic/SourceLocation.h" 0017 #include "clang/Basic/SourceManager.h" 0018 0019 namespace clang::tidy::utils { 0020 0021 /// A provider of fix-it hints to insert opening and closing braces. An instance 0022 /// of this type is the result of calling `getBraceInsertionsHints` below. 0023 struct BraceInsertionHints { 0024 /// The position of a potential diagnostic. It coincides with the position of 0025 /// the opening brace to insert, but can also just be the place to show a 0026 /// diagnostic in case braces cannot be inserted automatically. 0027 SourceLocation DiagnosticPos; 0028 0029 /// Constructor for a no-hint. 0030 BraceInsertionHints() = default; 0031 0032 /// Constructor for a valid hint that cannot insert braces automatically. 0033 BraceInsertionHints(SourceLocation DiagnosticPos) 0034 : DiagnosticPos(DiagnosticPos) {} 0035 0036 /// Constructor for a hint offering fix-its for brace insertion. Both 0037 /// positions must be valid. 0038 BraceInsertionHints(SourceLocation OpeningBracePos, 0039 SourceLocation ClosingBracePos, std::string ClosingBrace) 0040 : DiagnosticPos(OpeningBracePos), OpeningBracePos(OpeningBracePos), 0041 ClosingBracePos(ClosingBracePos), ClosingBrace(ClosingBrace) { 0042 assert(offersFixIts()); 0043 } 0044 0045 /// Indicates whether the hint provides at least the position of a diagnostic. 0046 operator bool() const; 0047 0048 /// Indicates whether the hint provides fix-its to insert braces. 0049 bool offersFixIts() const; 0050 0051 /// The number of lines between the inserted opening brace and its closing 0052 /// counterpart. 0053 unsigned resultingCompoundLineExtent(const SourceManager &SourceMgr) const; 0054 0055 /// Fix-it to insert an opening brace. 0056 FixItHint openingBraceFixIt() const; 0057 0058 /// Fix-it to insert a closing brace. 0059 FixItHint closingBraceFixIt() const; 0060 0061 private: 0062 SourceLocation OpeningBracePos; 0063 SourceLocation ClosingBracePos; 0064 std::string ClosingBrace; 0065 }; 0066 0067 /// Create fix-it hints for braces that wrap the given statement when applied. 0068 /// The algorithm computing them respects comment before and after the statement 0069 /// and adds line breaks before the braces accordingly. 0070 BraceInsertionHints 0071 getBraceInsertionsHints(const Stmt *const S, const LangOptions &LangOpts, 0072 const SourceManager &SM, SourceLocation StartLoc, 0073 SourceLocation EndLocHint = SourceLocation()); 0074 0075 } // namespace clang::tidy::utils
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|