stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
102 stars 27 forks source link

PSyIR does not correctly represent if(condition) statement code #291

Closed arporter closed 5 years ago

arporter commented 5 years ago

When constructing the PSyIR for the following Fortran:

IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' ubs2 adv - Ua: ', mask1=umask)

the resulting representation doesn't look correct:

If[]
    BinaryOperation[operator:'==']
        Reference[name:'nn_timing']
        Literal[value:'1']
    CodeBlock[[<class 'fparser.two.Fortran2003.Call_Stmt'>]]

I would expect the BinaryOperation part to be contained within the If[], not a child of it. I suspect this is my fault as when I first put in support for If conditions I was thinking only about if-then-else blocks.

sergisiso commented 5 years ago

I tried your statement with my implementation of IfBlock on PR #347 and I get:

    If[was_elseif:False]
        Reference[name:'ln_ctl']
        CodeBlock[[<class 'fparser.two.Fortran2003.Call_Stmt'>]]

It is what I am expecting (besides that I am still not sure if a single statement body should have an Schedule with just one child or not). I think the problem is that it is not documented what IfBlock contains and I didn't look properly how you were using them on Nemo.

I will document all that on the PR: the first child is the condition, second the body (and these could be easily accessible with the properties self.condition and self.ifbody). Would that be good for the nemo API?

arporter commented 5 years ago

Yes, that looks good to me.

arporter commented 5 years ago

347 is merged. Closing issue.