forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterfaceWrapper.cc
40 lines (34 loc) · 1.23 KB
/
InterfaceWrapper.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "rewriter/InterfaceWrapper.h"
#include "ast/Helpers.h"
#include "ast/ast.h"
#include "core/Context.h"
#include "core/Names.h"
#include "core/core.h"
#include "core/errors/rewriter.h"
#include "rewriter/Util.h"
#include "rewriter/rewriter.h"
using namespace std;
namespace sorbet::rewriter {
ast::ExpressionPtr InterfaceWrapper::run(core::MutableContext ctx, ast::Send *send) {
if (ctx.state.runningUnderAutogen) {
return nullptr;
}
if (send->fun != core::Names::wrapInstance()) {
return nullptr;
}
if (!ast::isa_tree<ast::UnresolvedConstantLit>(send->recv)) {
if (auto e = ctx.beginError(send->recv.loc(), core::errors::Rewriter::BadWrapInstance)) {
e.setHeader("Unsupported wrap_instance() on a non-constant-literal");
}
return nullptr;
}
if (send->numPosArgs() != 1) {
if (auto e = ctx.beginError(send->loc, core::errors::Rewriter::BadWrapInstance)) {
e.setHeader("Wrong number of arguments to `{}`. Expected: `{}`, got: `{}`", "wrap_instance", 0,
send->numPosArgs());
}
return nullptr;
}
return ast::MK::Let(send->loc, move(send->getPosArg(0)), move(send->recv));
}
} // namespace sorbet::rewriter