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

Unable to parse declarations with multiple [, ] pairs #87

Closed
g5t opened this issue Dec 6, 2024 · 4 comments
Closed

Unable to parse declarations with multiple [, ] pairs #87

g5t opened this issue Dec 6, 2024 · 4 comments

Comments

@g5t
Copy link
Collaborator

g5t commented Dec 6, 2024

As found by @willend, example instruments which use the Monochromator_bent component do not pass code-generation with mccode-antlr due to a RuntimError complaining about 'multi-level' arrays.

Partial stack trace highlighting where the error originates

... mccode_antlr/translators/c_listener.py", line 298, in visitDeclarator
    raise RuntimeError('No idea how to handle multi-level arrays')

This would appear to originate from the definition of double crystal_table[56][10]

It is probably more-sensible to not raise on this issue, but instead to handle it somehow.

@willend
Copy link
Contributor

willend commented Dec 6, 2024

@g5t one (reasonable?) way to fix / work around this is likely to use a malloc'ed approach, in the component, i.e.

DArray2D crystal_table;
cystal_table=create_darray2d(56,10);

( Do you know if a simple assignment of the table values "in one go" crystal_table = {{ ... }} would work after the above declaration?)

Plus then spread the word among comp writers that we prefer the use of the "array" definitions for 2/3 d arrays? (We have both are DArray and IArray as I remember...)

@willend
Copy link
Contributor

willend commented Dec 6, 2024

Oh and btw prior to yesterdays related PR om McCode there were other code-bits that raised the same error without being (fully) related, e.g. this function declaration:

double dSigdW(int sw, double Q, double Qtab[], double Itab[])

(replacing by a standard double* pointer declaration worked just fine of course)

@g5t
Copy link
Collaborator Author

g5t commented Dec 6, 2024

I've just merged #88 to handle the double crystal_table[56][10] case.

The new issue you mentioned raised the same runtime error because there was only a check for more than a single [, ] pair in one declaration statement.
With the changes I've made, that function (pre)declaration is parsed but the resulting information isn't entirely correct.
I doubt this will give problems until some unlikely distant future where I try to use declared C functions by extracting their signature and definition from an instrument.

@g5t g5t closed this as completed Dec 6, 2024
@willend
Copy link
Contributor

willend commented Dec 7, 2024

Confirmed to function as expected, see https://new-nightly.mcstas.org/2024-12-07_output.html

Only two Union event-logger related instruments now don't compile (section of 2nd column from above table):
Screenshot 2024-12-07 at 10 35 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants