Search code examples
abstract-syntax-treeadasemanticsgnatasis

List of Child Elements of a Element in ASIS(Ada Semantics interface Specification)


I am implementing a simple tool using ASIS(Ada Semantics interface Specifications). I am having problem with listing child elements in a given Elements.for example i am having assignment statement as C := A + B; i am able to get the element(expression) which represents "A + B", from the above assignment statement but need to extract A, B elements individually from the above expression. what is the query in ASIS for doing the same. i have tried "Traverse_element" but not able to succeed.


Solution

  • A + B is a function call, so you have to extract the actual parameters of the function call using:

    declare
       use ASIS.Expressions;
    begin
       for Parameter_Association of Function_Call_Parameters (Expression => Element,
                                                              Normalized => True) loop
         declare
            Formal : constant Asis.Element := Formal_Parameter (Parameter_Association);
            Actual : constant Asis.Element := Actual_Parameter (Parameter_Association);
         begin
            ...
         end;
       end loop;
    end;