BUILD 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
  5. load("//bazel/sh_run:rules.bzl", "glob_sh_run")
  6. load("//testing/fuzzing:rules.bzl", "cc_fuzz_test")
  7. package(default_visibility = ["//visibility:public"])
  8. filegroup(
  9. name = "testdata",
  10. data = glob(["testdata/**/*.carbon"]),
  11. )
  12. cc_library(
  13. name = "node_kind",
  14. srcs = ["node_kind.cpp"],
  15. hdrs = [
  16. "node_ids.h",
  17. "node_kind.h",
  18. "typed_nodes.h",
  19. ],
  20. textual_hdrs = ["node_kind.def"],
  21. deps = [
  22. "//common:check",
  23. "//common:enum_base",
  24. "//toolchain/base:index_base",
  25. "//toolchain/lex:token_kind",
  26. "@llvm-project//llvm:Support",
  27. ],
  28. )
  29. cc_test(
  30. name = "typed_nodes_test",
  31. size = "small",
  32. srcs = ["typed_nodes_test.cpp"],
  33. deps = [
  34. ":node_kind",
  35. ":parse",
  36. ":tree",
  37. "//testing/base:gtest_main",
  38. "//toolchain/diagnostics:diagnostic_emitter",
  39. "//toolchain/diagnostics:mocks",
  40. "//toolchain/lex",
  41. "//toolchain/lex:tokenized_buffer",
  42. "@com_google_googletest//:gtest",
  43. ],
  44. )
  45. cc_library(
  46. name = "context",
  47. srcs = ["context.cpp"],
  48. hdrs = ["context.h"],
  49. deps = [
  50. ":node_kind",
  51. ":precedence",
  52. ":state",
  53. ":tree",
  54. "//common:check",
  55. "//common:ostream",
  56. "//common:vlog",
  57. "//toolchain/lex:token_kind",
  58. "//toolchain/lex:tokenized_buffer",
  59. "@llvm-project//llvm:Support",
  60. ],
  61. )
  62. cc_library(
  63. name = "parse",
  64. srcs = ["parse.cpp"] +
  65. # Glob handler files to avoid missing any.
  66. glob([
  67. "handle_*.cpp",
  68. ]),
  69. hdrs = ["parse.h"],
  70. deps = [
  71. ":context",
  72. ":node_kind",
  73. ":state",
  74. ":tree",
  75. "//common:check",
  76. "//common:ostream",
  77. "//toolchain/base:pretty_stack_trace_function",
  78. "//toolchain/base:value_store",
  79. "//toolchain/diagnostics:diagnostic_emitter",
  80. "//toolchain/lex:token_kind",
  81. "//toolchain/lex:tokenized_buffer",
  82. ],
  83. )
  84. cc_library(
  85. name = "state",
  86. srcs = ["state.cpp"],
  87. hdrs = ["state.h"],
  88. textual_hdrs = ["state.def"],
  89. deps = ["//common:enum_base"],
  90. )
  91. cc_library(
  92. name = "tree",
  93. srcs = [
  94. "extract.cpp",
  95. "tree.cpp",
  96. ],
  97. hdrs = ["tree.h"],
  98. deps = [
  99. ":node_kind",
  100. "//common:check",
  101. "//common:error",
  102. "//common:ostream",
  103. "//common:struct_reflection",
  104. "//toolchain/base:pretty_stack_trace_function",
  105. "//toolchain/diagnostics:diagnostic_emitter",
  106. "//toolchain/lex:tokenized_buffer",
  107. "@llvm-project//llvm:Support",
  108. ],
  109. )
  110. cc_test(
  111. name = "tree_test",
  112. size = "small",
  113. srcs = ["tree_test.cpp"],
  114. deps = [
  115. ":node_kind",
  116. ":parse",
  117. ":tree",
  118. "//common:ostream",
  119. "//testing/base:gtest_main",
  120. "//testing/base:test_raw_ostream",
  121. "//toolchain/base:value_store",
  122. "//toolchain/diagnostics:diagnostic_emitter",
  123. "//toolchain/diagnostics:mocks",
  124. "//toolchain/lex",
  125. "//toolchain/lex:tokenized_buffer",
  126. "//toolchain/testing:yaml_test_helpers",
  127. "@com_google_googletest//:gtest",
  128. "@llvm-project//llvm:Support",
  129. ],
  130. )
  131. cc_fuzz_test(
  132. name = "parse_fuzzer",
  133. size = "small",
  134. srcs = ["parse_fuzzer.cpp"],
  135. corpus = glob(["fuzzer_corpus/*"]),
  136. deps = [
  137. ":parse",
  138. "//common:check",
  139. "//toolchain/base:value_store",
  140. "//toolchain/diagnostics:diagnostic_emitter",
  141. "//toolchain/diagnostics:null_diagnostics",
  142. "//toolchain/lex",
  143. "@llvm-project//llvm:Support",
  144. ],
  145. )
  146. cc_library(
  147. name = "tree_node_location_translator",
  148. hdrs = ["tree_node_location_translator.h"],
  149. deps = [
  150. ":tree",
  151. "//toolchain/diagnostics:diagnostic_emitter",
  152. "//toolchain/lex:tokenized_buffer",
  153. ],
  154. )
  155. cc_library(
  156. name = "precedence",
  157. srcs = ["precedence.cpp"],
  158. hdrs = ["precedence.h"],
  159. deps = [
  160. "//common:check",
  161. "//toolchain/lex:token_kind",
  162. "@llvm-project//llvm:Support",
  163. ],
  164. )
  165. cc_test(
  166. name = "precedence_test",
  167. size = "small",
  168. srcs = ["precedence_test.cpp"],
  169. deps = [
  170. ":precedence",
  171. "//testing/base:gtest_main",
  172. "//toolchain/lex:token_kind",
  173. "@com_google_googletest//:gtest",
  174. ],
  175. )
  176. glob_sh_run(
  177. args = [
  178. "$(location //toolchain/driver:carbon)",
  179. "compile",
  180. "--phase=parse",
  181. "--dump-parse-tree",
  182. ],
  183. data = ["//toolchain/driver:carbon"],
  184. file_exts = ["carbon"],
  185. )
  186. glob_sh_run(
  187. args = [
  188. "$(location //toolchain/driver:carbon)",
  189. "-v",
  190. "compile",
  191. "--phase=parse",
  192. ],
  193. data = ["//toolchain/driver:carbon"],
  194. file_exts = ["carbon"],
  195. run_ext = "verbose",
  196. )