clang-refactor中的'-selection'参数解析

clang/include/clang/Frontend/CommandLineSourceLoc.h

这个文件用于处理格式为file:start_line:start_column[-end_line:end_column]的选项:

  1. 定义了struct ParsedSourceLocation,它表示已在命令行上解析的一个源位置(source location)。它定义了一个函数FromString(StringRef Str),用于从一个字符串构造一个ParsedSourceLocation
  2. 定义了struct ParsedSourceRange,它表示已在命令行上解析的一个源范围(source range)。它定义一个函数fromString(StringRef Str),用于从一个字符串返回一个ParsedSourceRange
  3. 定义了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>的选项:

  1. 声明了struct TestSelectionRange,它表示当参数指定为-selection=test:<filename>时的一个源代码选择范围;
  2. 声明了struct TestSelectionRangesInFile,它表示在一个文件中指定的一组分组的源代码选择范围;
  3. 声明了一个函数findTestSelectionRanges(StringRef Filename),在给定文件(Filename)中返回一组分组的源代码选择范围(TestSelectionRangesInFile)。

clang/tools/clang-refactor/ClangRefactor.cpp

  1. 定义了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。
  2. 定义了TestSourceSelectionArgument,继承自SourceSelectionArgument,存储已解析的-selection=test:<filename>选项。
    • 添加了内部成员:TestSelectionRangesInFile TestSelections;
    • 重载了printcreateCustomConsumerforAllRanges方法
    • Consumer 类型为TestRefactoringResultConsumer,在clang/tools/clang-refactor/TestSupport.cpp中定义
  3. 定义了SourceRangeSelectionArgument,继承自SourceSelectionArgument,存储已解析的-selection=filename:line:column[-line:column]选项。
    • 添加了内部成员:ParsedSourceRange Range;
    • 重载了forAllRanges方法
  4. 实现了SourceSelectionArgument::fromString(StringRef Value)方法:
    Value-selection=之后的字符串,根据不同的格式进行解析,返回对应的子类。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值