forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sem: consolidate macro pragma processing (nim-works#1021)
## Summary Merge the separate implementations of macro/template pragma processing into a single one. The benefits: * less duplicated code * macro and template annotations are ensured to work the same for all types of definitions * a single place to change the behaviour in This changes: * routine AST passed to macro/template pragmas keeps the `nnkPragma` node, even if empty * ill-formed accent quoted expressions preceding a macro/template pragma don't prevent the transform from taking place ## Details Routines, types, and var/let/const definitions all had their own implementation, but their only difference was in where the AST was modified and whether a full copy was created or not. There's nothing that requires fundamentally different processing for each type of definition, so the processing is consolidated: * the new `tryMacroPragma` procedure processes a single pragma, returning either the raw transform or nil * the new `semAnnotation` processes a pragma list (`nkPragma`), trying each item with `tryMacroPragma` * sem'ing of routines, types, and var/let/const definitions use `semAnnotation` So that the macro/template pragma call can be temporarily removed from the definition's pragma list (which is at different tree positions for each definition AST), the address of the node is passed to `semAnnotation`. Differences compared to the previous implementation: * empty `nkPragma` nodes are kept. This was previously only the case for var/let/const annotations * instead of the manual `semMacroExpr` call, `afterCallActions` is used. This is a step towards removing the bare `semMacroExpr` calls Ideally, `semAnnotation` would always return the raw transformation result and leave sem'ing it to the callsite, but this is not yet possible.
- Loading branch information
Showing
4 changed files
with
99 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,7 +354,7 @@ ProcDef | |
Ident "s" | ||
Ident "string" | ||
Empty | ||
Empty | ||
Pragma | ||
Empty | ||
StmtList | ||
ReturnStmt | ||
|