Ada 编程/编译指示/限制
外观
Restrictions 编译指示用于禁止使用某些语言特性。
一些限制具有特殊标记
- Immediate_Reclamation
- Max_Asynchronous_Select_Nesting
- Max_Entry_Queue_Length (Ada 2005)
- Max_Protected_Entries
- Max_Select_Alternatives
- Max_Storage_At_Blocking
- Max_Task_Entries
- Max_Tasks
- No_Abort_Statements
- No_Access_Parameter_Allocators (Ada 2012)
- No_Access_Subprograms
- No_Allocators
- No_Anonymous_Allocators (Ada 2012)
- No_Asynchronous_Control
- No_Coextensions (Ada 2012)
- No_Delay
- No_Dependence (Ada 2005)
- No_Dispatch
- No_Dynamic_Attachment (Ada 2005)
- No_Dynamic_Priorities
- No_Exceptions
- No_Fixed_Point
- No_Floating_Point
- No_Implementation_Aspect_Specifications (Ada 2012)
- No_Implementation_Attributes (Ada 2005)
- No_Implementation_Identifiers (Ada 2012)
- No_Implementation_Pragmas (Ada 2005)
- No_Implementation_Units (Ada 2012)
- No_Implicit_Heap_Allocations
- No_IO
- No_Local_Allocators
- No_Local_Protected_Objects (Ada 2005)
- No_Local_Timing_Events (Ada 2005)
- No_Nested_Finalization
- No_Obsolescent_Features (Ada 2005)
- No_Protected_Type_Allocators (Ada 2005)
- No_Protected_Types
- No_Recursion
- No_Reentrancy
- No_Relative_Delay (Ada 2005)
- No_Requeue_Statements (Ada 2005)
- No_Select_Statements (Ada 2005)
- No_Specific_Termination_Handlers (Ada 2005)
- No_Specification_of_Aspect (Ada 2012)
- No_Standard_Allocators_After_Elaboration (Ada 2012)
- No_Task_Allocators
- No_Task_Hierarchy
- No_Task_Termination (Ada 2005)
- No_Terminate_Alternatives
- No_Unchecked_Access
- No_Unchecked_Conversion
- No_Unchecked_Deallocation
- No_Use_of_Attribute (Ada 2012)
- No_Use_of_Pragma (Ada 2012)
- Simple_Barriers (Ada 2005)
以下限制并非所有 Ada 编译器都支持,仅在那些已经实现它们的编译器中可用
- GNAT
- 这是一个 实现定义的限制标识符,属于 GNAT 编译器。
- No_Calendar (GNAT)
- No_Default_Initialization (GNAT)
- No_Direct_Boolean_Operators (GNAT)
- No_Dispatching_Calls (GNAT)
- No_Elaboration_Code (GNAT)
- No_Enumeration_Maps (GNAT)
- No_Entry_Calls_In_Elaboration_Code (GNAT)
- No_Entry_Queue (GNAT)
- No_Exception_Handlers (GNAT)
- No_Exception_Propagation (GNAT)
- No_Exception_Registration,之前名为 'No_Exception_Streams' (GNAT)
- No_Implementation_Restrictions (GNAT)
- No_Implicit_Aliasing (GNAT)
- No_Implicit_Conditionals (GNAT)
- No_Implicit_Dynamic_Code (GNAT)
- No_Implicit_Loops (GNAT)
- No_Initialize_Scalars (GNAT)
- No_Secondary_Stack (GNAT)
- No_Select_Statements (GNAT)
- No_Standard_Storage_Pools (GNAT)
- No_Streams (GNAT)
- No_Task_Attributes_Package (GNAT)
- No_Tasking (GNAT)
- No_Wide_Characters (GNAT)
- SPARK (GNAT)
- Static_Priorities (GNAT)
- Static_Storage_Size (GNAT)
以下示例演示了pragma
Restrictions的使用。请注意,在 Windows、Linux 和 macOS 上,给定的限制不会更改生成的代码。
pragma Restrictions (
Simple_Barriers,
No_Abort_Statements,
No_Asynchronous_Control,
No_Calendar,
No_Delay,
No_Dynamic_Attachment,
No_Dynamic_Priorities,
No_Enumeration_Maps,
No_Entry_Calls_In_Elaboration_Code,
No_Entry_Queue,
No_Exception_Registration,
No_Initialize_Scalars,
No_Local_Protected_Objects,
No_Protected_Type_Allocators,
No_Protected_Types,
No_Relative_Delay,
No_Requeue_Statements,
No_Select_Statements,
No_Streams,
No_Task_Allocators,
No_Task_Attributes_Package,
No_Task_Hierarchy,
No_Task_Termination,
No_Tasking,
No_Terminate_Alternatives,
No_Wide_Characters,
Static_Priorities,
Static_Storage_Size,
Immediate_Reclamation,
No_Implementation_Restrictions,
Max_Protected_Entries => 0,
Max_Protected_Entries => 0,
Max_Select_Alternatives => 0,
Max_Task_Entries => 0,
Max_Tasks => 0,
Max_Asynchronous_Select_Nesting => 0);
with Ada.Text_IO;
procedure Hello_World_Restricted is
begin
Ada.Text_IO.Put_Line ("Hello World!");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line ("This is a program with restricted runtime.");
end Hello_World_Restricted;
>alr run hello_world_restricted
ⓘ Building pragmas_restrictions=1.0.1/pragmas_restrictions.gpr...
Compile
[Ada] hello_world_restricted.adb
Bind
[gprbind] hello_world_restricted.bexch
[Ada] hello_world_restricted.ali
Link
[link] hello_world_restricted.adb
✓ Build finished successfully in 0.83 seconds.
Hello World!
This is a program with restricted runtime.