Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit f7df893

Browse files
committed
get rid of default ctors
1 parent c95957f commit f7df893

File tree

9 files changed

+769
-1044
lines changed

9 files changed

+769
-1044
lines changed

lib-ruby-parser-cpp-bindings/gen/cpp/nodes/classes_cpp.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ impl<'a> NodeImplementation<'a> {
4444

4545
fn code(&self) -> String {
4646
format!(
47-
"{class_name}::{class_name}({args})
48-
{{
49-
{constructor}
50-
}}
47+
"{class_name}::{class_name}({args}):
48+
{member_initializer_list} {{}}
5149
",
5250
class_name = self.node.struct_name,
5351
args = self.args().join(", "),
54-
constructor = self.construtor_stmts().join("\n")
52+
member_initializer_list = self.member_initializer_list().join(",\n ")
5553
)
5654
}
5755

@@ -65,7 +63,7 @@ impl<'a> NodeImplementation<'a> {
6563
})
6664
}
6765

68-
fn construtor_stmts(&self) -> Vec<String> {
66+
fn member_initializer_list(&self) -> Vec<String> {
6967
map_node_fields(&self.node.fields, |f| {
7068
let field_name = Field::new(f).cpp_name();
7169

@@ -74,11 +72,7 @@ impl<'a> NodeImplementation<'a> {
7472
rhs = format!("std::move({})", rhs)
7573
}
7674

77-
format!(
78-
"this->{field_name} = {rhs};",
79-
field_name = field_name,
80-
rhs = rhs
81-
)
75+
format!("{field_name}({rhs})", field_name = field_name, rhs = rhs)
8276
})
8377
}
8478
}

src/bytes.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ namespace lib_ruby_parser
1414
return result;
1515
}
1616

17-
Bytes::Bytes()
18-
{
19-
this->size_ = 0;
20-
this->bytes_ = nullptr;
21-
this->borrowed = false;
22-
}
23-
2417
Bytes::~Bytes()
2518
{
2619
if (borrowed)

src/bytes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace lib_ruby_parser
1515
bool borrowed = false;
1616

1717
public:
18-
Bytes();
1918
~Bytes();
2019

2120
explicit Bytes(std::string s);

src/custom_decoder.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
namespace lib_ruby_parser
66
{
7+
CustomDecoder::Result::Result(Bytes output) : data(std::move(output)){};
8+
CustomDecoder::Result::Result(std::string error_message) : data(std::move(error_message)){};
9+
710
CustomDecoder::Result CustomDecoder::Result::Ok(Bytes output)
811
{
9-
CustomDecoder::Result result;
10-
result.success = true;
11-
result.output = std::move(output);
12-
return result;
12+
return CustomDecoder::Result(std::move(output));
1313
}
1414

1515
CustomDecoder::Result CustomDecoder::Result::Error(std::string error_message)
1616
{
17-
CustomDecoder::Result result;
18-
result.success = false;
19-
result.error_message = std::move(error_message);
20-
return result;
17+
return CustomDecoder::Result(std::move(error_message));
2118
}
2219
} // namespace lib_ruby_parser

src/custom_decoder.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <string>
55
#include <vector>
6+
#include <variant>
67
#include "bytes.h"
78

89
namespace lib_ruby_parser
@@ -13,11 +14,11 @@ namespace lib_ruby_parser
1314
class Result
1415
{
1516
public:
16-
bool success;
17-
Bytes output;
18-
std::string error_message;
17+
std::variant<Bytes, std::string> data;
1918

20-
Result() = default;
19+
Result() = delete;
20+
explicit Result(Bytes output);
21+
explicit Result(std::string error_message);
2122
Result(Result &&) = default;
2223
Result(const Result &) = delete;
2324

0 commit comments

Comments
 (0)