mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 17:14:52 +01:00
Note, not trying to address every last error, just some obvious/easy ones.
```
/usr/local/google/home/jperkins/dev/carbon-lang/common/string_helpers.cpp:200:13: warning: prefer transparent functors 'less_equal<>' [modernize-use-transparent-functors]
auto le = std::less_equal<const char*>();
^
/usr/local/google/home/jperkins/dev/carbon-lang/toolchain/semantics/nodes/function.h:22:45: warning: pass by value and use std::move [modernize-pass-by-value]
Function(ParseTree::Node node, NodeId id, llvm::SmallVector<NodeRef> body)
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/ast/declaration.cpp:230:14: warning: static member accessed through instance [readability-static-accessed-through-instance]
return cast<SelfDeclaration>(declaration).name();
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/interpreter/type_checker.cpp:1104:33: warning: std::move of the variable 'impl' of the trivially-copyable type 'ConstraintType::ImplConstraint' has no effect [performance-move-const-arg]
impl_constraints_.push_back(std::move(impl));
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/interpreter/type_checker.cpp:1145:36: warning: std::move of the variable 'rewrite' of the trivially-copyable type 'ConstraintType::RewriteConstraint' has no effect [performance-move-const-arg]
rewrite_constraints_.push_back(std::move(rewrite));
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/interpreter/type_checker.cpp:1156:32: warning: std::move of the variable 'context' of the trivially-copyable type 'ConstraintType::LookupContext' has no effect [performance-move-const-arg]
lookup_contexts_.push_back(std::move(context));
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/fuzzing/fuzzverter.cpp:74:42: warning: argument name 'trace' in comment does not match parameter name 'parser_debug' [bugprone-argument-comment]
/*trace=*/false);
^
./explorer/syntax/parse.h:19:17: note: 'parser_debug' declared here
bool parser_debug) -> ErrorOr<Carbon::AST>;
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/fuzzing/proto_to_carbon_test.cpp:34:55: warning: argument name 'trace' in comment does not match parameter name 'parser_debug' [bugprone-argument-comment]
const ErrorOr<AST> ast = Carbon::Parse(&arena, f, /*trace=*/false);
^
./explorer/syntax/parse.h:19:17: note: 'parser_debug' declared here
bool parser_debug) -> ErrorOr<Carbon::AST>;
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/fuzzing/proto_to_carbon_test.cpp:42:41: warning: argument name 'trace' in comment does not match parameter name 'parser_debug' [bugprone-argument-comment]
&arena, f, source_from_proto, /*trace=*/false);
^
./explorer/syntax/parse.h:25:59: note: 'parser_debug' declared here
std::string_view file_contents, bool parser_debug)
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/syntax/parse_test.cpp:27:60: warning: argument name 'trace' in comment does not match parameter name 'parser_debug' [bugprone-argument-comment]
ParseFromString(&arena, "file.carbon", FileContents, /*trace=*/false);
^
./explorer/syntax/parse.h:25:59: note: 'parser_debug' declared here
std::string_view file_contents, bool parser_debug)
^
/usr/local/google/home/jperkins/dev/carbon-lang/migrate_cpp/cpp_refactoring/var_decl.cpp:57:58: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation]
segments.push_back({type_loc_class, qual_str + " " + range_str});
^
/usr/local/google/home/jperkins/dev/carbon-lang/explorer/fuzzing/ast_to_proto_test.cpp:105:55: warning: argument name 'trace' in comment does not match parameter name 'parser_debug' [bugprone-argument-comment]
const ErrorOr<AST> ast = Carbon::Parse(&arena, f, /*trace=*/false);
^
./explorer/syntax/parse.h:19:17: note: 'parser_debug' declared here
bool parser_debug) -> ErrorOr<Carbon::AST>;
^
```
64 lines
1.9 KiB
C++
64 lines
1.9 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
|
|
|
|
#include "common/fuzzing/proto_to_carbon.h"
|
|
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "explorer/fuzzing/ast_to_proto.h"
|
|
#include "explorer/syntax/parse.h"
|
|
|
|
namespace Carbon::Testing {
|
|
namespace {
|
|
|
|
static std::vector<llvm::StringRef>* carbon_files = nullptr;
|
|
|
|
// Returns a string representation of `ast`.
|
|
auto AstToString(const AST& ast) -> std::string {
|
|
std::string s;
|
|
llvm::raw_string_ostream out(s);
|
|
out << "package " << ast.package.package << (ast.is_api ? "api" : "impl")
|
|
<< ";\n";
|
|
for (auto* declaration : ast.declarations) {
|
|
out << *declaration << "\n";
|
|
}
|
|
return s;
|
|
}
|
|
|
|
TEST(ProtoToCarbonTest, Roundtrip) {
|
|
int parsed_ok_count = 0;
|
|
for (const llvm::StringRef f : *carbon_files) {
|
|
Carbon::Arena arena;
|
|
const ErrorOr<AST> ast = Carbon::Parse(&arena, f, /*parser_debug=*/false);
|
|
if (ast.ok()) {
|
|
++parsed_ok_count;
|
|
const std::string source_from_proto = ProtoToCarbon(AstToProto(*ast));
|
|
SCOPED_TRACE(testing::Message()
|
|
<< "Carbon file: " << f << ", source from proto:\n"
|
|
<< source_from_proto);
|
|
const ErrorOr<AST> ast_from_proto = Carbon::ParseFromString(
|
|
&arena, f, source_from_proto, /*parser_debug=*/false);
|
|
|
|
if (ast_from_proto.ok()) {
|
|
EXPECT_EQ(AstToString(*ast), AstToString(*ast_from_proto));
|
|
} else {
|
|
ADD_FAILURE() << "Parse error " << ast_from_proto.error().message();
|
|
}
|
|
}
|
|
}
|
|
// Makes sure files were actually processed.
|
|
EXPECT_GT(parsed_ok_count, 0);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace Carbon::Testing
|
|
|
|
auto main(int argc, char** argv) -> int {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
Carbon::Testing::carbon_files =
|
|
new std::vector<llvm::StringRef>(&argv[1], &argv[argc]);
|
|
return RUN_ALL_TESTS();
|
|
}
|