1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2010, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars
; use Err_Vars
;
27 with Prj
.Attr
; use Prj
.Attr
;
28 with Prj
.Err
; use Prj
.Err
;
31 with Uintp
; use Uintp
;
33 package body Prj
.Strt
is
35 Buffer
: String_Access
;
36 Buffer_Last
: Natural := 0;
38 type Choice_String
is record
40 Already_Used
: Boolean := False;
42 -- The string of a case label, and an indication that it has already
43 -- been used (to avoid duplicate case labels).
45 Choices_Initial
: constant := 10;
46 Choices_Increment
: constant := 100;
47 -- These should be in alloc.ads
49 Choice_Node_Low_Bound
: constant := 0;
50 Choice_Node_High_Bound
: constant := 099_999_999
;
51 -- In practice, infinite
53 type Choice_Node_Id
is
54 range Choice_Node_Low_Bound
.. Choice_Node_High_Bound
;
56 First_Choice_Node_Id
: constant Choice_Node_Id
:=
57 Choice_Node_Low_Bound
;
61 (Table_Component_Type
=> Choice_String
,
62 Table_Index_Type
=> Choice_Node_Id
'Base,
63 Table_Low_Bound
=> First_Choice_Node_Id
,
64 Table_Initial
=> Choices_Initial
,
65 Table_Increment
=> Choices_Increment
,
66 Table_Name
=> "Prj.Strt.Choices");
67 -- Used to store the case labels and check that there is no duplicate
69 package Choice_Lasts
is
71 (Table_Component_Type
=> Choice_Node_Id
,
72 Table_Index_Type
=> Nat
,
75 Table_Increment
=> 100,
76 Table_Name
=> "Prj.Strt.Choice_Lasts");
77 -- Used to store the indexes of the choices in table Choices, to
78 -- distinguish nested case constructions.
80 Choice_First
: Choice_Node_Id
:= 0;
81 -- Index in table Choices of the first case label of the current
82 -- case construction. Zero means no current case construction.
84 type Name_Location
is record
85 Name
: Name_Id
:= No_Name
;
86 Location
: Source_Ptr
:= No_Location
;
88 -- Store the identifier and the location of a simple name
92 (Table_Component_Type
=> Name_Location
,
93 Table_Index_Type
=> Nat
,
96 Table_Increment
=> 100,
97 Table_Name
=> "Prj.Strt.Names");
98 -- Used to accumulate the single names of a name
100 procedure Add
(This_String
: Name_Id
);
101 -- Add a string to the case label list, indicating that it has not
104 procedure Add_To_Names
(NL
: Name_Location
);
105 -- Add one single names to table Names
107 procedure External_Reference
108 (In_Tree
: Project_Node_Tree_Ref
;
109 Current_Project
: Project_Node_Id
;
110 Current_Package
: Project_Node_Id
;
111 External_Value
: out Project_Node_Id
;
112 Expr_Kind
: in out Variable_Kind
;
113 Flags
: Processing_Flags
);
114 -- Parse an external reference. Current token is "external"
116 procedure Attribute_Reference
117 (In_Tree
: Project_Node_Tree_Ref
;
118 Reference
: out Project_Node_Id
;
119 First_Attribute
: Attribute_Node_Id
;
120 Current_Project
: Project_Node_Id
;
121 Current_Package
: Project_Node_Id
;
122 Flags
: Processing_Flags
);
123 -- Parse an attribute reference. Current token is an apostrophe
126 (In_Tree
: Project_Node_Tree_Ref
;
127 Term
: out Project_Node_Id
;
128 Expr_Kind
: in out Variable_Kind
;
129 Current_Project
: Project_Node_Id
;
130 Current_Package
: Project_Node_Id
;
131 Optional_Index
: Boolean;
132 Flags
: Processing_Flags
);
133 -- Recursive procedure to parse one term or several terms concatenated
140 procedure Add
(This_String
: Name_Id
) is
142 Choices
.Increment_Last
;
143 Choices
.Table
(Choices
.Last
) :=
144 (The_String
=> This_String
,
145 Already_Used
=> False);
152 procedure Add_To_Names
(NL
: Name_Location
) is
154 Names
.Increment_Last
;
155 Names
.Table
(Names
.Last
) := NL
;
158 -------------------------
159 -- Attribute_Reference --
160 -------------------------
162 procedure Attribute_Reference
163 (In_Tree
: Project_Node_Tree_Ref
;
164 Reference
: out Project_Node_Id
;
165 First_Attribute
: Attribute_Node_Id
;
166 Current_Project
: Project_Node_Id
;
167 Current_Package
: Project_Node_Id
;
168 Flags
: Processing_Flags
)
170 Current_Attribute
: Attribute_Node_Id
:= First_Attribute
;
173 -- Declare the node of the attribute reference
177 (Of_Kind
=> N_Attribute_Reference
, In_Tree
=> In_Tree
);
178 Set_Location_Of
(Reference
, In_Tree
, To
=> Token_Ptr
);
179 Scan
(In_Tree
); -- past apostrophe
181 -- Body may be an attribute name
183 if Token
= Tok_Body
then
184 Token
:= Tok_Identifier
;
185 Token_Name
:= Snames
.Name_Body
;
188 Expect
(Tok_Identifier
, "identifier");
190 if Token
= Tok_Identifier
then
191 Set_Name_Of
(Reference
, In_Tree
, To
=> Token_Name
);
193 -- Check if the identifier is one of the attribute identifiers in the
194 -- context (package or project level attributes).
197 Attribute_Node_Id_Of
(Token_Name
, Starting_At
=> First_Attribute
);
199 -- If the identifier is not allowed, report an error
201 if Current_Attribute
= Empty_Attribute
then
202 Error_Msg_Name_1
:= Token_Name
;
203 Error_Msg
(Flags
, "unknown attribute %%", Token_Ptr
);
204 Reference
:= Empty_Node
;
206 -- Scan past the attribute name
211 -- Give its characteristics to this attribute reference
213 Set_Project_Node_Of
(Reference
, In_Tree
, To
=> Current_Project
);
214 Set_Package_Node_Of
(Reference
, In_Tree
, To
=> Current_Package
);
215 Set_Expression_Kind_Of
216 (Reference
, In_Tree
, To
=> Variable_Kind_Of
(Current_Attribute
));
219 To
=> Attribute_Kind_Of
(Current_Attribute
) in
220 All_Case_Insensitive_Associative_Array
);
222 -- Scan past the attribute name
226 -- If the attribute is an associative array, get the index
228 if Attribute_Kind_Of
(Current_Attribute
) /= Single
then
229 Expect
(Tok_Left_Paren
, "`(`");
231 if Token
= Tok_Left_Paren
then
234 if Others_Allowed_For
(Current_Attribute
)
235 and then Token
= Tok_Others
237 Set_Associative_Array_Index_Of
238 (Reference
, In_Tree
, To
=> All_Other_Names
);
242 if Others_Allowed_For
(Current_Attribute
) then
244 (Tok_String_Literal
, "literal string or others");
246 Expect
(Tok_String_Literal
, "literal string");
249 if Token
= Tok_String_Literal
then
250 Set_Associative_Array_Index_Of
251 (Reference
, In_Tree
, To
=> Token_Name
);
257 Expect
(Tok_Right_Paren
, "`)`");
259 if Token
= Tok_Right_Paren
then
265 -- Change name of obsolete attributes
267 if Present
(Reference
) then
268 case Name_Of
(Reference
, In_Tree
) is
269 when Snames
.Name_Specification
=>
270 Set_Name_Of
(Reference
, In_Tree
, To
=> Snames
.Name_Spec
);
272 when Snames
.Name_Specification_Suffix
=>
274 (Reference
, In_Tree
, To
=> Snames
.Name_Spec_Suffix
);
276 when Snames
.Name_Implementation
=>
277 Set_Name_Of
(Reference
, In_Tree
, To
=> Snames
.Name_Body
);
279 when Snames
.Name_Implementation_Suffix
=>
281 (Reference
, In_Tree
, To
=> Snames
.Name_Body_Suffix
);
288 end Attribute_Reference
;
290 ---------------------------
291 -- End_Case_Construction --
292 ---------------------------
294 procedure End_Case_Construction
295 (Check_All_Labels
: Boolean;
296 Case_Location
: Source_Ptr
;
297 Flags
: Processing_Flags
)
299 Non_Used
: Natural := 0;
300 First_Non_Used
: Choice_Node_Id
:= First_Choice_Node_Id
;
302 -- First, if Check_All_Labels is True, check if all values
303 -- of the string type have been used.
305 if Check_All_Labels
then
306 for Choice
in Choice_First
.. Choices
.Last
loop
307 if not Choices
.Table
(Choice
).Already_Used
then
308 Non_Used
:= Non_Used
+ 1;
311 First_Non_Used
:= Choice
;
316 -- If only one is not used, report a single warning for this value
319 Error_Msg_Name_1
:= Choices
.Table
(First_Non_Used
).The_String
;
320 Error_Msg
(Flags
, "?value %% is not used as label", Case_Location
);
322 -- If several are not used, report a warning for each one of them
324 elsif Non_Used
> 1 then
326 (Flags
, "?the following values are not used as labels:",
329 for Choice
in First_Non_Used
.. Choices
.Last
loop
330 if not Choices
.Table
(Choice
).Already_Used
then
331 Error_Msg_Name_1
:= Choices
.Table
(Choice
).The_String
;
332 Error_Msg
(Flags
, "\?%%", Case_Location
);
338 -- If this is the only case construction, empty the tables
340 if Choice_Lasts
.Last
= 1 then
341 Choice_Lasts
.Set_Last
(0);
342 Choices
.Set_Last
(First_Choice_Node_Id
);
345 elsif Choice_Lasts
.Last
= 2 then
347 -- This is the second case construction, set the tables to the first
349 Choice_Lasts
.Set_Last
(1);
350 Choices
.Set_Last
(Choice_Lasts
.Table
(1));
354 -- This is the 3rd or more case construction, set the tables to the
357 Choice_Lasts
.Decrement_Last
;
358 Choices
.Set_Last
(Choice_Lasts
.Table
(Choice_Lasts
.Last
));
359 Choice_First
:= Choice_Lasts
.Table
(Choice_Lasts
.Last
- 1) + 1;
361 end End_Case_Construction
;
363 ------------------------
364 -- External_Reference --
365 ------------------------
367 procedure External_Reference
368 (In_Tree
: Project_Node_Tree_Ref
;
369 Current_Project
: Project_Node_Id
;
370 Current_Package
: Project_Node_Id
;
371 External_Value
: out Project_Node_Id
;
372 Expr_Kind
: in out Variable_Kind
;
373 Flags
: Processing_Flags
)
375 Field_Id
: Project_Node_Id
:= Empty_Node
;
376 Ext_List
: Boolean := False;
381 (Of_Kind
=> N_External_Value
,
383 Set_Location_Of
(External_Value
, In_Tree
, To
=> Token_Ptr
);
385 -- The current token is either external or external_as_list
387 Ext_List
:= Token
= Tok_External_As_List
;
391 Set_Expression_Kind_Of
(External_Value
, In_Tree
, To
=> List
);
393 Set_Expression_Kind_Of
(External_Value
, In_Tree
, To
=> Single
);
396 if Expr_Kind
= Undefined
then
404 Expect
(Tok_Left_Paren
, "`(`");
406 -- Scan past the left parenthesis
408 if Token
= Tok_Left_Paren
then
412 -- Get the name of the external reference
414 Expect
(Tok_String_Literal
, "literal string");
416 if Token
= Tok_String_Literal
then
419 (Of_Kind
=> N_Literal_String
,
421 And_Expr_Kind
=> Single
);
422 Set_String_Value_Of
(Field_Id
, In_Tree
, To
=> Token_Name
);
423 Set_External_Reference_Of
(External_Value
, In_Tree
, To
=> Field_Id
);
425 -- Scan past the first argument
431 when Tok_Right_Paren
=>
433 Error_Msg
(Flags
, "`,` expected", Token_Ptr
);
436 Scan
(In_Tree
); -- scan past right paren
439 Scan
(In_Tree
); -- scan past comma
441 -- Get the string expression for the default
444 Loc
: constant Source_Ptr
:= Token_Ptr
;
449 Expression
=> Field_Id
,
451 Current_Project
=> Current_Project
,
452 Current_Package
=> Current_Package
,
453 Optional_Index
=> False);
455 if Expression_Kind_Of
(Field_Id
, In_Tree
) = List
then
457 (Flags
, "expression must be a single string", Loc
);
459 Set_External_Default_Of
460 (External_Value
, In_Tree
, To
=> Field_Id
);
464 Expect
(Tok_Right_Paren
, "`)`");
466 if Token
= Tok_Right_Paren
then
467 Scan
(In_Tree
); -- scan past right paren
472 Error_Msg
(Flags
, "`,` expected", Token_Ptr
);
474 Error_Msg
(Flags
, "`,` or `)` expected", Token_Ptr
);
478 end External_Reference
;
480 -----------------------
481 -- Parse_Choice_List --
482 -----------------------
484 procedure Parse_Choice_List
485 (In_Tree
: Project_Node_Tree_Ref
;
486 First_Choice
: out Project_Node_Id
;
487 Flags
: Processing_Flags
)
489 Current_Choice
: Project_Node_Id
:= Empty_Node
;
490 Next_Choice
: Project_Node_Id
:= Empty_Node
;
491 Choice_String
: Name_Id
:= No_Name
;
492 Found
: Boolean := False;
495 -- Declare the node of the first choice
499 (Of_Kind
=> N_Literal_String
,
501 And_Expr_Kind
=> Single
);
503 -- Initially Current_Choice is the same as First_Choice
505 Current_Choice
:= First_Choice
;
508 Expect
(Tok_String_Literal
, "literal string");
509 exit when Token
/= Tok_String_Literal
;
510 Set_Location_Of
(Current_Choice
, In_Tree
, To
=> Token_Ptr
);
511 Choice_String
:= Token_Name
;
513 -- Give the string value to the current choice
515 Set_String_Value_Of
(Current_Choice
, In_Tree
, To
=> Choice_String
);
517 -- Check if the label is part of the string type and if it has not
518 -- been already used.
521 for Choice
in Choice_First
.. Choices
.Last
loop
522 if Choices
.Table
(Choice
).The_String
= Choice_String
then
524 -- This label is part of the string type
528 if Choices
.Table
(Choice
).Already_Used
then
530 -- But it has already appeared in a choice list for this
531 -- case construction so report an error.
533 Error_Msg_Name_1
:= Choice_String
;
534 Error_Msg
(Flags
, "duplicate case label %%", Token_Ptr
);
537 Choices
.Table
(Choice
).Already_Used
:= True;
544 -- If the label is not part of the string list, report an error
547 Error_Msg_Name_1
:= Choice_String
;
548 Error_Msg
(Flags
, "illegal case label %%", Token_Ptr
);
551 -- Scan past the label
555 -- If there is no '|', we are done
557 if Token
= Tok_Vertical_Bar
then
559 -- Otherwise, declare the node of the next choice, link it to
560 -- Current_Choice and set Current_Choice to this new node.
564 (Of_Kind
=> N_Literal_String
,
566 And_Expr_Kind
=> Single
);
567 Set_Next_Literal_String
568 (Current_Choice
, In_Tree
, To
=> Next_Choice
);
569 Current_Choice
:= Next_Choice
;
575 end Parse_Choice_List
;
577 ----------------------
578 -- Parse_Expression --
579 ----------------------
581 procedure Parse_Expression
582 (In_Tree
: Project_Node_Tree_Ref
;
583 Expression
: out Project_Node_Id
;
584 Current_Project
: Project_Node_Id
;
585 Current_Package
: Project_Node_Id
;
586 Optional_Index
: Boolean;
587 Flags
: Processing_Flags
)
589 First_Term
: Project_Node_Id
:= Empty_Node
;
590 Expression_Kind
: Variable_Kind
:= Undefined
;
593 -- Declare the node of the expression
596 Default_Project_Node
(Of_Kind
=> N_Expression
, In_Tree
=> In_Tree
);
597 Set_Location_Of
(Expression
, In_Tree
, To
=> Token_Ptr
);
599 -- Parse the term or terms of the expression
601 Terms
(In_Tree
=> In_Tree
,
603 Expr_Kind
=> Expression_Kind
,
605 Current_Project
=> Current_Project
,
606 Current_Package
=> Current_Package
,
607 Optional_Index
=> Optional_Index
);
609 -- Set the first term and the expression kind
611 Set_First_Term
(Expression
, In_Tree
, To
=> First_Term
);
612 Set_Expression_Kind_Of
(Expression
, In_Tree
, To
=> Expression_Kind
);
613 end Parse_Expression
;
615 ----------------------------
616 -- Parse_String_Type_List --
617 ----------------------------
619 procedure Parse_String_Type_List
620 (In_Tree
: Project_Node_Tree_Ref
;
621 First_String
: out Project_Node_Id
;
622 Flags
: Processing_Flags
)
624 Last_String
: Project_Node_Id
:= Empty_Node
;
625 Next_String
: Project_Node_Id
:= Empty_Node
;
626 String_Value
: Name_Id
:= No_Name
;
629 -- Declare the node of the first string
633 (Of_Kind
=> N_Literal_String
,
635 And_Expr_Kind
=> Single
);
637 -- Initially, Last_String is the same as First_String
639 Last_String
:= First_String
;
642 Expect
(Tok_String_Literal
, "literal string");
643 exit when Token
/= Tok_String_Literal
;
644 String_Value
:= Token_Name
;
646 -- Give its string value to Last_String
648 Set_String_Value_Of
(Last_String
, In_Tree
, To
=> String_Value
);
649 Set_Location_Of
(Last_String
, In_Tree
, To
=> Token_Ptr
);
651 -- Now, check if the string is already part of the string type
654 Current
: Project_Node_Id
:= First_String
;
657 while Current
/= Last_String
loop
658 if String_Value_Of
(Current
, In_Tree
) = String_Value
then
660 -- This is a repetition, report an error
662 Error_Msg_Name_1
:= String_Value
;
663 Error_Msg
(Flags
, "duplicate value %% in type", Token_Ptr
);
667 Current
:= Next_Literal_String
(Current
, In_Tree
);
671 -- Scan past the literal string
675 -- If there is no comma following the literal string, we are done
677 if Token
/= Tok_Comma
then
681 -- Declare the next string, link it to Last_String and set
682 -- Last_String to its node.
686 (Of_Kind
=> N_Literal_String
,
688 And_Expr_Kind
=> Single
);
689 Set_Next_Literal_String
(Last_String
, In_Tree
, To
=> Next_String
);
690 Last_String
:= Next_String
;
694 end Parse_String_Type_List
;
696 ------------------------------
697 -- Parse_Variable_Reference --
698 ------------------------------
700 procedure Parse_Variable_Reference
701 (In_Tree
: Project_Node_Tree_Ref
;
702 Variable
: out Project_Node_Id
;
703 Current_Project
: Project_Node_Id
;
704 Current_Package
: Project_Node_Id
;
705 Flags
: Processing_Flags
)
707 Current_Variable
: Project_Node_Id
:= Empty_Node
;
709 The_Package
: Project_Node_Id
:= Current_Package
;
710 The_Project
: Project_Node_Id
:= Current_Project
;
712 Specified_Project
: Project_Node_Id
:= Empty_Node
;
713 Specified_Package
: Project_Node_Id
:= Empty_Node
;
714 Look_For_Variable
: Boolean := True;
715 First_Attribute
: Attribute_Node_Id
:= Empty_Attribute
;
716 Variable_Name
: Name_Id
;
722 Expect
(Tok_Identifier
, "identifier");
724 if Token
/= Tok_Identifier
then
725 Look_For_Variable
:= False;
729 Add_To_Names
(NL
=> (Name
=> Token_Name
, Location
=> Token_Ptr
));
731 exit when Token
/= Tok_Dot
;
735 if Look_For_Variable
then
737 if Token
= Tok_Apostrophe
then
739 -- Attribute reference
749 -- This may be a project name or a package name.
750 -- Project name have precedence.
752 -- First, look if it can be a package name
756 (Package_Node_Id_Of
(Names
.Table
(1).Name
));
758 -- Now, look if it can be a project name
760 if Names
.Table
(1).Name
=
761 Name_Of
(Current_Project
, In_Tree
)
763 The_Project
:= Current_Project
;
767 Imported_Or_Extended_Project_Of
768 (Current_Project
, In_Tree
, Names
.Table
(1).Name
);
771 if No
(The_Project
) then
773 -- If it is neither a project name nor a package name,
776 if First_Attribute
= Empty_Attribute
then
777 Error_Msg_Name_1
:= Names
.Table
(1).Name
;
778 Error_Msg
(Flags
, "unknown project %",
779 Names
.Table
(1).Location
);
780 First_Attribute
:= Attribute_First
;
783 -- If it is a package name, check if the package has
784 -- already been declared in the current project.
787 First_Package_Of
(Current_Project
, In_Tree
);
789 while Present
(The_Package
)
790 and then Name_Of
(The_Package
, In_Tree
) /=
794 Next_Package_In_Project
(The_Package
, In_Tree
);
797 -- If it has not been already declared, report an
800 if No
(The_Package
) then
801 Error_Msg_Name_1
:= Names
.Table
(1).Name
;
802 Error_Msg
(Flags
, "package % not yet defined",
803 Names
.Table
(1).Location
);
808 -- It is a project name
810 First_Attribute
:= Attribute_First
;
811 The_Package
:= Empty_Node
;
816 -- We have either a project name made of several simple
817 -- names (long project), or a project name (short project)
818 -- followed by a package name. The long project name has
822 Short_Project
: Name_Id
;
823 Long_Project
: Name_Id
;
830 -- Get the name of the short project
832 for Index
in 1 .. Names
.Last
- 1 loop
834 (Get_Name_String
(Names
.Table
(Index
).Name
),
835 Buffer
, Buffer_Last
);
837 if Index
/= Names
.Last
- 1 then
838 Add_To_Buffer
(".", Buffer
, Buffer_Last
);
842 Name_Len
:= Buffer_Last
;
843 Name_Buffer
(1 .. Buffer_Last
) :=
844 Buffer
(1 .. Buffer_Last
);
845 Short_Project
:= Name_Find
;
847 -- Now, add the last simple name to get the name of the
850 Add_To_Buffer
(".", Buffer
, Buffer_Last
);
852 (Get_Name_String
(Names
.Table
(Names
.Last
).Name
),
853 Buffer
, Buffer_Last
);
854 Name_Len
:= Buffer_Last
;
855 Name_Buffer
(1 .. Buffer_Last
) :=
856 Buffer
(1 .. Buffer_Last
);
857 Long_Project
:= Name_Find
;
859 -- Check if the long project is imported or extended
861 if Long_Project
= Name_Of
(Current_Project
, In_Tree
) then
862 The_Project
:= Current_Project
;
866 Imported_Or_Extended_Project_Of
872 -- If the long project exists, then this is the prefix
875 if Present
(The_Project
) then
876 First_Attribute
:= Attribute_First
;
877 The_Package
:= Empty_Node
;
880 -- Otherwise, check if the short project is imported
884 Name_Of
(Current_Project
, In_Tree
)
886 The_Project
:= Current_Project
;
889 The_Project
:= Imported_Or_Extended_Project_Of
890 (Current_Project
, In_Tree
,
894 -- If short project does not exist, report an error
896 if No
(The_Project
) then
897 Error_Msg_Name_1
:= Long_Project
;
898 Error_Msg_Name_2
:= Short_Project
;
899 Error_Msg
(Flags
, "unknown projects % or %",
900 Names
.Table
(1).Location
);
901 The_Package
:= Empty_Node
;
902 First_Attribute
:= Attribute_First
;
905 -- Now, we check if the package has been declared
909 First_Package_Of
(The_Project
, In_Tree
);
910 while Present
(The_Package
)
911 and then Name_Of
(The_Package
, In_Tree
) /=
912 Names
.Table
(Names
.Last
).Name
915 Next_Package_In_Project
(The_Package
, In_Tree
);
918 -- If it has not, then we report an error
920 if No
(The_Package
) then
922 Names
.Table
(Names
.Last
).Name
;
923 Error_Msg_Name_2
:= Short_Project
;
925 "package % not declared in project %",
926 Names
.Table
(Names
.Last
).Location
);
927 First_Attribute
:= Attribute_First
;
930 -- Otherwise, we have the correct project and
935 (Package_Id_Of
(The_Package
, In_Tree
));
946 Current_Project
=> The_Project
,
947 Current_Package
=> The_Package
,
948 First_Attribute
=> First_Attribute
);
955 (Of_Kind
=> N_Variable_Reference
, In_Tree
=> In_Tree
);
957 if Look_For_Variable
then
961 -- Cannot happen (so why null instead of raise PE???)
967 -- Simple variable name
969 Set_Name_Of
(Variable
, In_Tree
, To
=> Names
.Table
(1).Name
);
973 -- Variable name with a simple name prefix that can be
974 -- a project name or a package name. Project names have
975 -- priority over package names.
977 Set_Name_Of
(Variable
, In_Tree
, To
=> Names
.Table
(2).Name
);
979 -- Check if it can be a package name
981 The_Package
:= First_Package_Of
(Current_Project
, In_Tree
);
983 while Present
(The_Package
)
984 and then Name_Of
(The_Package
, In_Tree
) /=
988 Next_Package_In_Project
(The_Package
, In_Tree
);
991 -- Now look for a possible project name
993 The_Project
:= Imported_Or_Extended_Project_Of
994 (Current_Project
, In_Tree
, Names
.Table
(1).Name
);
996 if Present
(The_Project
) then
997 Specified_Project
:= The_Project
;
999 elsif No
(The_Package
) then
1000 Error_Msg_Name_1
:= Names
.Table
(1).Name
;
1001 Error_Msg
(Flags
, "unknown package or project %",
1002 Names
.Table
(1).Location
);
1003 Look_For_Variable
:= False;
1006 Specified_Package
:= The_Package
;
1011 -- Variable name with a prefix that is either a project name
1012 -- made of several simple names, or a project name followed
1013 -- by a package name.
1016 (Variable
, In_Tree
, To
=> Names
.Table
(Names
.Last
).Name
);
1019 Short_Project
: Name_Id
;
1020 Long_Project
: Name_Id
;
1023 -- First, we get the two possible project names
1029 -- Add all the simple names, except the last two
1031 for Index
in 1 .. Names
.Last
- 2 loop
1033 (Get_Name_String
(Names
.Table
(Index
).Name
),
1034 Buffer
, Buffer_Last
);
1036 if Index
/= Names
.Last
- 2 then
1037 Add_To_Buffer
(".", Buffer
, Buffer_Last
);
1041 Name_Len
:= Buffer_Last
;
1042 Name_Buffer
(1 .. Name_Len
) := Buffer
(1 .. Buffer_Last
);
1043 Short_Project
:= Name_Find
;
1045 -- Add the simple name before the name of the variable
1047 Add_To_Buffer
(".", Buffer
, Buffer_Last
);
1049 (Get_Name_String
(Names
.Table
(Names
.Last
- 1).Name
),
1050 Buffer
, Buffer_Last
);
1051 Name_Len
:= Buffer_Last
;
1052 Name_Buffer
(1 .. Name_Len
) := Buffer
(1 .. Buffer_Last
);
1053 Long_Project
:= Name_Find
;
1055 -- Check if the prefix is the name of an imported or
1056 -- extended project.
1058 The_Project
:= Imported_Or_Extended_Project_Of
1059 (Current_Project
, In_Tree
, Long_Project
);
1061 if Present
(The_Project
) then
1062 Specified_Project
:= The_Project
;
1065 -- Now check if the prefix may be a project name followed
1066 -- by a package name.
1068 -- First check for a possible project name
1071 Imported_Or_Extended_Project_Of
1072 (Current_Project
, In_Tree
, Short_Project
);
1074 if No
(The_Project
) then
1075 -- Unknown prefix, report an error
1077 Error_Msg_Name_1
:= Long_Project
;
1078 Error_Msg_Name_2
:= Short_Project
;
1080 (Flags
, "unknown projects % or %",
1081 Names
.Table
(1).Location
);
1082 Look_For_Variable
:= False;
1085 Specified_Project
:= The_Project
;
1087 -- Now look for the package in this project
1089 The_Package
:= First_Package_Of
(The_Project
, In_Tree
);
1091 while Present
(The_Package
)
1092 and then Name_Of
(The_Package
, In_Tree
) /=
1093 Names
.Table
(Names
.Last
- 1).Name
1096 Next_Package_In_Project
(The_Package
, In_Tree
);
1099 if No
(The_Package
) then
1101 -- The package does not exist, report an error
1103 Error_Msg_Name_1
:= Names
.Table
(2).Name
;
1104 Error_Msg
(Flags
, "unknown package %",
1105 Names
.Table
(Names
.Last
- 1).Location
);
1106 Look_For_Variable
:= False;
1109 Specified_Package
:= The_Package
;
1117 if Look_For_Variable
then
1118 Variable_Name
:= Name_Of
(Variable
, In_Tree
);
1119 Set_Project_Node_Of
(Variable
, In_Tree
, To
=> Specified_Project
);
1120 Set_Package_Node_Of
(Variable
, In_Tree
, To
=> Specified_Package
);
1122 if Present
(Specified_Project
) then
1123 The_Project
:= Specified_Project
;
1125 The_Project
:= Current_Project
;
1128 Current_Variable
:= Empty_Node
;
1130 -- Look for this variable
1132 -- If a package was specified, check if the variable has been
1133 -- declared in this package.
1135 if Present
(Specified_Package
) then
1137 First_Variable_Of
(Specified_Package
, In_Tree
);
1138 while Present
(Current_Variable
)
1140 Name_Of
(Current_Variable
, In_Tree
) /= Variable_Name
1142 Current_Variable
:= Next_Variable
(Current_Variable
, In_Tree
);
1146 -- Otherwise, if no project has been specified and we are in
1147 -- a package, first check if the variable has been declared in
1150 if No
(Specified_Project
)
1151 and then Present
(Current_Package
)
1154 First_Variable_Of
(Current_Package
, In_Tree
);
1155 while Present
(Current_Variable
)
1156 and then Name_Of
(Current_Variable
, In_Tree
) /= Variable_Name
1159 Next_Variable
(Current_Variable
, In_Tree
);
1163 -- If we have not found the variable in the package, check if the
1164 -- variable has been declared in the project, or in any of its
1167 if No
(Current_Variable
) then
1169 Proj
: Project_Node_Id
:= The_Project
;
1173 Current_Variable
:= First_Variable_Of
(Proj
, In_Tree
);
1175 Present
(Current_Variable
)
1177 Name_Of
(Current_Variable
, In_Tree
) /= Variable_Name
1180 Next_Variable
(Current_Variable
, In_Tree
);
1183 exit when Present
(Current_Variable
);
1185 Proj
:= Parent_Project_Of
(Proj
, In_Tree
);
1187 Set_Project_Node_Of
(Variable
, In_Tree
, To
=> Proj
);
1189 exit when No
(Proj
);
1195 -- If the variable was not found, report an error
1197 if No
(Current_Variable
) then
1198 Error_Msg_Name_1
:= Variable_Name
;
1200 (Flags
, "unknown variable %", Names
.Table
(Names
.Last
).Location
);
1204 if Present
(Current_Variable
) then
1205 Set_Expression_Kind_Of
1207 To
=> Expression_Kind_Of
(Current_Variable
, In_Tree
));
1209 if Kind_Of
(Current_Variable
, In_Tree
) =
1210 N_Typed_Variable_Declaration
1214 To
=> String_Type_Of
(Current_Variable
, In_Tree
));
1218 -- If the variable is followed by a left parenthesis, report an error
1219 -- but attempt to scan the index.
1221 if Token
= Tok_Left_Paren
then
1223 (Flags
, "\variables cannot be associative arrays", Token_Ptr
);
1225 Expect
(Tok_String_Literal
, "literal string");
1227 if Token
= Tok_String_Literal
then
1229 Expect
(Tok_Right_Paren
, "`)`");
1231 if Token
= Tok_Right_Paren
then
1236 end Parse_Variable_Reference
;
1238 ---------------------------------
1239 -- Start_New_Case_Construction --
1240 ---------------------------------
1242 procedure Start_New_Case_Construction
1243 (In_Tree
: Project_Node_Tree_Ref
;
1244 String_Type
: Project_Node_Id
)
1246 Current_String
: Project_Node_Id
;
1249 -- Set Choice_First, depending on whether this is the first case
1250 -- construction or not.
1252 if Choice_First
= 0 then
1254 Choices
.Set_Last
(First_Choice_Node_Id
);
1256 Choice_First
:= Choices
.Last
+ 1;
1259 -- Add the literal of the string type to the Choices table
1261 if Present
(String_Type
) then
1262 Current_String
:= First_Literal_String
(String_Type
, In_Tree
);
1263 while Present
(Current_String
) loop
1264 Add
(This_String
=> String_Value_Of
(Current_String
, In_Tree
));
1265 Current_String
:= Next_Literal_String
(Current_String
, In_Tree
);
1269 -- Set the value of the last choice in table Choice_Lasts
1271 Choice_Lasts
.Increment_Last
;
1272 Choice_Lasts
.Table
(Choice_Lasts
.Last
) := Choices
.Last
;
1273 end Start_New_Case_Construction
;
1280 (In_Tree
: Project_Node_Tree_Ref
;
1281 Term
: out Project_Node_Id
;
1282 Expr_Kind
: in out Variable_Kind
;
1283 Current_Project
: Project_Node_Id
;
1284 Current_Package
: Project_Node_Id
;
1285 Optional_Index
: Boolean;
1286 Flags
: Processing_Flags
)
1288 Next_Term
: Project_Node_Id
:= Empty_Node
;
1289 Term_Id
: Project_Node_Id
:= Empty_Node
;
1290 Current_Expression
: Project_Node_Id
:= Empty_Node
;
1291 Next_Expression
: Project_Node_Id
:= Empty_Node
;
1292 Current_Location
: Source_Ptr
:= No_Location
;
1293 Reference
: Project_Node_Id
:= Empty_Node
;
1296 -- Declare a new node for the term
1298 Term
:= Default_Project_Node
(Of_Kind
=> N_Term
, In_Tree
=> In_Tree
);
1299 Set_Location_Of
(Term
, In_Tree
, To
=> Token_Ptr
);
1302 when Tok_Left_Paren
=>
1304 -- If we have a left parenthesis and we don't know the expression
1305 -- kind, then this is a string list.
1316 -- If we already know that this is a single string, report
1317 -- an error, but set the expression kind to string list to
1318 -- avoid several errors.
1322 (Flags
, "literal string list cannot appear in a string",
1326 -- Declare a new node for this literal string list
1328 Term_Id
:= Default_Project_Node
1329 (Of_Kind
=> N_Literal_String_List
,
1331 And_Expr_Kind
=> List
);
1332 Set_Current_Term
(Term
, In_Tree
, To
=> Term_Id
);
1333 Set_Location_Of
(Term
, In_Tree
, To
=> Token_Ptr
);
1335 -- Scan past the left parenthesis
1339 -- If the left parenthesis is immediately followed by a right
1340 -- parenthesis, the literal string list is empty.
1342 if Token
= Tok_Right_Paren
then
1346 -- Otherwise parse the expression(s) in the literal string list
1349 Current_Location
:= Token_Ptr
;
1351 (In_Tree
=> In_Tree
,
1352 Expression
=> Next_Expression
,
1354 Current_Project
=> Current_Project
,
1355 Current_Package
=> Current_Package
,
1356 Optional_Index
=> Optional_Index
);
1358 -- The expression kind is String list, report an error
1360 if Expression_Kind_Of
(Next_Expression
, In_Tree
) = List
then
1361 Error_Msg
(Flags
, "single expression expected",
1365 -- If Current_Expression is empty, it means that the
1366 -- expression is the first in the string list.
1368 if No
(Current_Expression
) then
1369 Set_First_Expression_In_List
1370 (Term_Id
, In_Tree
, To
=> Next_Expression
);
1372 Set_Next_Expression_In_List
1373 (Current_Expression
, In_Tree
, To
=> Next_Expression
);
1376 Current_Expression
:= Next_Expression
;
1378 -- If there is a comma, continue with the next expression
1380 exit when Token
/= Tok_Comma
;
1381 Scan
(In_Tree
); -- past the comma
1384 -- We expect a closing right parenthesis
1386 Expect
(Tok_Right_Paren
, "`)`");
1388 if Token
= Tok_Right_Paren
then
1393 when Tok_String_Literal
=>
1395 -- If we don't know the expression kind (first term), then it is
1398 if Expr_Kind
= Undefined
then
1399 Expr_Kind
:= Single
;
1402 -- Declare a new node for the string literal
1405 Default_Project_Node
1406 (Of_Kind
=> N_Literal_String
, In_Tree
=> In_Tree
);
1407 Set_Current_Term
(Term
, In_Tree
, To
=> Term_Id
);
1408 Set_String_Value_Of
(Term_Id
, In_Tree
, To
=> Token_Name
);
1410 -- Scan past the string literal
1414 -- Check for possible index expression
1416 if Token
= Tok_At
then
1417 if not Optional_Index
then
1418 Error_Msg
(Flags
, "index not allowed here", Token_Ptr
);
1421 if Token
= Tok_Integer_Literal
then
1425 -- Set the index value
1429 Expect
(Tok_Integer_Literal
, "integer literal");
1431 if Token
= Tok_Integer_Literal
then
1433 Index
: constant Int
:= UI_To_Int
(Int_Literal_Value
);
1437 (Flags
, "index cannot be zero", Token_Ptr
);
1440 (Term_Id
, In_Tree
, To
=> Index
);
1449 when Tok_Identifier
=>
1450 Current_Location
:= Token_Ptr
;
1452 -- Get the variable or attribute reference
1454 Parse_Variable_Reference
1455 (In_Tree
=> In_Tree
,
1456 Variable
=> Reference
,
1458 Current_Project
=> Current_Project
,
1459 Current_Package
=> Current_Package
);
1460 Set_Current_Term
(Term
, In_Tree
, To
=> Reference
);
1462 if Present
(Reference
) then
1464 -- If we don't know the expression kind (first term), then it
1465 -- has the kind of the variable or attribute reference.
1467 if Expr_Kind
= Undefined
then
1468 Expr_Kind
:= Expression_Kind_Of
(Reference
, In_Tree
);
1470 elsif Expr_Kind
= Single
1471 and then Expression_Kind_Of
(Reference
, In_Tree
) = List
1473 -- If the expression is a single list, and the reference is
1474 -- a string list, report an error, and set the expression
1475 -- kind to string list to avoid multiple errors.
1480 "list variable cannot appear in single string expression",
1487 -- Project can appear in an expression as the prefix of an
1488 -- attribute reference of the current project.
1490 Current_Location
:= Token_Ptr
;
1492 Expect
(Tok_Apostrophe
, "`'`");
1494 if Token
= Tok_Apostrophe
then
1496 (In_Tree
=> In_Tree
,
1497 Reference
=> Reference
,
1499 First_Attribute
=> Prj
.Attr
.Attribute_First
,
1500 Current_Project
=> Current_Project
,
1501 Current_Package
=> Empty_Node
);
1502 Set_Current_Term
(Term
, In_Tree
, To
=> Reference
);
1505 -- Same checks as above for the expression kind
1507 if Present
(Reference
) then
1508 if Expr_Kind
= Undefined
then
1509 Expr_Kind
:= Expression_Kind_Of
(Reference
, In_Tree
);
1511 elsif Expr_Kind
= Single
1512 and then Expression_Kind_Of
(Reference
, In_Tree
) = List
1515 (Flags
, "lists cannot appear in single string expression",
1520 when Tok_External | Tok_External_As_List
=>
1522 (In_Tree
=> In_Tree
,
1524 Current_Project
=> Current_Project
,
1525 Current_Package
=> Current_Package
,
1526 Expr_Kind
=> Expr_Kind
,
1527 External_Value
=> Reference
);
1528 Set_Current_Term
(Term
, In_Tree
, To
=> Reference
);
1531 Error_Msg
(Flags
, "cannot be part of an expression", Token_Ptr
);
1536 -- If there is an '&', call Terms recursively
1538 if Token
= Tok_Ampersand
then
1539 Scan
(In_Tree
); -- scan past ampersand
1542 (In_Tree
=> In_Tree
,
1544 Expr_Kind
=> Expr_Kind
,
1546 Current_Project
=> Current_Project
,
1547 Current_Package
=> Current_Package
,
1548 Optional_Index
=> Optional_Index
);
1550 -- And link the next term to this term
1552 Set_Next_Term
(Term
, In_Tree
, To
=> Next_Term
);