AdaCore / libadalang

Ada semantic analysis library.
https://www.adacore.com
Other
147 stars 42 forks source link

Question: What is the best way to recursively explore record definitions? #969

Closed dmt117 closed 3 weeks ago

dmt117 commented 3 weeks ago

I'm trying to follow embedded record definitions, i.e. a record within a record definition, etc. I want to get all the way to the basic types embedded in the records. There doesn't seem to be a straightforward way to do this in libadlang. There is a component list for a record definition, but if one of those components is itself a record type, I'm not discovering how to reach the record definition for that type. Is there an easy way to do this?

Roldak commented 3 weeks ago

Hello!

You're right that this functionality is not built-in, so you'll have to roll your own recursive implementation.

The key of this algorithm would be that once you've managed to retrieve the TypeExpr node of a record component (which IIUC you have), you can find its corresponding type declaration using the P_Designated_Type_Decl property (corresponding documentation).

If this type declares a record as well, you can then recurse on its components, and so on.

I hope this helps!

dmt117 commented 3 weeks ago

thanks!

Roldak commented 3 weeks ago

No problem !