This patch prevents the user to provide parameter Symbol (reserved for compiler
use only) in any dimension output call.
------------
-- Source --
------------
with System.Dim.Mks; use System.Dim.Mks;
with System.Dim.Mks_IO; use System.Dim.Mks_IO;
procedure Main is
begin
Put (8.0**(1 / 3) * m , 1, 2, 0, "error");
end Main;
-----------------------------
-- Compilation & Execution --
-----------------------------
$ gcc -c -gnat12 main.adb
main.adb:6:37: Symbol parameter should not be provided
main.adb:6:37: reserved for compiler use only
Tested on x86_64-pc-linux-gnu, committed on trunk
2012-10-01 Vincent Pucci <[email protected]>
* sem_dim.adb (Has_Symbols): Complain if parameter Symbol has been
provided by the user in the dimension output call.
Index: sem_dim.adb
===================================================================
--- sem_dim.adb (revision 191911)
+++ sem_dim.adb (working copy)
@@ -2703,7 +2703,8 @@
-----------------
function Has_Symbols return Boolean is
- Actual : Node_Id;
+ Actual : Node_Id;
+ Actual_Str : Node_Id;
begin
Actual := First (Actuals);
@@ -2711,16 +2712,49 @@
-- Look for a symbols parameter association in the list of actuals
while Present (Actual) loop
- if Nkind (Actual) = N_Parameter_Association
+ -- Positional parameter association case when the actual is a
+ -- string literal.
+
+ if Nkind (Actual) = N_String_Literal then
+ Actual_Str := Actual;
+
+ -- Named parameter association case when the selector name is
+ -- Symbol.
+
+ elsif Nkind (Actual) = N_Parameter_Association
and then Chars (Selector_Name (Actual)) = Name_Symbol
then
+ Actual_Str := Explicit_Actual_Parameter (Actual);
+
+ -- Ignore all other cases
+
+ else
+ Actual_Str := Empty;
+ end if;
+
+ if Present (Actual_Str) then
-- Return True if the actual comes from source or if the string
-- of symbols doesn't have the default value (i.e. it is "").
- return Comes_From_Source (Actual)
- or else
- String_Length
- (Strval (Explicit_Actual_Parameter (Actual))) /= 0;
+ if Comes_From_Source (Actual)
+ or else String_Length (Strval (Actual_Str)) /= 0
+ then
+ -- Complain only if the actual comes from source or if it
+ -- hasn't been fully analyzed yet.
+
+ if Comes_From_Source (Actual)
+ or else not Analyzed (Actual)
+ then
+ Error_Msg_N ("Symbol parameter should not be provided",
+ Actual);
+ Error_Msg_N ("\reserved for compiler use only", Actual);
+ end if;
+
+ return True;
+
+ else
+ return False;
+ end if;
end if;
Next (Actual);