BUILD 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. "@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/lex:tokenized_buffer",
  105. "@llvm-project//llvm:Support",
  106. ],
  107. )
  108. cc_test(
  109. name = "tree_test",
  110. size = "small",
  111. srcs = ["tree_test.cpp"],
  112. deps = [
  113. ":node_kind",
  114. ":parse",
  115. ":tree",
  116. "//common:ostream",
  117. "//testing/base:gtest_main",
  118. "//testing/base:test_raw_ostream",
  119. "//toolchain/base:value_store",
  120. "//toolchain/diagnostics:diagnostic_emitter",
  121. "//toolchain/diagnostics:mocks",
  122. "//toolchain/lex",
  123. "//toolchain/lex:tokenized_buffer",
  124. "//toolchain/testing:yaml_test_helpers",
  125. "@googletest//:gtest",
  126. "@llvm-project//llvm:Support",
  127. ],
  128. )
  129. cc_fuzz_test(
  130. name = "parse_fuzzer",
  131. size = "small",
  132. srcs = ["parse_fuzzer.cpp"],
  133. corpus = glob(["fuzzer_corpus/*"]),
  134. deps = [
  135. ":parse",
  136. "//common:check",
  137. "//toolchain/base:value_store",
  138. "//toolchain/diagnostics:diagnostic_emitter",
  139. "//toolchain/diagnostics:null_diagnostics",
  140. "//toolchain/lex",
  141. "@llvm-project//llvm:Support",
  142. ],
  143. )
  144. cc_library(
  145. name = "tree_node_diagnostic_converter",
  146. hdrs = ["tree_node_diagnostic_converter.h"],
  147. deps = [
  148. ":tree",
  149. "//toolchain/diagnostics:diagnostic_emitter",
  150. "//toolchain/lex:tokenized_buffer",
  151. ],
  152. )
  153. cc_library(
  154. name = "precedence",
  155. srcs = ["precedence.cpp"],
  156. hdrs = ["precedence.h"],
  157. deps = [
  158. "//common:check",
  159. "//toolchain/lex:token_kind",
  160. "@llvm-project//llvm:Support",
  161. ],
  162. )
  163. cc_test(
  164. name = "precedence_test",
  165. size = "small",
  166. srcs = ["precedence_test.cpp"],
  167. deps = [
  168. ":precedence",
  169. "//testing/base:gtest_main",
  170. "//toolchain/lex:token_kind",
  171. "@googletest//:gtest",
  172. ],
  173. )
  174. glob_sh_run(
  175. args = [
  176. "$(location //toolchain/driver:carbon)",
  177. "compile",
  178. "--phase=parse",
  179. "--dump-parse-tree",
  180. ],
  181. data = ["//toolchain/driver:carbon"],
  182. file_exts = ["carbon"],
  183. )
  184. glob_sh_run(
  185. args = [
  186. "$(location //toolchain/driver:carbon)",
  187. "-v",
  188. "compile",
  189. "--phase=parse",
  190. ],
  191. data = ["//toolchain/driver:carbon"],
  192. file_exts = ["carbon"],
  193. run_ext = "verbose",
  194. )