Closed PressFforlove closed 10 months ago
i think the first Cpp_If_Stmt should be in Execution_Part
Yes, I can see that that behaviour is not the best. Essentially, if-defs are not part of Fortran and fparser's support for them is very limited. We recommend that, where possible, the code to be parsed is put through a pre-processor first so that it is valid Fortran. Otherwise, I shall bring in @reuterbal as he implemented support for CPP directives and may be able to comment further.
Like Andy said: Preprocessor statements are not part of Fortran, and fparser treats them the same way as comments - but makes them available as a separate node type for convenience.
The question of the split between specification-part and execution-part is somewhat arbitrary since comments can be allocated to either. The specific reason why it appears here in the specification-part rather than execution part is due to the fact, that fparser continues to allocate all nodes to the currently active part (i.e. the spec) until the first executable statement is encountered (i.e., the assignment).
If you are certain that all comments (inlcuding preprocessor statements) should always belong to the execution-part instead, you could update the parse tree accordingly afterwards. However, this is certainly not the case in general. An easy example where this assumption breaks down can be constructed, e.g., when using marker apis from profiling tools:
program test
implicit none
real(kind = 8) :: a, b, c
#ifdef USE_MARKER_API
integer :: marker
call start_marker(marker)
#endif
....
#ifdef USE_MARKER_API
call end_marker(marker)
#endif
end program
Sorry, it have been a long time to reply you, because my work about fparser has finished for a while.
Thank you for reply~
My opinion is not that all comment should belong to exec_part. After think about this quesion alone, my conclusion is almost the same as you, and i do some preprocessing before i do some change to AST(my work).
as the title says, when i have a code like below and want to gen ast:
why will the 2 #def stmts be split to to specification_part, execution_part, and even some tail(the last #endif) in Block_Nonlabel_Do_Construct? this confused me a lot...