|
| 1 | +package dotty.tools.dotc |
| 2 | +package transform |
| 3 | + |
| 4 | +import core.* |
| 5 | +import ast.tpd.* |
| 6 | +import Contexts.* |
| 7 | +import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer |
| 8 | + |
| 9 | +/** |
| 10 | + * ??? |
| 11 | + * @author Hamza REMMAL ([email protected]) |
| 12 | + */ |
| 13 | +class PostInlining2 extends MacroTransform, IdentityDenotTransformer: |
| 14 | + thisPhase => |
| 15 | + |
| 16 | + override def phaseName: String = PostInlining2.name |
| 17 | + |
| 18 | + override def description: String = PostInlining2.description |
| 19 | + |
| 20 | + override def changesMembers = true |
| 21 | + |
| 22 | + def newTransformer(using Context): Transformer = new Transformer: |
| 23 | + override def transform(tree: Tree)(using Context): Tree = |
| 24 | + super.transform(tree) match |
| 25 | + // HR : Check if the owner of the added symbols is correct. |
| 26 | + // HR : if yes, and the symbol is not entered. enter it |
| 27 | + |
| 28 | + /* HR : Questions : |
| 29 | + - What symbol are we allowed to change ? Check for now if the content of the tree is consistent |
| 30 | + - What happens if we enter a symbol twice ? I have a NamingError reported |
| 31 | + - What if we already have that symbol entered ? ignore it... |
| 32 | + - Can we merge it with the PostInlining phase ? |
| 33 | + - Is there an optimal way to check if a tree was generated by a macro annotation ? |
| 34 | + - Define a correct error message below |
| 35 | + */ |
| 36 | + |
| 37 | + case t@TypeDef(_, template: Template) => |
| 38 | + for tree <- template.constr :: template.body do |
| 39 | + if tree.symbol.owner == t.symbol then |
| 40 | + if !t.symbol.asClass.info.decls.exists(_ == tree.symbol) then |
| 41 | + tree.symbol.enteredAfter(thisPhase) |
| 42 | + else |
| 43 | + report.error("Macro added a definition with the wrong owner") |
| 44 | + t |
| 45 | + case t => t |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +object PostInlining2: |
| 50 | + val name: String = "postInlining2" |
| 51 | + val description: String = "check the result of the macro annotation extension" |
| 52 | + |
0 commit comments