~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
//     <copyright see="prj:///doc/copyright.txt"/>
3
3
//     <license see="prj:///doc/license.txt"/>
4
4
//     <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
5
 
//     <version>$Revision: 2200 $</version>
 
5
//     <version>$Revision: 3125 $</version>
6
6
// </file>
7
7
 
8
8
using System;
15
15
using ICSharpCode.NRefactory.Ast;
16
16
using ICSharpCode.NRefactory.Parser;
17
17
using ICSharpCode.NRefactory.Parser.VB;
 
18
using ICSharpCode.NRefactory.Visitors;
18
19
 
19
20
namespace ICSharpCode.NRefactory.PrettyPrinter
20
21
{
21
 
        public class VBNetOutputVisitor : IOutputAstVisitor
 
22
        public sealed class VBNetOutputVisitor : NodeTrackingAstVisitor, IOutputAstVisitor
22
23
        {
23
24
                Errors                  errors             = new Errors();
24
25
                VBNetOutputFormatter    outputFormatter;
25
26
                VBNetPrettyPrintOptions prettyPrintOptions = new VBNetPrettyPrintOptions();
26
 
                NodeTracker             nodeTracker;
27
27
                TypeDeclaration         currentType;
28
28
                bool printFullSystemType;
29
29
                
49
49
                        get { return prettyPrintOptions; }
50
50
                }
51
51
                
52
 
                public NodeTracker NodeTracker {
53
 
                        get {
54
 
                                return nodeTracker;
55
 
                        }
56
 
                }
57
 
                
58
52
                public IOutputFormatter OutputFormatter {
59
53
                        get {
60
54
                                return outputFormatter;
64
58
                public VBNetOutputVisitor()
65
59
                {
66
60
                        outputFormatter = new VBNetOutputFormatter(prettyPrintOptions);
67
 
                        nodeTracker     = new NodeTracker(this);
 
61
                }
 
62
                
 
63
                public void Reset ()
 
64
                {
 
65
                        outputFormatter.Reset ();
 
66
                }
 
67
                
 
68
                public event Action<INode> BeforeNodeVisit;
 
69
                public event Action<INode> AfterNodeVisit;
 
70
                
 
71
                protected override void BeginVisit(INode node)
 
72
                {
 
73
                        if (BeforeNodeVisit != null) {
 
74
                                BeforeNodeVisit(node);
 
75
                        }
 
76
                        base.BeginVisit(node);
 
77
                }
 
78
                
 
79
                protected override void EndVisit(INode node)
 
80
                {
 
81
                        base.EndVisit(node);
 
82
                        if (AfterNodeVisit != null) {
 
83
                                AfterNodeVisit(node);
 
84
                        }
 
85
                }
 
86
                
 
87
                object TrackedVisit(INode node, object data)
 
88
                {
 
89
                        return node.AcceptVisitor(this, data);
68
90
                }
69
91
                
70
92
                void Error(string text, Location position)
78
100
                }
79
101
                
80
102
                #region ICSharpCode.NRefactory.Parser.IASTVisitor interface implementation
81
 
                public object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
 
103
                public override object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data)
82
104
                {
83
 
                        nodeTracker.TrackedVisitChildren(compilationUnit, data);
 
105
                        compilationUnit.AcceptChildren(this, data);
84
106
                        outputFormatter.EndFile();
85
107
                        return null;
86
108
                }
96
118
                        return primitiveType;
97
119
                }
98
120
 
99
 
                public object VisitTypeReference(TypeReference typeReference, object data)
 
121
                public override object TrackedVisitTypeReference(TypeReference typeReference, object data)
100
122
                {
101
123
                        if (typeReference == TypeReference.ClassConstraint) {
102
124
                                outputFormatter.PrintToken(Tokens.Class);
154
176
                        }
155
177
                }
156
178
                
157
 
                public object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data)
 
179
                public override object TrackedVisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data)
158
180
                {
159
 
                        nodeTracker.TrackedVisit(innerClassTypeReference.BaseType, data);
 
181
                        TrackedVisit(innerClassTypeReference.BaseType, data);
160
182
                        outputFormatter.PrintToken(Tokens.Dot);
161
183
                        return VisitTypeReference((TypeReference)innerClassTypeReference, data);
162
184
                }
163
185
                
164
186
                #region Global scope
165
 
                public object VisitAttributeSection(AttributeSection attributeSection, object data)
 
187
                bool printAttributeSectionInline; // is set to true when printing parameter's attributes
 
188
                
 
189
                public override object TrackedVisitAttributeSection(AttributeSection attributeSection, object data)
166
190
                {
167
 
                        outputFormatter.Indent();
 
191
                        if (!printAttributeSectionInline)
 
192
                                outputFormatter.Indent();
168
193
                        outputFormatter.PrintText("<");
169
194
                        if (attributeSection.AttributeTarget != null && attributeSection.AttributeTarget.Length > 0) {
170
 
                                outputFormatter.PrintIdentifier(attributeSection.AttributeTarget);
 
195
                                outputFormatter.PrintText(char.ToUpperInvariant(attributeSection.AttributeTarget[0]) + attributeSection.AttributeTarget.Substring(1));
171
196
                                outputFormatter.PrintToken(Tokens.Colon);
172
197
                                outputFormatter.Space();
173
198
                        }
180
205
                            || "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) {
181
206
                                outputFormatter.NewLine();
182
207
                        } else {
183
 
                                outputFormatter.PrintLineContinuation();
 
208
                                if (printAttributeSectionInline)
 
209
                                        outputFormatter.Space();
 
210
                                else
 
211
                                        outputFormatter.PrintLineContinuation();
184
212
                        }
185
213
                        
186
214
                        return null;
187
215
                }
188
216
                
189
 
                public object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data)
 
217
                public override object TrackedVisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data)
190
218
                {
191
219
                        outputFormatter.PrintIdentifier(attribute.Name);
192
 
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
193
 
                        AppendCommaSeparatedList(attribute.PositionalArguments);
194
 
                        
195
 
                        if (attribute.NamedArguments != null && attribute.NamedArguments.Count > 0) {
196
 
                                if (attribute.PositionalArguments.Count > 0) {
197
 
                                        outputFormatter.PrintToken(Tokens.Comma);
198
 
                                        outputFormatter.Space();
 
220
                        if (attribute.PositionalArguments.Count > 0 || attribute.NamedArguments.Count > 0) {
 
221
                                outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
222
                                AppendCommaSeparatedList(attribute.PositionalArguments);
 
223
                                
 
224
                                if (attribute.NamedArguments.Count > 0) {
 
225
                                        if (attribute.PositionalArguments.Count > 0) {
 
226
                                                outputFormatter.PrintToken(Tokens.Comma);
 
227
                                                outputFormatter.Space();
 
228
                                        }
 
229
                                        AppendCommaSeparatedList(attribute.NamedArguments);
199
230
                                }
200
 
                                AppendCommaSeparatedList(attribute.NamedArguments);
 
231
                                outputFormatter.PrintToken(Tokens.CloseParenthesis);
201
232
                        }
202
 
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
203
233
                        return null;
204
234
                }
205
235
                
206
 
                public object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
 
236
                public override object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
207
237
                {
208
238
                        outputFormatter.PrintIdentifier(namedArgumentExpression.Name);
209
239
                        outputFormatter.Space();
210
240
                        outputFormatter.PrintToken(Tokens.Colon);
211
241
                        outputFormatter.PrintToken(Tokens.Assign);
212
242
                        outputFormatter.Space();
213
 
                        nodeTracker.TrackedVisit(namedArgumentExpression.Expression, data);
 
243
                        TrackedVisit(namedArgumentExpression.Expression, data);
214
244
                        return null;
215
245
                }
216
246
                
217
 
                public object VisitUsing(Using @using, object data)
 
247
                public override object TrackedVisitUsing(Using @using, object data)
218
248
                {
219
249
                        Debug.Fail("Should never be called. The usings should be handled in Visit(UsingDeclaration)");
220
250
                        return null;
221
251
                }
222
252
                
223
 
                public object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
 
253
                public override object TrackedVisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
224
254
                {
225
255
                        outputFormatter.Indent();
226
256
                        outputFormatter.PrintToken(Tokens.Imports);
232
262
                                        outputFormatter.PrintToken(Tokens.Assign);
233
263
                                        outputFormatter.Space();
234
264
                                        printFullSystemType = true;
235
 
                                        nodeTracker.TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data);
 
265
                                        TrackedVisit(((Using)usingDeclaration.Usings[i]).Alias, data);
236
266
                                        printFullSystemType = false;
237
267
                                }
238
268
                                if (i + 1 < usingDeclaration.Usings.Count) {
244
274
                        return null;
245
275
                }
246
276
                
247
 
                public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
 
277
                public override object TrackedVisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
248
278
                {
249
279
                        outputFormatter.Indent();
250
280
                        outputFormatter.PrintToken(Tokens.Namespace);
253
283
                        outputFormatter.NewLine();
254
284
                        
255
285
                        ++outputFormatter.IndentationLevel;
256
 
                        nodeTracker.TrackedVisitChildren(namespaceDeclaration, data);
 
286
                        namespaceDeclaration.AcceptChildren(this, data);
257
287
                        --outputFormatter.IndentationLevel;
258
288
                        
259
289
                        outputFormatter.Indent();
291
321
                        }
292
322
                }
293
323
                
294
 
                public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
 
324
                public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
295
325
                {
296
326
                        VisitAttributes(typeDeclaration.Attributes, data);
297
327
                        
312
342
                                outputFormatter.PrintToken(Tokens.As);
313
343
                                outputFormatter.Space();
314
344
                                foreach (TypeReference baseTypeRef in typeDeclaration.BaseTypes) {
315
 
                                        nodeTracker.TrackedVisit(baseTypeRef, data);
 
345
                                        TrackedVisit(baseTypeRef, data);
316
346
                                }
317
347
                        }
318
348
                        
335
365
                                                outputFormatter.PrintToken(Tokens.Implements);
336
366
                                        }
337
367
                                        outputFormatter.Space();
338
 
                                        nodeTracker.TrackedVisit(baseTypeRef, data);
 
368
                                        TrackedVisit(baseTypeRef, data);
339
369
                                        outputFormatter.NewLine();
340
370
                                }
341
371
                        }
346
376
                        if (typeDeclaration.Type == ClassType.Enum) {
347
377
                                OutputEnumMembers(typeDeclaration, data);
348
378
                        } else {
349
 
                                nodeTracker.TrackedVisitChildren(typeDeclaration, data);
 
379
                                typeDeclaration.AcceptChildren(this, data);
350
380
                        }
351
381
                        currentType = oldType;
352
382
                        
364
394
                void OutputEnumMembers(TypeDeclaration typeDeclaration, object data)
365
395
                {
366
396
                        foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) {
367
 
                                nodeTracker.BeginNode(fieldDeclaration);
 
397
                                BeginVisit(fieldDeclaration);
368
398
                                VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
369
399
                                VisitAttributes(fieldDeclaration.Attributes, data);
370
400
                                outputFormatter.Indent();
373
403
                                        outputFormatter.Space();
374
404
                                        outputFormatter.PrintToken(Tokens.Assign);
375
405
                                        outputFormatter.Space();
376
 
                                        nodeTracker.TrackedVisit(f.Initializer, data);
 
406
                                        TrackedVisit(f.Initializer, data);
377
407
                                }
378
408
                                outputFormatter.NewLine();
379
 
                                nodeTracker.EndNode(fieldDeclaration);
 
409
                                EndVisit(fieldDeclaration);
380
410
                        }
381
411
                }
382
412
                
383
 
                public object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data)
 
413
                public override object TrackedVisitTemplateDefinition(TemplateDefinition templateDefinition, object data)
384
414
                {
385
415
                        outputFormatter.PrintIdentifier(templateDefinition.Name);
386
416
                        if (templateDefinition.Bases.Count > 0) {
387
417
                                outputFormatter.PrintText(" As ");
388
418
                                if (templateDefinition.Bases.Count == 1) {
389
 
                                        nodeTracker.TrackedVisit(templateDefinition.Bases[0], data);
 
419
                                        TrackedVisit(templateDefinition.Bases[0], data);
390
420
                                } else {
391
421
                                        outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
392
422
                                        AppendCommaSeparatedList(templateDefinition.Bases);
396
426
                        return null;
397
427
                }
398
428
                
399
 
                public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
 
429
                public override object TrackedVisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
400
430
                {
401
431
                        VisitAttributes(delegateDeclaration.Attributes, data);
402
432
                        
425
455
                                outputFormatter.Space();
426
456
                                outputFormatter.PrintToken(Tokens.As);
427
457
                                outputFormatter.Space();
428
 
                                nodeTracker.TrackedVisit(delegateDeclaration.ReturnType, data);
 
458
                                TrackedVisit(delegateDeclaration.ReturnType, data);
429
459
                        }
430
460
                        outputFormatter.NewLine();
431
461
                        return null;
432
462
                }
433
463
                
434
 
                public object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data)
 
464
                public override object TrackedVisitOptionDeclaration(OptionDeclaration optionDeclaration, object data)
