1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2002-2008, 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 Csets; use Csets;
27 with Err_Vars; use Err_Vars;
29 with Osint; use Osint;
30 with Output; use Output;
31 with Scans; use Scans;
32 with Snames; use Snames;
34 with Stringt; use Stringt;
37 with GNAT.Heap_Sort_G;
43 type Token_Name_Array is array (Token_Type) of Name_Id;
44 Token_Names : constant Token_Name_Array :=
45 (Tok_Abort => Name_Abort,
47 Tok_Abstract => Name_Abstract,
48 Tok_Accept => Name_Accept,
49 Tok_Aliased => Name_Aliased,
51 Tok_Array => Name_Array,
54 Tok_Begin => Name_Begin,
55 Tok_Body => Name_Body,
56 Tok_Case => Name_Case,
57 Tok_Constant => Name_Constant,
58 Tok_Declare => Name_Declare,
59 Tok_Delay => Name_Delay,
60 Tok_Delta => Name_Delta,
61 Tok_Digits => Name_Digits,
62 Tok_Else => Name_Else,
63 Tok_Elsif => Name_Elsif,
65 Tok_Entry => Name_Entry,
66 Tok_Exception => Name_Exception,
67 Tok_Exit => Name_Exit,
69 Tok_Function => Name_Function,
70 Tok_Generic => Name_Generic,
71 Tok_Goto => Name_Goto,
74 Tok_Limited => Name_Limited,
75 Tok_Loop => Name_Loop,
78 Tok_Null => Name_Null,
81 Tok_Others => Name_Others,
83 Tok_Package => Name_Package,
84 Tok_Pragma => Name_Pragma,
85 Tok_Private => Name_Private,
86 Tok_Procedure => Name_Procedure,
87 Tok_Protected => Name_Protected,
88 Tok_Raise => Name_Raise,
89 Tok_Range => Name_Range,
90 Tok_Record => Name_Record,
92 Tok_Renames => Name_Renames,
93 Tok_Requeue => Name_Requeue,
94 Tok_Return => Name_Return,
95 Tok_Reverse => Name_Reverse,
96 Tok_Select => Name_Select,
97 Tok_Separate => Name_Separate,
98 Tok_Subtype => Name_Subtype,
99 Tok_Tagged => Name_Tagged,
100 Tok_Task => Name_Task,
101 Tok_Terminate => Name_Terminate,
102 Tok_Then => Name_Then,
103 Tok_Type => Name_Type,
104 Tok_Until => Name_Until,
106 Tok_When => Name_When,
107 Tok_While => Name_While,
108 Tok_With => Name_With,
112 Already_Initialized : Boolean := False;
113 -- Used to avoid repetition of the part of the initialisation that needs
114 -- to be done only once.
116 Empty_String : String_Id;
117 -- "", as a string_id
119 String_False : String_Id;
120 -- "false", as a string_id
122 Name_Defined : Name_Id;
123 -- defined, as a name_id
129 -- Accesses to procedure specified by procedure Initialize
131 Error_Msg : Error_Msg_Proc;
137 Set_Ignore_Errors : Set_Ignore_Errors_Proc;
138 -- Indicate if error should be taken into account
140 Put_Char : Put_Char_Proc;
141 -- Output one character
143 New_EOL : New_EOL_Proc;
144 -- Output an end of line indication
146 -------------------------------
147 -- State of the Preprocessor --
148 -------------------------------
150 type Pp_State is record
152 -- The location of the #if statement.
153 -- Used to flag #if with no corresponding #end if, at the end.
155 Else_Ptr : Source_Ptr;
156 -- The location of the #else statement.
157 -- Used to detect multiple #else.
160 -- Set to True when the code should be deleted or commented out
162 Match_Seen : Boolean;
163 -- Set to True when a condition in an #if or an #elsif is True.
164 -- Also set to True if Deleting at the previous level is True.
165 -- Used to decide if Deleting should be set to True in a following
170 type Pp_Depth is new Nat;
172 Ground : constant Pp_Depth := 0;
174 package Pp_States is new Table.Table
175 (Table_Component_Type => Pp_State,
176 Table_Index_Type => Pp_Depth,
177 Table_Low_Bound => 1,
179 Table_Increment => 100,
180 Table_Name => "Prep.Pp_States");
181 -- A stack of the states of the preprocessor, for nested #if
183 type Operator is (None, Op_Or, Op_And);
189 function Deleting return Boolean;
190 -- Return True if code should be deleted or commented out
193 (Evaluate_It : Boolean;
194 Complemented : Boolean := False) return Boolean;
195 -- Evaluate a condition in an #if or an #elsif statement.
196 -- If Evaluate_It is False, the condition is effectively evaluated,
197 -- otherwise, only the syntax is checked.
199 procedure Go_To_End_Of_Line;
200 -- Advance the scan pointer until we reach an end of line or the end
203 function Matching_Strings (S1, S2 : String_Id) return Boolean;
204 -- Returns True if the two string parameters are equal (case insensitive)
206 ---------------------------------------
207 -- Change_Reserved_Keyword_To_Symbol --
208 ---------------------------------------
210 procedure Change_Reserved_Keyword_To_Symbol
211 (All_Keywords : Boolean := False)
213 New_Name : constant Name_Id := Token_Names (Token);
216 if New_Name /= No_Name then
218 when Tok_If | Tok_Else | Tok_Elsif | Tok_End |
219 Tok_And | Tok_Or | Tok_Then =>
221 Token := Tok_Identifier;
222 Token_Name := New_Name;
226 Token := Tok_Identifier;
227 Token_Name := New_Name;
230 end Change_Reserved_Keyword_To_Symbol;
232 ------------------------------------------
233 -- Check_Command_Line_Symbol_Definition --
234 ------------------------------------------
236 procedure Check_Command_Line_Symbol_Definition
237 (Definition : String;
238 Data : out Symbol_Data)
240 Index : Natural := 0;
241 Result : Symbol_Data;
244 -- Look for the character '='
246 for J in Definition'Range loop
247 if Definition (J) = '=' then
253 -- If no character '=', then the value is True
256 -- Put the symbol in the name buffer
258 Name_Len := Definition'Length;
259 Name_Buffer (1 .. Name_Len) := Definition;
260 Result := True_Value;
262 elsif Index = Definition'First then
263 Fail ("invalid symbol definition """ & Definition & """");
266 -- Put the symbol in the name buffer
268 Name_Len := Index - Definition'First;
269 Name_Buffer (1 .. Name_Len) :=
270 String'(Definition (Definition'First .. Index - 1));
272 -- Check the syntax of the value
274 if Definition (Index + 1) /= '"'
275 or else Definition (Definition'Last) /= '"'
277 for J in Index + 1 .. Definition'Last loop
278 case Definition (J) is
279 when '_' | '.' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' =>
283 Fail ("illegal value """
284 & Definition (Index + 1 .. Definition'Last)
290 -- And put the value in the result
292 Result.Is_A_String := False;
294 Store_String_Chars (Definition (Index + 1 .. Definition'Last));
295 Result.Value := End_String;
298 -- Now, check the syntax of the symbol (we don't allow accented and
301 if Name_Buffer (1) not in 'a' .. 'z'
302 and then Name_Buffer (1) not in 'A' .. 'Z'
305 & Name_Buffer (1 .. Name_Len)
306 & """ does not start with a letter");
309 for J in 2 .. Name_Len loop
310 case Name_Buffer (J) is
311 when 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' =>
317 & Name_Buffer (1 .. Name_Len)
318 & """ end with a '_'");
320 elsif Name_Buffer (J + 1) = '_' then
322 & Name_Buffer (1 .. Name_Len)
323 & """ contains consecutive '_'");
328 & Name_Buffer (1 .. Name_Len)
329 & """ contains illegal character(s)");
333 Result.On_The_Command_Line := True;
335 -- Put the symbol name in the result
338 Sym : constant String := Name_Buffer (1 .. Name_Len);
341 for Index in 1 .. Name_Len loop
342 Name_Buffer (Index) := Fold_Lower (Name_Buffer (Index));
345 Result.Symbol := Name_Find;
346 Name_Len := Sym'Length;
347 Name_Buffer (1 .. Name_Len) := Sym;
348 Result.Original := Name_Find;
352 end Check_Command_Line_Symbol_Definition;
358 function Deleting return Boolean is
360 -- Always return False when not inside an #if statement
362 if Pp_States.Last = Ground then
365 return Pp_States.Table (Pp_States.Last).Deleting;
374 (Evaluate_It : Boolean;
375 Complemented : Boolean := False) return Boolean
377 Evaluation : Boolean := Evaluate_It;
378 -- Is set to False after an "or else" when left term is True and
379 -- after an "and then" when left term is False.
381 Final_Result : Boolean := False;
383 Current_Result : Boolean := False;
386 Current_Operator : Operator := None;
389 Symbol_Name1 : Name_Id;
390 Symbol_Name2 : Name_Id;
391 Symbol_Pos1 : Source_Ptr;
392 Symbol_Pos2 : Source_Ptr;
393 Symbol_Value1 : String_Id;
394 Symbol_Value2 : String_Id;
397 -- Loop for each term
400 Change_Reserved_Keyword_To_Symbol;
402 Current_Result := False;
406 when Tok_Left_Paren =>
411 Current_Result := Expression (Evaluation);
413 if Token = Tok_Right_Paren then
417 Error_Msg ("`)` expected", Token_Ptr);
426 not Expression (Evaluation, Complemented => True);
428 when Tok_Identifier =>
429 Symbol_Name1 := Token_Name;
430 Symbol_Pos1 := Token_Ptr;
433 if Token = Tok_Apostrophe then
439 if Token = Tok_Identifier
440 and then Token_Name = Name_Defined
445 Error_Msg ("identifier `Defined` expected", Token_Ptr);
449 Current_Result := Index_Of (Symbol_Name1) /= No_Symbol;
452 elsif Token = Tok_Equal then
455 Change_Reserved_Keyword_To_Symbol;
457 if Token = Tok_Identifier then
461 Symbol_Name2 := Token_Name;
462 Symbol_Pos2 := Token_Ptr;
466 Symbol1 := Index_Of (Symbol_Name1);
468 if Symbol1 = No_Symbol then
469 if Undefined_Symbols_Are_False then
470 Symbol_Value1 := String_False;
473 Error_Msg_Name_1 := Symbol_Name1;
474 Error_Msg ("unknown symbol %", Symbol_Pos1);
475 Symbol_Value1 := No_String;
480 Mapping.Table (Symbol1).Value;
483 Symbol2 := Index_Of (Symbol_Name2);
485 if Symbol2 = No_Symbol then
486 if Undefined_Symbols_Are_False then
487 Symbol_Value2 := String_False;
490 Error_Msg_Name_1 := Symbol_Name2;
491 Error_Msg ("unknown symbol %", Symbol_Pos2);
492 Symbol_Value2 := No_String;
496 Symbol_Value2 := Mapping.Table (Symbol2).Value;
499 if Symbol_Value1 /= No_String
500 and then Symbol_Value2 /= No_String
502 Current_Result := Matching_Strings
503 (Symbol_Value1, Symbol_Value2);
507 elsif Token = Tok_String_Literal then
512 Symbol1 := Index_Of (Symbol_Name1);
514 if Symbol1 = No_Symbol then
515 if Undefined_Symbols_Are_False then
516 Symbol_Value1 := String_False;
519 Error_Msg_Name_1 := Symbol_Name1;
520 Error_Msg ("unknown symbol %", Symbol_Pos1);
521 Symbol_Value1 := No_String;
525 Symbol_Value1 := Mapping.Table (Symbol1).Value;
528 if Symbol_Value1 /= No_String then
540 ("symbol or literal string expected", Token_Ptr);
544 -- symbol (True or False)
547 Symbol1 := Index_Of (Symbol_Name1);
549 if Symbol1 = No_Symbol then
550 if Undefined_Symbols_Are_False then
551 Symbol_Value1 := String_False;
554 Error_Msg_Name_1 := Symbol_Name1;
555 Error_Msg ("unknown symbol %", Symbol_Pos1);
556 Symbol_Value1 := No_String;
560 Symbol_Value1 := Mapping.Table (Symbol1).Value;
563 if Symbol_Value1 /= No_String then
564 String_To_Name_Buffer (Symbol_Value1);
566 for Index in 1 .. Name_Len loop
567 Name_Buffer (Index) :=
568 Fold_Lower (Name_Buffer (Index));
571 if Name_Buffer (1 .. Name_Len) = "true" then
572 Current_Result := True;
574 elsif Name_Buffer (1 .. Name_Len) = "false" then
575 Current_Result := False;
578 Error_Msg_Name_1 := Symbol_Name1;
580 ("value of symbol % is not True or False",
588 Error_Msg ("`(`, NOT or symbol expected", Token_Ptr);
591 -- Update the cumulative final result
593 case Current_Operator is
595 Final_Result := Current_Result;
598 Final_Result := Final_Result or Current_Result;
601 Final_Result := Final_Result and Current_Result;
604 -- Check the next operator
606 if Token = Tok_And then
609 ("mixing NOT and AND is not allowed, parentheses are required",
612 elsif Current_Operator = Op_Or then
613 Error_Msg ("mixing OR and AND is not allowed", Token_Ptr);
616 Current_Operator := Op_And;
619 if Token = Tok_Then then
622 if Final_Result = False then
627 elsif Token = Tok_Or then
630 ("mixing NOT and OR is not allowed, parentheses are required",
633 elsif Current_Operator = Op_And then
634 Error_Msg ("mixing AND and OR is not allowed", Token_Ptr);
637 Current_Operator := Op_Or;
640 if Token = Tok_Else then
649 -- No operator: exit the term loop
658 -----------------------
659 -- Go_To_End_Of_Line --
660 -----------------------
662 procedure Go_To_End_Of_Line is
664 -- Scan until we get an end of line or we reach the end of the buffer
666 while Token /= Tok_End_Of_Line
667 and then Token /= Tok_EOF
671 end Go_To_End_Of_Line;
677 function Index_Of (Symbol : Name_Id) return Symbol_Id is
679 if Mapping.Table /= null then
680 for J in Symbol_Id range 1 .. Symbol_Table.Last (Mapping) loop
681 if Mapping.Table (J).Symbol = Symbol then
695 (Error_Msg : Error_Msg_Proc;
697 Set_Ignore_Errors : Set_Ignore_Errors_Proc;
698 Put_Char : Put_Char_Proc;
699 New_EOL : New_EOL_Proc)
702 if not Already_Initialized then
704 Store_String_Chars ("True");
705 True_Value.Value := End_String;
708 Empty_String := End_String;
711 Name_Buffer (1 .. Name_Len) := "defined";
712 Name_Defined := Name_Find;
715 Store_String_Chars ("False");
716 String_False := End_String;
718 Already_Initialized := True;
721 Prep.Error_Msg := Error_Msg;
723 Prep.Set_Ignore_Errors := Set_Ignore_Errors;
724 Prep.Put_Char := Put_Char;
725 Prep.New_EOL := New_EOL;
732 procedure List_Symbols (Foreword : String) is
733 Order : array (0 .. Integer (Symbol_Table.Last (Mapping)))
735 -- After alphabetical sorting, this array stores the indices of
736 -- the symbols in the order they are displayed.
738 function Lt (Op1, Op2 : Natural) return Boolean;
739 -- Comparison routine for sort call
741 procedure Move (From : Natural; To : Natural);
742 -- Move routine for sort call
748 function Lt (Op1, Op2 : Natural) return Boolean is
749 S1 : constant String :=
750 Get_Name_String (Mapping.Table (Order (Op1)).Symbol);
751 S2 : constant String :=
752 Get_Name_String (Mapping.Table (Order (Op2)).Symbol);
762 procedure Move (From : Natural; To : Natural) is
764 Order (To) := Order (From);
767 package Sort_Syms is new GNAT.Heap_Sort_G (Move, Lt);
770 -- Maximum length of any symbol
772 -- Start of processing for List_Symbols_Case
775 if Symbol_Table.Last (Mapping) = 0 then
779 if Foreword'Length > 0 then
781 Write_Line (Foreword);
783 for J in Foreword'Range loop
788 -- Initialize the order
790 for J in Order'Range loop
791 Order (J) := Symbol_Id (J);
794 -- Sort alphabetically
796 Sort_Syms.Sort (Order'Last);
800 for J in 1 .. Symbol_Table.Last (Mapping) loop
801 Get_Name_String (Mapping.Table (J).Original);
802 Max_L := Integer'Max (Max_L, Name_Len);
806 Write_Str ("Symbol");
808 for J in 1 .. Max_L - 5 loop
812 Write_Line ("Value");
814 Write_Str ("------");
816 for J in 1 .. Max_L - 5 loop
820 Write_Line ("------");
822 for J in 1 .. Order'Last loop
824 Data : constant Symbol_Data := Mapping.Table (Order (J));
827 Get_Name_String (Data.Original);
828 Write_Str (Name_Buffer (1 .. Name_Len));
830 for K in Name_Len .. Max_L loop
834 String_To_Name_Buffer (Data.Value);
836 if Data.Is_A_String then
839 for J in 1 .. Name_Len loop
840 Write_Char (Name_Buffer (J));
842 if Name_Buffer (J) = '"' then
850 Write_Str (Name_Buffer (1 .. Name_Len));
860 ----------------------
861 -- Matching_Strings --
862 ----------------------
864 function Matching_Strings (S1, S2 : String_Id) return Boolean is
866 String_To_Name_Buffer (S1);
868 for Index in 1 .. Name_Len loop
869 Name_Buffer (Index) := Fold_Lower (Name_Buffer (Index));
873 String1 : constant String := Name_Buffer (1 .. Name_Len);
876 String_To_Name_Buffer (S2);
878 for Index in 1 .. Name_Len loop
879 Name_Buffer (Index) := Fold_Lower (Name_Buffer (Index));
882 return String1 = Name_Buffer (1 .. Name_Len);
884 end Matching_Strings;
890 procedure Parse_Def_File is
892 Symbol_Name : Name_Id;
893 Original_Name : Name_Id;
895 Value_Start : Source_Ptr;
896 Value_End : Source_Ptr;
906 exit Def_Line_Loop when Token = Tok_EOF;
908 if Token /= Tok_End_Of_Line then
909 Change_Reserved_Keyword_To_Symbol;
911 if Token /= Tok_Identifier then
912 Error_Msg ("identifier expected", Token_Ptr);
916 Symbol_Name := Token_Name;
919 for Ptr in Token_Ptr .. Scan_Ptr - 1 loop
920 Name_Len := Name_Len + 1;
921 Name_Buffer (Name_Len) := Sinput.Source (Ptr);
924 Original_Name := Name_Find;
927 if Token /= Tok_Colon_Equal then
928 Error_Msg ("`:=` expected", Token_Ptr);
934 if Token = Tok_String_Literal then
935 Data := (Symbol => Symbol_Name,
936 Original => Original_Name,
937 On_The_Command_Line => False,
939 Value => String_Literal_Id);
943 if Token /= Tok_End_Of_Line and then Token /= Tok_EOF then
944 Error_Msg ("extraneous text in definition", Token_Ptr);
948 elsif Token = Tok_End_Of_Line or Token = Tok_EOF then
949 Data := (Symbol => Symbol_Name,
950 Original => Original_Name,
951 On_The_Command_Line => False,
952 Is_A_String => False,
953 Value => Empty_String);
956 Value_Start := Token_Ptr;
957 Value_End := Token_Ptr - 1;
958 Scan_Ptr := Token_Ptr;
962 Ch := Sinput.Source (Scan_Ptr);
965 when '_' | '.' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' =>
966 Value_End := Scan_Ptr;
967 Scan_Ptr := Scan_Ptr + 1;
969 when ' ' | HT | VT | CR | LF | FF =>
970 exit Value_Chars_Loop;
973 Error_Msg ("illegal character", Scan_Ptr);
976 end loop Value_Chars_Loop;
980 if Token /= Tok_End_Of_Line and then Token /= Tok_EOF then
981 Error_Msg ("extraneous text in definition", Token_Ptr);
987 while Value_Start <= Value_End loop
988 Store_String_Char (Sinput.Source (Value_Start));
989 Value_Start := Value_Start + 1;
992 Data := (Symbol => Symbol_Name,
993 Original => Original_Name,
994 On_The_Command_Line => False,
995 Is_A_String => False,
996 Value => End_String);
999 -- Now that we have the value, get the symbol index
1001 Symbol := Index_Of (Symbol_Name);
1003 if Symbol /= No_Symbol then
1004 -- If we already have an entry for this symbol, replace it
1005 -- with the new value, except if the symbol was declared
1006 -- on the command line.
1008 if Mapping.Table (Symbol).On_The_Command_Line then
1013 -- As it is the first time we see this symbol, create a new
1014 -- entry in the table.
1016 if Mapping.Table = null then
1017 Symbol_Table.Init (Mapping);
1020 Symbol_Table.Increment_Last (Mapping);
1021 Symbol := Symbol_Table.Last (Mapping);
1024 Mapping.Table (Symbol) := Data;
1028 Set_Ignore_Errors (To => True);
1030 while Token /= Tok_End_Of_Line and Token /= Tok_EOF loop
1034 Set_Ignore_Errors (To => False);
1039 end loop Def_Line_Loop;
1046 procedure Preprocess (Source_Modified : out Boolean) is
1047 Start_Of_Processing : Source_Ptr;
1049 Preprocessor_Line : Boolean := False;
1050 No_Error_Found : Boolean := True;
1051 Modified : Boolean := False;
1053 procedure Output (From, To : Source_Ptr);
1054 -- Output the characters with indices From .. To in the buffer
1055 -- to the output file.
1057 procedure Output_Line (From, To : Source_Ptr);
1058 -- Output a line or the end of a line from the buffer to the output
1059 -- file, followed by an end of line terminator. Depending on the value
1060 -- of Deleting and the switches, the line may be commented out, blank or
1061 -- not output at all.
1067 procedure Output (From, To : Source_Ptr) is
1069 for J in From .. To loop
1070 Put_Char (Sinput.Source (J));
1078 procedure Output_Line (From, To : Source_Ptr) is
1080 if Deleting or Preprocessor_Line then
1081 if Blank_Deleted_Lines then
1084 elsif Comment_Deleted_Lines then
1103 -- Start of processing for Preprocess
1106 Start_Of_Processing := Scan_Ptr;
1108 -- We need to call Scan for the first time, because Initialize_Scanner
1109 -- is no longer doing it.
1113 Input_Line_Loop : loop
1114 exit Input_Line_Loop when Token = Tok_EOF;
1116 Preprocessor_Line := False;
1118 if Token /= Tok_End_Of_Line then
1120 -- Preprocessor line
1122 if Token = Tok_Special and then Special_Character = '#' then
1124 Preprocessor_Line := True;
1133 If_Ptr : constant Source_Ptr := Token_Ptr;
1137 Cond := Expression (not Deleting);
1139 -- Check for an eventual "then"
1141 if Token = Tok_Then then
1145 -- It is an error to have trailing characters after
1146 -- the condition or "then".
1148 if Token /= Tok_End_Of_Line
1149 and then Token /= Tok_EOF
1152 ("extraneous text on preprocessor line",
1154 No_Error_Found := False;
1159 -- Set the initial state of this new "#if". This
1160 -- must be done before incrementing the Last of
1161 -- the table, otherwise function Deleting does
1162 -- not report the correct value.
1164 New_State : constant Pp_State :=
1167 Deleting => Deleting or (not Cond),
1168 Match_Seen => Deleting or Cond);
1171 Pp_States.Increment_Last;
1172 Pp_States.Table (Pp_States.Last) := New_State;
1181 if Pp_States.Last = 0
1182 or else Pp_States.Table (Pp_States.Last).Else_Ptr /= 0
1184 Error_Msg ("no IF for this ELSIF", Token_Ptr);
1185 No_Error_Found := False;
1189 not Pp_States.Table (Pp_States.Last).Match_Seen;
1193 Cond := Expression (Cond);
1195 -- Check for an eventual "then"
1197 if Token = Tok_Then then
1201 -- It is an error to have trailing characters after
1202 -- the condition or "then".
1204 if Token /= Tok_End_Of_Line
1205 and then Token /= Tok_EOF
1208 ("extraneous text on preprocessor line",
1210 No_Error_Found := False;
1215 -- Depending on the value of the condition, set the
1216 -- new values of Deleting and Match_Seen.
1217 if Pp_States.Last > 0 then
1218 if Pp_States.Table (Pp_States.Last).Match_Seen then
1219 Pp_States.Table (Pp_States.Last).Deleting := True;
1222 Pp_States.Table (Pp_States.Last).Match_Seen :=
1224 Pp_States.Table (Pp_States.Last).Deleting :=
1233 if Pp_States.Last = 0 then
1234 Error_Msg ("no IF for this ELSE", Token_Ptr);
1235 No_Error_Found := False;
1238 Pp_States.Table (Pp_States.Last).Else_Ptr /= 0
1240 Error_Msg ("duplicate ELSE line", Token_Ptr);
1241 No_Error_Found := False;
1244 -- Set the possibly new values of Deleting and
1247 if Pp_States.Last > 0 then
1248 if Pp_States.Table (Pp_States.Last).Match_Seen then
1249 Pp_States.Table (Pp_States.Last).Deleting :=
1253 Pp_States.Table (Pp_States.Last).Match_Seen :=
1255 Pp_States.Table (Pp_States.Last).Deleting :=
1259 -- Set the Else_Ptr to check for illegal #elsif
1262 Pp_States.Table (Pp_States.Last).Else_Ptr :=
1268 -- It is an error to have characters after "#else"
1269 if Token /= Tok_End_Of_Line
1270 and then Token /= Tok_EOF
1273 ("extraneous text on preprocessor line",
1275 No_Error_Found := False;
1282 if Pp_States.Last = 0 then
1283 Error_Msg ("no IF for this END", Token_Ptr);
1284 No_Error_Found := False;
1289 if Token /= Tok_If then
1290 Error_Msg ("IF expected", Token_Ptr);
1291 No_Error_Found := False;
1296 if Token /= Tok_Semicolon then
1297 Error_Msg ("`;` Expected", Token_Ptr);
1298 No_Error_Found := False;
1303 -- It is an error to have character after
1305 if Token /= Tok_End_Of_Line
1306 and then Token /= Tok_EOF
1309 ("extraneous text on preprocessor line",
1311 No_Error_Found := False;
1316 -- In case of one of the errors above, skip the tokens
1317 -- until the end of line is reached.
1321 -- Decrement the depth of the #if stack
1323 if Pp_States.Last > 0 then
1324 Pp_States.Decrement_Last;
1327 -- Illegal preprocessor line
1330 No_Error_Found := False;
1332 if Pp_States.Last = 0 then
1333 Error_Msg ("IF expected", Token_Ptr);
1336 Pp_States.Table (Pp_States.Last).Else_Ptr = 0
1338 Error_Msg ("IF, ELSIF, ELSE, or `END IF` expected",
1342 Error_Msg ("IF or `END IF` expected", Token_Ptr);
1345 -- Skip to the end of this illegal line
1350 -- Not a preprocessor line
1353 -- Do not report errors for those lines, even if there are
1354 -- Ada parsing errors.
1356 Set_Ignore_Errors (To => True);
1362 while Token /= Tok_End_Of_Line
1363 and then Token /= Tok_EOF
1365 if Token = Tok_Special
1366 and then Special_Character = '$'
1371 Dollar_Ptr : constant Source_Ptr := Token_Ptr;
1376 Change_Reserved_Keyword_To_Symbol;
1378 if Token = Tok_Identifier
1379 and then Token_Ptr = Dollar_Ptr + 1
1383 Symbol := Index_Of (Token_Name);
1385 -- If symbol exists, replace by its value
1387 if Symbol /= No_Symbol then
1388 Output (Start_Of_Processing, Dollar_Ptr - 1);
1389 Start_Of_Processing := Scan_Ptr;
1390 String_To_Name_Buffer
1391 (Mapping.Table (Symbol).Value);
1393 if Mapping.Table (Symbol).Is_A_String then
1395 -- Value is an Ada string
1399 for J in 1 .. Name_Len loop
1400 Put_Char (Name_Buffer (J));
1402 if Name_Buffer (J) = '"' then
1410 -- Value is a sequence of characters, not
1413 for J in 1 .. Name_Len loop
1414 Put_Char (Name_Buffer (J));
1426 Set_Ignore_Errors (To => False);
1430 pragma Assert (Token = Tok_End_Of_Line or Token = Tok_EOF);
1432 -- At this point, the token is either end of line or EOF.
1433 -- The line to possibly output stops just before the token.
1435 Output_Line (Start_Of_Processing, Token_Ptr - 1);
1437 -- If we are at the end of a line, the scan pointer is at the first
1438 -- non blank character, not necessarily the first character of the
1439 -- line; so, we have to deduct Start_Of_Processing from the token
1442 if Token = Tok_End_Of_Line then
1443 if (Sinput.Source (Token_Ptr) = ASCII.CR
1444 and then Sinput.Source (Token_Ptr + 1) = ASCII.LF)
1446 (Sinput.Source (Token_Ptr) = ASCII.CR
1447 and then Sinput.Source (Token_Ptr + 1) = ASCII.LF)
1449 Start_Of_Processing := Token_Ptr + 2;
1451 Start_Of_Processing := Token_Ptr + 1;
1455 -- Now, scan the first token of the next line. If the token is EOF,
1456 -- the scan pointer will not move, and the token will still be EOF.
1458 Set_Ignore_Errors (To => True);
1460 Set_Ignore_Errors (To => False);
1461 end loop Input_Line_Loop;
1463 -- Report an error for any missing some "#end if;"
1465 for Level in reverse 1 .. Pp_States.Last loop
1466 Error_Msg ("no `END IF` for this IF", Pp_States.Table (Level).If_Ptr);
1467 No_Error_Found := False;
1470 Source_Modified := No_Error_Found and Modified;