The definition of a User-defined operator carries quotes around the name, as do operators invoked in functional notation. The parser handles these as strings and their source position is that of the opening quote. This is awkward for GPS navigation, where we want the highlight of occurrences of the entity to mark the operator and not the starting quote. This patch modifies the sloc in the reference table accordingly.
The following command: gcc -c bla.adb grep "+" bla.ali must yield: 2V14 "+"{integer} 2>18 2>24 6b14 9l9 9t12 11s21 13s24 --- procedure Bla is function "+" (Left, Right : Integer) return Integer; Zero : constant Integer := 0; function "+" (Left, Right : Integer) return Integer is begin return 42; end "+"; A : Integer := 0 + 0; B : Integer := Bla."+" (Zero, 10); function ">=" (X, Y : Integer) return Boolean is begin return X > 0; end ">="; Yes : Boolean := A >= B; begin null; end Bla; Tested on x86_64-pc-linux-gnu, committed on trunk 2012-04-02 Ed Schonberg <schonb...@adacore.com> * lib-xref.adb (Generate_Reference): For a reference to an operator symbol, set the sloc to point to the first character of the operator name, and not to the initial quaote. (Output_References): Ditto for the definition of an operator symbol.
Index: lib-xref.adb =================================================================== --- lib-xref.adb (revision 186067) +++ lib-xref.adb (working copy) @@ -1031,6 +1031,15 @@ Ref := Original_Location (Sloc (Nod)); Def := Original_Location (Sloc (Ent)); + -- If this is an operator symbol, skip the initial + -- quote, for navigation purposes. + + if Nkind (N) = N_Defining_Operator_Symbol + or else Nkind (Nod) = N_Operator_Symbol + then + Ref := Ref + 1; + end if; + Add_Entry ((Ent => Ent, Loc => Ref, @@ -1718,11 +1727,24 @@ -- since at the time the reference or definition is made, private -- types may be swapped, and the Sloc value may be incorrect. We -- also set up the pointer vector for the sort. + -- For user-defined operators we need to skip the initial + -- quote and point to the first character of the name, for + -- navigation purposes. for J in 1 .. Nrefs loop - Rnums (J) := J; - Xrefs.Table (J).Def := - Original_Location (Sloc (Xrefs.Table (J).Key.Ent)); + declare + E : constant Entity_Id := Xrefs.Table (J).Key.Ent; + Loc : constant Source_Ptr := Original_Location (Sloc (E)); + + begin + Rnums (J) := J; + + if Nkind (E) = N_Defining_Operator_Symbol then + Xrefs.Table (J).Def := Loc + 1; + else + Xrefs.Table (J).Def := Loc; + end if; + end; end loop; -- Sort the references