435
465
                {
436
466
                        outputFormatter.PrintToken(Tokens.Option);
437
467
                        outputFormatter.Space();
469
499
                
470
500
                #region Type level
471
501
                TypeReference currentVariableType;
472
 
                public object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
 
502
                public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
473
503
                {
474
504
                        
475
505
                        VisitAttributes(fieldDeclaration.Attributes, data);
492
522
                        return null;
493
523
                }
494
524
                
495
 
                public object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
 
525
                public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
496
526
                {
497
527
                        outputFormatter.PrintIdentifier(variableDeclaration.Name);
498
528
                        
508
538
                                outputFormatter.Space();
509
539
                                ObjectCreateExpression init = variableDeclaration.Initializer as ObjectCreateExpression;
510
540
                                if (init != null && TypeReference.AreEqualReferences(init.CreateType, varType)) {
511
 
                                        nodeTracker.TrackedVisit(variableDeclaration.Initializer, data);
 
541
                                        TrackedVisit(variableDeclaration.Initializer, data);
512
542
                                        return null;
513
543
                                } else {
514
 
                                        nodeTracker.TrackedVisit(varType, data);
 
544
                                        TrackedVisit(varType, data);
515
545
                                }
516
546
                        }
517
547
                        
519
549
                                outputFormatter.Space();
520
550
                                outputFormatter.PrintToken(Tokens.Assign);
521
551
                                outputFormatter.Space();
522
 
                                nodeTracker.TrackedVisit(variableDeclaration.Initializer, data);
 
552
                                TrackedVisit(variableDeclaration.Initializer, data);
523
553
                        }
524
554
                        return null;
525
555
                }
526
556
                
527
 
                public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
 
557
                public override object TrackedVisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
528
558
                {
529
559
                        VisitAttributes(propertyDeclaration.Attributes, data);
530
560
                        outputFormatter.Indent();
550
580
                        outputFormatter.Space();
551
581
                        outputFormatter.PrintToken(Tokens.As);
552
582
                        outputFormatter.Space();
553
 
                        nodeTracker.TrackedVisit(propertyDeclaration.TypeReference, data);
 
583
                        TrackedVisit(propertyDeclaration.TypeReference, data);
554
584
                        
555
585
                        PrintInterfaceImplementations(propertyDeclaration.InterfaceImplementations);
556
586
                        
557
587
                        outputFormatter.NewLine();
558
588
                        
559
589
                        if (!IsAbstract(propertyDeclaration)) {
 
590
                                outputFormatter.IsInMemberBody = true;
560
591
                                ++outputFormatter.IndentationLevel;
561
592
                                exitTokenStack.Push(Tokens.Property);
562
 
                                nodeTracker.TrackedVisit(propertyDeclaration.GetRegion, data);
563
 
                                nodeTracker.TrackedVisit(propertyDeclaration.SetRegion, data);
 
593
                                TrackedVisit(propertyDeclaration.GetRegion, data);
 
594
                                TrackedVisit(propertyDeclaration.SetRegion, data);
564
595
                                exitTokenStack.Pop();
565
596
                                --outputFormatter.IndentationLevel;
 
597
                                outputFormatter.IsInMemberBody = false;
566
598
                                
567
599
                                outputFormatter.Indent();
568
600
                                outputFormatter.PrintToken(Tokens.End);
574
606
                        return null;
575
607
                }
576
608
                
577
 
                public object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data)
 
609
                public override object TrackedVisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data)
578
610
                {
579
611
                        VisitAttributes(propertyGetRegion.Attributes, data);
580
612
                        outputFormatter.Indent();
583
615
                        outputFormatter.NewLine();
584
616
                        
585
617
                        ++outputFormatter.IndentationLevel;
586
 
                        nodeTracker.TrackedVisit(propertyGetRegion.Block, data);
 
618
                        TrackedVisit(propertyGetRegion.Block, data);
587
619
                        --outputFormatter.IndentationLevel;
588
620
                        outputFormatter.Indent();
589
621
                        outputFormatter.PrintToken(Tokens.End);
593
625
                        return null;
594
626
                }
595
627
                
596
 
                public object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data)
 
628
                public override object TrackedVisitPropertySetRegion(PropertySetRegion propertySetRegion, object data)
597
629
                {
598
630
                        VisitAttributes(propertySetRegion.Attributes, data);
599
631
                        outputFormatter.Indent();
602
634
                        outputFormatter.NewLine();
603
635
                        
604
636
                        ++outputFormatter.IndentationLevel;
605
 
                        nodeTracker.TrackedVisit(propertySetRegion.Block, data);
 
637
                        TrackedVisit(propertySetRegion.Block, data);
606
638
                        --outputFormatter.IndentationLevel;
607
639
                        outputFormatter.Indent();
608
640
                        outputFormatter.PrintToken(Tokens.End);
613
645
                }
614
646
                
615
647
                TypeReference currentEventType = null;
616
 
                public object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
 
648
                public override object TrackedVisitEventDeclaration(EventDeclaration eventDeclaration, object data)
617
649
                {
618
650
                        bool customEvent = eventDeclaration.HasAddRegion  || eventDeclaration.HasRemoveRegion;
619
651
                        
637
669
                        outputFormatter.Space();
638
670
                        outputFormatter.PrintToken(Tokens.As);
639
671
                        outputFormatter.Space();
640
 
                        nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data);
 
672
                        TrackedVisit(eventDeclaration.TypeReference, data);
641
673
                        
642
674
                        PrintInterfaceImplementations(eventDeclaration.InterfaceImplementations);
643
675
                        
645
677
                                outputFormatter.Space();
646
678
                                outputFormatter.PrintToken(Tokens.Assign);
647
679
                                outputFormatter.Space();
648
 
                                nodeTracker.TrackedVisit(eventDeclaration.Initializer, data);
 
680
                                TrackedVisit(eventDeclaration.Initializer, data);
649
681
                        }
650
682
                        
651
683
                        outputFormatter.NewLine();
654
686
                                ++outputFormatter.IndentationLevel;
655
687
                                currentEventType = eventDeclaration.TypeReference;
656
688
                                exitTokenStack.Push(Tokens.Sub);
657
 
                                nodeTracker.TrackedVisit(eventDeclaration.AddRegion, data);
658
 
                                nodeTracker.TrackedVisit(eventDeclaration.RemoveRegion, data);
 
689
                                TrackedVisit(eventDeclaration.AddRegion, data);
 
690
                                TrackedVisit(eventDeclaration.RemoveRegion, data);
659
691
                                exitTokenStack.Pop();
660
692
                                --outputFormatter.IndentationLevel;
661
693
                                
678
710
                                if (i > 0)
679
711
                                        outputFormatter.PrintToken(Tokens.Comma);
680
712
                                outputFormatter.Space();
681
 
                                nodeTracker.TrackedVisit(list[i].InterfaceType, null);
 
713
                                TrackedVisit(list[i].InterfaceType, null);
682
714
                                outputFormatter.PrintToken(Tokens.Dot);
683
715
                                outputFormatter.PrintIdentifier(list[i].MemberName);
684
716
                        }
685
717
                }
686
718
                
687
 
                public object VisitEventAddRegion(EventAddRegion eventAddRegion, object data)
 
719
                public override object TrackedVisitEventAddRegion(EventAddRegion eventAddRegion, object data)
688
720
                {
689
721
                        VisitAttributes(eventAddRegion.Attributes, data);
690
722
                        outputFormatter.Indent();
696
728
                                outputFormatter.Space();
697
729
                                outputFormatter.PrintToken(Tokens.As);
698
730
                                outputFormatter.Space();
699
 
                                nodeTracker.TrackedVisit(currentEventType, data);
 
731
                                TrackedVisit(currentEventType, data);
700
732
                        } else {
701
733
                                this.AppendCommaSeparatedList(eventAddRegion.Parameters);
702
734
                        }
704
736
                        outputFormatter.NewLine();
705
737
                        
706
738
                        ++outputFormatter.IndentationLevel;
707
 
                        nodeTracker.TrackedVisit(eventAddRegion.Block, data);
 
739
                        TrackedVisit(eventAddRegion.Block, data);
708
740
                        --outputFormatter.IndentationLevel;
709
741
                        
710
742
                        outputFormatter.Indent();
715
747
                        return null;
716
748
                }
717
749
                
718
 
                public object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data)
 
750
                public override object TrackedVisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data)
719
751
                {
720
752
                        VisitAttributes(eventRemoveRegion.Attributes, data);
721
753
                        outputFormatter.Indent();
728
760
                                outputFormatter.Space();
729
761
                                outputFormatter.PrintToken(Tokens.As);
730
762
                                outputFormatter.Space();
731
 
                                nodeTracker.TrackedVisit(currentEventType, data);
 
763
                                TrackedVisit(currentEventType, data);
732
764
                        } else {
733
765
                                this.AppendCommaSeparatedList(eventRemoveRegion.Parameters);
734
766
                        }
736
768
                        outputFormatter.NewLine();
737
769
                        
738
770
                        ++outputFormatter.IndentationLevel;
739
 
                        nodeTracker.TrackedVisit(eventRemoveRegion.Block, data);
 
771
                        TrackedVisit(eventRemoveRegion.Block, data);
740
772
                        --outputFormatter.IndentationLevel;
741
773
                        
742
774
                        outputFormatter.Indent();
747
779
                        return null;
748
780
                }
749
781
                
750
 
                public object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data)
 
782
                public override object TrackedVisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data)
751
783
                {
752
784
                        VisitAttributes(eventRaiseRegion.Attributes, data);
753
785
                        outputFormatter.Indent();
760
792
                                outputFormatter.Space();
761
793
                                outputFormatter.PrintToken(Tokens.As);
762
794
                                outputFormatter.Space();
763
 
                                nodeTracker.TrackedVisit(currentEventType, data);
 
795
                                TrackedVisit(currentEventType, data);
764
796
                        } else {
765
797
                                this.AppendCommaSeparatedList(eventRaiseRegion.Parameters);
766
798
                        }
768
800
                        outputFormatter.NewLine();
769
801
                        
770
802
                        ++outputFormatter.IndentationLevel;
771
 
                        nodeTracker.TrackedVisit(eventRaiseRegion.Block, data);
 
803
                        TrackedVisit(eventRaiseRegion.Block, data);
772
804
                        --outputFormatter.IndentationLevel;
773
805
                        
774
806
                        outputFormatter.Indent();
779
811
                        return null;
780
812
                }
781
813
                
782
 
                public object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
 
814
                public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
783
815
                {
 
816
                        printAttributeSectionInline = true;
784
817
                        VisitAttributes(parameterDeclarationExpression.Attributes, data);
 
818
                        printAttributeSectionInline = false;
785
819
                        OutputModifier(parameterDeclarationExpression.ParamModifier, parameterDeclarationExpression.StartLocation);
786
820
                        outputFormatter.PrintIdentifier(parameterDeclarationExpression.ParameterName);
787
821
                        outputFormatter.Space();
788
822
                        outputFormatter.PrintToken(Tokens.As);
789
823
                        outputFormatter.Space();
790
 
                        nodeTracker.TrackedVisit(parameterDeclarationExpression.TypeReference, data);
 
824
                        TrackedVisit(parameterDeclarationExpression.TypeReference, data);
791
825
                        return null;
792
826
                }
793
827
                
794
 
                public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
 
828
                public override object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
795
829
                {
796
830
                        VisitAttributes(methodDeclaration.Attributes, data);
 
831
                        if (methodDeclaration.IsExtensionMethod) {
 
832
                                outputFormatter.Indent();
 
833
                                outputFormatter.PrintText("<System.Runtime.CompilerServices.Extension> _");
 
834
                                outputFormatter.NewLine();
 
835
                        }
797
836
                        outputFormatter.Indent();
798
837
                        OutputModifier(methodDeclaration.Modifier);
799
838
                        
818
857
                                outputFormatter.Space();
819
858
                                outputFormatter.PrintToken(Tokens.As);
820
859
                                outputFormatter.Space();
821
 
                                nodeTracker.TrackedVisit(methodDeclaration.TypeReference, data);
 
860
                                TrackedVisit(methodDeclaration.TypeReference, data);
822
861
                        }
823
862
                        
824
863
                        PrintInterfaceImplementations(methodDeclaration.InterfaceImplementations);
825
864
                        
 
865
                        if (methodDeclaration.HandlesClause.Count > 0) {
 
866
                                outputFormatter.Space();
 
867
                                outputFormatter.PrintToken(Tokens.Handles);
 
868
                                for (int i = 0; i < methodDeclaration.HandlesClause.Count; i++) {
 
869
                                        if (i > 0)
 
870
                                                outputFormatter.PrintToken(Tokens.Comma);
 
871
                                        outputFormatter.Space();
 
872
                                        outputFormatter.PrintText(methodDeclaration.HandlesClause[i]);
 
873
                                }
 
874
                        }
 
875
                        
826
876
                        outputFormatter.NewLine();
827
877
                        
