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] fix handling of components and not null


Tested on i686-linux, committed on trunk

A component, discriminant, or object declaration that includes several
identifiers
is equivalent to separate declarations for each one of those identifiers. This
transformation is performed in the parser, which creates separate trees for
each one them. Instead of copying the tree for the subtype indication and
initial expression, the parser saves the state of the scanner at the end of the
list of identifiers, and restores it repeatedly for each successive identifier.
This forces  reparsing, and the construction of separate trees. However, the
routines that deal with discriminants and components saved the scanner state
after the colon, i.e. when the current token is the subtype mark. When restoring
the state of the scanner, the node corresponding to the subtype mark was reused
and shared during semantic analysis. As a result, the compiler did not diagnose
illegal declaration where some identifier in the list was a homograph of the
type name, because the type name was only resolved once (for the first identifier).

Compiling p2.ads below must produce the errors:

p2.ads:8:12: component "T" cannot be used before end of record declaration
p2.ads:11:22: object "Integer" cannot be used before end of its declaration
p2.ads:15:12: component "T" cannot be used before end of record declaration
p2.ads:18:17: discriminant "T" cannot be used before end of discriminant part
p2.ads:22:21: discriminant "T" cannot be used before end of discriminant part

package P2
is

   type T is range 1 .. 10;

   type R1 is record
      T1 : T; -- OK
      T  : T; -- illegal
   end record;

   Thing1, Integer : Integer;  --  Illegal

   type R2 is record
      T3,
      T  : T range 1..10;   -- Illegal
   end record;

   type T3 (T : T) is record   -- Illegal
     wow: integer;
   end record;

   type T4 (D1, T : T) is record   -- Illegal
     wow: integer;
   end record;
end P2;

This patch also causes the following error to be properly caught, it
was previously ignored:

     1. pragma Ada_05;
     2. package k is
     3.     type r is not null access integer;
     4.     type s is not null new r;
                      |
        >>> "not null" comes after "new", not before

     5. end k;

2007-06-06  Ed Schonberg  <schonberg@adacore.com>
	    Robert Dewar  <dewar@adacore.com>

	* par-ch12.adb (P_Generic_Associations): The source position of an
	Others association is that of the others keyword, not that of the token
	that follows the box.
	(P_Formal_Type_Definition): Handle formal access types that carry a
	not null indicator.

	* par-ch3.adb (P_Known_Discriminant_Part_Opt, P_Component_Items): If
	multiple identifier are present, save Scan_State before scanning the
	colon, to ensure that separate trees are constructed for each
	declaration.
	(P_Identifier_Declarations): For object declaration, set new flag
	Has_Init_Expression if initialization expression present.
	(P_Null_Exclusion): Properly diagnose NOT NULL coming before NULL
	Improve NOT NULL error messages

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]