Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [photran-dev] It's possible to get a body of an DoConstrucNode?

Hi Bruno,

I've observed that don't exists a correlation between the DoConstrucNode and the EndDoStmtNode. They don't form a block (as the IfConstructNode).

Why this is so? (see attached image)


Funny, I was just thinking about this same problem earlier today.

The problem is old-style Fortran DO loops, as in

      do 10 i = 1, n
         sum = sum + i
  10  continue

These require some semantic analysis to figure out the body of the loop; you have to make sure that there actually is a statement 10, and so on. So we don't try to do that in the parser.

For some reason, the parser does not distinguish between these old-style loops and the newer-style do/enddo loops. So they both end up as the same thing---just a list of statements---in the AST.

Luckily, it is easier to figure out what should be the body of a new-style do loop, since they always end with an EndDoStmt and should be properly nested.

I agree that we should have a pass that turns these into a "real" DoConstructNodes rather than just a list of statements. Unfortunately no one's implemented it yet.

It would not be hard to do. Basically, you would have to make a new class which is similar to ASTIfConstructNode, but for do-loops. Traverse the list of statements until you find the last loop header. Every statement until the next EndDoStmt is the loop body. Put those statements (and the loop header, and the EndDoStmt) into your new AST node, and replace the existing statements with that node. If you repeat this procedure until there are no loop headers left in the subroutine, you should have converted all of the loops, from innermost to outermost.

If you are interested in doing that, I would be glad to give advice as necessary. I'd offer to do it for you, but the next couple of weeks are very busy on my end...

Jeff


Back to the top