828
878
                        if (!IsAbstract(methodDeclaration)) {
829
 
                                nodeTracker.BeginNode(methodDeclaration.Body);
 
879
                                outputFormatter.IsInMemberBody = true;
 
880
                                BeginVisit(methodDeclaration.Body);
830
881
                                ++outputFormatter.IndentationLevel;
831
882
                                exitTokenStack.Push(isSub ? Tokens.Sub : Tokens.Function);
832
 
                                methodDeclaration.Body.AcceptVisitor(this, data);
 
883
                                // we're doing the tracking manually using BeginVisit/EndVisit, so call Tracked... directly
 
884
                                this.TrackedVisitBlockStatement(methodDeclaration.Body, data);
833
885
                                exitTokenStack.Pop();
834
886
                                --outputFormatter.IndentationLevel;
835
887
                                
842
894
                                        outputFormatter.PrintToken(Tokens.Function);
843
895
                                }
844
896
                                outputFormatter.NewLine();
845
 
                                nodeTracker.EndNode(methodDeclaration.Body);
 
897
                                EndVisit(methodDeclaration.Body);
 
898
                                outputFormatter.IsInMemberBody = false;
846
899
                        }
847
900
                        return null;
848
901
                }
849
902
                
850
 
                public object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data)
 
903
                public override object TrackedVisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data)
851
904
                {
852
905
                        throw new InvalidOperationException();
853
906
                }
859
912
                        return currentType != null && currentType.Type == ClassType.Interface;
860
913
                }
861
914
                
862
 
                public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
 
915
                public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
863
916
                {
864
917
                        VisitAttributes(constructorDeclaration.Attributes, data);
865
918
                        outputFormatter.Indent();
872
925
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
873
926
                        outputFormatter.NewLine();
874
927
                        
 
928
                        outputFormatter.IsInMemberBody = true;
875
929
                        ++outputFormatter.IndentationLevel;
876
930
                        exitTokenStack.Push(Tokens.Sub);
877
931
                        
878
 
                        nodeTracker.TrackedVisit(constructorDeclaration.ConstructorInitializer, data);
 
932
                        TrackedVisit(constructorDeclaration.ConstructorInitializer, data);
879
933
                        
880
 
                        nodeTracker.TrackedVisit(constructorDeclaration.Body, data);
 
934
                        TrackedVisit(constructorDeclaration.Body, data);
881
935
                        exitTokenStack.Pop();
882
936
                        --outputFormatter.IndentationLevel;
 
937
                        outputFormatter.IsInMemberBody = false;
883
938
                        
884
939
                        outputFormatter.Indent();
885
940
                        outputFormatter.PrintToken(Tokens.End);
890
945
                        return null;
891
946
                }
892
947
                
893
 
                public object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data)
 
948
                public override object TrackedVisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data)
894
949
                {
895
950
                        outputFormatter.Indent();
896
951
                        if (constructorInitializer.ConstructorInitializerType == ConstructorInitializerType.This) {
908
963
                        return null;
909
964
                }
910
965
                
911
 
                public object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
 
966
                public override object TrackedVisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
912
967
                {
913
968
                        VisitAttributes(indexerDeclaration.Attributes, data);
914
969
                        outputFormatter.Indent();
933
988
                        outputFormatter.Space();
934
989
                        outputFormatter.PrintToken(Tokens.As);
935
990
                        outputFormatter.Space();
936
 
                        nodeTracker.TrackedVisit(indexerDeclaration.TypeReference, data);
 
991
                        TrackedVisit(indexerDeclaration.TypeReference, data);
937
992
                        PrintInterfaceImplementations(indexerDeclaration.InterfaceImplementations);
938
993
                        
939
994
                        outputFormatter.NewLine();
940
995
                        ++outputFormatter.IndentationLevel;
941
996
                        exitTokenStack.Push(Tokens.Property);
942
 
                        nodeTracker.TrackedVisit(indexerDeclaration.GetRegion, data);
943
 
                        nodeTracker.TrackedVisit(indexerDeclaration.SetRegion, data);
 
997
                        TrackedVisit(indexerDeclaration.GetRegion, data);
 
998
                        TrackedVisit(indexerDeclaration.SetRegion, data);
944
999
                        exitTokenStack.Pop();
945
1000
                        --outputFormatter.IndentationLevel;
946
1001
                        
952
1007
                        return null;
953
1008
                }
954
1009
                
955
 
                public object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data)
 
1010
                public override object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data)
956
1011
                {
957
1012
                        outputFormatter.Indent();
958
1013
                        outputFormatter.PrintText("Protected Overrides Sub Finalize()");
966
1021
                        outputFormatter.NewLine();
967
1022
                        
968
1023
                        ++outputFormatter.IndentationLevel;
969
 
                        nodeTracker.TrackedVisit(destructorDeclaration.Body, data);
 
1024
                        TrackedVisit(destructorDeclaration.Body, data);
970
1025
                        --outputFormatter.IndentationLevel;
971
1026
                        
972
1027
                        outputFormatter.Indent();
997
1052
                        return null;
998
1053
                }
999
1054
                
1000
 
                public object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data)
 
1055
                public override object TrackedVisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data)
1001
1056
                {
1002
1057
                        VisitAttributes(operatorDeclaration.Attributes, data);
1003
1058
                        outputFormatter.Indent();
1118
1173
                                outputFormatter.Space();
1119
1174
                                outputFormatter.PrintToken(Tokens.As);
1120
1175
                                outputFormatter.Space();
1121
 
                                nodeTracker.TrackedVisit(operatorDeclaration.TypeReference, data);
 
1176
                                TrackedVisit(operatorDeclaration.TypeReference, data);
1122
1177
                        }
1123
1178
                        
1124
1179
                        outputFormatter.NewLine();
1125
1180
                        
1126
1181
                        ++outputFormatter.IndentationLevel;
1127
 
                        nodeTracker.TrackedVisit(operatorDeclaration.Body, data);
 
1182
                        TrackedVisit(operatorDeclaration.Body, data);
1128
1183
                        --outputFormatter.IndentationLevel;
1129
1184
                        
1130
1185
                        outputFormatter.Indent();
1136
1191
                        return null;
1137
1192
                }
1138
1193
                
1139
 
                public object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data)
 
1194
                public override object TrackedVisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data)
1140
1195
                {
1141
1196
                        VisitAttributes(declareDeclaration.Attributes, data);
1142
1197
                        outputFormatter.Indent();
1172
1227
                        outputFormatter.Space();
1173
1228
                        outputFormatter.PrintToken(Tokens.Lib);
1174
1229
                        outputFormatter.Space();
1175
 
                        outputFormatter.PrintText('"' + ConvertString(declareDeclaration.Library) + '"');
 
1230
                        outputFormatter.PrintText(ConvertString(declareDeclaration.Library));
1176
1231
                        outputFormatter.Space();
1177
1232
                        
1178
1233
                        if (declareDeclaration.Alias.Length > 0) {
1179
1234
                                outputFormatter.PrintToken(Tokens.Alias);
1180
1235
                                outputFormatter.Space();
1181
 
                                outputFormatter.PrintText('"' + ConvertString(declareDeclaration.Alias) + '"');
 
1236
                                outputFormatter.PrintText(ConvertString(declareDeclaration.Alias));
1182
1237
                                outputFormatter.Space();
1183
1238
                        }
1184
1239
                        
1190
1245
                                outputFormatter.Space();
1191
1246
                                outputFormatter.PrintToken(Tokens.As);
1192
1247
                                outputFormatter.Space();
1193
 
                                nodeTracker.TrackedVisit(declareDeclaration.TypeReference, data);
 
1248
                                TrackedVisit(declareDeclaration.TypeReference, data);
1194
1249
                        }
1195
1250
                        
1196
1251
                        outputFormatter.NewLine();
1200
1255
                #endregion
1201
1256
                
1202
1257
                #region Statements
1203
 
                public object VisitBlockStatement(BlockStatement blockStatement, object data)
 
1258
                public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
1204
1259
                {
 
1260
                        if (blockStatement.Parent is BlockStatement) {
 
1261
                                outputFormatter.Indent();
 
1262
                                outputFormatter.PrintText("If True Then");
 
1263
                                outputFormatter.NewLine();
 
1264
                                outputFormatter.IndentationLevel += 1;
 
1265
                        }
1205
1266
                        VisitStatementList(blockStatement.Children);
 
1267
                        if (blockStatement.Parent is BlockStatement) {
 
1268
                                outputFormatter.IndentationLevel -= 1;
 
1269
                                outputFormatter.Indent();
 
1270
                                outputFormatter.PrintText("End If");
 
1271
                                outputFormatter.NewLine();
 
1272
                        }
1206
1273
                        return null;
1207
1274
                }
1208
1275
                
1210
1277
                {
1211
1278
                        outputFormatter.IndentationLevel += 1;
1212
1279
                        if (stmt is BlockStatement) {
1213
 
                                nodeTracker.TrackedVisit(stmt, null);
 
1280
                                TrackedVisit(stmt, null);
1214
1281
                        } else {
1215
1282
                                outputFormatter.Indent();
1216
 
                                nodeTracker.TrackedVisit(stmt, null);
 
1283
                                TrackedVisit(stmt, null);
1217
1284
                                outputFormatter.NewLine();
1218
1285
                        }
1219
1286
                        outputFormatter.IndentationLevel -= 1;
1230
1297
                {
1231
1298
                        foreach (Statement stmt in statements) {
1232
1299
                                if (stmt is BlockStatement) {
1233
 
                                        nodeTracker.TrackedVisit(stmt, null);
 
1300
                                        TrackedVisit(stmt, null);
1234
1301
                                } else {
1235
1302
                                        outputFormatter.Indent();
1236
 
                                        nodeTracker.TrackedVisit(stmt, null);
 
1303
                                        TrackedVisit(stmt, null);
1237
1304
                                        outputFormatter.NewLine();
1238
1305
                                }
1239
1306
                        }
1240
1307
                }
1241
1308
                
1242
 
                public object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data)
 
1309
                public override object TrackedVisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data)
1243
1310
                {
1244
1311
                        outputFormatter.PrintToken(Tokens.AddHandler);
1245
1312
                        outputFormatter.Space();
1246
 
                        nodeTracker.TrackedVisit(addHandlerStatement.EventExpression, data);
 
1313
                        TrackedVisit(addHandlerStatement.EventExpression, data);
1247
1314
                        outputFormatter.PrintToken(Tokens.Comma);
1248
1315
                        outputFormatter.Space();
1249
 
                        nodeTracker.TrackedVisit(addHandlerStatement.HandlerExpression, data);
 
1316
                        TrackedVisit(addHandlerStatement.HandlerExpression, data);
1250
1317
                        return null;
1251
1318
                }
1252
1319
                
1253
 
                public object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data)
 
1320
                public override object TrackedVisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data)
1254
1321
                {
1255
1322
                        outputFormatter.PrintToken(Tokens.RemoveHandler);
1256
1323
                        outputFormatter.Space();
1257
 
                        nodeTracker.TrackedVisit(removeHandlerStatement.EventExpression, data);
 
1324
                        TrackedVisit(removeHandlerStatement.EventExpression, data);
1258
1325
                        outputFormatter.PrintToken(Tokens.Comma);
1259
1326
                        outputFormatter.Space();
1260
 
                        nodeTracker.TrackedVisit(removeHandlerStatement.HandlerExpression, data);
 
1327
                        TrackedVisit(removeHandlerStatement.HandlerExpression, data);
1261
1328
                        return null;
1262
1329
                }
1263
1330
                
1264
 
                public object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data)
 
1331
                public override object TrackedVisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data)
1265
1332
                {
1266
1333
                        outputFormatter.PrintToken(Tokens.RaiseEvent);
1267
1334
                        outputFormatter.Space();
1272
1339
                        return null;
1273
1340
                }
1274
1341
                
1275
 
                public object VisitEraseStatement(EraseStatement eraseStatement, object data)
 
1342
                public override object TrackedVisitEraseStatement(EraseStatement eraseStatement, object data)
1276
1343
                {
1277
1344
                        outputFormatter.PrintToken(Tokens.Erase);
1278
1345
                        outputFormatter.Space();
1280
1347
                        return null;
1281
1348
                }
1282
1349
                
1283
 
                public object VisitErrorStatement(ErrorStatement errorStatement, object data)
 
1350
                public override object TrackedVisitErrorStatement(ErrorStatement errorStatement, object data)
1284
1351
                {
1285
1352
                        outputFormatter.PrintToken(Tokens.Error);
1286
1353
                        outputFormatter.Space();
1287
 
                        nodeTracker.TrackedVisit(errorStatement.Expression, data);
 
1354
                        TrackedVisit(errorStatement.Expression, data);
1288
1355
                        return null;
1289
1356
                }
1290
1357
                
1291
 
                public object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data)
 
1358
                public override object TrackedVisitOnErrorStatement(OnErrorStatement onErrorStatement, object data)
1292
1359
                {
1293
1360
                        outputFormatter.PrintToken(Tokens.On);
1294
1361
                        outputFormatter.Space();
1295
1362
                        outputFormatter.PrintToken(Tokens.Error);
1296
1363
                        outputFormatter.Space();
1297
 
                        nodeTracker.TrackedVisit(onErrorStatement.EmbeddedStatement, data);
 
1364
                        TrackedVisit(onErrorStatement.EmbeddedStatement, data);
1298
1365
                        return null;
1299
1366
                }
1300
1367
                
1301
 
                public object VisitReDimStatement(ReDimStatement reDimStatement, object data)
 
1368
                public override object TrackedVisitReDimStatement(ReDimStatement reDimStatement, object data)
1302
1369
                {
1303
1370
                        outputFormatter.PrintToken(Tokens.ReDim);
1304
1371
                        outputFormatter.Space();
1311
1378
                        return null;
1312
1379
                }
1313
1380
                
1314
 
                public object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
 
1381
                public override object TrackedVisitExpressionStatement(ExpressionStatement expressionStatement, object data)
1315
1382
                {
1316
 
                        nodeTracker.TrackedVisit(expressionStatement.Expression, data);
 
1383
                        TrackedVisit(expressionStatement.Expression, data);
1317
1384
                        return null;
1318
1385
                }
1319
1386
                
1320
 
                public object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
 
1387
                public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
1321
1388
                {
1322
1389
                        if (localVariableDeclaration.Modifier != Modifiers.None) {
1323
1390
                                OutputModifier(localVariableDeclaration.Modifier);
1336
1403
                        return null;
1337
1404
                }
1338
1405
                
1339
 
                public object VisitEmptyStatement(EmptyStatement emptyStatement, object data)
 
1406
                public override object TrackedVisitEmptyStatement(EmptyStatement emptyStatement, object data)
1340
1407
                {
1341
1408
                        outputFormatter.NewLine();
1342
1409
                        return null;
1343
1410
                }
1344
1411
                
1345
 
                public virtual object VisitYieldStatement(YieldStatement yieldStatement, object data)
 
1412
                public override object TrackedVisitYieldStatement(YieldStatement yieldStatement, object data)
1346
1413
                {
1347
1414
                        UnsupportedNode(yieldStatement);
1348
1415
                        return null;
1349
1416
                }
1350
1417
                
1351
 
                public object VisitReturnStatement(ReturnStatement returnStatement, object data)
 
1418
                public override object TrackedVisitReturnStatement(ReturnStatement returnStatement, object data)
1352
1419
                {
1353
1420
                        outputFormatter.PrintToken(Tokens.Return);
1354
1421
                        if (!returnStatement.Expression.IsNull) {
1355
1422
                                outputFormatter.Space();
1356
 
                                nodeTracker.TrackedVisit(returnStatement.Expression, data);
 
1423
                                TrackedVisit(returnStatement.Expression, data);
1357
1424
                        }
1358
1425
                        return null;
1359
1426
                }
1360
1427
                
1361
 
                public object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
 
1428
                public override object TrackedVisitIfElseStatement(IfElseStatement ifElseStatement, object data)
1362
1429
                {
1363
1430
                        outputFormatter.PrintToken(Tokens.If);
1364
1431
                        outputFormatter.Space();
1365
 
                        nodeTracker.TrackedVisit(ifElseStatement.Condition, data);
 
1432
                        TrackedVisit(ifElseStatement.Condition, data);
1366
1433
                        outputFormatter.Space();
1367
1434
                        outputFormatter.PrintToken(Tokens.Then);
1368
1435
                        outputFormatter.NewLine();
1370
1437
                        PrintIndentedBlock(ifElseStatement.TrueStatement);
1371
1438
                        
1372
1439
                        foreach (ElseIfSection elseIfSection in ifElseStatement.ElseIfSections) {
1373
 
                                nodeTracker.TrackedVisit(elseIfSection, data);
 
1440
                                TrackedVisit(elseIfSection, data);
1374
1441
                        }
1375
1442
                        
1376
1443
                        if (ifElseStatement.HasElseStatements) {
1387
1454
                        return null;
1388
1455
                }
1389
1456
                
1390
 
                public object VisitElseIfSection(ElseIfSection elseIfSection, object data)
 
1457
                public override object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data)
1391
1458
                {
 
1459
                        outputFormatter.Indent();
1392
1460
                        outputFormatter.PrintToken(Tokens.ElseIf);
1393
1461
                        outputFormatter.Space();
1394
 
                        nodeTracker.TrackedVisit(elseIfSection.Condition, data);
 
1462
                        TrackedVisit(elseIfSection.Condition, data);
1395
1463
                        outputFormatter.Space();
1396
1464
                        outputFormatter.PrintToken(Tokens.Then);
1397
1465
                        outputFormatter.NewLine();
1399
1467
                        return null;
1400
1468
                }
1401
1469
                
1402
 
                public object VisitForStatement(ForStatement forStatement, object data)
 
1470
                public override object TrackedVisitForStatement(ForStatement forStatement, object data)
1403
1471
                {
1404
1472
                        // Is converted to {initializer} while <Condition> {Embedded} {Iterators} end while
1405
1473
                        exitTokenStack.Push(Tokens.While);
1408
1476
                                if (!isFirstLine)
1409
1477
                                        outputFormatter.Indent();
1410
1478
                                isFirstLine = false;
1411
 
                                nodeTracker.TrackedVisit(node, data);
 
1479
                                TrackedVisit(node, data);
1412
1480
                                outputFormatter.NewLine();
1413
1481
                        }
1414
1482
                        if (!isFirstLine)
1418
1486
                        if (forStatement.Condition.IsNull) {
1419
1487
                                outputFormatter.PrintToken(Tokens.True);
1420
1488
                        } else {
1421
 
                                nodeTracker.TrackedVisit(forStatement.Condition, data);
 
1489
                                TrackedVisit(forStatement.Condition, data);
1422
1490
                        }
1423
1491
                        outputFormatter.NewLine();
1424
1492
                        
1433
1501
                        return null;
1434
1502
                }
1435
1503
                
1436
 
                public object VisitLabelStatement(LabelStatement labelStatement, object data)
 
1504
                public override object TrackedVisitLabelStatement(LabelStatement labelStatement, object data)
1437
1505
                {
1438
1506
                        outputFormatter.PrintIdentifier(labelStatement.Label);
1439
1507
                        outputFormatter.PrintToken(Tokens.Colon);
1440
1508
                        return null;
1441
1509
                }
1442
1510
                
1443
 
                public object VisitGotoStatement(GotoStatement gotoStatement, object data)
 
1511
                public override object TrackedVisitGotoStatement(GotoStatement gotoStatement, object data)
1444
1512
                {
1445
1513
                        outputFormatter.PrintToken(Tokens.GoTo);
1446
1514
                        outputFormatter.Space();
1448
1516
                        return null;
1449
1517
                }
1450
1518
                
1451
 
                public object VisitSwitchStatement(SwitchStatement switchStatement, object data)
 
1519
                public override object TrackedVisitSwitchStatement(SwitchStatement switchStatement, object data)
1452
1520
                {
1453
1521
                        exitTokenStack.Push(Tokens.Select);
1454
1522
                        outputFormatter.PrintToken(Tokens.Select);
1455
1523
                        outputFormatter.Space();
1456
1524
                        outputFormatter.PrintToken(Tokens.Case);
1457
1525
                        outputFormatter.Space();
1458
 
                        nodeTracker.TrackedVisit(switchStatement.SwitchExpression, data);
 
1526
                        TrackedVisit(switchStatement.SwitchExpression, data);
1459
1527
                        outputFormatter.NewLine();
1460
1528
                        ++outputFormatter.IndentationLevel;
1461
1529
                        foreach (SwitchSection section in switchStatement.SwitchSections) {
1462
 
                                nodeTracker.TrackedVisit(section, data);
 
1530
                                TrackedVisit(section, data);
1463
1531
                        }
1464
1532
                        --outputFormatter.IndentationLevel;
1465
1533
                        outputFormatter.Indent();
1470
1538
                        return null;
1471
1539
                }
1472
1540
                
1473
 
                public object VisitSwitchSection(SwitchSection switchSection, object data)
 
1541
                public override object TrackedVisitSwitchSection(SwitchSection switchSection, object data)
1474
1542
                {
1475
1543
                        outputFormatter.Indent();
1476
1544
                        outputFormatter.PrintToken(Tokens.Case);
1483
1551
                        return null;
1484
1552
                }
1485
1553
                
1486
 
                public object VisitCaseLabel(CaseLabel caseLabel, object data)
 
1554
                public override object TrackedVisitCaseLabel(CaseLabel caseLabel, object data)
1487
1555
                {
1488
1556
                        if (caseLabel.IsDefault) {
1489
1557
                                outputFormatter.PrintToken(Tokens.Else);
1514
1582
                                        outputFormatter.Space();
1515
1583
                                }
1516
1584
                                
1517
 
                                nodeTracker.TrackedVisit(caseLabel.Label, data);
 
1585
                                TrackedVisit(caseLabel.Label, data);
1518
1586
                                if (!caseLabel.ToExpression.IsNull) {
1519
1587
                                        outputFormatter.Space();
1520
1588
                                        outputFormatter.PrintToken(Tokens.To);
1521
1589
                                        outputFormatter.Space();
1522
 
                                        nodeTracker.TrackedVisit(caseLabel.ToExpression, data);
 
1590
                                        TrackedVisit(caseLabel.ToExpression, data);
1523
1591
                                }
1524
1592
                        }
1525
1593
                        
1526
1594
                        return null;
1527
1595
                }
1528
1596
                
1529
 
                public object VisitBreakStatement(BreakStatement breakStatement, object data)
 
1597
                public override object TrackedVisitBreakStatement(BreakStatement breakStatement, object data)
1530
1598
                {
1531
1599
                        outputFormatter.PrintToken(Tokens.Exit);
1532
1600
                        if (exitTokenStack.Count > 0) {
1536
1604
                        return null;
1537
1605
                }
1538
1606
                
1539
 
                public object VisitStopStatement(StopStatement stopStatement, object data)
 
1607
                public override object TrackedVisitStopStatement(StopStatement stopStatement, object data)
1540
1608
                {
1541
1609
                        outputFormatter.PrintToken(Tokens.Stop);
1542
1610
                        return null;
1543
1611
                }
1544
1612
                
1545
 
                public object VisitResumeStatement(ResumeStatement resumeStatement, object data)
 
1613
                public override object TrackedVisitResumeStatement(ResumeStatement resumeStatement, object data)
1546
1614
                {
1547
1615
                        outputFormatter.PrintToken(Tokens.Resume);
1548
1616
                        outputFormatter.Space();
1554
1622
                        return null;
1555
1623
                }
1556
1624
                
1557
 
                public object VisitEndStatement(EndStatement endStatement, object data)
 
1625
                public override object TrackedVisitEndStatement(EndStatement endStatement, object data)
1558
1626
                {
1559
1627
                        outputFormatter.PrintToken(Tokens.End);
1560
1628
                        return null;
1561
1629
                }
1562
1630
                
1563
 
                public object VisitContinueStatement(ContinueStatement continueStatement, object data)
 
1631
                public override object TrackedVisitContinueStatement(ContinueStatement continueStatement, object data)
1564
1632
                {
1565
1633
                        outputFormatter.PrintToken(Tokens.Continue);
1566
1634
                        outputFormatter.Space();
1581
1649
                        return null;
1582
1650
                }
1583
1651
                
1584
 
                public object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data)
 
1652
                public override object TrackedVisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data)
1585
1653
                {
1586
1654
                        outputFormatter.PrintText("goto case ");
1587
1655
                        if (gotoCaseStatement.IsDefaultCase) {
1588
1656
                                outputFormatter.PrintText("default");
1589
1657
                        } else {
1590
 
                                nodeTracker.TrackedVisit(gotoCaseStatement.Expression, null);
 
1658
                                TrackedVisit(gotoCaseStatement.Expression, null);
1591
1659
                        }
1592
1660
                        return null;
1593
1661
                }
1594
1662
                
1595
 
                public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data)
 
1663
                public override object TrackedVisitDoLoopStatement(DoLoopStatement doLoopStatement, object data)
1596
1664
                {
1597
1665
                        if (doLoopStatement.ConditionPosition == ConditionPosition.None) {
1598
1666
                                Error(String.Format("Unknown condition position for loop : {0}.", doLoopStatement), doLoopStatement.StartLocation);
1620
1688
                                                throw new InvalidOperationException();
1621
1689
                                }
1622
1690
                                outputFormatter.Space();
1623
 
                                nodeTracker.TrackedVisit(doLoopStatement.Condition, null);
 
1691
                                TrackedVisit(doLoopStatement.Condition, null);
1624
1692
                        } else {
1625
1693
                                exitTokenStack.Push(Tokens.Do);
1626
1694
                                outputFormatter.PrintToken(Tokens.Do);
1651
1719
                                                break;
1652
1720
                                }
1653
1721
                                outputFormatter.Space();
1654
 
                                nodeTracker.TrackedVisit(doLoopStatement.Condition, null);
 
1722
                                TrackedVisit(doLoopStatement.Condition, null);
