crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Parser/PreProcessor/Workers/SymPreProcessorWorkerEndif.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.Parser.Framework;
       
    21 using SymBuildParsingLib.Parser.Framework.Nodes;
       
    22 using SymBuildParsingLib.Parser.Framework.Workers;
       
    23 using SymBuildParsingLib.Parser.PreProcessor.Parser;
       
    24 
       
    25 namespace SymBuildParsingLib.Parser.PreProcessor.Workers
       
    26 {
       
    27 	public class SymPreProcessorWorkerEndif : SymParserWorker
       
    28 	{
       
    29 		#region Constructors & destructor
       
    30 		public SymPreProcessorWorkerEndif( SymParserWorkerContext aContext )
       
    31 			: base( aContext )
       
    32 		{
       
    33 			// When the endif token is reached, we must work back up the tree
       
    34 			// looking for the previous (i.e. most recent) conditional expression
       
    35 			// node.
       
    36 			SymNodeConditionalExpression condExpNode = SymParserWorkerConditionalExpression.FindMostRecentConditionalExpression( aContext.Document.CurrentNode );
       
    37 			if	( condExpNode == null )
       
    38 			{
       
    39 				throw new Exception( "Unable to locate most recent condition expression during ENDIF handling" );
       
    40 			}
       
    41 
       
    42 			// There must always be a positive condition node and some kind of condition
       
    43 			if	( condExpNode.ChildTypeExists( typeof(SymNodeCondition) ) == false )
       
    44 			{
       
    45 				throw new Exception( "No child condition node found during ENDIF handling" );
       
    46 			}
       
    47 
       
    48 			// We change the current node to be the parent of the conditional expression. 
       
    49 			// Any new tokens will appear as siblings
       
    50 			aContext.Document.CurrentNode = condExpNode.Parent;
       
    51 
       
    52 			// Make sure we tell the parser that it can pop off this conditional expression node.
       
    53 			SymPreProcessorParser parser = (SymPreProcessorParser) aContext.Parser;
       
    54 			SymNodeConditionalExpression poppedExpression = parser.ConditionalExpressionPop();
       
    55 			System.Diagnostics.Debug.Assert( poppedExpression == condExpNode );
       
    56 
       
    57 			// Job done - dequeue
       
    58 			RemoveSelf();
       
    59 		}
       
    60 		#endregion
       
    61 	}
       
    62 }