crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Parser/Framework/Workers/SymParserWorkerConsumer.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 SymbianTree;
       
    22 
       
    23 namespace SymBuildParsingLib.Parser.Framework.Workers
       
    24 {
       
    25 	public class SymParserWorkerConsumer : SymParserWorker
       
    26 	{
       
    27 		#region Enumerations
       
    28 		public enum TDyingAction
       
    29 		{
       
    30 			EWhenDyingTakeNoAction = 0,
       
    31 			EWhenDyingMakeRelativeParentNodeCurrent,
       
    32 			EWhenDyingMakeAbsoluteParentNodeCurrent
       
    33 		}
       
    34 		#endregion
       
    35 
       
    36 		#region Constructors & destructor
       
    37 		public SymParserWorkerConsumer( SymParserWorkerContext aContext, SymToken.TClass aTerminatingClassType )
       
    38 			: this( aContext, aTerminatingClassType, TDyingAction.EWhenDyingTakeNoAction )
       
    39 		{
       
    40 		}
       
    41 
       
    42 		public SymParserWorkerConsumer( SymParserWorkerContext aContext, SymToken.TClass aTerminatingClassType, TDyingAction aDyingAction )
       
    43 			: base( aContext )
       
    44 		{
       
    45 			iTerminatingClassType = aTerminatingClassType;
       
    46 			iDyingAction = aDyingAction;
       
    47 		}
       
    48 		#endregion
       
    49 
       
    50 		#region Properties
       
    51 		public SymTokenContainer ConsumedTokens
       
    52 		{
       
    53 			get { return iConsumedTokens; }
       
    54 		}
       
    55 		#endregion
       
    56 
       
    57 		#region Abstract API
       
    58 		protected virtual void HandleTerminatingConditionMatch( SymToken aToken )
       
    59 		{
       
    60 		}
       
    61 		#endregion
       
    62 
       
    63 		#region From SymParserWorker
       
    64 		public override SymParserWorker.TTokenConsumptionType OfferToken( SymToken aToken )
       
    65 		{
       
    66 			iConsumedTokens.Append( aToken );
       
    67 
       
    68 			if	( aToken.Class == iTerminatingClassType )
       
    69 			{
       
    70 				// Work out which node will become the parent (if we are configured in that way)
       
    71 				SymNode newParent = CalculateNewParentNode();
       
    72 
       
    73 				// Call back to parent class
       
    74 				HandleTerminatingConditionMatch( aToken );
       
    75 
       
    76 				// Reached the new line token. Stop receiving the tokens. We're done.
       
    77 				WorkerContext.Parent.RemoveChild( this );
       
    78 
       
    79 				// If the dying action was to make the relative parent node
       
    80 				// the current one, then we must call CalculateNewParentNode again
       
    81 				// after the HandleTerminatingConditionMatch callback - since 
       
    82 				// it may have changed the tree.
       
    83 				if	( iDyingAction == TDyingAction.EWhenDyingMakeRelativeParentNodeCurrent )
       
    84 				{
       
    85 					newParent = CalculateNewParentNode();
       
    86 				}
       
    87 
       
    88 				// Update the document with the new parent node
       
    89 				WorkerContext.Document.CurrentNode = newParent;
       
    90 			}
       
    91 			//
       
    92 			return TTokenConsumptionType.ETokenConsumed;
       
    93 		}
       
    94 		#endregion
       
    95 
       
    96 		#region Internal methods
       
    97 		private SymNode CalculateNewParentNode()
       
    98 		{
       
    99 			SymNode ret = WorkerContext.Document.CurrentNode;
       
   100 			//
       
   101 			if	( iDyingAction != TDyingAction.EWhenDyingTakeNoAction && WorkerContext.Document.CurrentNode.HasParent )
       
   102 			{
       
   103 				ret = WorkerContext.Document.CurrentNode.Parent;
       
   104 			}
       
   105 			//
       
   106 			return ret;
       
   107 		}
       
   108 		#endregion
       
   109 
       
   110 		#region Data members
       
   111 		private readonly SymToken.TClass iTerminatingClassType;
       
   112 		private readonly TDyingAction iDyingAction = TDyingAction.EWhenDyingTakeNoAction;
       
   113 		private SymTokenContainer iConsumedTokens = new SymTokenContainer();
       
   114 		#endregion
       
   115 	}
       
   116 }