1655
1723
                        }
1656
1724
                        exitTokenStack.Pop();
1657
1725
                        return null;
1658
1726
                }
1659
1727
                
1660
 
                public object VisitForeachStatement(ForeachStatement foreachStatement, object data)
 
1728
                public override object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data)
1661
1729
                {
1662
1730
                        exitTokenStack.Push(Tokens.For);
1663
1731
                        outputFormatter.PrintToken(Tokens.For);
1670
1738
                        outputFormatter.Space();
1671
1739
                        outputFormatter.PrintToken(Tokens.As);
1672
1740
                        outputFormatter.Space();
1673
 
                        nodeTracker.TrackedVisit(foreachStatement.TypeReference, data);
 
1741
                        TrackedVisit(foreachStatement.TypeReference, data);
1674
1742
                        
1675
1743
                        outputFormatter.Space();
1676
1744
                        outputFormatter.PrintToken(Tokens.In);
1677
1745
                        outputFormatter.Space();
1678
1746
                        
1679
 
                        nodeTracker.TrackedVisit(foreachStatement.Expression, data);
 
1747
                        TrackedVisit(foreachStatement.Expression, data);
1680
1748
                        outputFormatter.NewLine();
1681
1749
                        
1682
1750
                        PrintIndentedBlock(foreachStatement.EmbeddedStatement);
1685
1753
                        outputFormatter.PrintToken(Tokens.Next);
1686
1754
                        if (!foreachStatement.NextExpression.IsNull) {
1687
1755
                                outputFormatter.Space();
1688
 
                                nodeTracker.TrackedVisit(foreachStatement.NextExpression, data);
 
1756
                                TrackedVisit(foreachStatement.NextExpression, data);
1689
1757
                        }
1690
1758
                        exitTokenStack.Pop();
1691
1759
                        return null;
1692
1760
                }
1693
1761
                
1694
 
                public object VisitLockStatement(LockStatement lockStatement, object data)
 
1762
                public override object TrackedVisitLockStatement(LockStatement lockStatement, object data)
1695
1763
                {
1696
1764
                        outputFormatter.PrintToken(Tokens.SyncLock);
1697
1765
                        outputFormatter.Space();
1698
 
                        nodeTracker.TrackedVisit(lockStatement.LockExpression, data);
 
1766
                        TrackedVisit(lockStatement.LockExpression, data);
1699
1767
                        outputFormatter.NewLine();
1700
1768
                        
1701
1769
                        PrintIndentedBlock(lockStatement.EmbeddedStatement);
1709
1777
                
1710
1778
                bool isUsingResourceAcquisition;
1711
1779
                
1712
 
                public object VisitUsingStatement(UsingStatement usingStatement, object data)
 
1780
                public override object TrackedVisitUsingStatement(UsingStatement usingStatement, object data)
1713
1781
                {
1714
1782
                        outputFormatter.PrintToken(Tokens.Using);
1715
1783
                        outputFormatter.Space();
1716
1784
                        
1717
1785
                        isUsingResourceAcquisition = true;
1718
 
                        nodeTracker.TrackedVisit(usingStatement.ResourceAcquisition, data);
 
1786
                        TrackedVisit(usingStatement.ResourceAcquisition, data);
1719
1787
                        isUsingResourceAcquisition = false;
1720
1788
                        outputFormatter.NewLine();
1721
1789
                        
1729
1797
                        return null;
1730
1798
                }
1731
1799
                
1732
 
                public object VisitWithStatement(WithStatement withStatement, object data)
 
1800
                public override object TrackedVisitWithStatement(WithStatement withStatement, object data)
1733
1801
                {
1734
1802
                        outputFormatter.PrintToken(Tokens.With);
1735
1803
                        outputFormatter.Space();
1736
 
                        nodeTracker.TrackedVisit(withStatement.Expression, data);
 
1804
                        TrackedVisit(withStatement.Expression, data);
1737
1805
                        outputFormatter.NewLine();
1738
1806
                        
1739
1807
                        PrintIndentedBlock(withStatement.Body);
1744
1812
                        return null;
1745
1813
                }
1746
1814
                
1747
 
                public object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
 
1815
                public override object TrackedVisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
1748
1816
                {
1749
1817
                        exitTokenStack.Push(Tokens.Try);
1750
1818
                        outputFormatter.PrintToken(Tokens.Try);
1753
1821
                        PrintIndentedBlock(tryCatchStatement.StatementBlock);
1754
1822
                        
1755
1823
                        foreach (CatchClause catchClause in tryCatchStatement.CatchClauses) {
1756
 
                                nodeTracker.TrackedVisit(catchClause, data);
 
1824
                                TrackedVisit(catchClause, data);
1757
1825
                        }
1758
1826
                        
1759
1827
                        if (!tryCatchStatement.FinallyBlock.IsNull) {
1770
1838
                        return null;
1771
1839
                }
1772
1840
                
1773
 
                public object VisitCatchClause(CatchClause catchClause, object data)
 
1841
                public override object TrackedVisitCatchClause(CatchClause catchClause, object data)
1774
1842
                {
1775
1843
                        outputFormatter.Indent();
1776
1844
                        outputFormatter.PrintToken(Tokens.Catch);
1792
1860
                                outputFormatter.Space();
1793
1861
                                outputFormatter.PrintToken(Tokens.When);
1794
1862
                                outputFormatter.Space();
1795
 
                                nodeTracker.TrackedVisit(catchClause.Condition, data);
 
1863
                                TrackedVisit(catchClause.Condition, data);
1796
1864
                        }
1797
1865
                        outputFormatter.NewLine();
1798
1866
                        
1801
1869
                        return null;
1802
1870
                }
1803
1871
                
1804
 
                public object VisitThrowStatement(ThrowStatement throwStatement, object data)
 
1872
                public override object TrackedVisitThrowStatement(ThrowStatement throwStatement, object data)
1805
1873
                {
1806
1874
                        outputFormatter.PrintToken(Tokens.Throw);
1807
1875
                        if (!throwStatement.Expression.IsNull) {
1808
1876
                                outputFormatter.Space();
1809
 
                                nodeTracker.TrackedVisit(throwStatement.Expression, data);
 
1877
                                TrackedVisit(throwStatement.Expression, data);
1810
1878
                        }
1811
1879
                        return null;
1812
1880
                }
1813
1881
                
1814
 
                public object VisitFixedStatement(FixedStatement fixedStatement, object data)
 
1882
                public override object TrackedVisitFixedStatement(FixedStatement fixedStatement, object data)
1815
1883
                {
1816
1884
                        UnsupportedNode(fixedStatement);
1817
 
                        return nodeTracker.TrackedVisit(fixedStatement.EmbeddedStatement, data);
 
1885
                        return TrackedVisit(fixedStatement.EmbeddedStatement, data);
1818
1886
                }
1819
1887
                
1820
 
                public object VisitUnsafeStatement(UnsafeStatement unsafeStatement, object data)
 
1888
                public override object TrackedVisitUnsafeStatement(UnsafeStatement unsafeStatement, object data)
1821
1889
                {
1822
1890
                        UnsupportedNode(unsafeStatement);
1823
 
                        return nodeTracker.TrackedVisit(unsafeStatement.Block, data);
 
1891
                        return TrackedVisit(unsafeStatement.Block, data);
1824
1892
                }
1825
1893
                
1826
 
                public object VisitCheckedStatement(CheckedStatement checkedStatement, object data)
 
1894
                public override object TrackedVisitCheckedStatement(CheckedStatement checkedStatement, object data)
1827
1895
                {
1828
1896
                        UnsupportedNode(checkedStatement);
1829
 
                        return nodeTracker.TrackedVisit(checkedStatement.Block, data);
 
1897
                        return TrackedVisit(checkedStatement.Block, data);
1830
1898
                }
1831
1899
                
1832
 
                public object VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data)
 
1900
                public override object TrackedVisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data)
1833
1901
                {
1834
1902
                        UnsupportedNode(uncheckedStatement);
1835
 
                        return nodeTracker.TrackedVisit(uncheckedStatement.Block, data);
 
1903
                        return TrackedVisit(uncheckedStatement.Block, data);
1836
1904
                }
1837
1905
                
1838
 
                public object VisitExitStatement(ExitStatement exitStatement, object data)
 
1906
                public override object TrackedVisitExitStatement(ExitStatement exitStatement, object data)
1839
1907
                {
1840
1908
                        outputFormatter.PrintToken(Tokens.Exit);
1841
1909
                        if (exitStatement.ExitType != ExitType.None) {
1874
1942
                        return null;
1875
1943
                }
1876
1944
                
1877
 
                public object VisitForNextStatement(ForNextStatement forNextStatement, object data)
 
1945
                public override object TrackedVisitForNextStatement(ForNextStatement forNextStatement, object data)
1878
1946
                {
1879
1947
                        exitTokenStack.Push(Tokens.For);
1880
1948
                        outputFormatter.PrintToken(Tokens.For);
1886
1954
                                outputFormatter.Space();
1887
1955
                                outputFormatter.PrintToken(Tokens.As);
1888
1956
                                outputFormatter.Space();
1889
 
                                nodeTracker.TrackedVisit(forNextStatement.TypeReference, data);
 
1957
                                TrackedVisit(forNextStatement.TypeReference, data);
1890
1958
                        }
1891
1959
                        
1892
1960
                        outputFormatter.Space();
1893
1961
                        outputFormatter.PrintToken(Tokens.Assign);
1894
1962
                        outputFormatter.Space();
1895
1963
                        
1896
 
                        nodeTracker.TrackedVisit(forNextStatement.Start, data);
 
1964
                        TrackedVisit(forNextStatement.Start, data);
1897
1965
                        
1898
1966
                        outputFormatter.Space();
1899
1967
                        outputFormatter.PrintToken(Tokens.To);
1900
1968
                        outputFormatter.Space();
1901
1969
                        
1902
 
                        nodeTracker.TrackedVisit(forNextStatement.End, data);
 
1970
                        TrackedVisit(forNextStatement.End, data);
1903
1971
                        
1904
1972
                        if (!forNextStatement.Step.IsNull) {
1905
1973
                                outputFormatter.Space();
1906
1974
                                outputFormatter.PrintToken(Tokens.Step);
1907
1975
                                outputFormatter.Space();
1908
 
                                nodeTracker.TrackedVisit(forNextStatement.Step, data);
 
1976
                                TrackedVisit(forNextStatement.Step, data);
1909
1977
                        }
1910
1978
                        outputFormatter.NewLine();
1911
1979
                        
1925
1993
                
1926
1994
                #region Expressions
1927
1995
                
1928
 
                public object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data)
 
1996
                public override object TrackedVisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data)
