|
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 System.Collections; |
|
20 using SymbianTree; |
|
21 using SymBuildParsingLib.Tree; |
|
22 using SymBuildParsingLib.Common.Objects; |
|
23 using SymBuildParsingLib.Parser.PreProcessor.Workers; |
|
24 using SymBuildParsingLib.Parser.PreProcessor.Document; |
|
25 using SymBuildParsingLib.Parser.Framework.Nodes; |
|
26 using SymBuildParsingLib.Parser.Framework.Document; |
|
27 using SymBuildParsingLib.Parser.Framework.Workers; |
|
28 using SymBuildParsingLib.Parser.Framework.Parser; |
|
29 |
|
30 |
|
31 namespace SymBuildParsingLib.Parser.PreProcessor.Parser |
|
32 { |
|
33 public abstract class SymPreProcessorParser : SymParserBase |
|
34 { |
|
35 #region Constructors & destructor |
|
36 public SymPreProcessorParser( SymParserDocument aDocument ) |
|
37 : base( aDocument ) |
|
38 { |
|
39 } |
|
40 #endregion |
|
41 |
|
42 #region Properties |
|
43 public SymPreProcessorWorker MainWorker |
|
44 { |
|
45 get { return iMainWorker; } |
|
46 } |
|
47 #endregion |
|
48 |
|
49 #region From SymParserBase |
|
50 protected override string ParserName |
|
51 { |
|
52 get { return this.ToString(); } |
|
53 } |
|
54 |
|
55 protected override void PrepareInitialWorkers() |
|
56 { |
|
57 SymParserWorkerContext context = new SymParserWorkerContext( Document.Context ); |
|
58 iMainWorker = new SymPreProcessorWorker( context ); |
|
59 // |
|
60 QueueWorker( iMainWorker ); |
|
61 |
|
62 // Make a base call |
|
63 base.PrepareInitialWorkers(); |
|
64 } |
|
65 #endregion |
|
66 |
|
67 #region Conditional expression related |
|
68 public bool ConditionalExpressionValue |
|
69 { |
|
70 get |
|
71 { |
|
72 bool ret = true; |
|
73 // |
|
74 SymNodeConditionalExpression top = ConditionalExpressionPeek(); |
|
75 if ( top != null && top.HasCondition ) |
|
76 { |
|
77 // Use the current inherited value as the first filter. |
|
78 // This means that nested #ifs are handled correctly, (e.g. |
|
79 // an outer #if that evaluates to false will prevent an inner |
|
80 // #if that evalutes to true from being emitted). |
|
81 ret = top.InheritedValue; |
|
82 |
|
83 if ( ret ) |
|
84 { |
|
85 SymNodeCondition condition = top.CurrentCondition; |
|
86 ret = condition.EvaluationResult; |
|
87 } |
|
88 } |
|
89 // |
|
90 return ret; |
|
91 } |
|
92 } |
|
93 |
|
94 public void ConditionalExpressionPush( SymNodeConditionalExpression aConditionalExpression ) |
|
95 { |
|
96 bool inheritedValue = true; |
|
97 // |
|
98 SymNodeConditionalExpression top = ConditionalExpressionPeek(); |
|
99 if ( top != null ) |
|
100 { |
|
101 inheritedValue = top.InheritedValue; |
|
102 } |
|
103 // |
|
104 aConditionalExpression.InheritedValue = inheritedValue; |
|
105 iCondExpResultStack.Push( aConditionalExpression ); |
|
106 } |
|
107 |
|
108 public SymNodeConditionalExpression ConditionalExpressionPop() |
|
109 { |
|
110 System.Diagnostics.Debug.Assert( iCondExpResultStack.Count > 0 ); |
|
111 // |
|
112 SymNodeConditionalExpression top = ConditionalExpressionPeek(); |
|
113 iCondExpResultStack.Pop(); |
|
114 return top; |
|
115 } |
|
116 |
|
117 public SymNodeConditionalExpression ConditionalExpressionPeek() |
|
118 { |
|
119 SymNodeConditionalExpression top = null; |
|
120 // |
|
121 if ( iCondExpResultStack.Count > 0 ) |
|
122 { |
|
123 top = (SymNodeConditionalExpression) iCondExpResultStack.Peek(); |
|
124 } |
|
125 // |
|
126 return top; |
|
127 } |
|
128 #endregion |
|
129 |
|
130 #region Data members |
|
131 private SymPreProcessorWorker iMainWorker; |
|
132 private Stack iCondExpResultStack = new Stack(); |
|
133 #endregion |
|
134 } |
|
135 } |