end Has_Aspect;
------------------
+ -- Is_Aspect_Id --
+ ------------------
+
+ function Is_Aspect_Id (Aspect : Name_Id) return Boolean is
+ (Get_Aspect_Id (Aspect) /= No_Aspect);
+
+ function Is_Aspect_Id (Aspect : Node_Id) return Boolean is
+ (Get_Aspect_Id (Aspect) /= No_Aspect);
+
+ ------------------
-- Move_Aspects --
------------------
-- Given an aspect specification, return the corresponding aspect_id value.
-- If the name does not match any aspect, return No_Aspect.
+ function Is_Aspect_Id (Aspect : Name_Id) return Boolean;
+ pragma Inline (Is_Aspect_Id);
+ -- Return True if a corresponding aspect id exists
+
+ function Is_Aspect_Id (Aspect : Node_Id) return Boolean;
+ pragma Inline (Is_Aspect_Id);
+ -- Return True if a corresponding aspect id exists
+
------------------------------------
-- Delaying Evaluation of Aspects --
------------------------------------
-- --
------------------------------------------------------------------------------
+with Aspects;
+with Snames;
with System.WCh_Cnv; use System.WCh_Cnv;
with GNAT.UTF_32_Spelling_Checker;
-- either Name_Buffer or Name_Len. The result is in Result (1 .. Length).
-- The caller must ensure that the result buffer is long enough.
+ ------------------------
+ -- Aspect_Spell_Check --
+ ------------------------
+
+ function Aspect_Spell_Check (Name : Name_Id) return Boolean is
+ (Aspect_Spell_Check (Name) /= No_Name);
+
+ function Aspect_Spell_Check (Name : Name_Id) return Name_Id is
+ use Aspects;
+ begin
+ for J in Aspect_Id_Exclude_No_Aspect loop
+ if Is_Bad_Spelling_Of (Name, Aspect_Names (J)) then
+ return Aspect_Names (J);
+ end if;
+ end loop;
+
+ return No_Name;
+ end Aspect_Spell_Check;
+
+ ---------------------------
+ -- Attribute_Spell_Check --
+ ---------------------------
+
+ function Attribute_Spell_Check (N : Name_Id) return Boolean is
+ (Attribute_Spell_Check (N) /= No_Name);
+
+ function Attribute_Spell_Check (N : Name_Id) return Name_Id is
+ use Snames;
+ begin
+ for J in First_Attribute_Name .. Last_Attribute_Name loop
+ if Is_Bad_Spelling_Of (N, J) then
+ return J;
+ end if;
+ end loop;
+
+ return No_Name;
+ end Attribute_Spell_Check;
+
----------------------------
-- Get_Name_String_UTF_32 --
----------------------------
package Namet.Sp is
+ function Aspect_Spell_Check (Name : Name_Id) return Boolean;
+ -- Returns True, if Name is a misspelling of some aspect name
+
+ function Aspect_Spell_Check (Name : Name_Id) return Name_Id;
+ -- Returns a possible correction, if Name is a misspelling of some aspect
+ -- name. If not, return No_Name.
+
+ function Attribute_Spell_Check (N : Name_Id) return Boolean;
+ -- Returns True, if Name is a misspelling of some attribute name
+
+ function Attribute_Spell_Check (N : Name_Id) return Name_Id;
+ -- Returns a possible correction, if Name is a misspelling of some
+ -- attribute name. If not, return No_Name.
+
function Is_Bad_Spelling_Of (Found, Expect : Name_Id) return Boolean;
-- Compares two identifier names from the names table, and returns True if
-- Found is a plausible misspelling of Expect. This function properly deals
Scan_State : Saved_Scan_State;
Result : Boolean;
- function Possible_Misspelled_Aspect return Boolean;
- -- Returns True, if Token_Name is a misspelling of some aspect name
-
function With_Present return Boolean;
-- Returns True if WITH is present, indicating presence of aspect
-- specifications. Also allows incorrect use of WHEN in place of WITH.
- --------------------------------
- -- Possible_Misspelled_Aspect --
- --------------------------------
-
- function Possible_Misspelled_Aspect return Boolean is
- begin
- for J in Aspect_Id_Exclude_No_Aspect loop
- if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
- return True;
- end if;
- end loop;
-
- return False;
- end Possible_Misspelled_Aspect;
-
------------------
-- With_Present --
------------------
Scan; -- past WHEN
if Token = Tok_Identifier
- and then Get_Aspect_Id (Token_Name) /= No_Aspect
+ and then Is_Aspect_Id (Token_Name)
then
Error_Msg_SC ("WHEN should be WITH");
Restore_Scan_State (Scan_State);
-- specification is ill-formed.
elsif not Strict then
- if Get_Aspect_Id (Token_Name) /= No_Aspect
- or else Possible_Misspelled_Aspect
+ if Is_Aspect_Id (Token_Name)
+ or else Aspect_Spell_Check (Token_Name)
then
Result := True;
else
-- is still an aspect specification so we give an appropriate message.
else
- if Get_Aspect_Id (Token_Name) = No_Aspect then
+ if not Is_Aspect_Id (Token_Name) then
Result := False;
else
begin
Check_Restriction (Msg_Issued, No_Unrecognized_Aspects, Aspect);
if not Msg_Issued then
- Error_Msg_Warn := not Debug_Flag_2;
- Error_Msg_N
- ("<<& is not a valid aspect identifier", Token_Node);
- OK := False;
+ Bad_Aspect (Token_Node, Token_Name, not Debug_Flag_2);
- -- Check bad spelling
+ OK := False;
- for J in Aspect_Id_Exclude_No_Aspect loop
- if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
- Error_Msg_Name_1 := Aspect_Names (J);
- Error_Msg_N -- CODEFIX
- ("\<<possible misspelling of%", Token_Node);
- exit;
- end if;
- end loop;
end if;
end;
-- Aspect => ...
if Token = Tok_Identifier
- and then Get_Aspect_Id (Token_Name) /= No_Aspect
+ and then Is_Aspect_Id (Token_Name)
then
Restore_Scan_State (Scan_State);
-- and proceed to the next aspect.
elsif Token = Tok_Identifier
- and then Get_Aspect_Id (Token_Name) /= No_Aspect
+ and then Is_Aspect_Id (Token_Name)
then
declare
Scan_State : Saved_Scan_State;
Scan; -- past semicolon
if Token = Tok_Identifier
- and then Get_Aspect_Id (Token_Name) /= No_Aspect
+ and then Is_Aspect_Id (Token_Name)
then
Scan; -- past identifier
-- current malformed aspect has been successfully skipped.
if Token = Tok_Identifier
- and then Get_Aspect_Id (Token_Name) /= No_Aspect
+ and then Is_Aspect_Id (Token_Name)
then
Restore_Scan_State (Scan_State);
exit;
Check_Restriction_No_Use_Of_Attribute (N);
- if Get_Aspect_Id (Chars (N)) /= No_Aspect then
+ if Is_Aspect_Id (Chars (N)) then
-- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
-- no aspect_specification, attribute_definition_clause, or pragma
-- is given.
Expr : Node_Id;
Val : Uint;
+ procedure Process_No_Specification_of_Aspect;
+ -- Process the No_Specification_of_Aspect restriction
+
+ procedure Process_No_Use_Of_Attribute;
+ -- Process the No_Use_Of_Attribute restriction
+
+ ----------------------------------------
+ -- Process_No_Specification_of_Aspect --
+ ----------------------------------------
+
+ procedure Process_No_Specification_of_Aspect is
+ Name : constant Name_Id := Chars (Expr);
+ begin
+ if Nkind (Expr) = N_Identifier
+ and then Is_Aspect_Id (Name)
+ then
+ Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
+ else
+ Bad_Aspect (Expr, Name, Warn => True);
+
+ raise Pragma_Exit;
+ end if;
+ end Process_No_Specification_of_Aspect;
+
+ ---------------------------------
+ -- Process_No_Use_Of_Attribute --
+ ---------------------------------
+
+ procedure Process_No_Use_Of_Attribute is
+ Name : constant Name_Id := Chars (Expr);
+ begin
+ if Nkind (Expr) = N_Identifier
+ and then Is_Attribute_Name (Name)
+ then
+ Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
+ else
+ Bad_Attribute (Expr, Name, Warn => True);
+ end if;
+
+ end Process_No_Use_Of_Attribute;
+
+ -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
+
begin
-- Ignore all Restrictions pragmas in CodePeer mode
-- Case of No_Specification_Of_Aspect => aspect-identifier
elsif Id = Name_No_Specification_Of_Aspect then
- declare
- A_Id : Aspect_Id;
-
- begin
- if Nkind (Expr) /= N_Identifier then
- A_Id := No_Aspect;
- else
- A_Id := Get_Aspect_Id (Chars (Expr));
- end if;
-
- if A_Id = No_Aspect then
- Error_Pragma_Arg ("invalid restriction name", Arg);
- else
- Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
- end if;
- end;
+ Process_No_Specification_of_Aspect;
-- Case of No_Use_Of_Attribute => attribute-identifier
elsif Id = Name_No_Use_Of_Attribute then
- if Nkind (Expr) /= N_Identifier
- or else not Is_Attribute_Name (Chars (Expr))
- then
- Error_Msg_N ("unknown attribute name??", Expr);
-
- else
- Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
- end if;
+ Process_No_Use_Of_Attribute;
-- Case of No_Use_Of_Entity => fully-qualified-name
Check_Restriction_No_Use_Of_Pragma (N);
- if Get_Aspect_Id (Chars (Pragma_Identifier (N))) /= No_Aspect then
+ if Is_Aspect_Id (Chars (Pragma_Identifier (N))) then
-- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
-- no aspect_specification, attribute_definition_clause, or pragma
-- is given.
and then Scope_Depth (ST) >= Scope_Depth (SCT);
end Available_Full_View_Of_Component;
+ ----------------
+ -- Bad_Aspect --
+ ----------------
+
+ procedure Bad_Aspect
+ (N : Node_Id;
+ Nam : Name_Id;
+ Warn : Boolean := False)
+ is
+ begin
+ Error_Msg_Warn := Warn;
+ Error_Msg_N ("<<& is not a valid aspect identifier", N);
+
+ -- Check bad spelling
+ Error_Msg_Name_1 := Aspect_Spell_Check (Nam);
+ if Error_Msg_Name_1 /= No_Name then
+ Error_Msg_N -- CODEFIX
+ ("\<<possible misspelling of %", N);
+ end if;
+ end Bad_Aspect;
+
-------------------
-- Bad_Attribute --
-------------------
is
begin
Error_Msg_Warn := Warn;
- Error_Msg_N ("unrecognized attribute&<<", N);
+ Error_Msg_N ("<<unrecognized attribute&", N);
-- Check for possible misspelling
- Error_Msg_Name_1 := First_Attribute_Name;
- while Error_Msg_Name_1 <= Last_Attribute_Name loop
- if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
- Error_Msg_N -- CODEFIX
- ("\possible misspelling of %<<", N);
- exit;
- end if;
-
- Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
- end loop;
+ Error_Msg_Name_1 := Attribute_Spell_Check (Nam);
+ if Error_Msg_Name_1 /= No_Name then
+ Error_Msg_N -- CODEFIX
+ ("\<<possible misspelling of %", N);
+ end if;
end Bad_Attribute;
--------------------------------
-- are open, and the scope of the array is not outside the scope of the
-- component.
+ procedure Bad_Aspect
+ (N : Node_Id;
+ Nam : Name_Id;
+ Warn : Boolean := False);
+ -- Called when node N is expected to contain a valid aspect name, and
+ -- Nam is found instead. If Warn is set True this is a warning, else this
+ -- is an error.
+
procedure Bad_Attribute
(N : Node_Id;
Nam : Name_Id;