1929
1997
                {
1930
1998
                        outputFormatter.PrintToken(Tokens.MyClass);
1931
1999
                        return null;
1935
2003
                static string ConvertCharLiteral(char ch)
1936
2004
                {
1937
2005
                        if (Char.IsControl(ch)) {
1938
 
                                return "Chr(" + ((int)ch) + ")";
 
2006
                                string charName = GetCharName(ch);
 
2007
                                if (charName != null)
 
2008
                                        return "ControlChars." + charName;
 
2009
                                else
 
2010
                                        return "ChrW(" + ((int)ch).ToString() + ")";
 
2011
                        } else if (ch == '"') {
 
2012
                                return "\"\"\"\"C";
1939
2013
                        } else {
1940
 
                                if (ch == '"') {
1941
 
                                        return "\"\"\"\"C";
1942
 
                                }
1943
 
                                return String.Concat("\"", ch.ToString(), "\"C");
 
2014
                                return "\"" + ch.ToString() + "\"C";
 
2015
                        }
 
2016
                }
 
2017
                
 
2018
                static string GetCharName(char ch)
 
2019
                {
 
2020
                        switch (ch) {
 
2021
                                case '\b':
 
2022
                                        return "Back";
 
2023
                                case '\r':
 
2024
                                        return "Cr";
 
2025
                                case '\f':
 
2026
                                        return "FormFeed";
 
2027
                                case '\n':
 
2028
                                        return "Lf";
 
2029
                                case '\0':
 
2030
                                        return "NullChar";
 
2031
                                case '\t':
 
2032
                                        return "Tab";
 
2033
                                case '\v':
 
2034
                                        return "VerticalTab";
 
2035
                                default:
 
2036
                                        return null;
1944
2037
                        }
1945
2038
                }
1946
2039
                
1947
2040
                static string ConvertString(string str)
1948
2041
                {
1949
2042
                        StringBuilder sb = new StringBuilder();
 
2043
                        bool inString = false;
1950
2044
                        foreach (char ch in str) {
1951
2045
                                if (char.IsControl(ch)) {
1952
 
                                        sb.Append("\" & Chr(" + ((int)ch) + ") & \"");
1953
 
                                } else if (ch == '"') {
1954
 
                                        sb.Append("\"\"");
 
2046
                                        if (inString) {
 
2047
                                                sb.Append('"');
 
2048
                                                inString = false;
 
2049
                                        }
 
2050
                                        if (sb.Length > 0)
 
2051
                                                sb.Append(" & ");
 
2052
                                        string charName = GetCharName(ch);
 
2053
                                        if (charName != null)
 
2054
                                                sb.Append("vb" + charName);
 
2055
                                        else
 
2056
                                                sb.Append("ChrW(" + ((int)ch) + ")");
1955
2057
                                } else {
1956
 
                                        sb.Append(ch);
 
2058
                                        if (!inString) {
 
2059
                                                if (sb.Length > 0)
 
2060
                                                        sb.Append(" & ");
 
2061
                                                sb.Append('"');
 
2062
                                                inString = true;
 
2063
                                        }
 
2064
                                        if (ch == '"') {
 
2065
                                                sb.Append("\"\"");
 
2066
                                        } else {
 
2067
                                                sb.Append(ch);
 
2068
                                        }
1957
2069
                                }
1958
2070
                        }
 
2071
                        if (inString)
 
2072
                                sb.Append('"');
 
2073
                        if (sb.Length == 0)
 
2074
                                return "\"\"";
1959
2075
                        return sb.ToString();
1960
2076
                }
1961
2077
                
1962
 
                public object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
 
2078
                public override object TrackedVisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
1963
2079
                {
1964
2080
                        object val = primitiveExpression.Value;
1965
2081
                        if (val == null) {
1976
2092
                        }
1977
2093
                        
1978
2094
                        if (val is string) {
1979
 
                                outputFormatter.PrintText('"' + ConvertString((string)val) + '"');
 
2095
                                outputFormatter.PrintText(ConvertString((string)val));
1980
2096
                                return null;
1981
2097
                        }
1982
2098
                        
2004
2120
                        return null;
2005
2121
                }
2006
2122
                
2007
 
                public object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
 
2123
                public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
2008
2124
                {
2009
2125
                        int  op = 0;
2010
2126
                        switch (binaryOperatorExpression.Op) {
 
2127
                                case BinaryOperatorType.Concat:
 
2128
                                        op = Tokens.ConcatString;
 
2129
                                        break;
 
2130
                                        
2011
2131
                                case BinaryOperatorType.Add:
2012
2132
                                        op = Tokens.Plus;
2013
2133
                                        break;
2024
2144
                                        op = Tokens.Div;
2025
2145
                                        break;
2026
2146
                                        
 
2147
                                case BinaryOperatorType.DivideInteger:
 
2148
                                        op = Tokens.DivInteger;
 
2149
                                        break;
 
2150
                                        
2027
2151
                                case BinaryOperatorType.Modulus:
2028
2152
                                        op = Tokens.Mod;
2029
2153
                                        break;
2069
2193
                                        op = Tokens.GreaterEqual;
2070
2194
                                        break;
2071
2195
                                case BinaryOperatorType.InEquality:
2072
 
                                        nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data);
2073
 
                                        outputFormatter.Space();
2074
 
                                        outputFormatter.PrintToken(Tokens.LessThan);
2075
 
                                        outputFormatter.PrintToken(Tokens.GreaterThan);
2076
 
                                        outputFormatter.Space();
2077
 
                                        nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data);
2078
 
                                        return null;
 
2196
                                        op = Tokens.NotEqual;
 
2197
                                        break;
2079
2198
                                case BinaryOperatorType.NullCoalescing:
2080
 
                                        outputFormatter.PrintText("IIf(");
2081
 
                                        nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data);
2082
 
                                        outputFormatter.PrintText(" Is Nothing, ");
2083
 
                                        nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data);
 
2199
                                        outputFormatter.PrintText("If(");
 
2200
                                        TrackedVisit(binaryOperatorExpression.Left, data);
2084
2201
                                        outputFormatter.PrintToken(Tokens.Comma);
2085
2202
                                        outputFormatter.Space();
2086
 
                                        nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data);
 
2203
                                        TrackedVisit(binaryOperatorExpression.Right, data);
2087
2204
                                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2088
2205
                                        return null;
 
2206
                                case BinaryOperatorType.DictionaryAccess:
 
2207
                                        {
 
2208
                                                PrimitiveExpression pright = binaryOperatorExpression.Right as PrimitiveExpression;
 
2209
                                                TrackedVisit(binaryOperatorExpression.Left, data);
 
2210
                                                if (pright != null && pright.Value is string) {
 
2211
                                                        outputFormatter.PrintText("!" + (string)pright.Value);
 
2212
                                                } else {
 
2213
                                                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
2214
                                                        TrackedVisit(binaryOperatorExpression.Right, data);
 
2215
                                                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
 
2216
                                                }
 
2217
                                                return null;
 
2218
                                        }
2089
2219
                                case BinaryOperatorType.LessThan:
2090
2220
                                        op = Tokens.LessThan;
2091
2221
                                        break;
2094
2224
                                        break;
2095
2225
                        }
2096
2226
                        
2097
 
                        nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data);
 
2227
                        
 
2228
                        BinaryOperatorExpression childBoe = binaryOperatorExpression.Left as BinaryOperatorExpression;
 
2229
                        bool requireParenthesis = childBoe != null && OperatorPrecedence.ComparePrecedenceVB(binaryOperatorExpression.Op, childBoe.Op) > 0;
 
2230
                        if (requireParenthesis)
 
2231
                                outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
2232
                        TrackedVisit(binaryOperatorExpression.Left, data);
 
2233
                        if (requireParenthesis)
 
2234
                                outputFormatter.PrintToken(Tokens.CloseParenthesis);
 
2235
                        
2098
2236
                        outputFormatter.Space();
2099
2237
                        outputFormatter.PrintToken(op);
2100
2238
                        outputFormatter.Space();
2101
 
                        nodeTracker.TrackedVisit(binaryOperatorExpression.Right, data);
 
2239
                        
 
2240
                        childBoe = binaryOperatorExpression.Right as BinaryOperatorExpression;
 
2241
                        requireParenthesis = childBoe != null && OperatorPrecedence.ComparePrecedenceVB(binaryOperatorExpression.Op, childBoe.Op) >= 0;
 
2242
                        if (requireParenthesis)
 
2243
                                outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
2244
                        TrackedVisit(binaryOperatorExpression.Right, data);
 
2245
                        if (requireParenthesis)
 
2246
                                outputFormatter.PrintToken(Tokens.CloseParenthesis);
2102
2247
                        
2103
2248
                        return null;
2104
2249
                }
2105
2250
                
2106
 
                public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
 
2251
                public override object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
2107
2252
                {
2108
2253
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2109
 
                        nodeTracker.TrackedVisit(parenthesizedExpression.Expression, data);
 
2254
                        TrackedVisit(parenthesizedExpression.Expression, data);
2110
2255
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2111
2256
                        return null;
2112
2257
                }
2113
2258
                
2114
 
                public object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
 
2259
                public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
2115
2260
                {
2116
 
                        nodeTracker.TrackedVisit(invocationExpression.TargetObject, data);
2117
 
                        if (invocationExpression.TypeArguments != null && invocationExpression.TypeArguments.Count > 0) {
2118
 
                                outputFormatter.PrintToken(Tokens.OpenParenthesis);
2119
 
                                outputFormatter.PrintToken(Tokens.Of);
2120
 
                                outputFormatter.Space();
2121
 
                                AppendCommaSeparatedList(invocationExpression.TypeArguments);
2122
 
                                outputFormatter.PrintToken(Tokens.CloseParenthesis);
2123
 
                        }
 
2261
                        TrackedVisit(invocationExpression.TargetObject, data);
2124
2262
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2125
2263
                        AppendCommaSeparatedList(invocationExpression.Arguments);
2126
2264
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2127
2265
                        return null;
2128
2266
                }
2129
2267
                
2130
 
                public object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
 
2268
                void PrintTypeArguments(List<TypeReference> typeArguments)
 
2269
                {
 
2270
                        if (typeArguments != null && typeArguments.Count > 0) {
 
2271
                                outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
2272
                                outputFormatter.PrintToken(Tokens.Of);
 
2273
                                outputFormatter.Space();
 
2274
                                AppendCommaSeparatedList(typeArguments);
 
2275
                                outputFormatter.PrintToken(Tokens.CloseParenthesis);
 
2276
                        }
 
2277
                }
 
2278
                
 
2279
                public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
2131
2280
                {
2132
2281
                        outputFormatter.PrintIdentifier(identifierExpression.Identifier);
 
2282
                        PrintTypeArguments(identifierExpression.TypeArguments);
2133
2283
                        return null;
2134
2284
                }
2135
2285
                
2136
 
                public object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data)
 
2286
                public override object TrackedVisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data)
2137
2287
                {
2138
 
                        nodeTracker.TrackedVisit(typeReferenceExpression.TypeReference, data);
 
2288
                        TrackedVisit(typeReferenceExpression.TypeReference, data);
2139
2289
                        return null;
2140
2290
                }
2141
2291
                
2142
 
                public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
 
2292
                public override object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
2143
2293
                {
2144
2294
                        switch (unaryOperatorExpression.Op) {
2145
2295
                                case UnaryOperatorType.Not:
2146
2296
                                case UnaryOperatorType.BitNot:
2147
2297
                                        outputFormatter.PrintToken(Tokens.Not);
2148
2298
                                        outputFormatter.Space();
2149
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2299
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2150
2300
                                        return null;
2151
2301
                                        
2152
2302
                                case UnaryOperatorType.Decrement:
2153
2303
                                        outputFormatter.PrintText("System.Threading.Interlocked.Decrement(");
2154
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2304
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2155
2305
                                        outputFormatter.PrintText(")");
2156
2306
                                        return null;
2157
2307
                                        
2158
2308
                                case UnaryOperatorType.Increment:
2159
2309
                                        outputFormatter.PrintText("System.Threading.Interlocked.Increment(");
2160
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2310
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2161
2311
                                        outputFormatter.PrintText(")");
2162
2312
                                        return null;
2163
2313
                                        
2164
2314
                                case UnaryOperatorType.Minus:
2165
2315
                                        outputFormatter.PrintToken(Tokens.Minus);
2166
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2316
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2167
2317
                                        return null;
2168
2318
                                        
2169
2319
                                case UnaryOperatorType.Plus:
2170
2320
                                        outputFormatter.PrintToken(Tokens.Plus);
2171
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2321
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2172
2322
                                        return null;
2173
2323
                                        
2174
2324
                                case UnaryOperatorType.PostDecrement:
2175
2325
                                        outputFormatter.PrintText("System.Math.Max(System.Threading.Interlocked.Decrement(");
2176
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2326
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2177
2327
                                        outputFormatter.PrintText("),");
2178
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2328
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2179
2329
                                        outputFormatter.PrintText(" + 1)");
2180
2330
                                        return null;
2181
2331
                                        
2182
2332
                                case UnaryOperatorType.PostIncrement:
2183
2333
                                        outputFormatter.PrintText("System.Math.Max(System.Threading.Interlocked.Increment(");
2184
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2334
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2185
2335
                                        outputFormatter.PrintText("),");
2186
 
                                        nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data);
 
2336
                                        TrackedVisit(unaryOperatorExpression.Expression, data);
2187
2337
                                        outputFormatter.PrintText(" - 1)");
2188
2338
                                        return null;
2189
2339
                                        
2190
 
                                case UnaryOperatorType.Star:
 
2340
                                case UnaryOperatorType.Dereference:
2191
2341
                                        outputFormatter.PrintToken(Tokens.Times);
2192
2342
                                        return null;
2193
 
                                case UnaryOperatorType.BitWiseAnd:
 
2343
                                case UnaryOperatorType.AddressOf:
2194
2344
                                        outputFormatter.PrintToken(Tokens.AddressOf);
2195
2345
                                        return null;
2196
2346
                                default:
2199
2349
                        }
2200
2350
                }
2201
2351
                
2202
 
                public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
 
2352
                public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
2203
2353
                {
2204
2354
                        int  op = 0;
2205
2355
                        bool unsupportedOpAssignment = false;
2209
2359
                                        break;
2210
2360
                                case AssignmentOperatorType.Add:
2211
2361
                                        op = Tokens.PlusAssign;
2212
 
                                        if (IsEventHandlerCreation(assignmentExpression.Right)) {
2213
 
                                                outputFormatter.PrintToken(Tokens.AddHandler);
2214
 
                                                outputFormatter.Space();
2215
 
                                                nodeTracker.TrackedVisit(assignmentExpression.Left, data);
2216
 
                                                outputFormatter.PrintToken(Tokens.Comma);
2217
 
                                                outputFormatter.Space();
2218
 
                                                outputFormatter.PrintToken(Tokens.AddressOf);
2219
 
                                                outputFormatter.Space();
2220
 
                                                nodeTracker.TrackedVisit(GetEventHandlerMethod(assignmentExpression.Right), data);
2221
 
                                                return null;
2222
 
                                        }
2223
2362
                                        break;
2224
2363
                                case AssignmentOperatorType.Subtract:
2225
2364
                                        op = Tokens.MinusAssign;
2226
 
                                        if (IsEventHandlerCreation(assignmentExpression.Right)) {
2227
 
                                                outputFormatter.PrintToken(Tokens.RemoveHandler);
2228
 
                                                outputFormatter.Space();
2229
 
                                                nodeTracker.TrackedVisit(assignmentExpression.Left, data);
2230
 
                                                outputFormatter.PrintToken(Tokens.Comma);
2231
 
                                                outputFormatter.Space();
2232
 
                                                outputFormatter.PrintToken(Tokens.AddressOf);
2233
 
                                                outputFormatter.Space();
2234
 
                                                nodeTracker.TrackedVisit(GetEventHandlerMethod(assignmentExpression.Right), data);
2235
 
                                                return null;
2236
 
                                        }
2237
2365
                                        break;
2238
2366
                                case AssignmentOperatorType.Multiply:
2239
2367
                                        op = Tokens.TimesAssign;
2266
2394
                                        break;
2267
2395
                        }
