| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- D I A G N O S T I C S . C O N S T R U C T O R S -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 27 |
with Diagnostics.Utils; use Diagnostics.Utils; |
| 28 |
|
| 29 |
package body Diagnostics.Constructors is |
| 30 |
|
| 31 |
----------------------------------------------- |
| 32 |
-- Make_Default_Iterator_Not_Primitive_Error -- |
| 33 |
----------------------------------------------- |
| 34 |
|
| 35 |
function Make_Default_Iterator_Not_Primitive_Error |
| 36 |
(Expr : Node_Id; |
| 37 |
Subp : Entity_Id) return Diagnostic_Type |
| 38 |
is |
| 39 |
begin |
| 40 |
return |
| 41 |
Make_Diagnostic |
| 42 |
(Msg => "improper function for default iterator", |
| 43 |
Location => Primary_Labeled_Span (Expr), |
| 44 |
Id => GNAT0001, |
| 45 |
Kind => Diagnostics.Error, |
| 46 |
Sub_Diags => |
| 47 |
(1 => |
| 48 |
Continuation |
| 49 |
(Msg => |
| 50 |
"default iterator defined " & |
| 51 |
Sloc_To_String (Subp, Sloc (Expr)) & |
| 52 |
" must be a local primitive or class-wide function", |
| 53 |
Locations => |
| 54 |
(1 => Primary_Labeled_Span (Subp))))); |
| 55 |
end Make_Default_Iterator_Not_Primitive_Error; |
| 56 |
|
| 57 |
------------------------------------------------- |
| 58 |
-- Record_Default_Iterator_Not_Primitive_Error -- |
| 59 |
------------------------------------------------- |
| 60 |
|
| 61 |
procedure Record_Default_Iterator_Not_Primitive_Error |
| 62 |
(Expr : Node_Id; |
| 63 |
Subp : Entity_Id) |
| 64 |
is |
| 65 |
begin |
| 66 |
Record_Diagnostic |
| 67 |
(Make_Default_Iterator_Not_Primitive_Error (Expr, Subp)); |
| 68 |
end Record_Default_Iterator_Not_Primitive_Error; |
| 69 |
|
| 70 |
--------------------------------------------------- |
| 71 |
-- Make_Invalid_Operand_Types_For_Operator_Error -- |
| 72 |
--------------------------------------------------- |
| 73 |
|
| 74 |
function Make_Invalid_Operand_Types_For_Operator_Error |
| 75 |
(Op : Node_Id; |
| 76 |
L : Node_Id; |
| 77 |
L_Type : Node_Id; |
| 78 |
R : Node_Id; |
| 79 |
R_Type : Node_Id) return Diagnostic_Type |
| 80 |
is |
| 81 |
begin |
| 82 |
return |
| 83 |
Make_Diagnostic |
| 84 |
(Msg => "invalid operand types for operator " & To_Name (Op), |
| 85 |
Location => Primary_Labeled_Span (Op), |
| 86 |
Id => GNAT0002, |
| 87 |
Kind => Diagnostics.Error, |
| 88 |
Spans => |
| 89 |
(1 => |
| 90 |
(Secondary_Labeled_Span |
| 91 |
(N => L, |
| 92 |
Label => To_Type_Name (L_Type))), |
| 93 |
2 => |
| 94 |
Secondary_Labeled_Span |
| 95 |
(N => R, |
| 96 |
Label => To_Type_Name (R_Type)))); |
| 97 |
end Make_Invalid_Operand_Types_For_Operator_Error; |
| 98 |
|
| 99 |
----------------------------------------------------- |
| 100 |
-- Record_Invalid_Operand_Types_For_Operator_Error -- |
| 101 |
----------------------------------------------------- |
| 102 |
|
| 103 |
procedure Record_Invalid_Operand_Types_For_Operator_Error |
| 104 |
(Op : Node_Id; |
| 105 |
L : Node_Id; |
| 106 |
L_Type : Node_Id; |
| 107 |
R : Node_Id; |
| 108 |
R_Type : Node_Id) |
| 109 |
is |
| 110 |
|
| 111 |
begin |
| 112 |
Record_Diagnostic |
| 113 |
(Make_Invalid_Operand_Types_For_Operator_Error |
| 114 |
(Op, L, L_Type, R, R_Type)); |
| 115 |
end Record_Invalid_Operand_Types_For_Operator_Error; |
| 116 |
|
| 117 |
--------------------------------------------------------- |
| 118 |
-- Make_Invalid_Operand_Types_For_Operator_L_Int_Error -- |
| 119 |
--------------------------------------------------------- |
| 120 |
|
| 121 |
function Make_Invalid_Operand_Types_For_Operator_L_Int_Error |
| 122 |
(Op : Node_Id; |
| 123 |
L : Node_Id; |
| 124 |
L_Type : Node_Id; |
| 125 |
R : Node_Id; |
| 126 |
R_Type : Node_Id) return Diagnostic_Type |
| 127 |
is |
| 128 |
begin |
| 129 |
return |
| 130 |
Make_Diagnostic |
| 131 |
(Msg => "invalid operand types for operator " & To_Name (Op), |
| 132 |
Location => Primary_Labeled_Span (Op), |
| 133 |
Id => GNAT0003, |
| 134 |
Kind => Diagnostics.Error, |
| 135 |
Spans => |
| 136 |
(1 => |
| 137 |
(Secondary_Labeled_Span |
| 138 |
(N => L, |
| 139 |
Label => |
| 140 |
"left operand has type " & |
| 141 |
To_Name (L_Type))), |
| 142 |
2 => |
| 143 |
Secondary_Labeled_Span |
| 144 |
(N => R, |
| 145 |
Label => |
| 146 |
"right operand has type " & |
| 147 |
To_Name (R_Type))), |
| 148 |
Sub_Diags => |
| 149 |
(1 => Suggestion (Msg => "Convert left operand to ""Integer""") |
| 150 |
) |
| 151 |
); |
| 152 |
end Make_Invalid_Operand_Types_For_Operator_L_Int_Error; |
| 153 |
|
| 154 |
----------------------------------------------------------- |
| 155 |
-- Record_Invalid_Operand_Types_For_Operator_L_Int_Error -- |
| 156 |
----------------------------------------------------------- |
| 157 |
|
| 158 |
procedure Record_Invalid_Operand_Types_For_Operator_L_Int_Error |
| 159 |
(Op : Node_Id; |
| 160 |
L : Node_Id; |
| 161 |
L_Type : Node_Id; |
| 162 |
R : Node_Id; |
| 163 |
R_Type : Node_Id) |
| 164 |
is |
| 165 |
|
| 166 |
begin |
| 167 |
Record_Diagnostic |
| 168 |
(Make_Invalid_Operand_Types_For_Operator_L_Int_Error |
| 169 |
(Op, L, L_Type, R, R_Type)); |
| 170 |
end Record_Invalid_Operand_Types_For_Operator_L_Int_Error; |
| 171 |
|
| 172 |
--------------------------------------------------------- |
| 173 |
-- Make_Invalid_Operand_Types_For_Operator_R_Int_Error -- |
| 174 |
--------------------------------------------------------- |
| 175 |
|
| 176 |
function Make_Invalid_Operand_Types_For_Operator_R_Int_Error |
| 177 |
(Op : Node_Id; |
| 178 |
L : Node_Id; |
| 179 |
L_Type : Node_Id; |
| 180 |
R : Node_Id; |
| 181 |
R_Type : Node_Id) return Diagnostic_Type |
| 182 |
is |
| 183 |
begin |
| 184 |
return |
| 185 |
Make_Diagnostic |
| 186 |
(Msg => "invalid operand types for operator " & To_Name (Op), |
| 187 |
Location => Primary_Labeled_Span (Op), |
| 188 |
Id => GNAT0004, |
| 189 |
Kind => Diagnostics.Error, |
| 190 |
Spans => |
| 191 |
(1 => |
| 192 |
Secondary_Labeled_Span |
| 193 |
(N => L, |
| 194 |
Label => |
| 195 |
"left operand has type " & |
| 196 |
To_Name (L_Type)), |
| 197 |
2 => |
| 198 |
Secondary_Labeled_Span |
| 199 |
(N => R, |
| 200 |
Label => |
| 201 |
"right operand has type " & |
| 202 |
To_Name (R_Type))), |
| 203 |
Sub_Diags => |
| 204 |
(1 => Suggestion (Msg => "Convert right operand to ""Integer""") |
| 205 |
) |
| 206 |
); |
| 207 |
end Make_Invalid_Operand_Types_For_Operator_R_Int_Error; |
| 208 |
|
| 209 |
----------------------------------------------------------- |
| 210 |
-- Record_Invalid_Operand_Types_For_Operator_R_Int_Error -- |
| 211 |
----------------------------------------------------------- |
| 212 |
|
| 213 |
procedure Record_Invalid_Operand_Types_For_Operator_R_Int_Error |
| 214 |
(Op : Node_Id; |
| 215 |
L : Node_Id; |
| 216 |
L_Type : Node_Id; |
| 217 |
R : Node_Id; |
| 218 |
R_Type : Node_Id) |
| 219 |
is |
| 220 |
|
| 221 |
begin |
| 222 |
Record_Diagnostic |
| 223 |
(Make_Invalid_Operand_Types_For_Operator_R_Int_Error |
| 224 |
(Op, L, L_Type, R, R_Type)); |
| 225 |
end Record_Invalid_Operand_Types_For_Operator_R_Int_Error; |
| 226 |
|
| 227 |
--------------------------------------------------------- |
| 228 |
-- Make_Invalid_Operand_Types_For_Operator_L_Acc_Error -- |
| 229 |
--------------------------------------------------------- |
| 230 |
|
| 231 |
function Make_Invalid_Operand_Types_For_Operator_L_Acc_Error |
| 232 |
(Op : Node_Id; |
| 233 |
L : Node_Id) return Diagnostic_Type |
| 234 |
is |
| 235 |
|
| 236 |
begin |
| 237 |
return |
| 238 |
Make_Diagnostic |
| 239 |
(Msg => "invalid operand types for operator " & To_Name (Op), |
| 240 |
Location => Primary_Labeled_Span (Op), |
| 241 |
Id => GNAT0005, |
| 242 |
Kind => Diagnostics.Error, |
| 243 |
Spans => |
| 244 |
(1 => |
| 245 |
Secondary_Labeled_Span |
| 246 |
(N => L, |
| 247 |
Label => |
| 248 |
"left operand is access type ") |
| 249 |
) |
| 250 |
); |
| 251 |
end Make_Invalid_Operand_Types_For_Operator_L_Acc_Error; |
| 252 |
|
| 253 |
----------------------------------------------------------- |
| 254 |
-- Record_Invalid_Operand_Types_For_Operator_L_Acc_Error -- |
| 255 |
----------------------------------------------------------- |
| 256 |
|
| 257 |
procedure Record_Invalid_Operand_Types_For_Operator_L_Acc_Error |
| 258 |
(Op : Node_Id; |
| 259 |
L : Node_Id) |
| 260 |
is |
| 261 |
begin |
| 262 |
Record_Diagnostic |
| 263 |
(Make_Invalid_Operand_Types_For_Operator_R_Acc_Error |
| 264 |
(Op, L)); |
| 265 |
end Record_Invalid_Operand_Types_For_Operator_L_Acc_Error; |
| 266 |
|
| 267 |
--------------------------------------------------------- |
| 268 |
-- Make_Invalid_Operand_Types_For_Operator_L_Acc_Error -- |
| 269 |
--------------------------------------------------------- |
| 270 |
|
| 271 |
function Make_Invalid_Operand_Types_For_Operator_R_Acc_Error |
| 272 |
(Op : Node_Id; |
| 273 |
R : Node_Id) return Diagnostic_Type |
| 274 |
is |
| 275 |
|
| 276 |
begin |
| 277 |
return |
| 278 |
Make_Diagnostic |
| 279 |
(Msg => "invalid operand types for operator " & To_Name (Op), |
| 280 |
Location => Primary_Labeled_Span (Op), |
| 281 |
Id => GNAT0006, |
| 282 |
Kind => Diagnostics.Error, |
| 283 |
Spans => |
| 284 |
(1 => |
| 285 |
Secondary_Labeled_Span |
| 286 |
(N => R, |
| 287 |
Label => |
| 288 |
"right operand is access type ") |
| 289 |
) |
| 290 |
); |
| 291 |
end Make_Invalid_Operand_Types_For_Operator_R_Acc_Error; |
| 292 |
|
| 293 |
----------------------------------------------------------- |
| 294 |
-- Record_Invalid_Operand_Types_For_Operator_R_Acc_Error -- |
| 295 |
----------------------------------------------------------- |
| 296 |
|
| 297 |
procedure Record_Invalid_Operand_Types_For_Operator_R_Acc_Error |
| 298 |
(Op : Node_Id; |
| 299 |
R : Node_Id) |
| 300 |
is |
| 301 |
begin |
| 302 |
Record_Diagnostic |
| 303 |
(Make_Invalid_Operand_Types_For_Operator_R_Acc_Error |
| 304 |
(Op, R)); |
| 305 |
end Record_Invalid_Operand_Types_For_Operator_R_Acc_Error; |
| 306 |
|
| 307 |
----------------------------------------------------------- |
| 308 |
-- Make_Invalid_Operand_Types_For_Operator_General_Error -- |
| 309 |
----------------------------------------------------------- |
| 310 |
|
| 311 |
function Make_Invalid_Operand_Types_For_Operator_General_Error |
| 312 |
(Op : Node_Id) return Diagnostic_Type |
| 313 |
is |
| 314 |
|
| 315 |
begin |
| 316 |
return |
| 317 |
Make_Diagnostic |
| 318 |
(Msg => "invalid operand types for operator " & To_Name (Op), |
| 319 |
Location => Primary_Labeled_Span (Op), |
| 320 |
Id => GNAT0007, |
| 321 |
Kind => Diagnostics.Error |
| 322 |
); |
| 323 |
end Make_Invalid_Operand_Types_For_Operator_General_Error; |
| 324 |
|
| 325 |
------------------------------------------------------------- |
| 326 |
-- Record_Invalid_Operand_Types_For_Operator_General_Error -- |
| 327 |
------------------------------------------------------------- |
| 328 |
|
| 329 |
procedure Record_Invalid_Operand_Types_For_Operator_General_Error |
| 330 |
(Op : Node_Id) |
| 331 |
is |
| 332 |
begin |
| 333 |
Record_Diagnostic |
| 334 |
(Make_Invalid_Operand_Types_For_Operator_General_Error (Op)); |
| 335 |
end Record_Invalid_Operand_Types_For_Operator_General_Error; |
| 336 |
|
| 337 |
-------------------------------------------------- |
| 338 |
-- Make_Pragma_No_Effect_With_Lock_Free_Warning -- |
| 339 |
-------------------------------------------------- |
| 340 |
|
| 341 |
function Make_Pragma_No_Effect_With_Lock_Free_Warning |
| 342 |
(Pragma_Node : Node_Id; Pragma_Name : Name_Id; |
| 343 |
Lock_Free_Node : Node_Id; Lock_Free_Range : Node_Id) |
| 344 |
return Diagnostic_Type |
| 345 |
is |
| 346 |
begin |
| 347 |
return |
| 348 |
Make_Diagnostic |
| 349 |
(Msg => |
| 350 |
"pragma " & '"' & Get_Name_String (Pragma_Name) & '"' & |
| 351 |
" for " & To_Name (Lock_Free_Node) & |
| 352 |
" has no effect when Lock_Free given", |
| 353 |
Location => Primary_Labeled_Span (Pragma_Node, "No effect"), |
| 354 |
Id => GNAT0008, |
| 355 |
Kind => Diagnostics.Warning, |
| 356 |
Spans => |
| 357 |
(1 => |
| 358 |
Labeled_Span |
| 359 |
(Span => To_Full_Span (Lock_Free_Range), |
| 360 |
Label => "Lock_Free in effect here", |
| 361 |
Is_Primary => False, |
| 362 |
Is_Region => True))); |
| 363 |
end Make_Pragma_No_Effect_With_Lock_Free_Warning; |
| 364 |
|
| 365 |
-------------------------------------------- |
| 366 |
-- Record_Pragma_No_Effect_With_Lock_Free -- |
| 367 |
-------------------------------------------- |
| 368 |
|
| 369 |
procedure Record_Pragma_No_Effect_With_Lock_Free_Warning |
| 370 |
(Pragma_Node : Node_Id; |
| 371 |
Pragma_Name : Name_Id; |
| 372 |
Lock_Free_Node : Node_Id; |
| 373 |
Lock_Free_Range : Node_Id) |
| 374 |
is |
| 375 |
begin |
| 376 |
Record_Diagnostic |
| 377 |
(Make_Pragma_No_Effect_With_Lock_Free_Warning |
| 378 |
(Pragma_Node, Pragma_Name, Lock_Free_Node, Lock_Free_Range)); |
| 379 |
end Record_Pragma_No_Effect_With_Lock_Free_Warning; |
| 380 |
|
| 381 |
---------------------------------- |
| 382 |
-- Make_End_Loop_Expected_Error -- |
| 383 |
---------------------------------- |
| 384 |
|
| 385 |
function Make_End_Loop_Expected_Error |
| 386 |
(End_Loc : Source_Span; |
| 387 |
Start_Loc : Source_Ptr) return Diagnostic_Type |
| 388 |
is |
| 389 |
begin |
| 390 |
return |
| 391 |
Make_Diagnostic |
| 392 |
(Msg => |
| 393 |
"""end loop;"" expected for ""loop"" " & |
| 394 |
Sloc_To_String (Start_Loc, End_Loc.Ptr), |
| 395 |
Location => Primary_Labeled_Span (End_Loc), |
| 396 |
Id => GNAT0009, |
| 397 |
Kind => Diagnostics.Error, |
| 398 |
Spans => (1 => Secondary_Labeled_Span (To_Span (Start_Loc))), |
| 399 |
Fixes => |
| 400 |
(1 => |
| 401 |
Fix |
| 402 |
(Description => "Replace with 'end loop;'", |
| 403 |
Edits => |
| 404 |
(1 => Edit (Text => "end loop;", Span => End_Loc)), |
| 405 |
Applicability => Legal))); |
| 406 |
end Make_End_Loop_Expected_Error; |
| 407 |
|
| 408 |
------------------------------------ |
| 409 |
-- Record_End_Loop_Expected_Error -- |
| 410 |
------------------------------------ |
| 411 |
|
| 412 |
procedure Record_End_Loop_Expected_Error |
| 413 |
(End_Loc : Source_Span; Start_Loc : Source_Ptr) |
| 414 |
is |
| 415 |
begin |
| 416 |
Record_Diagnostic (Make_End_Loop_Expected_Error (End_Loc, Start_Loc)); |
| 417 |
end Record_End_Loop_Expected_Error; |
| 418 |
|
| 419 |
---------------------------------------- |
| 420 |
-- Make_Representation_Too_Late_Error -- |
| 421 |
---------------------------------------- |
| 422 |
|
| 423 |
function Make_Representation_Too_Late_Error |
| 424 |
(Rep : Node_Id; |
| 425 |
Freeze : Node_Id; |
| 426 |
Def : Node_Id) |
| 427 |
return Diagnostic_Type |
| 428 |
is |
| 429 |
begin |
| 430 |
return |
| 431 |
Make_Diagnostic |
| 432 |
(Msg => |
| 433 |
"record representation cannot be specified" & |
| 434 |
" after the type is frozen", |
| 435 |
Location => |
| 436 |
Primary_Labeled_Span |
| 437 |
(N => Rep, |
| 438 |
Label => "record representation clause specified here"), |
| 439 |
Id => GNAT0010, |
| 440 |
Kind => Error, |
| 441 |
Spans => |
| 442 |
(1 => |
| 443 |
Secondary_Labeled_Span |
| 444 |
(N => Freeze, |
| 445 |
Label => |
| 446 |
"Type " & To_Name (Def) & " is frozen here"), |
| 447 |
2 => |
| 448 |
Secondary_Labeled_Span |
| 449 |
(N => Def, |
| 450 |
Label => |
| 451 |
"Type " & To_Name (Def) & " is declared here")), |
| 452 |
Sub_Diags => |
| 453 |
(1 => |
| 454 |
Suggestion |
| 455 |
(Msg => |
| 456 |
"move the record representation clause" & |
| 457 |
" before the freeze point " & |
| 458 |
Sloc_To_String (Sloc (Freeze), Sloc (Rep))))); |
| 459 |
end Make_Representation_Too_Late_Error; |
| 460 |
|
| 461 |
------------------------------------------ |
| 462 |
-- Record_Representation_Too_Late_Error -- |
| 463 |
------------------------------------------ |
| 464 |
|
| 465 |
procedure Record_Representation_Too_Late_Error |
| 466 |
(Rep : Node_Id; |
| 467 |
Freeze : Node_Id; |
| 468 |
Def : Node_Id) |
| 469 |
is |
| 470 |
begin |
| 471 |
Record_Diagnostic |
| 472 |
(Make_Representation_Too_Late_Error (Rep, Freeze, Def)); |
| 473 |
end Record_Representation_Too_Late_Error; |
| 474 |
|
| 475 |
------------------------------------------ |
| 476 |
-- Make_Mixed_Container_Aggregate_Error -- |
| 477 |
------------------------------------------ |
| 478 |
|
| 479 |
function Make_Mixed_Container_Aggregate_Error |
| 480 |
(Aggr : Node_Id; |
| 481 |
Pos_Elem : Node_Id; |
| 482 |
Named_Elem : Node_Id) return Diagnostic_Type |
| 483 |
is |
| 484 |
|
| 485 |
begin |
| 486 |
return |
| 487 |
Make_Diagnostic |
| 488 |
(Msg => |
| 489 |
"container aggregate cannot be both positional and named", |
| 490 |
Location => Primary_Labeled_Span (Aggr), |
| 491 |
Id => GNAT0011, |
| 492 |
Kind => Diagnostics.Error, |
| 493 |
Spans => |
| 494 |
(1 => Secondary_Labeled_Span |
| 495 |
(Pos_Elem, "positional element "), |
| 496 |
2 => Secondary_Labeled_Span |
| 497 |
(Named_Elem, "named element"))); |
| 498 |
end Make_Mixed_Container_Aggregate_Error; |
| 499 |
|
| 500 |
-------------------------------------------- |
| 501 |
-- Record_Mixed_Container_Aggregate_Error -- |
| 502 |
-------------------------------------------- |
| 503 |
|
| 504 |
procedure Record_Mixed_Container_Aggregate_Error |
| 505 |
(Aggr : Node_Id; |
| 506 |
Pos_Elem : Node_Id; |
| 507 |
Named_Elem : Node_Id) |
| 508 |
is |
| 509 |
begin |
| 510 |
Record_Diagnostic |
| 511 |
(Make_Mixed_Container_Aggregate_Error (Aggr, Pos_Elem, Named_Elem)); |
| 512 |
end Record_Mixed_Container_Aggregate_Error; |
| 513 |
|
| 514 |
end Diagnostics.Constructors; |