tree_node_location_translator.h 1.0 KB

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