2268
2396
                        
2269
 
                        nodeTracker.TrackedVisit(assignmentExpression.Left, data);
 
2397
                        TrackedVisit(assignmentExpression.Left, data);
2270
2398
                        outputFormatter.Space();
2271
2399
                        
2272
2400
                        if (unsupportedOpAssignment) { // left = left OP right
2273
2401
                                outputFormatter.PrintToken(Tokens.Assign);
2274
2402
                                outputFormatter.Space();
2275
 
                                nodeTracker.TrackedVisit(assignmentExpression.Left, data);
 
2403
                                TrackedVisit(assignmentExpression.Left, data);
2276
2404
                                outputFormatter.Space();
2277
2405
                        }
2278
2406
                        
2279
2407
                        outputFormatter.PrintToken(op);
2280
2408
                        outputFormatter.Space();
2281
 
                        nodeTracker.TrackedVisit(assignmentExpression.Right, data);
 
2409
                        TrackedVisit(assignmentExpression.Right, data);
2282
2410
                        
2283
2411
                        return null;
2284
2412
                }
2285
2413
                
2286
 
                public object VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data)
 
2414
                public override object TrackedVisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data)
2287
2415
                {
2288
2416
                        UnsupportedNode(sizeOfExpression);
2289
2417
                        return null;
2290
2418
                }
2291
2419
                
2292
 
                public object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data)
 
2420
                public override object TrackedVisitTypeOfExpression(TypeOfExpression typeOfExpression, object data)
2293
2421
                {
2294
2422
                        outputFormatter.PrintToken(Tokens.GetType);
2295
2423
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2296
 
                        nodeTracker.TrackedVisit(typeOfExpression.TypeReference, data);
 
2424
                        TrackedVisit(typeOfExpression.TypeReference, data);
2297
2425
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2298
2426
                        return null;
2299
2427
                }
2300
2428
                
2301
 
                public object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data)
 
2429
                public override object TrackedVisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data)
2302
2430
                {
2303
2431
                        // assigning nothing to a generic type in VB compiles to a DefaultValueExpression
2304
2432
                        outputFormatter.PrintToken(Tokens.Nothing);
2305
2433
                        return null;
2306
2434
                }
2307
2435
                
2308
 
                public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data)
 
2436
                public override object TrackedVisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data)
2309
2437
                {
2310
2438
                        outputFormatter.PrintToken(Tokens.TypeOf);
2311
2439
                        outputFormatter.Space();
2312
 
                        nodeTracker.TrackedVisit(typeOfIsExpression.Expression, data);
 
2440
                        TrackedVisit(typeOfIsExpression.Expression, data);
2313
2441
                        outputFormatter.Space();
2314
2442
                        outputFormatter.PrintToken(Tokens.Is);
2315
2443
                        outputFormatter.Space();
2316
 
                        nodeTracker.TrackedVisit(typeOfIsExpression.TypeReference, data);
 
2444
                        TrackedVisit(typeOfIsExpression.TypeReference, data);
2317
2445
                        return null;
2318
2446
                }
2319
2447
                
2320
 
                public object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data)
 
2448
                public override object TrackedVisitAddressOfExpression(AddressOfExpression addressOfExpression, object data)
2321
2449
                {
2322
2450
                        outputFormatter.PrintToken(Tokens.AddressOf);
2323
2451
                        outputFormatter.Space();
2324
 
                        nodeTracker.TrackedVisit(addressOfExpression.Expression, data);
 
2452
                        TrackedVisit(addressOfExpression.Expression, data);
2325
2453
                        return null;
2326
2454
                }
2327
2455
                
2328
 
                public object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
 
2456
                public override object TrackedVisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
2329
2457
                {
2330
 
                        UnsupportedNode(anonymousMethodExpression);
 
2458
                        OutputAnonymousMethodWithStatementBody(anonymousMethodExpression.Parameters, anonymousMethodExpression.Body);
2331
2459
                        return null;
2332
2460
                }
2333
2461
                
2334
 
                public object VisitCheckedExpression(CheckedExpression checkedExpression, object data)
 
2462
                public override object TrackedVisitCheckedExpression(CheckedExpression checkedExpression, object data)
2335
2463
                {
2336
2464
                        UnsupportedNode(checkedExpression);
2337
 
                        return nodeTracker.TrackedVisit(checkedExpression.Expression, data);
 
2465
                        return TrackedVisit(checkedExpression.Expression, data);
2338
2466
                }
2339
2467
                
2340
 
                public object VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data)
 
2468
                public override object TrackedVisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data)
2341
2469
                {
2342
2470
                        UnsupportedNode(uncheckedExpression);
2343
 
                        return nodeTracker.TrackedVisit(uncheckedExpression.Expression, data);
 
2471
                        return TrackedVisit(uncheckedExpression.Expression, data);
2344
2472
                }
2345
2473
                
2346
 
                public object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data)
 
2474
                public override object TrackedVisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data)
2347
2475
                {
2348
2476
                        UnsupportedNode(pointerReferenceExpression);
2349
2477
                        return null;
2350
2478
                }
2351
2479
                
2352
 
                public object VisitCastExpression(CastExpression castExpression, object data)
 
2480
                public override object TrackedVisitCastExpression(CastExpression castExpression, object data)
2353
2481
                {
2354
 
                        if (castExpression.CastType == CastType.Cast) {
2355
 
                                return PrintCast(Tokens.DirectCast, castExpression);
2356
 
                        }
2357
2482
                        if (castExpression.CastType == CastType.TryCast) {
2358
2483
                                return PrintCast(Tokens.TryCast, castExpression);
2359
2484
                        }
 
2485
                        if (castExpression.CastType == CastType.Cast || castExpression.CastTo.IsArrayType) {
 
2486
                                return PrintCast(Tokens.DirectCast, castExpression);
 
2487
                        }
2360
2488
                        switch (castExpression.CastTo.SystemType) {
2361
2489
                                case "System.Boolean":
2362
2490
                                        outputFormatter.PrintToken(Tokens.CBool);
2392
2520
                                        outputFormatter.PrintToken(Tokens.CUShort);
2393
2521
                                        break;
2394
2522
                                case "System.UInt32":
2395
 
                                        outputFormatter.PrintToken(Tokens.CInt);
 
2523
                                        outputFormatter.PrintToken(Tokens.CUInt);
2396
2524
                                        break;
2397
2525
                                case "System.UInt64":
2398
 
                                        outputFormatter.PrintToken(Tokens.CLng);
 
2526
                                        outputFormatter.PrintToken(Tokens.CULng);
2399
2527
                                        break;
2400
2528
                                case "System.Object":
2401
2529
                                        outputFormatter.PrintToken(Tokens.CObj);
2410
2538
                                        return PrintCast(Tokens.CType, castExpression);
2411
2539
                        }
2412
2540
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2413
 
                        nodeTracker.TrackedVisit(castExpression.Expression, data);
 
2541
                        TrackedVisit(castExpression.Expression, data);
2414
2542
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2415
2543
                        return null;
2416
2544
                }
2419
2547
                {
2420
2548
                        outputFormatter.PrintToken(castToken);
2421
2549
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2422
 
                        nodeTracker.TrackedVisit(castExpression.Expression, null);
 
2550
                        TrackedVisit(castExpression.Expression, null);
2423
2551
                        outputFormatter.PrintToken(Tokens.Comma);
2424
2552
                        outputFormatter.Space();
2425
 
                        nodeTracker.TrackedVisit(castExpression.CastTo, null);
 
2553
                        TrackedVisit(castExpression.CastTo, null);
2426
2554
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2427
2555
                        return null;
2428
2556
                }
2429
2557
                
2430
 
                public object VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data)
 
2558
                public override object TrackedVisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data)
2431
2559
                {
2432
2560
                        UnsupportedNode(stackAllocExpression);
2433
2561
                        return null;
2434
2562
                }
2435
2563
                
2436
 
                public object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
 
2564
                public override object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data)
2437
2565
                {
2438
 
                        nodeTracker.TrackedVisit(indexerExpression.TargetObject, data);
 
2566
                        TrackedVisit(indexerExpression.TargetObject, data);
2439
2567
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2440
2568
                        AppendCommaSeparatedList(indexerExpression.Indexes);
2441
2569
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2442
2570
                        return null;
2443
2571
                }
2444
2572
                
2445
 
                public object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
 
2573
                public override object TrackedVisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
2446
2574
                {
2447
2575
                        outputFormatter.PrintToken(Tokens.Me);
2448
2576
                        return null;
2449
2577
                }
2450
2578
                
2451
 
                public object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data)
 
2579
                public override object TrackedVisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data)
2452
2580
                {
2453
2581
                        outputFormatter.PrintToken(Tokens.MyBase);
2454
2582
                        return null;
2455
2583
                }
2456
2584
                
2457
 
                public object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
 
2585
                public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
2458
2586
                {
2459
2587
                        outputFormatter.PrintToken(Tokens.New);
2460
2588
                        outputFormatter.Space();
2461
 
                        nodeTracker.TrackedVisit(objectCreateExpression.CreateType, data);
 
2589
                        TrackedVisit(objectCreateExpression.CreateType, data);
2462
2590
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2463
2591
                        AppendCommaSeparatedList(objectCreateExpression.Parameters);
2464
2592
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2465
2593
                        return null;
2466
2594
                }
2467
2595
                
2468
 
                public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
 
2596
                public override object TrackedVisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
2469
2597
                {
2470
2598
                        outputFormatter.PrintToken(Tokens.New);
2471
2599
                        outputFormatter.Space();
2486
2614
                                outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
2487
2615
                                outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
2488
2616
                        } else {
2489
 
                                nodeTracker.TrackedVisit(arrayCreateExpression.ArrayInitializer, data);
 
2617
                                TrackedVisit(arrayCreateExpression.ArrayInitializer, data);
2490
2618
                        }
2491
2619
                        return null;
2492
2620
                }
2493
2621
                
2494
 
                public object VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, object data)
 
2622
                public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data)
2495
2623
                {
2496
2624
                        outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
2497
2625
                        this.AppendCommaSeparatedList(arrayInitializerExpression.CreateExpressions);
2499
2627
                        return null;
2500
2628
                }
2501
2629
                
2502
 
                public object VisitFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression, object data)
 
2630
                public override object TrackedVisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
2503
2631
                {
2504
 
                        nodeTracker.TrackedVisit(fieldReferenceExpression.TargetObject, data);
 
2632
                        TrackedVisit(memberReferenceExpression.TargetObject, data);
2505
2633
                        outputFormatter.PrintToken(Tokens.Dot);
2506
 
                        outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName);
 
2634
                        outputFormatter.PrintIdentifier(memberReferenceExpression.MemberName);
 
2635
                        PrintTypeArguments(memberReferenceExpression.TypeArguments);
2507
2636
                        return null;
2508
2637
                }
2509
2638
                
2510
 
                public object VisitDirectionExpression(DirectionExpression directionExpression, object data)
 
2639
                public override object TrackedVisitDirectionExpression(DirectionExpression directionExpression, object data)
2511
2640
                {
2512
2641
                        // VB does not need to specify the direction in method calls
2513
 
                        nodeTracker.TrackedVisit(directionExpression.Expression, data);
 
2642
                        TrackedVisit(directionExpression.Expression, data);
2514
2643
                        return null;
2515
2644
                }
2516
2645
                
2517
2646
                
2518
 
                public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 
2647
                public override object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
2519
2648
                {
2520
 
                        // No representation in VB.NET, but VB conversion is possible.
2521
 
                        outputFormatter.PrintText("IIf");
 
2649
                        outputFormatter.PrintText("If");
2522
2650
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
2523
 
                        nodeTracker.TrackedVisit(conditionalExpression.Condition, data);
2524
 
                        outputFormatter.PrintToken(Tokens.Comma);
2525
 
                        nodeTracker.TrackedVisit(conditionalExpression.TrueExpression, data);
2526
 
                        outputFormatter.PrintToken(Tokens.Comma);
2527
 
                        nodeTracker.TrackedVisit(conditionalExpression.FalseExpression, data);
 
2651
                        TrackedVisit(conditionalExpression.Condition, data);
 
2652
                        outputFormatter.PrintToken(Tokens.Comma);
 
2653
                        outputFormatter.Space();
 
2654
                        TrackedVisit(conditionalExpression.TrueExpression, data);
 
2655
                        outputFormatter.PrintToken(Tokens.Comma);
 
2656
                        outputFormatter.Space();
 
2657
                        TrackedVisit(conditionalExpression.FalseExpression, data);
2528
2658
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
2529
2659
                        return null;
2530
2660
                }
