|
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 SymBuildParsingLib.Tree; |
|
21 using SymBuildParsingLib.Token; |
|
22 using SymBuildParsingLib.Parser.Framework; |
|
23 using SymBuildParsingLib.Parser.Framework.Workers; |
|
24 using SymBuildParsingLib.Parser.Framework.Nodes; |
|
25 using SymBuildParsingLib.Parser.PreProcessor.Parser; |
|
26 |
|
27 namespace SymBuildParsingLib.Parser.PreProcessor.Workers |
|
28 { |
|
29 public class SymPreProcessorWorker : SymParserWorker |
|
30 { |
|
31 #region Constructors & destructor |
|
32 public SymPreProcessorWorker( SymParserWorkerContext aContext ) |
|
33 : base( aContext, 1000 ) |
|
34 { |
|
35 } |
|
36 #endregion |
|
37 |
|
38 #region From SymParserWorker |
|
39 public override SymParserWorker.TTokenConsumptionType OfferToken( SymToken aToken ) |
|
40 { |
|
41 TTokenConsumptionType ret = TTokenConsumptionType.ETokenNotConsumed; |
|
42 |
|
43 #region Identify preprocessor tokens |
|
44 if ( aToken.Class == SymToken.TClass.EClassPreProcessor ) |
|
45 { |
|
46 if ( ChildCount == 0 ) |
|
47 { |
|
48 if ( aToken.Value == "#" ) |
|
49 { |
|
50 // Always consume initial preprocessor tokens... |
|
51 ret = TTokenConsumptionType.ETokenConsumed; |
|
52 } |
|
53 else |
|
54 { |
|
55 // Try to find a new child worker to handle this kind |
|
56 // of data. |
|
57 SymParserWorker worker = CreateWorkerByTokenType( aToken ); |
|
58 // |
|
59 if ( worker != null ) |
|
60 { |
|
61 System.Diagnostics.Debug.WriteLine( "SymPreProcessorWorker.OfferToken() - FOUND HANDLER FOR: " + aToken.Value ); |
|
62 |
|
63 AddChild( worker ); |
|
64 ret = TTokenConsumptionType.ETokenConsumed; |
|
65 } |
|
66 } |
|
67 } |
|
68 } |
|
69 #endregion |
|
70 |
|
71 // Give it to the children |
|
72 if ( ret == TTokenConsumptionType.ETokenNotConsumed ) |
|
73 { |
|
74 // Check whether we're inside a conditional expression skip state. |
|
75 bool allowedToOffer = Parser.ConditionalExpressionValue; |
|
76 if ( allowedToOffer ) |
|
77 { |
|
78 ret = base.OfferToken( aToken ); |
|
79 } |
|
80 } |
|
81 // |
|
82 return ret; |
|
83 } |
|
84 #endregion |
|
85 |
|
86 #region Internal methods |
|
87 private SymParserWorker CreateWorkerByTokenType( SymToken aToken ) |
|
88 { |
|
89 // Find a worker to handle the token type |
|
90 SymParserWorker worker = null; |
|
91 SymParserWorkerContext context = new SymParserWorkerContext( WorkerContext, this, aToken ); |
|
92 // |
|
93 switch( aToken.Value ) |
|
94 { |
|
95 // Simple preprocessor operations |
|
96 case "define": |
|
97 worker = new SymPreProcessorWorkerDefine( context ); |
|
98 break; |
|
99 case "undef": |
|
100 break; |
|
101 case "include": |
|
102 worker = new SymPreProcessorWorkerInclude( context ); |
|
103 break; |
|
104 |
|
105 // Conditionality |
|
106 case "if": |
|
107 worker = new SymPreProcessorWorkerIf( context ); |
|
108 break; |
|
109 case "ifdef": |
|
110 worker = new SymPreProcessorWorkerIfdef( context ); |
|
111 break; |
|
112 case "ifndef": |
|
113 worker = new SymPreProcessorWorkerIfndef( context ); |
|
114 break; |
|
115 case "else": |
|
116 worker = new SymPreProcessorWorkerElse( context ); |
|
117 break; |
|
118 case "elif": |
|
119 worker = new SymPreProcessorWorkerElseIf( context ); |
|
120 break; |
|
121 case "endif": |
|
122 worker = new SymPreProcessorWorkerEndif( context ); |
|
123 break; |
|
124 |
|
125 // Skip unhandled preprocessor directives |
|
126 default: |
|
127 worker = new SymParserWorkerConsumer( context, SymToken.TClass.EClassNewLine ); |
|
128 break; |
|
129 } |
|
130 // |
|
131 return worker; |
|
132 } |
|
133 #endregion |
|
134 |
|
135 #region Internal properties |
|
136 private SymPreProcessorParser Parser |
|
137 { |
|
138 get |
|
139 { |
|
140 return (SymPreProcessorParser) WorkerContext.Parser; |
|
141 } |
|
142 } |
|
143 #endregion |
|
144 |
|
145 #region Data members |
|
146 #endregion |
|
147 } |
|
148 } |