Commit f95fd3b2 by Vincent Celier Committed by Arnaud Charlet

prep.ads, prep.adb (Expression): New Boolean parameter Complemented, defaulted to False.

2007-04-20  Vincent Celier  <celier@adacore.com>

	* prep.ads, prep.adb (Expression): New Boolean parameter Complemented,
	defaulted to False.
	In the "not" case, recursive call with Complemented set to True.
	Do not allow "or" or "and" operators when Complemented is True.

From-SVN: r125441
parent af1a7c88
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2002-2006, Free Software Foundation, Inc. -- -- Copyright (C) 2002-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
with Csets; use Csets; with Csets; use Csets;
with Err_Vars; use Err_Vars; with Err_Vars; use Err_Vars;
with Namet; use Namet;
with Opt; use Opt; with Opt; use Opt;
with Osint; use Osint; with Osint; use Osint;
with Output; use Output; with Output; use Output;
...@@ -191,7 +190,9 @@ package body Prep is ...@@ -191,7 +190,9 @@ package body Prep is
function Deleting return Boolean; function Deleting return Boolean;
-- Return True if code should be deleted or commented out -- Return True if code should be deleted or commented out
function Expression (Evaluate_It : Boolean) return Boolean; function Expression
(Evaluate_It : Boolean;
Complemented : Boolean := False) return Boolean;
-- Evaluate a condition in an #if or an #elsif statement. -- Evaluate a condition in an #if or an #elsif statement.
-- If Evaluate_It is False, the condition is effectively evaluated, -- If Evaluate_It is False, the condition is effectively evaluated,
-- otherwise, only the syntax is checked. -- otherwise, only the syntax is checked.
...@@ -361,7 +362,6 @@ package body Prep is ...@@ -361,7 +362,6 @@ package body Prep is
if Pp_States.Last = Ground then if Pp_States.Last = Ground then
return False; return False;
else else
return Pp_States.Table (Pp_States.Last).Deleting; return Pp_States.Table (Pp_States.Last).Deleting;
end if; end if;
...@@ -371,7 +371,10 @@ package body Prep is ...@@ -371,7 +371,10 @@ package body Prep is
-- Expression -- -- Expression --
---------------- ----------------
function Expression (Evaluate_It : Boolean) return Boolean is function Expression
(Evaluate_It : Boolean;
Complemented : Boolean := False) return Boolean
is
Evaluation : Boolean := Evaluate_It; Evaluation : Boolean := Evaluate_It;
-- Is set to False after an "or else" when left term is True and -- Is set to False after an "or else" when left term is True and
-- after an "and then" when left term is False. -- after an "and then" when left term is False.
...@@ -420,7 +423,8 @@ package body Prep is ...@@ -420,7 +423,8 @@ package body Prep is
-- not expression -- not expression
Scan.all; Scan.all;
Current_Result := not Expression (Evaluation); Current_Result :=
not Expression (Evaluation, Complemented => True);
when Tok_Identifier => when Tok_Identifier =>
Symbol_Name1 := Token_Name; Symbol_Name1 := Token_Name;
...@@ -601,7 +605,12 @@ package body Prep is ...@@ -601,7 +605,12 @@ package body Prep is
-- Check the next operator -- Check the next operator
if Token = Tok_And then if Token = Tok_And then
if Current_Operator = Op_Or then if Complemented then
Error_Msg
("mixing NOT and AND is not allowed, parentheses are required",
Token_Ptr);
elsif Current_Operator = Op_Or then
Error_Msg ("mixing OR and AND is not allowed", Token_Ptr); Error_Msg ("mixing OR and AND is not allowed", Token_Ptr);
end if; end if;
...@@ -617,7 +626,12 @@ package body Prep is ...@@ -617,7 +626,12 @@ package body Prep is
end if; end if;
elsif Token = Tok_Or then elsif Token = Tok_Or then
if Current_Operator = Op_And then if Complemented then
Error_Msg
("mixing NOT and OR is not allowed, parentheses are required",
Token_Ptr);
elsif Current_Operator = Op_And then
Error_Msg ("mixing AND and OR is not allowed", Token_Ptr); Error_Msg ("mixing AND and OR is not allowed", Token_Ptr);
end if; end if;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 2002-2006, Free Software Foundation, Inc. -- -- Copyright (C) 2002-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
with GNAT.Dynamic_Tables; with GNAT.Dynamic_Tables;
with Types; use Types; with Namet; use Namet;
with Types; use Types;
package Prep is package Prep is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment