Files
carbon-lang/toolchain/parser/parse_tree_node_location_translator.h
T
Jon Ross-Perkins a7c2885728 Clean up handling of incomplete line locations. (#3011)
Building on #3010, the handling of incomplete lines seems like it can be
straightened out. Doing this separately because it seemed better to
demonstrate tests aren't affected by the change.
2023-07-24 23:17:58 +00:00

32 lines
1.1 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_PARSER_PARSE_TREE_NODE_LOCATION_TRANSLATOR_H_
#define CARBON_TOOLCHAIN_PARSER_PARSE_TREE_NODE_LOCATION_TRANSLATOR_H_
#include "toolchain/parser/parse_tree.h"
namespace Carbon {
class ParseTreeNodeLocationTranslator
: public DiagnosticLocationTranslator<ParseTree::Node> {
public:
explicit ParseTreeNodeLocationTranslator(const TokenizedBuffer* tokens,
const ParseTree* parse_tree)
: token_translator_(tokens), parse_tree_(parse_tree) {}
// Map the given token into a diagnostic location.
auto GetLocation(ParseTree::Node node) -> DiagnosticLocation override {
return token_translator_.GetLocation(parse_tree_->node_token(node));
}
private:
TokenizedBuffer::TokenLocationTranslator token_translator_;
const ParseTree* parse_tree_;
};
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_PARSER_PARSE_TREE_NODE_LOCATION_TRANSLATOR_H_