1

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?

David Boshton
  • 2,555
  • 5
  • 30
  • 51

2 Answers2

2

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.

flyx
  • 35,506
  • 7
  • 89
  • 126
  • @JeffreyR.Carter That package is almost empty and the only thing it does is inspecting the tag of a tagged type at runtime, which is exactly the part of Ada's type system that does exist at runtime. A quick look at [Ada.Tags](http://www.ada-auth.org/standards/12rm/html/RM-3-9.html) which is used there shows that the package does not provide the facilities to inspect the components of a tagged type (which is what OP needs). – flyx Jun 11 '18 at 09:15
1

Which attributes a type has depends on which kind of type it is:

Jacob Sparre Andersen
  • 6,733
  • 17
  • 22