1------------------------------------------------------------------------------ 2-- -- 3-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- 4-- -- 5-- A 4 G . Q U E R I E S -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1995-2013, Free Software Foundation, Inc. -- 10-- -- 11-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it -- 12-- under terms of the GNU General Public License as published by the Free -- 13-- Software Foundation; either version 2, or (at your option) any later -- 14-- version. ASIS-for-GNAT is distributed in the hope that it will be use- -- 15-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- 16-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- 17-- Public License for more details. You should have received a copy of the -- 18-- GNU General Public License distributed with ASIS-for-GNAT; see file -- 19-- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- 20-- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- 21-- -- 22-- -- 23-- -- 24-- -- 25-- -- 26-- -- 27-- -- 28-- -- 29-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- 30-- Software Engineering Laboratory of the Swiss Federal Institute of -- 31-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- 32-- Scientific Research Computer Center of Moscow State University (SRCC -- 33-- MSU), Russia, with funding partially provided by grants from the Swiss -- 34-- National Science Foundation and the Swiss Academy of Engineering -- 35-- Sciences. ASIS-for-GNAT is now maintained by AdaCore -- 36-- (http://www.adaccore.com). -- 37-- -- 38-- The original version of this component has been developed by Jean-Charles-- 39-- Marteau (Jean-Charles.Marteau@ensimag.imag.fr) and Serge Reboul -- 40-- (Serge.Reboul@ensimag.imag.fr), ENSIMAG High School Graduates (Computer -- 41-- sciences) Grenoble, France in Sema Group Grenoble, France. Now this -- 42-- component is maintained by the ASIS team -- 43-- -- 44------------------------------------------------------------------------------ 45 46pragma Ada_2012; 47 48with Asis; use Asis; 49 50---------------------------------------------------------- 51-- The goal of this package is, when we have an element -- 52-- to let us have ALL the possible queries for that -- 53-- element that return its children. -- 54---------------------------------------------------------- 55 56with Asis.Extensions.Flat_Kinds; use Asis.Extensions.Flat_Kinds; 57 58package A4G.Queries is 59 60 -- Structural_Queries is an enumeration of all the structural (syntactic) 61 -- queries. Note that these enumeration literals are overloaded with the 62 -- names of the query functions themselves. So for example, there is a 63 -- function Clause_Names in Asis.Clauses, and there is a corresponding 64 -- enumeration literal Clause_Names below. 65 66 type Structural_Queries is 67 (No_Query, 68 69 -- The following are queries of Compilation_Unit 70 71 Context_Clause_Elements, 72 Unit_Declaration, 73 Pragmas_After, 74 75 -- The following are Boolean queries, used only by gnat2xml. These are 76 -- not used in ASIS itself. Subtype Boolean_Queries below needs to be 77 -- kept in synch with this. 78 79 Has_Aliased, 80 Has_Null_Exclusion, 81 Is_Not_Null_Return, 82 Has_Reverse, 83 Has_Limited, 84 Has_Synchronized, 85 Has_Private, 86 Has_Abstract, 87 Has_Tagged, 88 Is_Overriding_Declaration, 89 Is_Not_Overriding_Declaration, 90 Is_Prefix_Call, 91 Is_Prefix_Notation, 92 93 -- The rest below are the normal queries of Elements 94 95 -- Queries in A4G.Queries: 96 All_But_First_Associations, 97 First_Parameter_Association, 98 99 -- Queries in Asis.Clauses: 100 Clause_Names, 101 Component_Clause_Position, 102 Component_Clause_Range, 103 Component_Clauses, 104 Mod_Clause_Expression, 105 Representation_Clause_Expression, 106 Representation_Clause_Name, 107 108 -- Queries in Asis.Declarations: 109 Aspect_Specifications, 110 Body_Declarative_Items, 111 Body_Exception_Handlers, 112 Body_Statements, 113 Declaration_Interface_List, 114 Defining_Prefix, 115 Defining_Selector, 116 Discriminant_Part, 117 Entry_Barrier, 118 Entry_Family_Definition, 119 Entry_Index_Specification, 120 Generic_Actual_Part, 121 Generic_Formal_Part, 122 Generic_Unit_Name, 123 Initialization_Expression, 124 Iteration_Scheme_Name, 125 Names, 126 Object_Declaration_View, 127 Parameter_Profile, 128 Private_Part_Declarative_Items, 129 Protected_Operation_Items, 130 Renamed_Entity, 131 Result_Expression, 132 Result_Profile, 133 Specification_Subtype_Definition, 134 Subtype_Indication, 135 Type_Declaration_View, 136 Visible_Part_Declarative_Items, 137 138 -- Queries in Asis.Definitions: 139 Access_To_Function_Result_Profile, 140 Access_To_Object_Definition, 141 Access_To_Subprogram_Parameter_Profile, 142 Ancestor_Subtype_Indication, 143 Anonymous_Access_To_Object_Subtype_Mark, 144 Array_Component_Definition, 145 Aspect_Definition, 146 Aspect_Mark, 147 Component_Definition_View, 148 Definition_Interface_List, 149 Delta_Expression, 150 Digits_Expression, 151 Discrete_Ranges, 152 Discrete_Subtype_Definitions, 153 Discriminant_Associations, 154 Discriminant_Direct_Name, 155 Discriminants, 156 Enumeration_Literal_Declarations, 157 Index_Subtype_Definitions, 158 Integer_Constraint, 159 Lower_Bound, 160 Mod_Static_Expression, 161 Parent_Subtype_Indication, 162 Private_Part_Items, 163 Range_Attribute, 164 Real_Range_Constraint, 165 Record_Components, 166 Record_Definition, 167 Subtype_Constraint, 168 Subtype_Mark, 169 Upper_Bound, 170 Variant_Choices, 171 Variants, 172 Visible_Part_Items, 173 174 -- Queries in Asis.Elements: 175 Pragma_Argument_Associations, 176 177 -- Queries in Asis.Expressions: 178 Actual_Parameter, 179 Allocator_Qualified_Expression, 180 Allocator_Subtype_Indication, 181 Array_Component_Associations, 182 Array_Component_Choices, 183 Attribute_Designator_Expressions, 184 Attribute_Designator_Identifier, 185 Component_Expression, 186 Converted_Or_Qualified_Expression, 187 Converted_Or_Qualified_Subtype_Mark, 188 Dependent_Expression, 189 Discriminant_Expression, 190 Discriminant_Selector_Names, 191 Expression_Parenthesized, 192 Expression_Paths, 193 Extension_Aggregate_Expression, 194 Formal_Parameter, 195 Function_Call_Parameters, 196 Index_Expressions, 197 Iterator_Specification, 198 Membership_Test_Choices, 199 Membership_Test_Expression, 200 Predicate, 201 Prefix, 202 Record_Component_Associations, 203 Record_Component_Choices, 204 Selector, 205 Short_Circuit_Operation_Left_Expression, 206 Short_Circuit_Operation_Right_Expression, 207 Slice_Range, 208 Subpool_Name, 209 210 -- Queries in Asis.Extensions: 211 Formal_Subprogram_Default, 212 213 -- Queries in Asis.Statements: 214 Aborted_Tasks, 215 Accept_Body_Exception_Handlers, 216 Accept_Body_Statements, 217 Accept_Entry_Direct_Name, 218 Accept_Entry_Index, 219 Accept_Parameters, 220 Assignment_Expression, 221 Assignment_Variable_Name, 222 Associated_Message, 223 Block_Declarative_Items, 224 Block_Exception_Handlers, 225 Block_Statements, 226 Called_Name, 227 Call_Statement_Parameters, 228 Case_Expression, 229 Case_Path_Alternative_Choices, 230 Choice_Parameter_Specification, 231 Condition_Expression, 232 Delay_Expression, 233 Exception_Choices, 234 Exit_Condition, 235 Exit_Loop_Name, 236 Extended_Return_Exception_Handlers, 237 Extended_Return_Statements, 238 For_Loop_Parameter_Specification, 239 Goto_Label, 240 Guard, 241 Handler_Statements, 242 Label_Names, 243 Loop_Statements, 244 Qualified_Expression, 245 Raised_Exception, 246 Requeue_Entry_Name, 247 Return_Expression, 248 Return_Object_Declaration, 249 Sequence_Of_Statements, 250 Statement_Identifier, 251 Statement_Paths, 252 While_Condition 253 ); -- end Structural_Queries 254 255 subtype Boolean_Queries is Structural_Queries 256 range Has_Aliased .. Is_Prefix_Notation; 257 258 type Query_Kinds is 259 (Bug, 260 -- just for the discriminant default expression 261 Single_Element_Query, 262 -- Queries taking an element and returning an element. 263 Element_List_Query, 264 -- Queries taking an element and returning a list of elements. 265 Element_List_Query_With_Boolean, 266 -- Queries taking an element and a boolean and returning a list 267 -- of elements. 268 Boolean_Query, 269 -- Queries taking an element and returning a Boolean. These are used in 270 -- gnat2xml. 271 Single_Element_CU_Query, 272 -- Queries taking Compilation_Unit and returning an element. 273 Element_List_CU_Query 274 -- Queries taking a Compilation_Unit and returning a list of elements. 275 ); 276 277 subtype CU_Query_Kinds is Query_Kinds range 278 Single_Element_CU_Query .. Element_List_CU_Query; 279 280 type A_Single_Element_CU_Query is access 281 function (Elem : Asis.Compilation_Unit) return Asis.Element; 282 283 type A_Element_List_CU_Query is access 284 function 285 (Elem : Asis.Compilation_Unit; 286 Bool : Boolean) 287 return Asis.Element_List; 288 289 type A_Single_Element_Query is access 290 function (Elem : Asis.Element) return Asis.Element; 291 292 type A_Element_List_Query is access 293 function (Elem : Asis.Element) return Asis.Element_List; 294 295 type A_Element_List_Query_With_Boolean is access 296 function 297 (Elem : Asis.Element; 298 Bool : Boolean) 299 return Asis.Element_List; 300 301 type A_Boolean_Query is access 302 function 303 (Elem : Asis.Element) 304 return Boolean; 305 306 -- Discriminated record that can access any type of query. 307 type Func_Elem 308 (Q : Structural_Queries := Structural_Queries'First; 309 Query_Kind : Query_Kinds := Bug) 310 is 311 record 312 case Query_Kind is 313 when Bug => 314 null; 315 when Single_Element_CU_Query => 316 Func_Simple_CU : A_Single_Element_CU_Query; 317 when Element_List_CU_Query => 318 Func_List_CU : A_Element_List_CU_Query; 319 when Single_Element_Query => 320 Func_Simple : A_Single_Element_Query; 321 when Element_List_Query => 322 Func_List : A_Element_List_Query; 323 when Element_List_Query_With_Boolean => 324 Func_List_Boolean : A_Element_List_Query_With_Boolean; 325 Bool : Boolean; 326 when Boolean_Query => 327 Func_Boolean : A_Boolean_Query; 328 end case; 329 end record; 330 331 type Query_Index is new Positive; 332 subtype Query_Count is Query_Index'Base range 0 .. Query_Index'Last; 333 type Func_Elem_Array is array (Query_Index range <>) of Func_Elem; 334 335 type Query_List is array (Query_Index range <>) of Structural_Queries; 336 type Query_List_Ptr is access constant Query_List; 337 338 No_Queries : aliased constant Query_List := (1 .. 0 => <>); 339 340 -- Appropriate_Queries returns the sequence of syntactic queries that 341 -- applies to a given element or element kind. Syntactic determines the 342 -- handling of prefix-notation calls; see Asis.Extensions.Iterator for 343 -- details. 344 345 function Appropriate_Queries 346 (Kind : Flat_Element_Kinds'Base) return Query_List_Ptr; 347 -- This version operates on an element kind, and behaves as if Syntactic is 348 -- False. 349 350 function Appropriate_Queries 351 (Element : Asis.Element; Syntactic : Boolean) 352 return Query_List_Ptr; 353 -- This version operates on an element, and takes the Syntactic parameter 354 -- into account. 355 356 function Appropriate_Queries 357 (Element : Asis.Element; Syntactic : Boolean := True) 358 return Func_Elem_Array; 359 -- This version is similar to the previous one, but returns the information 360 -- in a different form (a Func_Elem_Array instead of a Query_List_Ptr). 361 -- ???We can probably get rid of this last one at some point. 362 363 function Num_Queries 364 (Kind : Flat_Element_Kinds'Base) return A4G.Queries.Query_Count; 365 -- Number of queries (i.e. subelements), assuming Syntactic = False. 366 367 function Get_Func_Elem (Q : Structural_Queries) return Func_Elem; 368 -- Get the Func_Elem corresponding to the given query, showing the 369 -- parameter and result type profile, and the actual Ada function to call. 370 371 -- The following table is a mapping from queries to the type returned by 372 -- that query. Queries can also return a Nil_Element. Currently used in 373 -- gnat2xml. 374 375 type Query_Result_Type_Table is 376 array (Structural_Queries) of Flat_Element_Kinds'Base; 377 378 Query_Result_Types : constant Query_Result_Type_Table := 379 (No_Query => 380 Not_An_Element, 381 382 -- The following are queries of Compilation_Unit 383 384 Context_Clause_Elements => 385 A_Context_Clause_List, 386 Unit_Declaration => 387 A_Declaration_Class, 388 Pragmas_After => 389 An_Element_List, 390 391 -- For the Boolean queries, the values below show what is returned to 392 -- mean True. These queries can also return Not_An_Element, which means 393 -- False. So for example Has_Aliased returns An_Aliased if "aliased" is 394 -- present in the source code, and Not_An_Element otherwise. 395 396 Has_Aliased => 397 An_Aliased, 398 Has_Null_Exclusion => 399 A_Null_Exclusion, 400 Is_Not_Null_Return => 401 A_Not_Null_Return, 402 Has_Reverse => 403 A_Reverse, 404 Has_Limited => 405 A_Limited, 406 Has_Synchronized => 407 A_Synchronized, 408 Has_Private => 409 A_Private, 410 Has_Abstract => 411 An_Abstract, 412 Has_Tagged => 413 A_Tagged, 414 Is_Overriding_Declaration => 415 An_Overriding, 416 Is_Not_Overriding_Declaration => 417 A_Not_Overriding, 418 Is_Prefix_Call => 419 An_Is_Prefix_Call, 420 Is_Prefix_Notation => 421 An_Is_Prefix_Notation, 422 423 -- Queries in A4G.Queries: 424 All_But_First_Associations => 425 An_Association_List, 426 First_Parameter_Association => 427 An_Association_Class, 428 429 -- Queries in Asis.Clauses: 430 Clause_Names => 431 A_Name_List, 432 Component_Clause_Position => 433 An_Expression_Class, 434 Component_Clause_Range => 435 A_Discrete_Range_Class, 436 Component_Clauses => 437 A_Component_Clause_List, 438 Mod_Clause_Expression => 439 An_Expression_Class, 440 Representation_Clause_Expression => 441 An_Expression_Class, 442 Representation_Clause_Name => 443 A_Name_Class, 444 445 -- Queries in Asis.Declarations: 446 Aspect_Specifications => 447 An_Element_List, 448 Body_Declarative_Items => 449 An_Element_List, 450 Body_Exception_Handlers => 451 An_Exception_Handler_List, 452 Body_Statements => 453 A_Statement_List, 454 Declaration_Interface_List => 455 An_Expression_List, 456 Defining_Prefix => 457 A_Name_Class, 458 Defining_Selector => 459 A_Defining_Name_Class, 460 Discriminant_Part => 461 A_Definition_Class, 462 Entry_Barrier => 463 An_Expression_Class, 464 Entry_Family_Definition => 465 A_Discrete_Subtype_Definition_Class, 466 Entry_Index_Specification => 467 A_Declaration_Class, 468 Generic_Actual_Part => 469 An_Association_List, 470 Generic_Formal_Part => 471 An_Element_List, 472 Generic_Unit_Name => 473 An_Expression_Class, 474 Initialization_Expression => 475 An_Expression_Class, 476 Iteration_Scheme_Name => 477 An_Element_Class, 478 Names => 479 A_Defining_Name_List, 480 Object_Declaration_View => 481 A_Definition_Class, 482 Parameter_Profile => 483 A_Parameter_Specification_List, 484 Private_Part_Declarative_Items => 485 A_Declarative_Item_List, 486 Protected_Operation_Items => 487 A_Declaration_List, 488 Renamed_Entity => 489 An_Expression_Class, 490 Result_Expression => 491 An_Expression_Class, 492 Result_Profile => 493 An_Element_Class, 494 Specification_Subtype_Definition => 495 A_Discrete_Subtype_Definition_Class, 496 Subtype_Indication => 497 An_Element_Class, 498 Type_Declaration_View => 499 A_Definition_Class, 500 Visible_Part_Declarative_Items => 501 A_Declarative_Item_List, 502 503 -- Queries in Asis.Definitions: 504 Access_To_Function_Result_Profile => 505 An_Element_Class, 506 Access_To_Object_Definition => 507 A_Subtype_Indication, 508 Access_To_Subprogram_Parameter_Profile => 509 A_Parameter_Specification_List, 510 Ancestor_Subtype_Indication => 511 A_Subtype_Indication, 512 Anonymous_Access_To_Object_Subtype_Mark => 513 An_Expression_Class, 514 Array_Component_Definition => 515 A_Component_Definition, 516 Aspect_Definition => 517 An_Element_Class, 518 Aspect_Mark => 519 An_Element_Class, 520 Component_Definition_View => 521 A_Definition_Class, 522 Definition_Interface_List => 523 An_Expression_List, 524 Delta_Expression => 525 An_Expression_Class, 526 Digits_Expression => 527 An_Expression_Class, 528 Discrete_Ranges => 529 A_Discrete_Range_List, 530 Discrete_Subtype_Definitions => 531 A_Definition_List, 532 Discriminant_Associations => 533 A_Discriminant_Association_List, 534 Discriminant_Direct_Name => 535 A_Name_Class, 536 Discriminants => 537 A_Discriminant_Specification_List, 538 Enumeration_Literal_Declarations => 539 A_Declaration_List, 540 Index_Subtype_Definitions => 541 An_Expression_List, 542 Integer_Constraint => 543 A_Range_Constraint_Class, 544 Lower_Bound => 545 An_Expression_Class, 546 Mod_Static_Expression => 547 An_Expression_Class, 548 Parent_Subtype_Indication => 549 A_Subtype_Indication, 550 Private_Part_Items => 551 A_Declarative_Item_List, 552 Range_Attribute => 553 An_Expression_Class, 554 Real_Range_Constraint => 555 A_Range_Constraint_Class, 556 Record_Components => 557 A_Record_Component_List, 558 Record_Definition => 559 A_Definition_Class, 560 Subtype_Constraint => 561 A_Constraint_Class, 562 Subtype_Mark => 563 An_Expression_Class, 564 Upper_Bound => 565 An_Expression_Class, 566 Variant_Choices => 567 An_Element_List, 568 Variants => 569 A_Variant_List, 570 Visible_Part_Items => 571 A_Declarative_Item_List, 572 573 -- Queries in Asis.Elements: 574 Pragma_Argument_Associations => 575 An_Association_List, 576 577 -- Queries in Asis.Expressions: 578 Actual_Parameter => 579 An_Expression_Class, 580 Allocator_Qualified_Expression => 581 An_Expression_Class, 582 Allocator_Subtype_Indication => 583 A_Subtype_Indication, 584 Array_Component_Associations => 585 An_Association_List, 586 Array_Component_Choices => 587 An_Element_List, 588 Attribute_Designator_Expressions => 589 An_Expression_List, 590 Attribute_Designator_Identifier => 591 An_Expression_Class, 592 Component_Expression => 593 An_Expression_Class, 594 Converted_Or_Qualified_Expression => 595 An_Expression_Class, 596 Converted_Or_Qualified_Subtype_Mark => 597 An_Expression_Class, 598 Dependent_Expression => 599 An_Expression_Class, 600 Discriminant_Expression => 601 An_Expression_Class, 602 Discriminant_Selector_Names => 603 An_Expression_List, 604 Expression_Parenthesized => 605 An_Expression_Class, 606 Expression_Paths => 607 An_Element_List, 608 Extension_Aggregate_Expression => 609 An_Expression_Class, 610 Formal_Parameter => 611 An_Element_Class, 612 Function_Call_Parameters => 613 An_Association_List, 614 Index_Expressions => 615 An_Expression_List, 616 Iterator_Specification => 617 A_Declaration_Class, 618 Membership_Test_Choices => 619 An_Element_List, 620 Membership_Test_Expression => 621 An_Expression_Class, 622 Predicate => 623 An_Expression_Class, 624 Prefix => 625 An_Expression_Class, 626 Record_Component_Associations => 627 An_Association_List, 628 Record_Component_Choices => 629 An_Expression_List, 630 Selector => 631 An_Expression_Class, 632 Short_Circuit_Operation_Left_Expression => 633 An_Expression_Class, 634 Short_Circuit_Operation_Right_Expression => 635 An_Expression_Class, 636 Slice_Range => 637 A_Discrete_Range_Class, 638 Subpool_Name => 639 An_Expression_Class, 640 641 -- Queries in Asis.Extensions: 642 Formal_Subprogram_Default => 643 An_Expression_Class, 644 645 -- Queries in Asis.Statements: 646 Aborted_Tasks => 647 An_Expression_List, 648 Accept_Body_Exception_Handlers => 649 A_Statement_List, 650 Accept_Body_Statements => 651 A_Statement_List, 652 Accept_Entry_Direct_Name => 653 A_Name_Class, 654 Accept_Entry_Index => 655 An_Expression_Class, 656 Accept_Parameters => 657 A_Parameter_Specification_List, 658 Assignment_Expression => 659 An_Expression_Class, 660 Assignment_Variable_Name => 661 An_Expression_Class, 662 Associated_Message => 663 An_Expression_Class, 664 Block_Declarative_Items => 665 A_Declarative_Item_List, 666 Block_Exception_Handlers => 667 An_Exception_Handler_List, 668 Block_Statements => 669 A_Statement_List, 670 Called_Name => 671 An_Expression_Class, 672 Call_Statement_Parameters => 673 An_Association_List, 674 Case_Expression => 675 An_Expression_Class, 676 Case_Path_Alternative_Choices => 677 An_Element_List, 678 Choice_Parameter_Specification => 679 A_Declaration_Class, 680 Condition_Expression => 681 An_Expression_Class, 682 Delay_Expression => 683 An_Expression_Class, 684 Exception_Choices => 685 An_Element_List, 686 Exit_Condition => 687 An_Expression_Class, 688 Exit_Loop_Name => 689 An_Expression_Class, 690 Extended_Return_Exception_Handlers => 691 An_Exception_Handler_List, 692 Extended_Return_Statements => 693 A_Statement_List, 694 For_Loop_Parameter_Specification => 695 A_Declaration_Class, 696 Goto_Label => 697 An_Expression_Class, 698 Guard => 699 An_Expression_Class, 700 Handler_Statements => 701 A_Statement_List, 702 Label_Names => 703 A_Defining_Name_List, 704 Loop_Statements => 705 A_Statement_List, 706 Qualified_Expression => 707 An_Expression_Class, 708 Raised_Exception => 709 An_Expression_Class, 710 Requeue_Entry_Name => 711 A_Name_Class, 712 Return_Expression => 713 An_Expression_Class, 714 Return_Object_Declaration => 715 A_Declaration_Class, 716 Sequence_Of_Statements => 717 A_Statement_List, 718 Statement_Identifier => 719 A_Defining_Name_Class, 720 Statement_Paths => 721 A_Path_List, 722 While_Condition => 723 An_Expression_Class 724 ); -- end Query_Result_Types 725 726end A4G.Queries; 727