crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Parser/Framework/Nodes/SymNodeCondition.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2004-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 using System;
       
    19 using SymBuildParsingLib.Tree;
       
    20 using SymBuildParsingLib.Token;
       
    21 using SymBuildParsingLib.Utils;
       
    22 using SymBuildParsingLib.Parser.Framework.Document;
       
    23 using SymBuildParsingLib.Parser.Framework.Workers;
       
    24 using SymbianTree;
       
    25 
       
    26 namespace SymBuildParsingLib.Parser.Framework.Nodes
       
    27 {
       
    28 	public class SymNodeCondition : SymNodeAddAsChild
       
    29 	{
       
    30 		#region Enumerations
       
    31 		public enum TType
       
    32 		{
       
    33 			ETypeUnknown = -1,
       
    34 			ETypeIf = 0,
       
    35 			ETypeIfdef,
       
    36 			ETypeIfndef,
       
    37 			ETypeElseIf,
       
    38 			ETypeElse
       
    39 		}
       
    40 		#endregion
       
    41 
       
    42 		#region Constructors & destructor
       
    43 		public SymNodeCondition( TType aType )
       
    44 		{
       
    45 			iType = aType;
       
    46 		}
       
    47 
       
    48 		public SymNodeCondition( string aName )
       
    49 			: this( SymNodeCondition.TypeByName( aName ) )
       
    50 		{
       
    51 			if	( Type == TType.ETypeUnknown )
       
    52 			{
       
    53 				throw new ArgumentException( "Invalid condition name: " + aName );
       
    54 			}
       
    55 		}
       
    56 		#endregion
       
    57 
       
    58 		#region API
       
    59 		public void MakeConditionalArgumentCurrent( SymParserDocument aDocument )
       
    60 		{
       
    61 			SymNodeConditionalExpression condExpNode = SymParserWorkerConditionalExpression.FindMostRecentConditionalExpression( this );
       
    62 			if	( condExpNode == null )
       
    63 			{
       
    64 				throw new Exception( "Unable to locate conditional expression. Document is corrupt" );
       
    65 			}
       
    66 
       
    67 			aDocument.CurrentNode = condExpNode;
       
    68 		}
       
    69 
       
    70 		static public TType TypeByName( string aName )
       
    71 		{
       
    72 			TType ret = TType.ETypeUnknown;
       
    73 			//
       
    74 			switch( aName )
       
    75 			{
       
    76 				case "if":
       
    77 					ret = TType.ETypeIf;
       
    78 					break;
       
    79 				case "ifdef":
       
    80 					ret = TType.ETypeIfdef;
       
    81 					break;
       
    82 				case "ifndef":
       
    83 					ret = TType.ETypeIfndef;
       
    84 					break;
       
    85 				case "elif":
       
    86 				case "else if":
       
    87 					ret = TType.ETypeElseIf;
       
    88 					break;
       
    89 				case "else":
       
    90 					ret = TType.ETypeElse;
       
    91 					break;
       
    92 				default:
       
    93 					break;
       
    94 			}
       
    95 			//
       
    96 			return ret;
       
    97 		}
       
    98 
       
    99 		public void AssignArgumentTokens( SymTokenBalancerDocument aDocument )
       
   100 		{
       
   101 			Data = aDocument;
       
   102 		}
       
   103 
       
   104 		public virtual void Evaluate( SymParserDocumentContext aContext )
       
   105 		{
       
   106 			IsEvaluated = false;
       
   107 
       
   108 			// Evaluate the expression, taking into account the current #define'd 
       
   109 			// values. Prepares a new document with these expressions evaluated.
       
   110 			SymTokenDocument evalDoc = BalancedArguments.ExtractTokensAsDocument( false, true );
       
   111 			string expression = evalDoc.ChildrenAsString( false, true );
       
   112 
       
   113 			// Get evaluated result from evaluator
       
   114 			iEvaluationResult = SymExpressionEvaluator.EvaluateAsBoolean( expression );
       
   115 
       
   116 			IsEvaluated = true;
       
   117 		}
       
   118 		#endregion
       
   119 
       
   120 		#region Properties
       
   121 		public TType Type
       
   122 		{
       
   123 			get { return iType; }
       
   124 		}
       
   125 
       
   126 		public bool EvaluationResult
       
   127 		{
       
   128 			get { return iEvaluationResult; }
       
   129 			set { iEvaluationResult = value; }
       
   130 		}
       
   131 
       
   132 		public bool IsEvaluated
       
   133 		{
       
   134 			get { return iIsEvaluated; }
       
   135 			set { iIsEvaluated = value; }
       
   136 		}
       
   137 
       
   138 		public SymTokenBalancerDocument BalancedArguments
       
   139 		{
       
   140 			get { return (SymTokenBalancerDocument) Data; }
       
   141 		}
       
   142 		#endregion
       
   143 
       
   144 		#region Data members
       
   145 		private bool iIsEvaluated = false;
       
   146 		private bool iEvaluationResult = true;
       
   147 		private readonly TType iType;
       
   148 		#endregion
       
   149 	}
       
   150 }