Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source locations lost during transforming visit traversal #2015

Open
tvdstorm opened this issue Aug 15, 2024 · 0 comments
Open

Source locations lost during transforming visit traversal #2015

tvdstorm opened this issue Aug 15, 2024 · 0 comments
Labels

Comments

@tvdstorm
Copy link
Member

tvdstorm commented Aug 15, 2024

When doing a transforming visit on a parse tree, rewriting a nested element, the enclosing tree (trees?) don't get their source locations back. Strangely enough, adding a dummy case for the enclosing nonterminal fixes the problem.

NB: the exception says "Undeclared" but it is physically not there.
NB: there is no difference between insert and =>

Reproduce:

module Bug

import IO;
import Node;

extend lang::std::Layout;
extend lang::std::Id;

syntax Stmt 
  = "if" Expr cond "{" Stmt body "}"
  | Id x "=" Id y
  ;

lexical Expr = [a-z];


void bug() {
    Stmt stmt = (Stmt)`if a { x = y }`;

    stmt2 = visit (stmt) {
        case (Expr)`a`: insert (Expr)`b`;
    }

    // original statement has a source location
    println(stmt.src);

    // prints empty map
    println(getKeywordParameters(stmt2));

    // throws exception Undeclared field: src for Tree = appl(Production prod,list[Tree] args)
    println(stmt2.src); 

    // However: the following does work... (commenting out previous statement)

    stmt3 = visit (stmt) {
        case (Expr)`a`: insert (Expr)`b`;
        case Stmt _: ;
    }

    // prints map with src entry
    println(getKeywordParameters(stmt3));

    // prints correct loc
    println(stmt3.src); 

}
@tvdstorm tvdstorm added the bug label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant