parse_tree_node_location_translator.h 1.1 KB

12345678910111213141516171819202122232425262728293031
  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. #ifndef CARBON_TOOLCHAIN_PARSER_PARSE_TREE_NODE_LOCATION_TRANSLATOR_H_
  5. #define CARBON_TOOLCHAIN_PARSER_PARSE_TREE_NODE_LOCATION_TRANSLATOR_H_
  6. #include "toolchain/parser/parse_tree.h"
  7. namespace Carbon {
  8. class ParseTreeNodeLocationTranslator
  9. : public DiagnosticLocationTranslator<ParseTree::Node> {
  10. public:
  11. explicit ParseTreeNodeLocationTranslator(const TokenizedBuffer* tokens,
  12. const ParseTree* parse_tree)
  13. : token_translator_(tokens), parse_tree_(parse_tree) {}
  14. // Map the given token into a diagnostic location.
  15. auto GetLocation(ParseTree::Node node) -> DiagnosticLocation override {
  16. return token_translator_.GetLocation(parse_tree_->node_token(node));
  17. }
  18. private:
  19. TokenizedBuffer::TokenLocationTranslator token_translator_;
  20. const ParseTree* parse_tree_;
  21. };
  22. } // namespace Carbon
  23. #endif // CARBON_TOOLCHAIN_PARSER_PARSE_TREE_NODE_LOCATION_TRANSLATOR_H_