Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5eec2a7a4921
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: de242c9838a7
Choose a head ref
  • 4 commits
  • 5 files changed
  • 2 contributors

Commits on Jun 25, 2020

  1. Use Contains.

    pleroy committed Jun 25, 2020
    Copy the full SHA
    918b4cb View commit details
  2. Custom marshaler hack.

    pleroy committed Jun 25, 2020
    Copy the full SHA
    e64989c View commit details
  3. += and -= for polynomials.

    pleroy committed Jun 25, 2020
    Copy the full SHA
    5b9793f View commit details
  4. Merge pull request #2614 from pleroy/Todo

    Fix a few TODOs
    pleroy authored Jun 25, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    de242c9 View commit details
Showing with 59 additions and 47 deletions.
  1. +2 −1 base/not_null_test.cpp
  2. +3 −5 numerics/poisson_series_body.hpp
  3. +3 −0 numerics/polynomial.hpp
  4. +21 −0 numerics/polynomial_body.hpp
  5. +30 −41 tools/journal_proto_processor.cpp
3 changes: 2 additions & 1 deletion base/not_null_test.cpp
Original file line number Diff line number Diff line change
@@ -67,7 +67,8 @@ TEST_F(NotNullTest, Move) {
_MSC_FULL_VER == 192'428'314 || \
_MSC_FULL_VER == 192'428'316 || \
_MSC_FULL_VER == 192'528'610 || \
_MSC_FULL_VER == 192'528'611)
_MSC_FULL_VER == 192'528'611 || \
_MSC_FULL_VER == 192'628'806)
EXPECT_THAT(*(std::unique_ptr<int> const&)int_ptr1, Eq(3));
#endif
not_null<std::unique_ptr<int>> int_ptr2 = std::move(int_ptr1);
8 changes: 3 additions & 5 deletions numerics/poisson_series_body.hpp
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ PoissonSeries<Value, degree_, Evaluator>::PoissonSeries(
// The |periodic| map may have elements with positive or negative angular
// frequencies. Normalize our member variable to only have positive angular
// frequencies.
// TODO(phl): It would be good to have +=, -=, etc. for polynomials.
for (auto it = periodic.crbegin(); it != periodic.crend(); ++it) {
auto const ω = it->first;
if (ω < AngularFrequency{}) {
@@ -37,14 +36,13 @@ PoissonSeries<Value, degree_, Evaluator>::PoissonSeries(
Polynomials{/*sin=*/-it->second.sin,
/*cos=*/it->second.cos});
} else {
positive_it->second = {
/*sin=*/positive_it->second.sin - it->second.sin,
/*cos=*/positive_it->second.cos + it->second.cos};
positive_it->second.sin -= it->second.sin;
positive_it->second.cos += it->second.cos;
}
} else if (ω > AngularFrequency{}) {
periodic_.insert(*it);
} else {
aperiodic_ = aperiodic_ + it->second.cos;
aperiodic_ += it->second.cos;
}
}
}
3 changes: 3 additions & 0 deletions numerics/polynomial.hpp
Original file line number Diff line number Diff line change
@@ -82,6 +82,9 @@ class PolynomialInMonomialBasis : public Polynomial<Value, Argument> {
Derivative<Value, Argument, order>, Argument, degree_ - order, Evaluator>
Derivative() const;

PolynomialInMonomialBasis& operator+=(const PolynomialInMonomialBasis& right);
PolynomialInMonomialBasis& operator-=(const PolynomialInMonomialBasis& right);

void WriteToMessage(
not_null<serialization::Polynomial*> message) const override;
static PolynomialInMonomialBasis ReadFromMessage(
21 changes: 21 additions & 0 deletions numerics/polynomial_body.hpp
Original file line number Diff line number Diff line change
@@ -184,6 +184,27 @@ Derivative() const {
TupleDerivation<Coefficients, order>::Derive(coefficients_));
}

template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>&
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::operator+=(
const PolynomialInMonomialBasis& right) {
*this = *this + right;
return *this;
}

template<typename Value,
typename Argument,
int degree_,
template<typename, typename, int>
class Evaluator>
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>&
PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::operator-=(
const PolynomialInMonomialBasis& right) {
*this = *this - right;
return *this;
}

template<typename Value, typename Argument, int degree_,
template<typename, typename, int> class Evaluator>
void PolynomialInMonomialBasis<Value, Argument, degree_, Evaluator>::
71 changes: 30 additions & 41 deletions tools/journal_proto_processor.cpp
Original file line number Diff line number Diff line change
@@ -198,16 +198,15 @@ void JournalProtoProcessor::ProcessRepeatedMessageField(

FieldOptions const& options = descriptor->options();
field_cs_type_[descriptor] = message_type_name + "[]";
// TODO(phl): Use Contains instead of empty for all the set/map predicates.
if (cs_custom_marshaler_name_[message_type].empty()) {
if (Contains(cs_custom_marshaler_name_, message_type)) {
field_cs_custom_marshaler_[descriptor] =
"RepeatedMarshaler<" + message_type_name + ", " +
cs_custom_marshaler_name_[message_type] + ">";
} else {
// This wouldn't be hard, we'd need another RepeatedMarshaller that copies
// structs, but we don't need it yet.
LOG(FATAL) << "Repeated messages with an element that does not have a "
"custom marshaller are not yet implemented.";
} else {
field_cs_custom_marshaler_[descriptor] =
"RepeatedMarshaler<" + message_type_name + ", " +
cs_custom_marshaler_name_[message_type] + ">";
}
field_cxx_type_[descriptor] = message_type_name + " const* const*";

@@ -289,14 +288,14 @@ void JournalProtoProcessor::ProcessOptionalNonStringField(
if (Contains(interchange_, descriptor)) {
// This may be null as we may be called on a scalar field.
Descriptor const* message_type = descriptor->message_type();
if (cs_custom_marshaler_name_[message_type].empty()) {
field_cs_custom_marshaler_[descriptor] =
custom_marshaler_generic_name(cs_unboxed_type);
} else {
if (Contains(cs_custom_marshaler_name_, message_type)) {
// This wouldn't be hard, we'd need another OptionalMarshaller that calls
// the element's marshaler, but we don't need it yet.
LOG(FATAL) << "Optional messages with an element that does have a custom "
"marshaller are not yet implemented.";
} else {
field_cs_custom_marshaler_[descriptor] =
custom_marshaler_generic_name(cs_unboxed_type);
}
// For fields of interchange messages we can use a |T?| as the field is not
// the part being marshaled, it is the entire interchange message.
@@ -529,7 +528,7 @@ void JournalProtoProcessor::ProcessRequiredMessageField(
field_cs_type_[descriptor] = message_type_name;
field_cxx_type_[descriptor] = message_type_name;

if (!cs_custom_marshaler_name_[message_type].empty()) {
if (Contains(cs_custom_marshaler_name_, message_type)) {
if (Contains(in_, descriptor)) {
field_cs_custom_marshaler_[descriptor] =
cs_custom_marshaler_name_[message_type];
@@ -1045,31 +1044,21 @@ void JournalProtoProcessor::ProcessInterchangeMessage(

// Start by processing the fields. We need to know if any of them has a
// custom marshaler to decide whether we generate a struct or a class.
// TODO(phl): Make this const once we generate the marshaler for
// BodyParameters.
bool has_custom_marshaler =
bool const has_custom_marshaler =
options.HasExtension(journal::serialization::custom_marshaler);
bool needs_custom_marshaler = false;
for (int i = 0; i < descriptor->field_count(); ++i) {
FieldDescriptor const* field_descriptor = descriptor->field(i);
interchange_.insert(field_descriptor);
ProcessField(field_descriptor);
if (!has_custom_marshaler &&
!field_cs_custom_marshaler_[field_descriptor].empty()) {
Contains(field_cs_custom_marshaler_, field_descriptor)) {
needs_custom_marshaler = true;
}
}
if (has_custom_marshaler) {
// TODO(phl): Remove this hack once we generate the marshaler for
// BodyParameters.
if (options.GetExtension(journal::serialization::custom_marshaler) ==
"none") {
has_custom_marshaler = false;
needs_custom_marshaler = false;
} else {
cs_custom_marshaler_name_[descriptor] =
options.GetExtension(journal::serialization::custom_marshaler);
}
cs_custom_marshaler_name_[descriptor] =
options.GetExtension(journal::serialization::custom_marshaler);
} else if (needs_custom_marshaler) {
cs_custom_marshaler_name_[descriptor] = name + "Marshaler";
}
@@ -1137,11 +1126,7 @@ void JournalProtoProcessor::ProcessInterchangeMessage(
field_cxx_indirect_member_get_fn_[field_descriptor](
serialize_member_name)));

if (field_cs_private_type_[field_descriptor].empty()) {
cs_interchange_type_declaration_[descriptor] +=
" public " + field_cs_type_[field_descriptor] + " " +
field_descriptor_name + ";\n";
} else {
if (Contains(field_cs_private_type_, field_descriptor)) {
std::string const field_private_member_name = field_descriptor_name + "_";
std::vector<std::string> fn_arguments = {field_private_member_name};
cs_interchange_type_declaration_[descriptor] +=
@@ -1155,6 +1140,10 @@ void JournalProtoProcessor::ProcessInterchangeMessage(
" " + field_cs_private_setter_fn_[field_descriptor](fn_arguments) +
"\n" +
" }\n";
} else {
cs_interchange_type_declaration_[descriptor] +=
" public " + field_cs_type_[field_descriptor] + " " +
field_descriptor_name + ";\n";
}
cxx_interchange_type_declaration_[descriptor] +=
" " + field_cxx_type_[field_descriptor] + " " + field_descriptor_name +
@@ -1163,17 +1152,7 @@ void JournalProtoProcessor::ProcessInterchangeMessage(
// If we need to generate a marshaler, do it now.
if (needs_custom_marshaler) {
cs_representation_type_declaration_[descriptor] += " public ";
if (field_cs_custom_marshaler_[field_descriptor].empty()) {
cs_representation_type_declaration_[descriptor] +=
field_cs_type_[field_descriptor] + " " + field_descriptor_name +
";\n";
cs_managed_to_native_definition_[descriptor] +=
" " + field_descriptor_name + " = value." +
field_descriptor_name + ",\n";
cs_native_to_managed_definition_[descriptor] +=
" " + field_descriptor_name + " = representation." +
field_descriptor_name + ",\n";
} else {
if (Contains(field_cs_custom_marshaler_, field_descriptor)) {
cs_representation_type_declaration_[descriptor] +=
"IntPtr " + field_descriptor_name + ";\n";
cs_clean_up_native_definition_[descriptor] +=
@@ -1191,6 +1170,16 @@ void JournalProtoProcessor::ProcessInterchangeMessage(
".GetInstance(null).MarshalNativeToManaged(representation." +
field_descriptor_name + ") as " + field_cs_type_[field_descriptor] +
",\n";
} else {
cs_representation_type_declaration_[descriptor] +=
field_cs_type_[field_descriptor] + " " + field_descriptor_name +
";\n";
cs_managed_to_native_definition_[descriptor] +=
" " + field_descriptor_name + " = value." +
field_descriptor_name + ",\n";
cs_native_to_managed_definition_[descriptor] +=
" " + field_descriptor_name + " = representation." +
field_descriptor_name + ",\n";
}
}
}