diff --git a/explorer/ast/ast_test_matchers_internal.cpp b/explorer/ast/ast_test_matchers_internal.cpp index a6ef93574232..f39735b07d76 100644 --- a/explorer/ast/ast_test_matchers_internal.cpp +++ b/explorer/ast/ast_test_matchers_internal.cpp @@ -49,10 +49,11 @@ auto BinaryOperatorExpressionMatcher::MatchAndExplainImpl( return false; } if (op->op() != op_) { - *out << "whose operator is not " << ToString(op_); + *out << "whose operator is not " << OperatorToString(op_); return false; } - *out << "which is a " << ToString(op_) << " expression whose left operand "; + *out << "which is a " << OperatorToString(op_) + << " expression whose left operand "; bool matched = lhs_.MatchAndExplain(*op->arguments()[0], out); *out << " and right operand "; if (!rhs_.MatchAndExplain(*op->arguments()[1], out)) { @@ -63,7 +64,7 @@ auto BinaryOperatorExpressionMatcher::MatchAndExplainImpl( void BinaryOperatorExpressionMatcher::DescribeToImpl(std::ostream* out, bool negated) const { - *out << "is " << (negated ? "not " : "") << "a " << ToString(op_) + *out << "is " << (negated ? "not " : "") << "a " << OperatorToString(op_) << " expression whose "; *out << "left operand "; lhs_.DescribeTo(out); diff --git a/explorer/ast/expression.cpp b/explorer/ast/expression.cpp index d39717103fe5..14c98866e2bb 100644 --- a/explorer/ast/expression.cpp +++ b/explorer/ast/expression.cpp @@ -111,7 +111,7 @@ auto TupleExpressionFromParenContents( Expression::~Expression() = default; -auto ToString(Operator op) -> std::string_view { +auto OperatorToString(Operator op) -> std::string_view { switch (op) { case Operator::Add: return "+"; @@ -217,13 +217,13 @@ void Expression::Print(llvm::raw_ostream& out) const { const auto& op = cast(*this); switch (op.arguments().size()) { case 0: - out << ToString(op.op()); + out << OperatorToString(op.op()); break; case 1: - out << ToString(op.op()) << " " << *op.arguments()[0]; + out << OperatorToString(op.op()) << " " << *op.arguments()[0]; break; case 2: - out << *op.arguments()[0] << " " << ToString(op.op()) << " " + out << *op.arguments()[0] << " " << OperatorToString(op.op()) << " " << *op.arguments()[1]; break; default: diff --git a/explorer/ast/expression.h b/explorer/ast/expression.h index b37fb0d3c922..e6c0ea0090b2 100644 --- a/explorer/ast/expression.h +++ b/explorer/ast/expression.h @@ -169,7 +169,7 @@ enum class Operator { }; // Returns the lexical representation of `op`, such as "+" for `Add`. -auto ToString(Operator op) -> std::string_view; +auto OperatorToString(Operator op) -> std::string_view; class IdentifierExpression : public Expression { public: diff --git a/explorer/interpreter/interpreter.cpp b/explorer/interpreter/interpreter.cpp index bbf21733796a..7a59e195e34e 100644 --- a/explorer/interpreter/interpreter.cpp +++ b/explorer/interpreter/interpreter.cpp @@ -253,7 +253,7 @@ auto Interpreter::EvalPrim(Operator op, Nonnull /*static_type*/, case Operator::BitShiftLeft: case Operator::BitShiftRight: case Operator::Complement: - CARBON_FATAL() << "operator " << ToString(op) + CARBON_FATAL() << "operator " << OperatorToString(op) << " should always be rewritten"; } } diff --git a/explorer/interpreter/type_checker.cpp b/explorer/interpreter/type_checker.cpp index 1bcd3d9b17a7..d3d339b7dc73 100644 --- a/explorer/interpreter/type_checker.cpp +++ b/explorer/interpreter/type_checker.cpp @@ -3034,7 +3034,7 @@ auto TypeChecker::TypeCheckExp(Nonnull e, if (!result.ok()) { // We couldn't find a matching `impl`. return ProgramError(e->source_loc()) - << "type error in `" << ToString(op.op()) << "`:\n" + << "type error in `" << OperatorToString(op.op()) << "`:\n" << result.error().message(); } op.set_rewritten_form(*result); @@ -3049,7 +3049,7 @@ auto TypeChecker::TypeCheckExp(Nonnull e, if (!result.ok()) { // We couldn't find a matching `impl`. return ProgramError(e->source_loc()) - << "type error in `" << ToString(op.op()) << "`:\n" + << "type error in `" << OperatorToString(op.op()) << "`:\n" << result.error().message(); } op.set_rewritten_form(*result); @@ -3203,7 +3203,7 @@ auto TypeChecker::TypeCheckExp(Nonnull e, case Operator::AddressOf: if (op.arguments()[0]->value_category() != ValueCategory::Var) { return ProgramError(op.arguments()[0]->source_loc()) - << "Argument to " << ToString(op.op()) + << "Argument to " << OperatorToString(op.op()) << " should be an lvalue."; } op.set_static_type(arena_->New(ts[0]));