forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleFunction.h
46 lines (40 loc) · 1.46 KB
/
ModuleFunction.h
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
41
42
43
44
45
46
#ifndef SORBET_REWRITER_MODULE_FUNCTION_H
#define SORBET_REWRITER_MODULE_FUNCTION_H
#include "ast/ast.h"
namespace sorbet::rewriter {
/**
* This class desugars `module_function`, which has several ways it can be used. If it is used with a method definition
* as its argument, then it will desugar
*
* module_function def foo(x, y, ...); end
*
* into
*
* private def foo(x, y, ...); end
* def self.foo(x, y, ...); end
*
* possibly replicating the sig for the method if possible. If it is used with a string or symbol, then it instead
* desugars into an untyped empty method for the purposes of fowarding, so
*
* module function def :foo
*
* becomes
*
* private def foo(*args, **kwargs); end
* def self.foo(*args, **kwargs); end
*
* finally, you can use module_function on its on, in which case it will do the above-described rewrite to every
* subsequent method definition in the class
*/
class ModuleFunction final {
public:
static void run(core::MutableContext ctx, ast::ClassDef *cdef);
ModuleFunction() = delete;
private:
static std::vector<ast::ExpressionPtr> run(core::MutableContext ctx, ast::Send *send,
const ast::ExpressionPtr *prevStat);
static std::vector<ast::ExpressionPtr> rewriteDefn(core::MutableContext ctx, const ast::ExpressionPtr &expr,
const ast::ExpressionPtr *prevStat);
};
} // namespace sorbet::rewriter
#endif