@@ -191,8 +191,9 @@ public void ParseComponent(VBComponent vbComponent, TokenStreamRewriter rewriter
191
191
commentListener
192
192
} ;
193
193
194
- var tree = GetParseTree ( vbComponent , listeners , preprocessedModuleBody , qualifiedName ) ;
195
- WalkParseTree ( vbComponent , listeners , qualifiedName , tree ) ;
194
+ DeclarationSymbolsListener listener ;
195
+ var tree = GetParseTree ( vbComponent , listeners , preprocessedModuleBody , qualifiedName , out listener ) ;
196
+ WalkParseTree ( listeners , qualifiedName , tree , listener ) ;
196
197
197
198
State . SetModuleState ( vbComponent , ParserState . Parsed ) ;
198
199
}
@@ -212,12 +213,26 @@ public void ParseComponent(VBComponent vbComponent, TokenStreamRewriter rewriter
212
213
}
213
214
}
214
215
215
- private IParseTree GetParseTree ( VBComponent vbComponent , IParseTreeListener [ ] listeners , string code , QualifiedModuleName qualifiedName )
216
+ private IParseTree GetParseTree ( VBComponent vbComponent , IParseTreeListener [ ] listeners , string code , QualifiedModuleName qualifiedName , out DeclarationSymbolsListener declarationsListener )
216
217
{
217
218
var commentListener = listeners . OfType < CommentListener > ( ) . Single ( ) ;
218
219
ITokenStream stream ;
219
220
220
221
var stopwatch = Stopwatch . StartNew ( ) ;
222
+ if ( ! _componentAttributes . ContainsKey ( vbComponent ) )
223
+ {
224
+ _componentAttributes . Add ( vbComponent , _attributeParser . Parse ( vbComponent ) ) ;
225
+ }
226
+ var attributes = _componentAttributes [ vbComponent ] ;
227
+
228
+ // cannot locate declarations in one pass *the way it's currently implemented*,
229
+ // because the context in EnterSubStmt() doesn't *yet* have child nodes when the context enters.
230
+ // so we need to EnterAmbiguousIdentifier() and evaluate the parent instead - this *might* work.
231
+ declarationsListener = new DeclarationSymbolsListener ( qualifiedName , Accessibility . Implicit , vbComponent . Type , _state . GetModuleComments ( vbComponent ) , attributes ) ;
232
+
233
+ declarationsListener . NewDeclaration += declarationsListener_NewDeclaration ;
234
+ declarationsListener . CreateModuleDeclarations ( ) ;
235
+
221
236
var tree = ParseInternal ( code , listeners , out stream ) ;
222
237
stopwatch . Stop ( ) ;
223
238
if ( tree != null )
@@ -237,30 +252,15 @@ private IParseTree GetParseTree(VBComponent vbComponent, IParseTreeListener[] li
237
252
private readonly IDictionary < VBComponent , IDictionary < Tuple < string , DeclarationType > , Attributes > > _componentAttributes
238
253
= new Dictionary < VBComponent , IDictionary < Tuple < string , DeclarationType > , Attributes > > ( ) ;
239
254
240
- private void WalkParseTree ( VBComponent vbComponent , IReadOnlyList < IParseTreeListener > listeners , QualifiedModuleName qualifiedName , IParseTree tree )
255
+ private void WalkParseTree ( IReadOnlyList < IParseTreeListener > listeners , QualifiedModuleName qualifiedName , IParseTree tree , DeclarationSymbolsListener declarationsListener )
241
256
{
242
257
var obsoleteCallsListener = listeners . OfType < ObsoleteCallStatementListener > ( ) . Single ( ) ;
243
258
var obsoleteLetListener = listeners . OfType < ObsoleteLetStatementListener > ( ) . Single ( ) ;
244
259
var emptyStringLiteralListener = listeners . OfType < EmptyStringLiteralListener > ( ) . Single ( ) ;
245
260
var argListsWithOneByRefParamListener = listeners . OfType < ArgListWithOneByRefParamListener > ( ) . Single ( ) ;
246
261
247
- if ( ! _componentAttributes . ContainsKey ( vbComponent ) )
248
- {
249
- _componentAttributes . Add ( vbComponent , _attributeParser . Parse ( vbComponent ) ) ;
250
- }
251
- var attributes = _componentAttributes [ vbComponent ] ;
252
-
253
- // cannot locate declarations in one pass *the way it's currently implemented*,
254
- // because the context in EnterSubStmt() doesn't *yet* have child nodes when the context enters.
255
- // so we need to EnterAmbiguousIdentifier() and evaluate the parent instead - this *might* work.
256
- var declarationsListener = new DeclarationSymbolsListener ( qualifiedName , Accessibility . Implicit , vbComponent . Type , _state . GetModuleComments ( vbComponent ) , attributes ) ;
257
-
258
- declarationsListener . NewDeclaration += declarationsListener_NewDeclaration ;
259
- declarationsListener . CreateModuleDeclarations ( ) ;
260
-
261
262
var walker = new ParseTreeWalker ( ) ;
262
263
walker . Walk ( declarationsListener , tree ) ;
263
- declarationsListener . NewDeclaration -= declarationsListener_NewDeclaration ;
264
264
265
265
_state . ObsoleteCallContexts = obsoleteCallsListener . Contexts . Select ( context => new QualifiedContext ( qualifiedName , context ) ) ;
266
266
_state . ObsoleteLetContexts = obsoleteLetListener . Contexts . Select ( context => new QualifiedContext ( qualifiedName , context ) ) ;
0 commit comments