mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
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.
32 lines
1.1 KiB
C++
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_
|