Files
carbon-lang/migrate_cpp/cpp_refactoring/BUILD
T
Jon Meow 6fa42a7f3c For-range in replacement logic (#631)
This replaces GetAstMatcher with AddMatcher because cxxForRangeStmt is a StatementMatcher. addMatcher has multiple definitions (https://clang.llvm.org/doxygen/classclang_1_1ast__matchers_1_1MatchFinder.html) and so this approach allows using the right addMatcher without writing per-call overloads.

To handle the `var`, I'm considering something like moving VarDecl logic into a VarMatcherBase so that I can just use CXXForRangeStmt's getLoopVariable. The problem is a for-range statement has multiple VarDecls, and getLoopVariable may be the easiest way to identify the real one.
2021-07-12 16:20:44 -07:00

101 lines
2.1 KiB
Python

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
package(default_visibility = ["//visibility:public"])
cc_binary(
name = "cpp_refactoring",
srcs = ["main.cpp"],
deps = [
":fn_inserter",
":for_range",
":var_decl",
"@llvm-project//clang:tooling",
],
)
cc_library(
name = "matcher",
srcs = ["matcher.cpp"],
hdrs = [
"matcher.h",
"matcher_manager.h",
],
deps = [
"@llvm-project//clang:ast_matchers",
"@llvm-project//clang:tooling_core",
],
)
cc_library(
name = "matcher_test_base",
testonly = 1,
hdrs = ["matcher_test_base.h"],
deps = [
":matcher",
"@llvm-project//clang:ast_matchers",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:gmock",
"@llvm-project//llvm:gtest",
],
)
# Individual matchers
cc_library(
name = "fn_inserter",
srcs = ["fn_inserter.cpp"],
hdrs = ["fn_inserter.h"],
deps = [":matcher"],
)
cc_test(
name = "fn_inserter_test",
srcs = ["fn_inserter_test.cpp"],
deps = [
":fn_inserter",
":matcher_test_base",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:gtest_main",
],
)
cc_library(
name = "for_range",
srcs = ["for_range.cpp"],
hdrs = ["for_range.h"],
deps = [":matcher"],
)
cc_test(
name = "for_range_test",
srcs = ["for_range_test.cpp"],
deps = [
":for_range",
":matcher_test_base",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:gtest_main",
],
)
cc_library(
name = "var_decl",
srcs = ["var_decl.cpp"],
hdrs = ["var_decl.h"],
deps = [":matcher"],
)
cc_test(
name = "var_decl_test",
srcs = ["var_decl_test.cpp"],
deps = [
":matcher_test_base",
":var_decl",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:gtest_main",
],
)