1
votes

Is there a way of seeing attributes of a type in Ada? I've not been able to find anything so far. I'd like to be able to pass a type into a generic function with some corresponding XML and parse one to the other without writing a bespoke function for each record. Obviously I'll need to tell the parser how to do basic types, but I want composites to be automatically processed. Python's dir() method seems to be the thing I'd use in Python if I were doing this from scratch, so is there a better way of doing this entirely or is there an equivalent of dir() in Ada?

2
What does Python's dir() do? - Jacob Sparre Andersen
Lists all the attributes and methods of a types. in my case, just the fields in the records of a variable would do. - David Boshton
You can do that with ASIS or libadalang. - Jacob Sparre Andersen

2 Answers

2
votes

Ada has no metaprogramming facilities nor does it have reflection (which is how these kind of things are done in Java/C#). Since the type system largely only exists at compile time, you cannot query much information at runtime, and certainly not the kind of information you need. You cannot simply do this with a generic function.

The best thing to do is probably generate Ada code from the XML schema, or (if Ada types define the XML structure) use ASIS or libadalang to generate the parsing code from the Ada types' AST. Note that this is rather complex and I wouldn't recommend it unless you are familiar with handling ASTs. If it is possible to write an XML schema, I would rather use that schema to generate the Ada types and corresponding loading code.