aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2013-10-14 15:19:17 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2013-10-14 15:19:17 +0200
commitcf3b97ef62af198eacdafcbb4c6d24e0591520e7 (patch)
tree76679a8107ecb3d17bc0702a961d8e4130ecfa21
parent5c211bfd5afac2c366e840291e8fca8f4b5e2976 (diff)
downloadgcc-cf3b97ef62af198eacdafcbb4c6d24e0591520e7.zip
gcc-cf3b97ef62af198eacdafcbb4c6d24e0591520e7.tar.gz
gcc-cf3b97ef62af198eacdafcbb4c6d24e0591520e7.tar.bz2
[multiple changes]
2013-10-14 Robert Dewar <dewar@adacore.com> * gnat_rm.texi: Library_Level attribute now applies to an entity name. * sem_attr.adb (Analyze_Attribute, case Library_Level): Prefix is now an entity name. 2013-10-14 Jose Ruiz <ruiz@adacore.com> * sem_ch13.adb (Analyze_Aspect_Specification): For Priority and CPU aspects in subprograms, the expression in the aspect is analyzed and exported. From-SVN: r203543
-rw-r--r--gcc/ada/ChangeLog13
-rw-r--r--gcc/ada/gnat_rm.texi17
-rw-r--r--gcc/ada/sem_attr.adb7
-rw-r--r--gcc/ada/sem_ch13.adb124
4 files changed, 138 insertions, 23 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 5880379..fbfb947 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,5 +1,18 @@
2013-10-14 Robert Dewar <dewar@adacore.com>
+ * gnat_rm.texi: Library_Level attribute now applies to an
+ entity name.
+ * sem_attr.adb (Analyze_Attribute, case Library_Level): Prefix
+ is now an entity name.
+
+2013-10-14 Jose Ruiz <ruiz@adacore.com>
+
+ * sem_ch13.adb (Analyze_Aspect_Specification): For
+ Priority and CPU aspects in subprograms, the expression in the
+ aspect is analyzed and exported.
+
+2013-10-14 Robert Dewar <dewar@adacore.com>
+
* s-valuti.adb, prep.adb, scng.adb, errout.adb: Minor reformatting.
2013-10-14 Eric Botcazou <ebotcazou@adacore.com>
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index cc3f248..c10ba33 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -8348,21 +8348,20 @@ this attribute.
@findex Library_Level
@noindent
@noindent
-@code{Standard'Library_Level} (@code{Standard} is the only allowed
-prefix) returns a Boolean value which is True if the attribute is
-evaluated at the library level (e.g. with a package declaration),
-and false if evaluated elsewhere (e.g. within a subprogram body).
-In the case of generics, the value indicates the placement of
-the instantiation, not the template, and indeed the use of this
-attribute within a generic is the intended common application
-as shown in this example:
+@code{P'Library_Level}, where P is an entity name,
+returns a Boolean value which is True if the entity is declared
+at the library level, and False otherwise. Note that within a
+generic instantition, the name of the generic unit denotes the
+instance, which means that this attribute can be used to test
+if a generic is instantiated at the library level, as shown
+in this example:
@smallexample @c ada
generic
...
package Gen is
pragma Compile_Time_Error
- (not Standard'Library_Level,
+ (not Gen'Library_Level,
"Gen can only be instantiated at library level");
...
end Gen;
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index f235921..493f544 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -3689,11 +3689,14 @@ package body Sem_Attr is
when Attribute_Library_Level =>
Check_E0;
- Check_Standard_Prefix;
+
+ if not Is_Entity_Name (P) then
+ Error_Attr_P ("prefix of % attribute must be an entity name");
+ end if;
if not Inside_A_Generic then
Set_Boolean_Result (N,
- Nearest_Dynamic_Scope (Current_Scope) = Standard_Standard);
+ Is_Library_Level_Entity (Entity (P)));
end if;
Set_Etype (N, Standard_Boolean);
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 0e01c8e..0264d31 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -1794,22 +1794,123 @@ package body Sem_Ch13 is
-- CPU, Interrupt_Priority, Priority
- -- These three aspects can be specified for a subprogram body,
- -- in which case we generate pragmas for them and insert them
- -- ahead of local declarations, rather than after the body.
+ -- These three aspects can be specified for a subprogram spec
+ -- or body, in which case we analyze the expression and export
+ -- the value of the aspect.
+
+ -- Previously, we generated an equivalent pragma for bodies
+ -- (note that the specs cannot contain these pragmas). The
+ -- pragma was inserted ahead of local declarations, rather than
+ -- after the body. This leads to a certain duplication between
+ -- the processing performed for the aspect and the pragma, but
+ -- given the straightforward handling required it is simpler
+ -- to duplicate than to translate the aspect in the spec into
+ -- a pragma in the declarative part of the body.
when Aspect_CPU |
Aspect_Interrupt_Priority |
Aspect_Priority =>
- if Nkind (N) = N_Subprogram_Body then
- Make_Aitem_Pragma
- (Pragma_Argument_Associations => New_List (
- Make_Pragma_Argument_Association (Sloc (Expr),
- Expression => Relocate_Node (Expr))),
- Pragma_Name => Chars (Id));
+ if Nkind_In (N, N_Subprogram_Body,
+ N_Subprogram_Declaration)
+ then
+ -- Analyze the aspect expression
+
+ Analyze_And_Resolve (Expr, Standard_Integer);
+
+ -- Interrupt_Priority aspect not allowed for main
+ -- subprograms. ARM D.1 does not forbid this explicitly,
+ -- but ARM J.15.11 (6/3) does not permit pragma
+ -- Interrupt_Priority for subprograms.
+
+ if A_Id = Aspect_Interrupt_Priority then
+ Error_Msg_N
+ ("Interrupt_Priority aspect cannot apply to "
+ & "subprogram", Expr);
+
+ -- The expression must be static
+
+ elsif not Is_Static_Expression (Expr) then
+ Flag_Non_Static_Expr
+ ("aspect requires static expression!", Expr);
+
+ -- Check whether this is the main subprogram
+
+ elsif Current_Sem_Unit /= Main_Unit
+ and then
+ Cunit_Entity (Current_Sem_Unit) /= Main_Unit_Entity
+ then
+ -- See ARM D.1 (14/3) and D.16 (12/3)
+
+ Error_Msg_N
+ ("aspect applied to subprogram other than the "
+ & "main subprogram has no effect??", Expr);
+
+ -- Otherwise check in range and export the value
+
+ -- For the CPU aspect
+
+ elsif A_Id = Aspect_CPU then
+ if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
+
+ -- Value is correct so we export the value to make
+ -- it available at execution time.
+
+ Set_Main_CPU
+ (Main_Unit, UI_To_Int (Expr_Value (Expr)));
+
+ else
+ Error_Msg_N
+ ("main subprogram CPU is out of range", Expr);
+ end if;
+
+ -- For the Priority aspect
+
+ elsif A_Id = Aspect_Priority then
+ if Is_In_Range (Expr, RTE (RE_Priority)) then
+
+ -- Value is correct so we export the value to make
+ -- it available at execution time.
+
+ Set_Main_Priority
+ (Main_Unit, UI_To_Int (Expr_Value (Expr)));
+
+ else
+ Error_Msg_N
+ ("main subprogram priority is out of range",
+ Expr);
+ end if;
+ end if;
+
+ -- Load an arbitrary entity from System.Tasking.Stages
+ -- or System.Tasking.Restricted.Stages (depending on
+ -- the supported profile) to make sure that one of these
+ -- packages is implicitly with'ed, since we need to have
+ -- the tasking run time active for the pragma Priority to
+ -- have any effect. Previously with with'ed the package
+ -- System.Tasking, but this package does not trigger the
+ -- required initialization of the run-time library.
+
+ declare
+ Discard : Entity_Id;
+ pragma Warnings (Off, Discard);
+ begin
+ if Restricted_Profile then
+ Discard := RTE (RE_Activate_Restricted_Tasks);
+ else
+ Discard := RTE (RE_Activate_Tasks);
+ end if;
+ end;
+
+ -- Handling for these Aspects in subprograms is complete
+
+ goto Continue;
+
+ -- For tasks
else
+ -- Pass the aspect as an attribute
+
Aitem :=
Make_Attribute_Definition_Clause (Loc,
Name => Ent,
@@ -2566,9 +2667,8 @@ package body Sem_Ch13 is
end if;
end if;
- -- If the aspect is on a subprogram body (relevant aspects
- -- are Inline and Priority), add the pragma in front of
- -- the declarations.
+ -- If the aspect is on a subprogram body (relevant aspect
+ -- is Inline), add the pragma in front of the declarations.
if Nkind (N) = N_Subprogram_Body then
if No (Declarations (N)) then