Changeset View
Changeset View
Standalone View
Standalone View
clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
Show All 38 Lines | private: | ||||
bool isMainHeader(StringRef IncludeName) const; | bool isMainHeader(StringRef IncludeName) const; | ||||
const IncludeStyle Style; | const IncludeStyle Style; | ||||
bool IsMainFile; | bool IsMainFile; | ||||
std::string FileName; | std::string FileName; | ||||
SmallVector<llvm::Regex, 4> CategoryRegexs; | SmallVector<llvm::Regex, 4> CategoryRegexs; | ||||
}; | }; | ||||
/// Generates replacements for inserting or deleting #include directives in a | /// Generates replacements for inserting or deleting #include directives in a | ||||
kadircet: this will leak enum values to the whole `clang::tooling` namespace. can you make this an `enum… | |||||
/// file. | /// file. | ||||
class HeaderIncludes { | class HeaderIncludes { | ||||
public: | public: | ||||
HeaderIncludes(llvm::StringRef FileName, llvm::StringRef Code, | HeaderIncludes(llvm::StringRef FileName, llvm::StringRef Code, | ||||
const IncludeStyle &Style); | const IncludeStyle &Style); | ||||
/// Inserts an #include directive of \p Header into the code. If \p IsAngled | /// Inserts an #include or #import directive of \p Header into the code. | ||||
/// is true, \p Header will be quoted with <> in the directive; otherwise, it | /// If \p IsAngled is true, \p Header will be quoted with <> in the directive; | ||||
/// will be quoted with "". | /// otherwise, it will be quoted with "". | ||||
/// | /// | ||||
/// When searching for points to insert new header, this ignores #include's | /// When searching for points to insert new header, this ignores #include's | ||||
/// after the #include block(s) in the beginning of a file to avoid inserting | /// after the #include block(s) in the beginning of a file to avoid inserting | ||||
/// headers into code sections where new #include's should not be added by | /// headers into code sections where new #include's should not be added by | ||||
/// default. These code sections include: | /// default. These code sections include: | ||||
/// - raw string literals (containing #include). | /// - raw string literals (containing #include). | ||||
/// - #if blocks. | /// - #if blocks. | ||||
/// - Special #include's among declarations (e.g. functions). | /// - Special #include's among declarations (e.g. functions). | ||||
/// | /// | ||||
/// Returns a replacement that inserts the new header into a suitable #include | /// Returns a replacement that inserts the new header into a suitable #include | ||||
/// block of the same category. This respects the order of the existing | /// block of the same category. This respects the order of the existing | ||||
/// #includes in the block; if the existing #includes are not already sorted, | /// #includes in the block; if the existing #includes are not already sorted, | ||||
/// this will simply insert the #include in front of the first #include of the | /// this will simply insert the #include in front of the first #include of the | ||||
/// same category in the code that should be sorted after \p IncludeName. If | /// same category in the code that should be sorted after \p IncludeName. If | ||||
/// \p IncludeName already exists (with exactly the same spelling), this | /// \p IncludeName already exists (with exactly the same spelling), this | ||||
/// returns None. | /// returns None. | ||||
llvm::Optional<tooling::Replacement> insert(llvm::StringRef Header, | llvm::Optional<tooling::Replacement> | ||||
bool IsAngled) const; | insert(llvm::StringRef Header, bool IsAngled, bool IsImport = false) const; | ||||
rather than a boolean flag, can you introduce an enum IncludeDirective { Include, Import }; and default it to Include here? kadircet: rather than a boolean flag, can you introduce an `enum IncludeDirective { Include, Import };`… | |||||
i don't think we have many callers here. can we just update them instead of defaulting to Include here? kadircet: i don't think we have many callers here. can we just update them instead of defaulting to… | |||||
/// Removes all existing #includes of \p Header quoted with <> if \p IsAngled | /// Removes all existing #includes of \p Header quoted with <> if \p IsAngled | ||||
s/#includes/#includes and #imports/ kadircet: s/#includes/#includes and #imports/ | |||||
/// is true or "" if \p IsAngled is false. | /// is true or "" if \p IsAngled is false. | ||||
/// This doesn't resolve the header file path; it only deletes #includes with | /// This doesn't resolve the header file path; it only deletes #includes and | ||||
/// exactly the same spelling. | /// #imports with exactly the same spelling. | ||||
tooling::Replacements remove(llvm::StringRef Header, bool IsAngled) const; | tooling::Replacements remove(llvm::StringRef Header, bool IsAngled) const; | ||||
// Matches a whole #include directive. | // Matches a whole #include directive. | ||||
static const llvm::Regex IncludeRegex; | static const llvm::Regex IncludeRegex; | ||||
private: | private: | ||||
struct Include { | struct Include { | ||||
we also need to preserve includedirective here now. as the behaviour of insert is to return none iff it's exactly the same spelling. so if there's a #include "foo.h" and we want to insert #import "foo.h" it shouldn't fail. kadircet: we also need to preserve includedirective here now. as the behaviour of `insert` is to return… | |||||
Include(StringRef Name, tooling::Range R) : Name(Name), R(R) {} | Include(StringRef Name, tooling::Range R) : Name(Name), R(R) {} | ||||
// An include header quoted with either <> or "". | // An include header quoted with either <> or "". | ||||
std::string Name; | std::string Name; | ||||
// The range of the whole line of include directive including any leading | // The range of the whole line of include directive including any leading | ||||
// whitespaces and trailing comment. | // whitespaces and trailing comment. | ||||
tooling::Range R; | tooling::Range R; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
this will leak enum values to the whole clang::tooling namespace. can you make this an enum class IncludeDirective instead (sorry for forgetting that in the initial comment)