crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Parser/PreProcessor/Workers/SymPreProcessorWorkerElses.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.Nodes;
       
    24 
       
    25 namespace SymBuildParsingLib.Parser.PreProcessor.Workers
       
    26 {
       
    27 	public class SymPreProcessorWorkerElse : SymParserWorker
       
    28 	{
       
    29 		#region Constructors & destructor
       
    30 		public SymPreProcessorWorkerElse( SymParserWorkerContext aContext )
       
    31 			: base( aContext )
       
    32 		{
       
    33 			// When the else 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 ELSE 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 ELSE handling" );
       
    46 			}
       
    47 
       
    48 			// Make the conditional expression the current node
       
    49 			aContext.Document.CurrentNode = condExpNode;
       
    50 
       
    51 			// Make a new condition worker. The condition worker creates a new condition node
       
    52 			// which becomes the new current node.
       
    53 			SymParserWorkerContext context = new SymParserWorkerContext( aContext.Document.Context, this );
       
    54 			SymParserWorkerCondition conditionWorker = new SymParserWorkerCondition( context, new SymNodePreProcessorCondition( aContext.CurrentToken.Value ) );
       
    55 			AddChild( conditionWorker );
       
    56 
       
    57 			// If we didn't find any appropriately handled condition object, then
       
    58 			// we make this the catch-all condition (with no expression to evaluate)
       
    59 			if	( condExpNode.HasPositiveBranch == false )
       
    60 			{
       
    61 			}
       
    62 		}
       
    63 		#endregion
       
    64 
       
    65 		#region From SymParserWorker
       
    66 		public override void RemoveChild( SymParserWorker aWorker )
       
    67 		{
       
    68 			base.RemoveChild( aWorker );
       
    69 			RemoveSelf();
       
    70 		}
       
    71 		#endregion
       
    72 	}
       
    73 
       
    74 	public class SymPreProcessorWorkerElseIf : SymParserWorker
       
    75 	{
       
    76 		#region Constructors & destructor
       
    77 		public SymPreProcessorWorkerElseIf( SymParserWorkerContext aContext )
       
    78 			: base( aContext )
       
    79 		{
       
    80 			// When the else token is reached, we must work back up the tree
       
    81 			// looking for the previous (i.e. most recent) conditional expression
       
    82 			// node.
       
    83 			SymNodeConditionalExpression condExpNode = SymParserWorkerConditionalExpression.FindMostRecentConditionalExpression( aContext.Document.CurrentNode );
       
    84 			if	( condExpNode == null )
       
    85 			{
       
    86 				throw new Exception( "Unable to locate most recent condition expression during ELSE IF handling" );
       
    87 			}
       
    88 
       
    89 			// There must always be a positive condition node and some kind of condition
       
    90 			if	( condExpNode.ChildTypeExists( typeof(SymNodeCondition) ) == false )
       
    91 			{
       
    92 				throw new Exception( "No child condition node found during ELSE IF handling" );
       
    93 			}
       
    94 
       
    95 			// Make the conditional expression the current node
       
    96 			aContext.Document.CurrentNode = condExpNode;
       
    97 
       
    98 			// Make a new condition worker. The condition worker creates a new condition node
       
    99 			// which becomes the new current node.
       
   100 			SymParserWorkerContext context = new SymParserWorkerContext( aContext.Document.Context, this );
       
   101 			SymParserWorkerCondition conditionWorker = new SymParserWorkerCondition( context, new SymNodePreProcessorCondition( aContext.CurrentToken.Value ) );
       
   102 			AddChild( conditionWorker );
       
   103 		}
       
   104 		#endregion
       
   105 
       
   106 		#region From SymParserWorker
       
   107 		public override void RemoveChild( SymParserWorker aWorker )
       
   108 		{
       
   109 			base.RemoveChild( aWorker );
       
   110 			RemoveSelf();
       
   111 		}
       
   112 		#endregion
       
   113 	}
       
   114 }