Apply decorators to a function. Given a decorated FuncDef and an instance of the callable class representing that FuncDef, apply the corresponding decorator functions on that decorated FuncDef and return the decorated function.
(builder: IRBuilder, fdef: FuncDef, orig_func_reg: Value)
| 609 | |
| 610 | |
| 611 | def load_decorated_func(builder: IRBuilder, fdef: FuncDef, orig_func_reg: Value) -> Value: |
| 612 | """Apply decorators to a function. |
| 613 | |
| 614 | Given a decorated FuncDef and an instance of the callable class |
| 615 | representing that FuncDef, apply the corresponding decorator |
| 616 | functions on that decorated FuncDef and return the decorated |
| 617 | function. |
| 618 | """ |
| 619 | if not is_decorated(builder, fdef): |
| 620 | # If there are no decorators associated with the function, then just return the |
| 621 | # original function. |
| 622 | return orig_func_reg |
| 623 | |
| 624 | decorators = builder.fdefs_to_decorators[fdef] |
| 625 | func_reg = orig_func_reg |
| 626 | for d in reversed(decorators): |
| 627 | decorator = d.accept(builder.visitor) |
| 628 | assert isinstance(decorator, Value), decorator |
| 629 | func_reg = builder.py_call(decorator, [func_reg], func_reg.line) |
| 630 | return func_reg |
| 631 | |
| 632 | |
| 633 | def is_decorated(builder: IRBuilder, fdef: FuncDef) -> bool: |
no test coverage detected
searching dependent graphs…