This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Implement case expressions


This patch implements a new Ada 2012 feature, case expressions, under
control of the -gnatX switch. This allows the use of the proposed
new construct as illustrated by the following example:
  X := (case Y is when 1 => 2, when 2 => 3, when others => 31)
The implementation is complete, and works for some simple examples
like the following one:

with Text_IO; use Text_IO;
procedure caseexp_1 is
begin
   for J in 1 .. 3 loop
      Put_Line
        (Integer'Image
           ((case J is when 1 => 2, when 2 => 32, when 3 => 45)));
   end loop;
end caseexp_1;

which, compiled with -gnatX generates the output
 2
 32
 45
as expected

However, there are still some problems with the use of unconstrained
array results (e.g. strings) which need more work.

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-06-18  Robert Dewar  <dewar@adacore.com>

	* checks.adb (Safe_To_Capture_In_Parameter_Value): Deal with case
	expression (cannot count on a particular branch being executed).
	* exp_ch4.adb (Expand_N_Case_Expression): New procedure.
	* exp_ch4.ads (Expand_N_Case_Expression): New procedure.
	* exp_util.adb (Insert_Actions): Deal with proper insertion of actions
	within case expression.
	* expander.adb (Expand): Add call to Expand_N_Case_Expression
	* par-ch4.adb Add calls to P_Case_Expression at appropriate points
	(P_Case_Expression): New procedure
	(P_Case_Expression_Alternative): New procedure
	* par.adb (P_Case_Expression): New procedure
	* par_sco.adb (Process_Decisions): Add dummy place holder entry for
	N_Case_Expression.
	* sem.adb (Analyze): Add call to Analyze_Case_Expression
	* sem_case.ads (Analyze_Choices): Also used for case expressions now,
	this is a documentation change only.
	* sem_ch4.ads, sem_ch4.adb (Analyze_Case_Expression): New procedure.
	* sem_ch6.adb (Fully_Conformant_Expressions): Add handling of case
	expressions.
	* sem_eval.ads, sem_eval.adb (Eval_Case_Expression): New procedure.
	* sem_res.adb (Resolve_Case_Expression): New procedure.
	* sem_scil.adb (Find_SCIL_Node): Add processing for
	N_Case_Expression_Alternative.
	* sinfo.ads, sinfo.adb (N_Case_Expression): New node.
	(N_Case_Expression_Alternative): New node.
	* sprint.adb (Sprint_Node_Actual): Add processing for new nodes
	N_Case_Expression and N_Case_Expression_Alternative.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]