clang-refactor中的'-selection'参数解析
clang/include/clang/Frontend/CommandLineSourceLoc.h
这个文件用于处理格式为file:start_line:start_column[-end_line:end_column]
的选项:
- 定义了
struct ParsedSourceLocation
,它表示已在命令行上解析的一个源位置(source location)。它定义了一个函数FromString(StringRef Str)
,用于从一个字符串构造一个ParsedSourceLocation
; - 定义了
struct ParsedSourceRange
,它表示已在命令行上解析的一个源范围(source range)。它定义一个函数fromString(StringRef Str)
,用于从一个字符串返回一个ParsedSourceRange
; - 定义了
class parser<clang::ParsedSourceLocation>
,它定义了一个函数parse(Option &O, StringRef ArgName, StringRef ArgValue, clang::ParsedSourceLocation &Val)
,可以解析ArgValue
(格式为filename:line:column
)为Val
。
clang/tools/clang-refactor/TestSupport.h
这个文件用于处理格式为test:<filename>
的选项:
- 声明了
struct TestSelectionRange
,它表示当参数指定为-selection=test:<filename>
时的一个源代码选择范围; - 声明了
struct TestSelectionRangesInFile
,它表示在一个文件中指定的一组分组的源代码选择范围; - 声明了一个函数
findTestSelectionRanges(StringRef Filename)
,在给定文件(Filename
)中返回一组分组的源代码选择范围(TestSelectionRangesInFile
)。
clang/tools/clang-refactor/ClangRefactor.cpp
- 定义了
SourceSelectionArgument
,它是个基类,存储已解析的-selection
参数。内部成员函数简介:static std::unique_ptr<SourceSelectionArgument> fromString(StringRef Value);
解析-selection
参数:当解析成功时返回一个SourceSelectionArgument
的子类,否则返回null。virtual void print(raw_ostream &OS);
将与-selection
参数关联的任何附加状态打印到给定的输出流。virtual std::unique_ptr<ClangRefactorToolConsumerInterface> createCustomConsumer();
返回一个RefactoringResultConsumer(如果有的话),它应该consume一个重构操作的结果。virtual bool forAllRanges(const SourceManager &SM, llvm::function_ref<void(SourceRange R)> Callback) = 0;
为每个指定的-selection
参数运行给定的重构函数(Callback
)。如果发生了错误,返回true,否则返回false。
- 定义了
TestSourceSelectionArgument
,继承自SourceSelectionArgument
,存储已解析的-selection=test:<filename>
选项。- 添加了内部成员:
TestSelectionRangesInFile TestSelections;
- 重载了
print
、createCustomConsumer
、forAllRanges
方法 - Consumer 类型为
TestRefactoringResultConsumer
,在clang/tools/clang-refactor/TestSupport.cpp
中定义
- 添加了内部成员:
- 定义了
SourceRangeSelectionArgument
,继承自SourceSelectionArgument
,存储已解析的-selection=filename:line:column[-line:column]
选项。- 添加了内部成员:
ParsedSourceRange Range;
- 重载了
forAllRanges
方法
- 添加了内部成员:
- 实现了
SourceSelectionArgument::fromString(StringRef Value)
方法:
Value
是-selection=
之后的字符串,根据不同的格式进行解析,返回对应的子类。