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
104 stars 28 forks source link

[psyir] Missing comma separator if argument list to a call contains a CodeBlock #1303

Closed arporter closed 3 years ago

arporter commented 3 years ago

If we have some code that results in a CodeBlock in the argument list, e.g.:

call output("hello "//my_string, unit_num=6)

Then the PSyIR is:

1: Call[name='output']
    CodeBlock[[<class 'fparser.two.Fortran2003.Level_3_Expr'>, <class 'fparser.two.Fortran2003.Actual_Arg_Spec'>]]

But the generated code is:

call output("hello " // my_stringunit_num = 6)

i.e. we're missing the comma separator between the two arguments.

arporter commented 3 years ago

I think the problem is that the various arguments are being grouped into a single CodeBlock whereas, in this case, we need separate CodeBlocks.

sergisiso commented 3 years ago

Aha, this seems the same error that I am getting in NemoLite2D with @rupertford PR #1228 : call timer_start(itimer0, label = 'Time-stepping'num_repeats = nrepeat)

arporter commented 3 years ago

Oh yes, that's the one. I have a 'fix' - I add a new type of Structure to CodeBlock (ARGUMENT_LIST) and set this if the parent node in the frontend is a Call or a Reference to a RoutineSymbol. I think this will still fail though if we have a function call and haven't resolved the type of the Symbol representing the function (e.g. if it's imported via a wildcard USE).

arporter commented 3 years ago

A better alternative might be to change the frontend so that it doesn't merge CodeBlocks in this context.