2538
2668
                        switch (modifier) {
2539
2669
                                case ParameterModifiers.None:
2540
2670
                                case ParameterModifiers.In:
2541
 
                                        outputFormatter.PrintToken(Tokens.ByVal);
 
2671
                                        if (prettyPrintOptions.OutputByValModifier) {
 
2672
                                                outputFormatter.PrintToken(Tokens.ByVal);
 
2673
                                                outputFormatter.Space();
 
2674
                                        }
2542
2675
                                        break;
2543
2676
                                case ParameterModifiers.Out:
2544
 
                                        Error("Out parameter converted to ByRef", position);
 
2677
                                        //Error("Out parameter converted to ByRef", position);
2545
2678
                                        outputFormatter.PrintToken(Tokens.ByRef);
 
2679
                                        outputFormatter.Space();
2546
2680
                                        break;
2547
2681
                                case ParameterModifiers.Params:
2548
2682
                                        outputFormatter.PrintToken(Tokens.ParamArray);
 
2683
                                        outputFormatter.Space();
2549
2684
                                        break;
2550
2685
                                case ParameterModifiers.Ref:
2551
2686
                                        outputFormatter.PrintToken(Tokens.ByRef);
 
2687
                                        outputFormatter.Space();
2552
2688
                                        break;
2553
2689
                                case ParameterModifiers.Optional:
2554
2690
                                        outputFormatter.PrintToken(Tokens.Optional);
 
2691
                                        outputFormatter.Space();
2555
2692
                                        break;
2556
2693
                                default:
2557
2694
                                        Error(String.Format("Unsupported modifier : {0}", modifier), position);
2558
2695
                                        break;
2559
2696
                        }
2560
 
                        outputFormatter.Space();
2561
2697
                }
2562
2698
                
2563
2699
                void OutputModifier(Modifiers modifier)
2635
2771
                                // not required in VB
2636
2772
                        }
2637
2773
                        
2638
 
                        // TODO : Volatile
2639
2774
                        if ((modifier & Modifiers.Volatile) == Modifiers.Volatile) {
2640
2775
                                Error("'Volatile' modifier not convertable", Location.Empty);
2641
2776
                        }
2642
2777
                        
2643
 
                        // TODO : Unsafe
2644
2778
                        if ((modifier & Modifiers.Unsafe) == Modifiers.Unsafe) {
2645
2779
                                Error("'Unsafe' modifier not convertable", Location.Empty);
2646
2780
                        }
2651
2785
                        if (list != null) {
2652
2786
                                int i = 0;
2653
2787
                                foreach (T node in list) {
2654
 
                                        nodeTracker.TrackedVisit(node, null);
 
2788
                                        TrackedVisit(node, null);
2655
2789
                                        if (i + 1 < list.Count) {
2656
2790
                                                outputFormatter.PrintToken(Tokens.Comma);
2657
2791
                                                outputFormatter.Space();
2672
2806
                                return;
2673
2807
                        }
2674
2808
                        foreach (AttributeSection section in attributes) {
2675
 
                                nodeTracker.TrackedVisit(section, data);
2676
 
                        }
2677
 
                }
2678
 
                
2679
 
                
2680
 
                static bool IsEventHandlerCreation(Expression expr)
2681
 
                {
2682
 
                        if (expr is ObjectCreateExpression) {
2683
 
                                ObjectCreateExpression oce = (ObjectCreateExpression) expr;
2684
 
                                if (oce.Parameters.Count == 1) {
2685
 
                                        return oce.CreateType.SystemType.EndsWith("Handler");
2686
 
                                }
2687
 
                        }
2688
 
                        return false;
2689
 
                }
2690
 
                
2691
 
                // can only get called if IsEventHandlerCreation returned true for the expression
2692
 
                static Expression GetEventHandlerMethod(Expression expr)
2693
 
                {
2694
 
                        ObjectCreateExpression oce = (ObjectCreateExpression)expr;
2695
 
                        return oce.Parameters[0];
 
2809
                                TrackedVisit(section, data);
 
2810
                        }
 
2811
                }
 
2812
                
 
2813
                public override object TrackedVisitLambdaExpression(LambdaExpression lambdaExpression, object data)
 
2814
                {
 
2815
                        if (!lambdaExpression.ExpressionBody.IsNull) {
 
2816
                                outputFormatter.PrintToken(Tokens.Function);
 
2817
                                outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
2818
                                AppendCommaSeparatedList(lambdaExpression.Parameters);
 
2819
                                outputFormatter.PrintToken(Tokens.CloseParenthesis);
 
2820
                                outputFormatter.Space();
 
2821
                                return lambdaExpression.ExpressionBody.AcceptVisitor(this, data);
 
2822
                        } else {
 
2823
                                OutputAnonymousMethodWithStatementBody(lambdaExpression.Parameters, lambdaExpression.StatementBody);
 
2824
                                return null;
 
2825
                        }
 
2826
                }
 
2827
                
 
2828
                void OutputAnonymousMethodWithStatementBody(List<ParameterDeclarationExpression> parameters, BlockStatement body)
 
2829
                {
 
2830
                        Error("VB does not support anonymous methods/lambda expressions with a statement body", body.StartLocation);
 
2831
                        
 
2832
                        outputFormatter.PrintToken(Tokens.Function);
 
2833
                        outputFormatter.PrintToken(Tokens.OpenParenthesis);
 
2834
                        AppendCommaSeparatedList(parameters);
 
2835
                        outputFormatter.PrintToken(Tokens.CloseParenthesis);
 
2836
                        outputFormatter.Space();
 
2837
                        outputFormatter.PrintToken(Tokens.Do);
 
2838
                        outputFormatter.NewLine();
 
2839
                        
 
2840
                        ++outputFormatter.IndentationLevel;
 
2841
                        exitTokenStack.Push(Tokens.Function);
 
2842
                        body.AcceptVisitor(this, null);
 
2843
                        exitTokenStack.Pop();
 
2844
                        --outputFormatter.IndentationLevel;
 
2845
                        
 
2846
                        outputFormatter.Indent();
 
2847
                        outputFormatter.PrintToken(Tokens.End);
 
2848
                        outputFormatter.Space();
 
2849
                        outputFormatter.PrintToken(Tokens.Function);
 
2850
                }
 
2851
                
 
2852
                public override object TrackedVisitQueryExpression(QueryExpression queryExpression, object data)
 
2853
                {
 
2854
                        outputFormatter.IndentationLevel++;
 
2855
                        queryExpression.FromClause.AcceptVisitor(this, data);
 
2856
                        queryExpression.MiddleClauses.ForEach(PrintClause);
 
2857
                        PrintClause(queryExpression.SelectOrGroupClause);
 
2858
                        PrintClause(queryExpression.IntoClause);
 
2859
                        outputFormatter.IndentationLevel--;
 
2860
                        return null;
 
2861
                }
 
2862
                
 
2863
                void PrintClause(QueryExpressionClause clause)
 
2864
                {
 
2865
                        if (!clause.IsNull) {
 
2866
                                outputFormatter.PrintLineContinuation();
 
2867
                                outputFormatter.Indent();
 
2868
                                clause.AcceptVisitor(this, null);
 
2869
                        }
 
2870
                }
 
2871
                
 
2872
                public override object TrackedVisitQueryExpressionFromClause(QueryExpressionFromClause fromClause, object data)
 
2873
                {
 
2874
                        outputFormatter.PrintText("From");
 
2875
                        outputFormatter.Space();
 
2876
                        VisitQueryExpressionFromOrJoinClause(fromClause, data);
 
2877
                        return null;
 
2878
                }
 
2879
                
 
2880
                public override object TrackedVisitQueryExpressionJoinClause(QueryExpressionJoinClause joinClause, object data)
 
2881
                {
 
2882
                        outputFormatter.PrintText("Join");
 
2883
                        outputFormatter.Space();
 
2884
                        VisitQueryExpressionFromOrJoinClause(joinClause, data);
 
2885
                        outputFormatter.Space();
 
2886
                        outputFormatter.PrintToken(Tokens.On);
 
2887
                        outputFormatter.Space();
 
2888
                        joinClause.OnExpression.AcceptVisitor(this, data);
 
2889
                        outputFormatter.Space();
 
2890
                        outputFormatter.PrintToken(Tokens.Assign);
 
2891
                        outputFormatter.Space();
 
2892
                        joinClause.EqualsExpression.AcceptVisitor(this, data);
 
2893
                        if (!string.IsNullOrEmpty(joinClause.IntoIdentifier)) {
 
2894
                                outputFormatter.Space();
 
2895
                                outputFormatter.PrintText("Into");
 
2896
                                outputFormatter.Space();
 
2897
                                outputFormatter.PrintIdentifier(joinClause.IntoIdentifier);
 
2898
                        }
 
2899
                        return null;
 
2900
                }
 
2901
                
 
2902
                void VisitQueryExpressionFromOrJoinClause(QueryExpressionFromOrJoinClause clause, object data)
 
2903
                {
 
2904
                        outputFormatter.PrintIdentifier(clause.Identifier);
 
2905
                        outputFormatter.Space();
 
2906
                        outputFormatter.PrintToken(Tokens.In);
 
2907
                        outputFormatter.Space();
 
2908
                        clause.InExpression.AcceptVisitor(this, data);
 
2909
                }
 
2910
                
 
2911
                public override object TrackedVisitQueryExpressionLetClause(QueryExpressionLetClause letClause, object data)
 
2912
                {
 
2913
                        outputFormatter.PrintToken(Tokens.Let);
 
2914
                        outputFormatter.Space();
 
2915
                        outputFormatter.PrintIdentifier(letClause.Identifier);
 
2916
                        outputFormatter.Space();
 
2917
                        outputFormatter.PrintToken(Tokens.Assign);
 
2918
                        outputFormatter.Space();
 
2919
                        return letClause.Expression.AcceptVisitor(this, data);
 
2920
                }
 
2921
                
 
2922
                public override object TrackedVisitQueryExpressionGroupClause(QueryExpressionGroupClause groupClause, object data)
 
2923
                {
 
2924
                        outputFormatter.PrintText("Group");
 
2925
                        outputFormatter.Space();
 
2926
                        groupClause.Projection.AcceptVisitor(this, data);
 
2927
                        outputFormatter.Space();
 
2928
                        outputFormatter.PrintText("By");
 
2929
                        outputFormatter.Space();
 
2930
                        return groupClause.GroupBy.AcceptVisitor(this, data);
 
2931
                }
 
2932
                
 
2933
                public override object TrackedVisitQueryExpressionIntoClause(QueryExpressionIntoClause intoClause, object data)
 
2934
                {
 
2935
                        outputFormatter.PrintText("Into");
 
2936
                        outputFormatter.Space();
 
2937
                        outputFormatter.PrintIdentifier(intoClause.IntoIdentifier);
 
2938
                        outputFormatter.Space();
 
2939
                        return intoClause.ContinuedQuery.AcceptVisitor(this, data);
 
2940
                }
 
2941
                
 
2942
                public override object TrackedVisitQueryExpressionOrderClause(QueryExpressionOrderClause queryExpressionOrderClause, object data)
 
2943
                {
 
2944
                        outputFormatter.PrintText("Order By");
 
2945
                        outputFormatter.Space();
 
2946
                        AppendCommaSeparatedList(queryExpressionOrderClause.Orderings);
 
2947
                        return null;
 
2948
                }
 
2949
                
 
2950
                public override object TrackedVisitQueryExpressionOrdering(QueryExpressionOrdering ordering, object data)
 
2951
                {
 
2952
                        ordering.Criteria.AcceptVisitor(this, data);
 
2953
                        if (ordering.Direction == QueryExpressionOrderingDirection.Ascending) {
 
2954
                                outputFormatter.Space();
 
2955
                                outputFormatter.PrintText("Ascending");
 
2956
                        } else if (ordering.Direction == QueryExpressionOrderingDirection.Descending) {
 
2957
                                outputFormatter.Space();
 
2958
                                outputFormatter.PrintText("Descending");
 
2959
                        }
 
2960
                        return null;
 
2961
                }
 
2962
                
 
2963
                public override object TrackedVisitQueryExpressionSelectClause(QueryExpressionSelectClause selectClause, object data)
 
2964
                {
 
2965
                        outputFormatter.PrintToken(Tokens.Select);
 
2966
                        outputFormatter.Space();
 
2967
                        return selectClause.Projection.AcceptVisitor(this, data);
 
2968
                }
 
2969
                
 
2970
                public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause whereClause, object data)
 
2971
                {
 
2972
                        outputFormatter.PrintText("Where");
 
2973
                        outputFormatter.Space();
 
2974
                        return whereClause.Condition.AcceptVisitor(this, data);
2696
2975
                }
2697
2976
        }
2698
2977
}