Node: Aggregates in assignments statements, Previous: Aggregates with non-static bounds, Up: Code generation for array aggregates



Aggregates in assignments statements

In general, aggregate assignment requires the construction of a temporary, and a copy from the temporary to the target of the assignment. This is because it is not always possible to convert the assignment into a series of individual component assignments. For example, consider the simple case:

     
A := (A(2), A(1));

This cannot be converted into:

             A(1) := A(2);
             A(2) := A(1);
     

So the aggregate has to be built first in a separate location, and then copied into the target. GNAT recognizes simple cases where this intermediate step is not required, and the assignments can be performed in place, directly into the target. The following sufficient criteria are applied:

  1. The bounds of the aggregate are static, and the associations are static.
  2. The components of the aggregate are static constants, names of simple variables that are not renamings, or expressions not involving indexed components whose operands obey these rules.

If any of these conditions are violated, the aggregate will be built in a temporary (created either by the front-end or the code generator) and then that temporary will be copied onto the target.