Skip to content

Commit 9688e95

Browse files
committed
format
1 parent 710f98b commit 9688e95

5 files changed

Lines changed: 38 additions & 30 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5186,24 +5186,31 @@ std::string Converter::ConvertIRFragment(
51865186
ConvertIRFragment((*re)->inner, bindings, expr, args, num_args, ctx);
51875187
} else if (auto *call =
51885188
std::get_if<std::unique_ptr<GenericCallFragment>>(&frag)) {
5189-
result +=
5190-
ConvertGenericCall(**call, bindings, expr, args, num_args, ctx);
5189+
result += ConvertGenericCall(**call, bindings, expr, args, num_args, ctx);
51915190
}
51925191
}
51935192

51945193
return result;
51955194
}
51965195

5197-
std::string Converter::ConvertGenericCall(
5198-
const TranslationRule::GenericCallFragment &call,
5199-
llvm::ArrayRef<clang::TemplateArgument> bindings, clang::Expr *expr,
5200-
clang::Expr **args, unsigned num_args, TempMaterializationCtx *ctx) {
5196+
std::string
5197+
Converter::ConvertGenericCall(const TranslationRule::GenericCallFragment &call,
5198+
llvm::ArrayRef<clang::TemplateArgument> bindings,
5199+
clang::Expr *expr, clang::Expr **args,
5200+
unsigned num_args, TempMaterializationCtx *ctx) {
52015201
std::vector<std::string> call_args;
52025202
for (const auto &arg : call.args) {
52035203
call_args.push_back(
52045204
ConvertIRFragment(arg, bindings, expr, args, num_args, ctx));
52055205
}
5206-
auto type = RuleRegistry::GetGenericType(ctx_, expr, call.generic);
5206+
clang::QualType type;
5207+
if (call.generic <= bindings.size() &&
5208+
bindings[call.generic - 1].getKind() == clang::TemplateArgument::Type) {
5209+
type = bindings[call.generic - 1].getAsType();
5210+
} else {
5211+
assert(expr && "unbound generic outside an expression rule");
5212+
type = RuleRegistry::GetGenericType(ctx_, expr, call.generic);
5213+
}
52075214
if (call.method == "default") {
52085215
assert(call_args.empty() && "default takes no arguments");
52095216
return GetUnboxedDefaultAsString(type);

‎cpp2rust/converter/rules/registry.cpp‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ clang::QualType getInitPattern(const clang::FunctionDecl *rule) {
8787

8888
void collectGenerics(const std::vector<TranslationRule::BodyFragment> &body,
8989
std::unordered_set<unsigned> &used) {
90-
TranslationRule::AnyFragment(
91-
body, [&](const TranslationRule::BodyFragment &fragment) {
92-
if (auto generic =
93-
std::get_if<TranslationRule::GenericFragment>(&fragment)) {
94-
used.insert(generic->n);
95-
}
96-
if (auto call = std::get_if<
97-
std::unique_ptr<TranslationRule::GenericCallFragment>>(
90+
TranslationRule::AnyFragment(body, [&](const TranslationRule::BodyFragment
91+
&fragment) {
92+
if (auto generic =
93+
std::get_if<TranslationRule::GenericFragment>(&fragment)) {
94+
used.insert(generic->n);
95+
}
96+
if (auto call =
97+
std::get_if<std::unique_ptr<TranslationRule::GenericCallFragment>>(
9898
&fragment)) {
99-
used.insert((*call)->generic);
100-
}
101-
return false;
102-
});
99+
used.insert((*call)->generic);
100+
}
101+
return false;
102+
});
103103
}
104104

105105
void collectGenerics(llvm::StringRef type, std::unordered_set<unsigned> &used) {

‎cpp2rust/converter/translation_rule.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "converter/translation_rule.h"
55

66
#include <llvm/ADT/STLExtras.h>
7-
87
#include <llvm/Support/JSON.h>
98

109
#include <algorithm>
@@ -155,8 +154,7 @@ bool AnyFragment(const std::vector<BodyFragment> &body,
155154
if (auto *re = std::get_if<std::unique_ptr<RefExprFragment>>(&frag)) {
156155
return AnyFragment((*re)->inner, pred);
157156
}
158-
if (auto *call =
159-
std::get_if<std::unique_ptr<GenericCallFragment>>(&frag)) {
157+
if (auto *call = std::get_if<std::unique_ptr<GenericCallFragment>>(&frag)) {
160158
return llvm::any_of((*call)->args, [&](const auto &arg) {
161159
return AnyFragment(arg, pred);
162160
});

‎cpp2rust/converter/translation_rule.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ struct MethodCallFragment; // forward declaration
5252
struct RefExprFragment;
5353
struct GenericCallFragment;
5454

55-
using BodyFragment =
56-
std::variant<TextFragment, PlaceholderFragment, GenericFragment,
57-
VaArgsFragment, InitFragment,
58-
std::unique_ptr<MethodCallFragment>,
59-
std::unique_ptr<RefExprFragment>,
60-
std::unique_ptr<GenericCallFragment>>;
55+
using BodyFragment = std::variant<
56+
TextFragment, PlaceholderFragment, GenericFragment, VaArgsFragment,
57+
InitFragment, std::unique_ptr<MethodCallFragment>,
58+
std::unique_ptr<RefExprFragment>, std::unique_ptr<GenericCallFragment>>;
6159

6260
struct MethodCallFragment {
6361
std::vector<BodyFragment> receiver;

‎rule-preprocessor/src/syntactic.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ impl<'a> FragmentCtx<'a> {
194194
ast::CallExpr::cast(node.clone()).and_then(|call| self.generic_call(&call))
195195
{
196196
self.flush_text();
197-
self.fragments.push(BodyFragment::GenericCall { generic_call });
197+
self.fragments
198+
.push(BodyFragment::GenericCall { generic_call });
198199
return;
199200
}
200201
for child in node.children_with_tokens() {
@@ -296,7 +297,11 @@ impl<'a> FragmentCtx<'a> {
296297
ctx.finish()
297298
})
298299
.collect();
299-
Some(GenericCallInner { generic, method, args })
300+
Some(GenericCallInner {
301+
generic,
302+
method,
303+
args,
304+
})
300305
}
301306

302307
fn emit_method_call(&mut self, call: &ast::MethodCallExpr) {

0 commit comments

Comments
 (0)