Skip to content

Commit 5f973cd

Browse files
authored
Merge pull request GaijinEntertainment#2106 from GaijinEntertainment/doc-doc-2
pass macro documentation
2 parents 82030fd + c43e268 commit 5f973cd

6 files changed

Lines changed: 553 additions & 7 deletions

File tree

doc/source/reference/language/macros.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,22 +446,32 @@ Note how the name is provided in the ``[call_macro]`` annotation.
446446
AstPassMacro
447447
------------
448448

449-
``AstPassMacro`` is one macro to rule them all. It gets entire module as an input,
450-
and can be invoked at numerous passes:
449+
``AstPassMacro`` is one macro to rule them all. It gets the entire program as
450+
input and can be invoked at numerous passes:
451451

452452
.. code-block:: das
453453
454454
class AstPassMacro {
455-
def abstract apply ( prog:ProgramPtr; mod:Module? ) : bool
455+
def abstract apply(prog : ProgramPtr; mod : Module?) : bool
456456
}
457457
458+
Five annotations control when a pass macro runs:
459+
460+
- ``[infer_macro]`` — after clean type inference. Returning ``true`` re-infers.
461+
- ``[dirty_infer_macro]`` — during each dirty inference pass.
462+
- ``[lint_macro]`` — after successful compilation (lint phase, read-only).
463+
- ``[global_lint_macro]`` — same as ``[lint_macro]`` but for all modules.
464+
- ``[optimization_macro]`` — during the optimisation loop.
465+
458466
``make_pass_macro`` registers a class as a pass macro.
459467

460-
``add_new_infer_macro`` adds a pass macro to the infer pass. The ``[infer]`` annotation accomplishes the same thing.
468+
Typically, such macros create an ``AstVisitor`` which performs the necessary
469+
transformations via ``visit(prog, adapter)``.
461470

462-
``add_new_dirty_infer_macro`` adds a pass macro to the ``dirty`` section of infer pass. The ``[dirty_infer]`` annotation accomplishes the same thing.
471+
.. seealso::
463472

464-
Typically, such macros create an ``AstVisitor`` which performs the necessary transformations.
473+
:ref:`tutorial_macro_pass_macro` — step-by-step tutorial with lint and
474+
infer macro examples.
465475

466476
----------------
467477
AstTypeInfoMacro

doc/source/reference/tutorials.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,5 @@ Run any tutorial from the project root::
157157
tutorials/macros/10_capture_macro.rst
158158
tutorials/macros/11_reader_macro.rst
159159
tutorials/macros/12_typeinfo_macro.rst
160-
tutorials/macros/13_enumeration_macro.rst
160+
tutorials/macros/13_enumeration_macro.rst
161+
tutorials/macros/14_pass_macro.rst

doc/source/reference/tutorials/macros/13_enumeration_macro.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ enumeration macro use cases:
297297

298298
Previous tutorial: :ref:`tutorial_macro_typeinfo_macro`
299299

300+
Next tutorial: :ref:`tutorial_macro_pass_macro`
301+
300302
Standard library: ``daslib/enum_trait.das`` —
301303
:ref:`enum_trait module reference <stdlib_enum_trait>`
302304

0 commit comments

Comments
 (0)