forked from boo-lang/boo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support value comparison for defines
- Loading branch information
Showing
2 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#region license | ||
#region license | ||
// Copyright (c) 2009 Rodrigo B. de Oliveira ([email protected]) | ||
// All rights reserved. | ||
// | ||
|
@@ -25,8 +25,8 @@ | |
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
#endregion | ||
|
||
|
||
|
||
|
||
namespace Boo.Lang.Extensions | ||
|
||
import Boo.Lang.Compiler | ||
|
@@ -59,6 +59,25 @@ class IfdefMacro(AbstractAstMacro): | |
return Parameters.Defines.ContainsKey(condition.Name) | ||
|
||
private def EvaluateBinary(condition as BinaryExpression): | ||
if condition.Operator in (BinaryOperatorType.Equality, BinaryOperatorType.Inequality): | ||
lft = condition.Left.ToString() | ||
|
||
if not Parameters.Defines.ContainsKey(lft): | ||
return false | ||
|
||
rgt as string | ||
if condition.Right isa ReferenceExpression: | ||
rgt = (condition.Right as ReferenceExpression).Name | ||
elif condition.Right isa StringLiteralExpression: | ||
rgt = (condition.Right as StringLiteralExpression).Value | ||
else: | ||
rgt = condition.Right.ToString() | ||
|
||
if condition.Operator == BinaryOperatorType.Equality: | ||
return Parameters.Defines[lft] == rgt | ||
else: | ||
return Parameters.Defines[lft] != rgt | ||
|
||
if condition.Operator == BinaryOperatorType.Or: | ||
return Evaluate(condition.Left) or Evaluate(condition.Right) | ||
if condition.Operator == BinaryOperatorType.And: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters