# # Copyright 2021 Google, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Bison is a parser generator which reads a specification of a context-free # language and generates a parser which decides whether the input conforms to # the grammar specified. # Generate header and source files using Bison. # # Note: We generate C++ output for Bison. We also set --language to C++ # (equivalent to %language c++) which forces Bison to generate a C++ parser. # # Parameters: # sources: Grammar files used to generate the parsers. template("bison_source") { action_name = "${target_name}_gen" action_foreach(action_name) { forward_variables_from(invoker, [ "sources" ]) assert(defined(sources), "sources must be set") foreach(s, sources) { assert(get_path_info(s, "extension") == "yy", "Expecting Bison extension yy: ${s}") } script = "//common-mk/file_generator_wrapper.py" outprefix = "${target_gen_dir}/{{source_name_part}}" args = [ "bison", "--language=c++", "--defines=${outprefix}.h", "-o", "${outprefix}.cc", "{{source}}", ] outputs = [ "${outprefix}.h", "${outprefix}.cc", ] } all_dependent_config_name = "_${target_name}_all_dependent_config" config(all_dependent_config_name) { include_dirs = [ "${target_gen_dir}" ] } source_set(target_name) { sources = get_target_outputs(":${action_name}") all_dependent_configs = [ ":${all_dependent_config_name}" ] deps = [ ":${action_name}" ] if (defined(invoker.configs)) { configs += invoker.configs } # Silence some warnings. The autogenerated code includes parts that have # fallthroughs and unreachable code. This may silence legitimate issues in # user written code in the grammar files as well. User beware! cflags_cc = [ "-Wno-implicit-fallthrough", "-Wno-unreachable-code", ] } }