/NRefactory/ICSharpCode.NRefactory.VB/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

http://github.com/icsharpcode/ILSpy · C# · 3023 lines · 13 code · 3 blank · 3007 comment · 0 complexity · e098561aafdc0914575cd1308fe85882 MD5 · raw file

Large files are truncated click here to view the full file

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2. // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
  3. using System;
  4. using System.Linq;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Globalization;
  9. using System.Text;
  10. using ICSharpCode.NRefactory.VB.Ast;
  11. using ICSharpCode.NRefactory.VB.Parser;
  12. using ICSharpCode.NRefactory.VB.Visitors;
  13. namespace ICSharpCode.NRefactory.VB.PrettyPrinter
  14. {
  15. // public sealed class VBNetOutputVisitor : NodeTrackingAstVisitor, IOutputDomVisitor
  16. // {
  17. // Errors errors = new Errors();
  18. // VBNetOutputFormatter outputFormatter;
  19. // VBNetPrettyPrintOptions prettyPrintOptions = new VBNetPrettyPrintOptions();
  20. // TypeDeclaration currentType;
  21. //
  22. // Stack<int> exitTokenStack = new Stack<int>();
  23. //
  24. // public string Text {
  25. // get {
  26. // return outputFormatter.Text;
  27. // }
  28. // }
  29. //
  30. // public Errors Errors {
  31. // get {
  32. // return errors;
  33. // }
  34. // }
  35. //
  36. // AbstractPrettyPrintOptions IOutputDomVisitor.Options {
  37. // get { return prettyPrintOptions; }
  38. // }
  39. //
  40. // public VBNetPrettyPrintOptions Options {
  41. // get { return prettyPrintOptions; }
  42. // }
  43. //
  44. // public IOutputFormatter OutputFormatter {
  45. // get {
  46. // return outputFormatter;
  47. // }
  48. // }
  49. //
  50. // public VBNetOutputVisitor()
  51. // {
  52. // outputFormatter = new VBNetOutputFormatter(prettyPrintOptions);
  53. // }
  54. //
  55. // public event Action<INode> BeforeNodeVisit;
  56. // public event Action<INode> AfterNodeVisit;
  57. //
  58. // protected override void BeginVisit(INode node)
  59. // {
  60. // if (BeforeNodeVisit != null) {
  61. // BeforeNodeVisit(node);
  62. // }
  63. // base.BeginVisit(node);
  64. // }
  65. //
  66. // protected override void EndVisit(INode node)
  67. // {
  68. // base.EndVisit(node);
  69. // if (AfterNodeVisit != null) {
  70. // AfterNodeVisit(node);
  71. // }
  72. // }
  73. //
  74. // object TrackedVisit(INode node, object data)
  75. // {
  76. // return node.AcceptVisitor(this, data);
  77. // }
  78. //
  79. // void Error(string text, Location position)
  80. // {
  81. // errors.Error(position.Line, position.Column, text);
  82. // }
  83. //
  84. // void UnsupportedNode(INode node)
  85. // {
  86. // Error(node.GetType().Name + " is unsupported", node.StartLocation);
  87. // }
  88. //
  89. // #region ICSharpCode.NRefactory.Parser.IAstVisitor interface implementation
  90. // public override object TrackedVisitCompilationUnit(CompilationUnit compilationUnit, object data)
  91. // {
  92. // compilationUnit.AcceptChildren(this, data);
  93. // outputFormatter.EndFile();
  94. // return null;
  95. // }
  96. //
  97. // /// <summary>
  98. // /// Converts type name to primitive type name. Returns typeString if typeString is not
  99. // /// a primitive type.
  100. // /// </summary>
  101. // static string ConvertTypeString(string typeString)
  102. // {
  103. // string primitiveType;
  104. // if (TypeReference.PrimitiveTypesVBReverse.TryGetValue(typeString, out primitiveType))
  105. // return primitiveType;
  106. // else
  107. // return typeString;
  108. // }
  109. //
  110. // public override object TrackedVisitTypeReference(TypeReference typeReference, object data)
  111. // {
  112. // if (typeReference == TypeReference.ClassConstraint) {
  113. // outputFormatter.PrintToken(Tokens.Class);
  114. // } else if (typeReference == TypeReference.StructConstraint) {
  115. // outputFormatter.PrintToken(Tokens.Structure);
  116. // } else if (typeReference == TypeReference.NewConstraint) {
  117. // outputFormatter.PrintToken(Tokens.New);
  118. // } else {
  119. // PrintTypeReferenceWithoutArray(typeReference);
  120. // if (typeReference.IsArrayType) {
  121. // PrintArrayRank(typeReference.RankSpecifier, 0);
  122. // }
  123. // }
  124. // return null;
  125. // }
  126. //
  127. // void PrintTypeReferenceWithoutArray(TypeReference typeReference)
  128. // {
  129. // if (typeReference.IsGlobal) {
  130. // outputFormatter.PrintToken(Tokens.Global);
  131. // outputFormatter.PrintToken(Tokens.Dot);
  132. // }
  133. // bool printGenerics = true;
  134. // if (typeReference.IsKeyword) {
  135. // outputFormatter.PrintText(ConvertTypeString(typeReference.Type));
  136. // } else {
  137. // outputFormatter.PrintIdentifier(typeReference.Type);
  138. // }
  139. // if (printGenerics && typeReference.GenericTypes != null && typeReference.GenericTypes.Count > 0) {
  140. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  141. // outputFormatter.PrintToken(Tokens.Of);
  142. // outputFormatter.Space();
  143. // AppendCommaSeparatedList(typeReference.GenericTypes);
  144. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  145. // }
  146. // for (int i = 0; i < typeReference.PointerNestingLevel; ++i) {
  147. // outputFormatter.PrintToken(Tokens.Times);
  148. // }
  149. // }
  150. //
  151. // void PrintArrayRank(int[] rankSpecifier, int startRank)
  152. // {
  153. // for (int i = startRank; i < rankSpecifier.Length; ++i) {
  154. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  155. // for (int j = 0; j < rankSpecifier[i]; ++j) {
  156. // outputFormatter.PrintToken(Tokens.Comma);
  157. // }
  158. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  159. // }
  160. // }
  161. //
  162. // public override object TrackedVisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data)
  163. // {
  164. // TrackedVisit(innerClassTypeReference.BaseType, data);
  165. // outputFormatter.PrintToken(Tokens.Dot);
  166. // return VisitTypeReference((TypeReference)innerClassTypeReference, data);
  167. // }
  168. //
  169. // #region Global scope
  170. // bool printAttributeSectionInline; // is set to true when printing parameter's attributes
  171. //
  172. // public override object TrackedVisitAttributeSection(AttributeSection attributeSection, object data)
  173. // {
  174. // if (!printAttributeSectionInline)
  175. // outputFormatter.Indent();
  176. // outputFormatter.PrintText("<");
  177. // if (!string.IsNullOrEmpty(attributeSection.AttributeTarget) && !string.Equals(attributeSection.AttributeTarget, "return", StringComparison.OrdinalIgnoreCase)) {
  178. // outputFormatter.PrintText(char.ToUpperInvariant(attributeSection.AttributeTarget[0]) + attributeSection.AttributeTarget.Substring(1));
  179. // outputFormatter.PrintToken(Tokens.Colon);
  180. // outputFormatter.Space();
  181. // }
  182. // Debug.Assert(attributeSection.Attributes != null);
  183. // AppendCommaSeparatedList(attributeSection.Attributes);
  184. //
  185. // outputFormatter.PrintText(">");
  186. //
  187. // if ("assembly".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)
  188. // || "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) {
  189. // outputFormatter.NewLine();
  190. // } else {
  191. // if (printAttributeSectionInline)
  192. // outputFormatter.Space();
  193. // else
  194. // outputFormatter.PrintLineContinuation();
  195. // }
  196. //
  197. // return null;
  198. // }
  199. //
  200. // public override object TrackedVisitAttribute(ICSharpCode.NRefactory.VB.Ast.Attribute attribute, object data)
  201. // {
  202. // outputFormatter.PrintIdentifier(attribute.Type);
  203. // if (attribute.PositionalArguments.Count > 0 || attribute.NamedArguments.Count > 0) {
  204. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  205. // AppendCommaSeparatedList(attribute.PositionalArguments);
  206. //
  207. // if (attribute.NamedArguments.Count > 0) {
  208. // if (attribute.PositionalArguments.Count > 0) {
  209. // outputFormatter.PrintToken(Tokens.Comma);
  210. // outputFormatter.Space();
  211. // }
  212. // AppendCommaSeparatedList(attribute.NamedArguments);
  213. // }
  214. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  215. // }
  216. // return null;
  217. // }
  218. //
  219. // public override object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
  220. // {
  221. // outputFormatter.PrintIdentifier(namedArgumentExpression.Name);
  222. // outputFormatter.Space();
  223. // outputFormatter.PrintToken(Tokens.Colon);
  224. // outputFormatter.PrintToken(Tokens.Assign);
  225. // outputFormatter.Space();
  226. // TrackedVisit(namedArgumentExpression.Expression, data);
  227. // return null;
  228. // }
  229. //
  230. // public override object TrackedVisitUsing(ImportsClause @using, object data)
  231. // {
  232. // Debug.Fail("Should never be called. The usings should be handled in Visit(UsingDeclaration)");
  233. // return null;
  234. // }
  235. //
  236. // public override object TrackedVisitUsingDeclaration(ImportsStatement usingDeclaration, object data)
  237. // {
  238. // outputFormatter.Indent();
  239. // outputFormatter.PrintToken(Tokens.Imports);
  240. // outputFormatter.Space();
  241. // for (int i = 0; i < usingDeclaration.ImportsClauses.Count; ++i) {
  242. // outputFormatter.PrintIdentifier(((ImportsClause)usingDeclaration.ImportsClauses[i]).Name);
  243. // if (((ImportsClause)usingDeclaration.ImportsClauses[i]).IsAlias) {
  244. // outputFormatter.Space();
  245. // outputFormatter.PrintToken(Tokens.Assign);
  246. // outputFormatter.Space();
  247. // TrackedVisit(((ImportsClause)usingDeclaration.ImportsClauses[i]).Alias, data);
  248. // }
  249. // if (i + 1 < usingDeclaration.ImportsClauses.Count) {
  250. // outputFormatter.PrintToken(Tokens.Comma);
  251. // outputFormatter.Space();
  252. // }
  253. // }
  254. // outputFormatter.NewLine();
  255. // return null;
  256. // }
  257. //
  258. // public override object TrackedVisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
  259. // {
  260. // outputFormatter.Indent();
  261. // outputFormatter.PrintToken(Tokens.Namespace);
  262. // outputFormatter.Space();
  263. // outputFormatter.PrintIdentifier(namespaceDeclaration.Name);
  264. // outputFormatter.NewLine();
  265. //
  266. // ++outputFormatter.IndentationLevel;
  267. // namespaceDeclaration.AcceptChildren(this, data);
  268. // --outputFormatter.IndentationLevel;
  269. //
  270. // outputFormatter.Indent();
  271. // outputFormatter.PrintToken(Tokens.End);
  272. // outputFormatter.Space();
  273. // outputFormatter.PrintToken(Tokens.Namespace);
  274. // outputFormatter.NewLine();
  275. // return null;
  276. // }
  277. //
  278. // static int GetTypeToken(TypeDeclaration typeDeclaration)
  279. // {
  280. // switch (typeDeclaration.Type) {
  281. // case ClassType.Class:
  282. // return Tokens.Class;
  283. // case ClassType.Enum:
  284. // return Tokens.Enum;
  285. // case ClassType.Interface:
  286. // return Tokens.Interface;
  287. // case ClassType.Struct:
  288. // return Tokens.Structure;
  289. // case ClassType.Module:
  290. // return Tokens.Module;
  291. // default:
  292. // return Tokens.Class;
  293. // }
  294. // }
  295. //
  296. // void PrintTemplates(List<TemplateDefinition> templates)
  297. // {
  298. // if (templates != null && templates.Count > 0) {
  299. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  300. // outputFormatter.PrintToken(Tokens.Of);
  301. // outputFormatter.Space();
  302. // AppendCommaSeparatedList(templates);
  303. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  304. // }
  305. // }
  306. //
  307. // public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
  308. // {
  309. // VisitAttributes(typeDeclaration.Attributes, data);
  310. //
  311. // outputFormatter.Indent();
  312. // OutputModifier(typeDeclaration.Modifier, true, false);
  313. //
  314. // int typeToken = GetTypeToken(typeDeclaration);
  315. // outputFormatter.PrintToken(typeToken);
  316. // outputFormatter.Space();
  317. // outputFormatter.PrintIdentifier(typeDeclaration.Name);
  318. //
  319. // PrintTemplates(typeDeclaration.Templates);
  320. //
  321. // if (typeDeclaration.Type == ClassType.Enum
  322. // && typeDeclaration.BaseTypes != null && typeDeclaration.BaseTypes.Count > 0)
  323. // {
  324. // outputFormatter.Space();
  325. // outputFormatter.PrintToken(Tokens.As);
  326. // outputFormatter.Space();
  327. // foreach (TypeReference baseTypeRef in typeDeclaration.BaseTypes) {
  328. // TrackedVisit(baseTypeRef, data);
  329. // }
  330. // }
  331. //
  332. // outputFormatter.NewLine();
  333. // ++outputFormatter.IndentationLevel;
  334. //
  335. // if (typeDeclaration.BaseTypes != null && typeDeclaration.Type != ClassType.Enum) {
  336. // foreach (TypeReference baseTypeRef in typeDeclaration.BaseTypes) {
  337. // outputFormatter.Indent();
  338. //
  339. // string baseType = baseTypeRef.Type;
  340. // if (baseType.IndexOf('.') >= 0) {
  341. // baseType = baseType.Substring(baseType.LastIndexOf('.') + 1);
  342. // }
  343. // bool baseTypeIsInterface = baseType.Length >= 2 && baseType[0] == 'I' && Char.IsUpper(baseType[1]);
  344. //
  345. // if (!baseTypeIsInterface || typeDeclaration.Type == ClassType.Interface) {
  346. // outputFormatter.PrintToken(Tokens.Inherits);
  347. // } else {
  348. // outputFormatter.PrintToken(Tokens.Implements);
  349. // }
  350. // outputFormatter.Space();
  351. // TrackedVisit(baseTypeRef, data);
  352. // outputFormatter.NewLine();
  353. // }
  354. // }
  355. //
  356. // TypeDeclaration oldType = currentType;
  357. // currentType = typeDeclaration;
  358. //
  359. // if (typeDeclaration.Type == ClassType.Enum) {
  360. // OutputEnumMembers(typeDeclaration, data);
  361. // } else {
  362. // typeDeclaration.AcceptChildren(this, data);
  363. // }
  364. // currentType = oldType;
  365. //
  366. // --outputFormatter.IndentationLevel;
  367. //
  368. //
  369. // outputFormatter.Indent();
  370. // outputFormatter.PrintToken(Tokens.End);
  371. // outputFormatter.Space();
  372. // outputFormatter.PrintToken(typeToken);
  373. // outputFormatter.NewLine();
  374. // return null;
  375. // }
  376. //
  377. // void OutputEnumMembers(TypeDeclaration typeDeclaration, object data)
  378. // {
  379. // foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) {
  380. // BeginVisit(fieldDeclaration);
  381. // VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
  382. // VisitAttributes(fieldDeclaration.Attributes, data);
  383. // outputFormatter.Indent();
  384. // outputFormatter.PrintIdentifier(f.Name);
  385. // if (f.Initializer != null && !f.Initializer.IsNull) {
  386. // outputFormatter.Space();
  387. // outputFormatter.PrintToken(Tokens.Assign);
  388. // outputFormatter.Space();
  389. // TrackedVisit(f.Initializer, data);
  390. // }
  391. // outputFormatter.NewLine();
  392. // EndVisit(fieldDeclaration);
  393. // }
  394. // }
  395. //
  396. // public override object TrackedVisitTemplateDefinition(TemplateDefinition templateDefinition, object data)
  397. // {
  398. // VisitAttributes(templateDefinition.Attributes, data);
  399. // switch (templateDefinition.VarianceModifier) {
  400. // case VarianceModifier.Invariant:
  401. // // nothing
  402. // break;
  403. // case VarianceModifier.Covariant:
  404. // outputFormatter.Space();
  405. // outputFormatter.PrintToken(Tokens.Out);
  406. // outputFormatter.Space();
  407. // break;
  408. // case VarianceModifier.Contravariant:
  409. // outputFormatter.Space();
  410. // outputFormatter.PrintToken(Tokens.In);
  411. // outputFormatter.Space();
  412. // break;
  413. // default:
  414. // throw new Exception("Invalid value for VarianceModifier");
  415. // }
  416. // outputFormatter.PrintIdentifier(templateDefinition.Name);
  417. // if (templateDefinition.Bases.Count > 0) {
  418. // outputFormatter.PrintText(" As ");
  419. // VisitReturnTypeAttributes(templateDefinition.Attributes, data);
  420. // if (templateDefinition.Bases.Count == 1) {
  421. // TrackedVisit(templateDefinition.Bases[0], data);
  422. // } else {
  423. // outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
  424. // AppendCommaSeparatedList(templateDefinition.Bases);
  425. // outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
  426. // }
  427. // }
  428. // return null;
  429. // }
  430. //
  431. // public override object TrackedVisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
  432. // {
  433. // VisitAttributes(delegateDeclaration.Attributes, data);
  434. //
  435. // outputFormatter.Indent();
  436. // OutputModifier(delegateDeclaration.Modifier, true, false);
  437. // outputFormatter.PrintToken(Tokens.Delegate);
  438. // outputFormatter.Space();
  439. //
  440. // bool isFunction = (delegateDeclaration.ReturnType.Type != "System.Void");
  441. // if (isFunction) {
  442. // outputFormatter.PrintToken(Tokens.Function);
  443. // outputFormatter.Space();
  444. // } else {
  445. // outputFormatter.PrintToken(Tokens.Sub);
  446. // outputFormatter.Space();
  447. // }
  448. // outputFormatter.PrintIdentifier(delegateDeclaration.Name);
  449. //
  450. // PrintTemplates(delegateDeclaration.Templates);
  451. //
  452. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  453. // AppendCommaSeparatedList(delegateDeclaration.Parameters);
  454. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  455. //
  456. // if (isFunction) {
  457. // outputFormatter.Space();
  458. // outputFormatter.PrintToken(Tokens.As);
  459. // outputFormatter.Space();
  460. // VisitReturnTypeAttributes(delegateDeclaration.Attributes, data);
  461. // TrackedVisit(delegateDeclaration.ReturnType, data);
  462. // }
  463. // outputFormatter.NewLine();
  464. // return null;
  465. // }
  466. //
  467. // public override object TrackedVisitOptionDeclaration(OptionDeclaration optionDeclaration, object data)
  468. // {
  469. // outputFormatter.PrintToken(Tokens.Option);
  470. // outputFormatter.Space();
  471. // switch (optionDeclaration.OptionType) {
  472. // case OptionType.Strict:
  473. // outputFormatter.PrintToken(Tokens.Strict);
  474. // outputFormatter.Space();
  475. // outputFormatter.PrintToken(optionDeclaration.OptionValue ? Tokens.On : Tokens.Off);
  476. // break;
  477. // case OptionType.Explicit:
  478. // outputFormatter.PrintToken(Tokens.Explicit);
  479. // outputFormatter.Space();
  480. // outputFormatter.PrintToken(optionDeclaration.OptionValue ? Tokens.On : Tokens.Off);
  481. // break;
  482. // case OptionType.Infer:
  483. // outputFormatter.PrintToken(Tokens.Infer);
  484. // outputFormatter.Space();
  485. // outputFormatter.PrintToken(optionDeclaration.OptionValue ? Tokens.On : Tokens.Off);
  486. // break;
  487. // case OptionType.CompareBinary:
  488. // outputFormatter.PrintToken(Tokens.Compare);
  489. // outputFormatter.Space();
  490. // outputFormatter.PrintToken(Tokens.Binary);
  491. // break;
  492. // case OptionType.CompareText:
  493. // outputFormatter.PrintToken(Tokens.Compare);
  494. // outputFormatter.Space();
  495. // outputFormatter.PrintToken(Tokens.Text);
  496. // break;
  497. // }
  498. // outputFormatter.NewLine();
  499. // return null;
  500. // }
  501. // #endregion
  502. //
  503. // #region Type level
  504. // TypeReference currentVariableType;
  505. // public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
  506. // {
  507. //
  508. // VisitAttributes(fieldDeclaration.Attributes, data);
  509. // outputFormatter.Indent();
  510. // if (fieldDeclaration.Modifier == Modifiers.None) {
  511. // outputFormatter.PrintToken(Tokens.Private);
  512. // outputFormatter.Space();
  513. // } else {
  514. // OutputModifier(fieldDeclaration.Modifier, false, true);
  515. // }
  516. // currentVariableType = fieldDeclaration.TypeReference;
  517. // AppendCommaSeparatedList(fieldDeclaration.Fields);
  518. // currentVariableType = null;
  519. //
  520. // outputFormatter.NewLine();
  521. //
  522. // return null;
  523. // }
  524. //
  525. // public override object TrackedVisitVariableDeclaration(VariableDeclaration variableDeclaration, object data)
  526. // {
  527. // outputFormatter.PrintIdentifier(variableDeclaration.Name);
  528. //
  529. // TypeReference varType = currentVariableType;
  530. // if (varType != null && varType.IsNull)
  531. // varType = null;
  532. // if (varType == null && !variableDeclaration.TypeReference.IsNull)
  533. // varType = variableDeclaration.TypeReference;
  534. //
  535. // if (varType != null) {
  536. // outputFormatter.Space();
  537. // outputFormatter.PrintToken(Tokens.As);
  538. // outputFormatter.Space();
  539. // ObjectCreateExpression init = variableDeclaration.Initializer as ObjectCreateExpression;
  540. // if (init != null && TypeReference.AreEqualReferences(init.CreateType, varType)) {
  541. // TrackedVisit(variableDeclaration.Initializer, data);
  542. // return null;
  543. // } else {
  544. // TrackedVisit(varType, data);
  545. // }
  546. // }
  547. //
  548. // if (!variableDeclaration.Initializer.IsNull) {
  549. // outputFormatter.Space();
  550. // outputFormatter.PrintToken(Tokens.Assign);
  551. // outputFormatter.Space();
  552. // TrackedVisit(variableDeclaration.Initializer, data);
  553. // }
  554. // return null;
  555. // }
  556. //
  557. // public override object TrackedVisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
  558. // {
  559. // VisitAttributes(propertyDeclaration.Attributes, data);
  560. // outputFormatter.Indent();
  561. // OutputModifier(propertyDeclaration.Modifier);
  562. //
  563. // if ((propertyDeclaration.Modifier & (Modifiers.ReadOnly | Modifiers.WriteOnly)) == Modifiers.None) {
  564. // if (propertyDeclaration.IsReadOnly) {
  565. // outputFormatter.PrintToken(Tokens.ReadOnly);
  566. // outputFormatter.Space();
  567. // } else if (propertyDeclaration.IsWriteOnly) {
  568. // outputFormatter.PrintToken(Tokens.WriteOnly);
  569. // outputFormatter.Space();
  570. // }
  571. // }
  572. //
  573. // outputFormatter.PrintToken(Tokens.Property);
  574. // outputFormatter.Space();
  575. // outputFormatter.PrintIdentifier(propertyDeclaration.Name);
  576. //
  577. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  578. // AppendCommaSeparatedList(propertyDeclaration.Parameters);
  579. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  580. //
  581. // if (!propertyDeclaration.TypeReference.IsNull) {
  582. // outputFormatter.Space();
  583. // outputFormatter.PrintToken(Tokens.As);
  584. // outputFormatter.Space();
  585. //
  586. // VisitReturnTypeAttributes(propertyDeclaration.Attributes, data);
  587. //
  588. // ObjectCreateExpression init = propertyDeclaration.Initializer as ObjectCreateExpression;
  589. // if (init != null && TypeReference.AreEqualReferences(init.CreateType, propertyDeclaration.TypeReference)) {
  590. // TrackedVisit(propertyDeclaration.Initializer, data);
  591. // } else {
  592. // TrackedVisit(propertyDeclaration.TypeReference, data);
  593. // }
  594. // }
  595. //
  596. // PrintInterfaceImplementations(propertyDeclaration.InterfaceImplementations);
  597. //
  598. // if (!propertyDeclaration.Initializer.IsNull && !(propertyDeclaration.Initializer is ObjectCreateExpression)) {
  599. // outputFormatter.Space();
  600. // outputFormatter.PrintToken(Tokens.Assign);
  601. // outputFormatter.Space();
  602. // TrackedVisit(propertyDeclaration.Initializer, data);
  603. // }
  604. //
  605. // outputFormatter.NewLine();
  606. //
  607. // if (!IsAbstract(propertyDeclaration) && (propertyDeclaration.GetRegion.Block != NullBlockStatement.Instance || propertyDeclaration.SetRegion.Block != NullBlockStatement.Instance)) {
  608. // outputFormatter.IsInMemberBody = true;
  609. // ++outputFormatter.IndentationLevel;
  610. // exitTokenStack.Push(Tokens.Property);
  611. // TrackedVisit(propertyDeclaration.GetRegion, data);
  612. // TrackedVisit(propertyDeclaration.SetRegion, data);
  613. // exitTokenStack.Pop();
  614. // --outputFormatter.IndentationLevel;
  615. // outputFormatter.IsInMemberBody = false;
  616. //
  617. // outputFormatter.Indent();
  618. // outputFormatter.PrintToken(Tokens.End);
  619. // outputFormatter.Space();
  620. // outputFormatter.PrintToken(Tokens.Property);
  621. // outputFormatter.NewLine();
  622. // }
  623. //
  624. // return null;
  625. // }
  626. //
  627. // public override object TrackedVisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data)
  628. // {
  629. // VisitAttributes(propertyGetRegion.Attributes, data);
  630. // outputFormatter.Indent();
  631. // OutputModifier(propertyGetRegion.Modifier);
  632. // outputFormatter.PrintToken(Tokens.Get);
  633. // outputFormatter.NewLine();
  634. //
  635. // ++outputFormatter.IndentationLevel;
  636. // TrackedVisit(propertyGetRegion.Block, data);
  637. // --outputFormatter.IndentationLevel;
  638. // outputFormatter.Indent();
  639. // outputFormatter.PrintToken(Tokens.End);
  640. // outputFormatter.Space();
  641. // outputFormatter.PrintToken(Tokens.Get);
  642. // outputFormatter.NewLine();
  643. // return null;
  644. // }
  645. //
  646. // public override object TrackedVisitPropertySetRegion(PropertySetRegion propertySetRegion, object data)
  647. // {
  648. // VisitAttributes(propertySetRegion.Attributes, data);
  649. // outputFormatter.Indent();
  650. // OutputModifier(propertySetRegion.Modifier);
  651. // outputFormatter.PrintToken(Tokens.Set);
  652. // outputFormatter.NewLine();
  653. //
  654. // ++outputFormatter.IndentationLevel;
  655. // TrackedVisit(propertySetRegion.Block, data);
  656. // --outputFormatter.IndentationLevel;
  657. // outputFormatter.Indent();
  658. // outputFormatter.PrintToken(Tokens.End);
  659. // outputFormatter.Space();
  660. // outputFormatter.PrintToken(Tokens.Set);
  661. // outputFormatter.NewLine();
  662. // return null;
  663. // }
  664. //
  665. // TypeReference currentEventType = null;
  666. // public override object TrackedVisitEventDeclaration(EventDeclaration eventDeclaration, object data)
  667. // {
  668. // bool customEvent = eventDeclaration.HasAddRegion || eventDeclaration.HasRemoveRegion;
  669. //
  670. // VisitAttributes(eventDeclaration.Attributes, data);
  671. // outputFormatter.Indent();
  672. // OutputModifier(eventDeclaration.Modifier);
  673. // if (customEvent) {
  674. // outputFormatter.PrintText("Custom");
  675. // outputFormatter.Space();
  676. // }
  677. //
  678. // outputFormatter.PrintToken(Tokens.Event);
  679. // outputFormatter.Space();
  680. // outputFormatter.PrintIdentifier(eventDeclaration.Name);
  681. //
  682. // if (eventDeclaration.Parameters.Count > 0) {
  683. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  684. // this.AppendCommaSeparatedList(eventDeclaration.Parameters);
  685. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  686. // }
  687. // if (!eventDeclaration.TypeReference.IsNull) {
  688. // outputFormatter.Space();
  689. // outputFormatter.PrintToken(Tokens.As);
  690. // outputFormatter.Space();
  691. // VisitReturnTypeAttributes(eventDeclaration.Attributes, data);
  692. // TrackedVisit(eventDeclaration.TypeReference, data);
  693. // }
  694. //
  695. // PrintInterfaceImplementations(eventDeclaration.InterfaceImplementations);
  696. //
  697. // if (!eventDeclaration.Initializer.IsNull) {
  698. // outputFormatter.Space();
  699. // outputFormatter.PrintToken(Tokens.Assign);
  700. // outputFormatter.Space();
  701. // TrackedVisit(eventDeclaration.Initializer, data);
  702. // }
  703. //
  704. // outputFormatter.NewLine();
  705. //
  706. // if (customEvent) {
  707. // ++outputFormatter.IndentationLevel;
  708. // currentEventType = eventDeclaration.TypeReference;
  709. // exitTokenStack.Push(Tokens.Sub);
  710. // TrackedVisit(eventDeclaration.AddRegion, data);
  711. // TrackedVisit(eventDeclaration.RemoveRegion, data);
  712. // exitTokenStack.Pop();
  713. // --outputFormatter.IndentationLevel;
  714. //
  715. // outputFormatter.Indent();
  716. // outputFormatter.PrintToken(Tokens.End);
  717. // outputFormatter.Space();
  718. // outputFormatter.PrintToken(Tokens.Event);
  719. // outputFormatter.NewLine();
  720. // }
  721. // return null;
  722. // }
  723. //
  724. // void PrintInterfaceImplementations(IList<InterfaceImplementation> list)
  725. // {
  726. // if (list == null || list.Count == 0)
  727. // return;
  728. // outputFormatter.Space();
  729. // outputFormatter.PrintToken(Tokens.Implements);
  730. // for (int i = 0; i < list.Count; i++) {
  731. // if (i > 0)
  732. // outputFormatter.PrintToken(Tokens.Comma);
  733. // outputFormatter.Space();
  734. // TrackedVisit(list[i].InterfaceType, null);
  735. // outputFormatter.PrintToken(Tokens.Dot);
  736. // outputFormatter.PrintIdentifier(list[i].MemberName);
  737. // }
  738. // }
  739. //
  740. // public override object TrackedVisitEventAddRegion(EventAddRegion eventAddRegion, object data)
  741. // {
  742. // VisitAttributes(eventAddRegion.Attributes, data);
  743. // outputFormatter.Indent();
  744. // outputFormatter.PrintText("AddHandler(");
  745. // if (eventAddRegion.Parameters.Count == 0) {
  746. // outputFormatter.PrintToken(Tokens.ByVal);
  747. // outputFormatter.Space();
  748. // outputFormatter.PrintIdentifier("value");
  749. // outputFormatter.Space();
  750. // outputFormatter.PrintToken(Tokens.As);
  751. // outputFormatter.Space();
  752. // TrackedVisit(currentEventType, data);
  753. // } else {
  754. // this.AppendCommaSeparatedList(eventAddRegion.Parameters);
  755. // }
  756. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  757. // outputFormatter.NewLine();
  758. //
  759. // ++outputFormatter.IndentationLevel;
  760. // TrackedVisit(eventAddRegion.Block, data);
  761. // --outputFormatter.IndentationLevel;
  762. //
  763. // outputFormatter.Indent();
  764. // outputFormatter.PrintToken(Tokens.End);
  765. // outputFormatter.Space();
  766. // outputFormatter.PrintText("AddHandler");
  767. // outputFormatter.NewLine();
  768. // return null;
  769. // }
  770. //
  771. // public override object TrackedVisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data)
  772. // {
  773. // VisitAttributes(eventRemoveRegion.Attributes, data);
  774. // outputFormatter.Indent();
  775. // outputFormatter.PrintText("RemoveHandler");
  776. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  777. // if (eventRemoveRegion.Parameters.Count == 0) {
  778. // outputFormatter.PrintToken(Tokens.ByVal);
  779. // outputFormatter.Space();
  780. // outputFormatter.PrintIdentifier("value");
  781. // outputFormatter.Space();
  782. // outputFormatter.PrintToken(Tokens.As);
  783. // outputFormatter.Space();
  784. // TrackedVisit(currentEventType, data);
  785. // } else {
  786. // this.AppendCommaSeparatedList(eventRemoveRegion.Parameters);
  787. // }
  788. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  789. // outputFormatter.NewLine();
  790. //
  791. // ++outputFormatter.IndentationLevel;
  792. // TrackedVisit(eventRemoveRegion.Block, data);
  793. // --outputFormatter.IndentationLevel;
  794. //
  795. // outputFormatter.Indent();
  796. // outputFormatter.PrintToken(Tokens.End);
  797. // outputFormatter.Space();
  798. // outputFormatter.PrintText("RemoveHandler");
  799. // outputFormatter.NewLine();
  800. // return null;
  801. // }
  802. //
  803. // public override object TrackedVisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data)
  804. // {
  805. // VisitAttributes(eventRaiseRegion.Attributes, data);
  806. // outputFormatter.Indent();
  807. // outputFormatter.PrintText("RaiseEvent");
  808. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  809. // if (eventRaiseRegion.Parameters.Count == 0) {
  810. // outputFormatter.PrintToken(Tokens.ByVal);
  811. // outputFormatter.Space();
  812. // outputFormatter.PrintIdentifier("value");
  813. // outputFormatter.Space();
  814. // outputFormatter.PrintToken(Tokens.As);
  815. // outputFormatter.Space();
  816. // TrackedVisit(currentEventType, data);
  817. // } else {
  818. // this.AppendCommaSeparatedList(eventRaiseRegion.Parameters);
  819. // }
  820. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  821. // outputFormatter.NewLine();
  822. //
  823. // ++outputFormatter.IndentationLevel;
  824. // TrackedVisit(eventRaiseRegion.Block, data);
  825. // --outputFormatter.IndentationLevel;
  826. //
  827. // outputFormatter.Indent();
  828. // outputFormatter.PrintToken(Tokens.End);
  829. // outputFormatter.Space();
  830. // outputFormatter.PrintText("RaiseEvent");
  831. // outputFormatter.NewLine();
  832. // return null;
  833. // }
  834. //
  835. // public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
  836. // {
  837. // printAttributeSectionInline = true;
  838. // VisitAttributes(parameterDeclarationExpression.Attributes, data);
  839. // printAttributeSectionInline = false;
  840. // OutputModifier(parameterDeclarationExpression.ParamModifier);
  841. // outputFormatter.PrintIdentifier(parameterDeclarationExpression.ParameterName);
  842. // if (!parameterDeclarationExpression.TypeReference.IsNull) {
  843. // outputFormatter.Space();
  844. // outputFormatter.PrintToken(Tokens.As);
  845. // outputFormatter.Space();
  846. // VisitReturnTypeAttributes(parameterDeclarationExpression.Attributes, data);
  847. // TrackedVisit(parameterDeclarationExpression.TypeReference, data);
  848. // }
  849. // if (!parameterDeclarationExpression.DefaultValue.IsNull) {
  850. // outputFormatter.Space();
  851. // outputFormatter.PrintToken(Tokens.Assign);
  852. // outputFormatter.Space();
  853. // TrackedVisit(parameterDeclarationExpression.DefaultValue, data);
  854. // }
  855. // return null;
  856. // }
  857. //
  858. // public override object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
  859. // {
  860. // VisitAttributes(methodDeclaration.Attributes, data);
  861. // if (methodDeclaration.IsExtensionMethod) {
  862. // outputFormatter.Indent();
  863. // outputFormatter.PrintText("<System.Runtime.CompilerServices.Extension> _");
  864. // outputFormatter.NewLine();
  865. // }
  866. // outputFormatter.Indent();
  867. // OutputModifier(methodDeclaration.Modifier);
  868. //
  869. // bool isSub = methodDeclaration.TypeReference.IsNull ||
  870. // methodDeclaration.TypeReference.Type == "System.Void";
  871. //
  872. // if (isSub) {
  873. // outputFormatter.PrintToken(Tokens.Sub);
  874. // } else {
  875. // outputFormatter.PrintToken(Tokens.Function);
  876. // }
  877. // outputFormatter.Space();
  878. // outputFormatter.PrintIdentifier(methodDeclaration.Name);
  879. //
  880. // PrintTemplates(methodDeclaration.Templates);
  881. //
  882. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  883. // AppendCommaSeparatedList(methodDeclaration.Parameters);
  884. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  885. //
  886. // if (!isSub) {
  887. // outputFormatter.Space();
  888. // outputFormatter.PrintToken(Tokens.As);
  889. // outputFormatter.Space();
  890. // VisitReturnTypeAttributes(methodDeclaration.Attributes, data);
  891. // TrackedVisit(methodDeclaration.TypeReference, data);
  892. // }
  893. //
  894. // PrintInterfaceImplementations(methodDeclaration.InterfaceImplementations);
  895. //
  896. // if (methodDeclaration.HandlesClause.Count > 0) {
  897. // outputFormatter.Space();
  898. // outputFormatter.PrintToken(Tokens.Handles);
  899. // for (int i = 0; i < methodDeclaration.HandlesClause.Count; i++) {
  900. // if (i > 0)
  901. // outputFormatter.PrintToken(Tokens.Comma);
  902. // outputFormatter.Space();
  903. // outputFormatter.PrintText(methodDeclaration.HandlesClause[i]);
  904. // }
  905. // }
  906. //
  907. // outputFormatter.NewLine();
  908. //
  909. // if (!IsAbstract(methodDeclaration)) {
  910. // outputFormatter.IsInMemberBody = true;
  911. // BeginVisit(methodDeclaration.Body);
  912. // ++outputFormatter.IndentationLevel;
  913. // exitTokenStack.Push(isSub ? Tokens.Sub : Tokens.Function);
  914. // // we're doing the tracking manually using BeginVisit/EndVisit, so call Tracked... directly
  915. // this.TrackedVisitBlockStatement(methodDeclaration.Body, data);
  916. // exitTokenStack.Pop();
  917. // --outputFormatter.IndentationLevel;
  918. //
  919. // outputFormatter.Indent();
  920. // outputFormatter.PrintToken(Tokens.End);
  921. // outputFormatter.Space();
  922. // if (isSub) {
  923. // outputFormatter.PrintToken(Tokens.Sub);
  924. // } else {
  925. // outputFormatter.PrintToken(Tokens.Function);
  926. // }
  927. // outputFormatter.NewLine();
  928. // EndVisit(methodDeclaration.Body);
  929. // outputFormatter.IsInMemberBody = false;
  930. // }
  931. // return null;
  932. // }
  933. //
  934. // public override object TrackedVisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data)
  935. // {
  936. // throw new InvalidOperationException();
  937. // }
  938. //
  939. // bool IsAbstract(AttributedNode node)
  940. // {
  941. // if ((node.Modifier & Modifiers.Abstract) == Modifiers.Abstract)
  942. // return true;
  943. // return currentType != null && currentType.Type == ClassType.Interface;
  944. // }
  945. //
  946. // public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
  947. // {
  948. // VisitAttributes(constructorDeclaration.Attributes, data);
  949. // outputFormatter.Indent();
  950. // OutputModifier(constructorDeclaration.Modifier);
  951. // outputFormatter.PrintToken(Tokens.Sub);
  952. // outputFormatter.Space();
  953. // outputFormatter.PrintToken(Tokens.New);
  954. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  955. // AppendCommaSeparatedList(constructorDeclaration.Parameters);
  956. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  957. // outputFormatter.NewLine();
  958. //
  959. // outputFormatter.IsInMemberBody = true;
  960. // ++outputFormatter.IndentationLevel;
  961. // exitTokenStack.Push(Tokens.Sub);
  962. //
  963. // TrackedVisit(constructorDeclaration.ConstructorInitializer, data);
  964. //
  965. // TrackedVisit(constructorDeclaration.Body, data);
  966. // exitTokenStack.Pop();
  967. // --outputFormatter.IndentationLevel;
  968. // outputFormatter.IsInMemberBody = false;
  969. //
  970. // outputFormatter.Indent();
  971. // outputFormatter.PrintToken(Tokens.End);
  972. // outputFormatter.Space();
  973. // outputFormatter.PrintToken(Tokens.Sub);
  974. // outputFormatter.NewLine();
  975. //
  976. // return null;
  977. // }
  978. //
  979. // public override object TrackedVisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data)
  980. // {
  981. // outputFormatter.Indent();
  982. // if (constructorInitializer.ConstructorInitializerType == ConstructorInitializerType.This) {
  983. // outputFormatter.PrintToken(Tokens.Me);
  984. // } else {
  985. // outputFormatter.PrintToken(Tokens.MyBase);
  986. // }
  987. // outputFormatter.PrintToken(Tokens.Dot);
  988. // outputFormatter.PrintToken(Tokens.New);
  989. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  990. // AppendCommaSeparatedList(constructorInitializer.Arguments);
  991. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  992. //
  993. // outputFormatter.NewLine();
  994. // return null;
  995. // }
  996. //
  997. // public override object TrackedVisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data)
  998. // {
  999. // VisitAttributes(operatorDeclaration.Attributes, data);
  1000. // outputFormatter.Indent();
  1001. // OutputModifier(operatorDeclaration.Modifier);
  1002. //
  1003. // if (operatorDeclaration.IsConversionOperator) {
  1004. // if (operatorDeclaration.ConversionType == ConversionType.Implicit) {
  1005. // outputFormatter.PrintToken(Tokens.Widening);
  1006. // } else {
  1007. // outputFormatter.PrintToken(Tokens.Narrowing);
  1008. // }
  1009. // outputFormatter.Space();
  1010. // }
  1011. //
  1012. // outputFormatter.PrintToken(Tokens.Operator);
  1013. // outputFormatter.Space();
  1014. //
  1015. // int op = -1;
  1016. //
  1017. // switch(operatorDeclaration.OverloadableOperator)
  1018. // {
  1019. // case OverloadableOperatorType.Add:
  1020. // case OverloadableOperatorType.UnaryPlus:
  1021. // op = Tokens.Plus;
  1022. // break;
  1023. // case OverloadableOperatorType.UnaryMinus:
  1024. // case OverloadableOperatorType.Subtract:
  1025. // op = Tokens.Minus;
  1026. // break;
  1027. // case OverloadableOperatorType.Multiply:
  1028. // op = Tokens.Times;
  1029. // break;
  1030. // case OverloadableOperatorType.Divide:
  1031. // op = Tokens.Div;
  1032. // break;
  1033. // case OverloadableOperatorType.Modulus:
  1034. // op = Tokens.Mod;
  1035. // break;
  1036. // case OverloadableOperatorType.Concat:
  1037. // op = Tokens.ConcatString;
  1038. // break;
  1039. // case OverloadableOperatorType.Not:
  1040. // op = Tokens.Not;
  1041. // break;
  1042. // case OverloadableOperatorType.BitNot:
  1043. // op = Tokens.Not;
  1044. // break;
  1045. // case OverloadableOperatorType.BitwiseAnd:
  1046. // op = Tokens.And;
  1047. // break;
  1048. // case OverloadableOperatorType.BitwiseOr:
  1049. // op = Tokens.Or;
  1050. // break;
  1051. // case OverloadableOperatorType.ExclusiveOr:
  1052. // op = Tokens.Xor;
  1053. // break;
  1054. // case OverloadableOperatorType.ShiftLeft:
  1055. // op = Tokens.ShiftLeft;
  1056. // break;
  1057. // case OverloadableOperatorType.ShiftRight:
  1058. // op = Tokens.ShiftRight;
  1059. // break;
  1060. // case OverloadableOperatorType.GreaterThan:
  1061. // op = Tokens.GreaterThan;
  1062. // break;
  1063. // case OverloadableOperatorType.GreaterThanOrEqual:
  1064. // op = Tokens.GreaterEqual;
  1065. // break;
  1066. // case OverloadableOperatorType.Equality:
  1067. // op = Tokens.Assign;
  1068. // break;
  1069. // case OverloadableOperatorType.InEquality:
  1070. // op = Tokens.NotEqual;
  1071. // break;
  1072. // case OverloadableOperatorType.LessThan:
  1073. // op = Tokens.LessThan;
  1074. // break;
  1075. // case OverloadableOperatorType.LessThanOrEqual:
  1076. // op = Tokens.LessEqual;
  1077. // break;
  1078. // case OverloadableOperatorType.Increment:
  1079. // Error("Increment operator is not supported in Visual Basic", operatorDeclaration.StartLocation);
  1080. // break;
  1081. // case OverloadableOperatorType.Decrement:
  1082. // Error("Decrement operator is not supported in Visual Basic", operatorDeclaration.StartLocation);
  1083. // break;
  1084. // case OverloadableOperatorType.IsTrue:
  1085. // outputFormatter.PrintText("IsTrue");
  1086. // break;
  1087. // case OverloadableOperatorType.IsFalse:
  1088. // outputFormatter.PrintText("IsFalse");
  1089. // break;
  1090. // case OverloadableOperatorType.Like:
  1091. // op = Tokens.Like;
  1092. // break;
  1093. // case OverloadableOperatorType.Power:
  1094. // op = Tokens.Power;
  1095. // break;
  1096. // case OverloadableOperatorType.CType:
  1097. // op = Tokens.CType;
  1098. // break;
  1099. // case OverloadableOperatorType.DivideInteger:
  1100. // op = Tokens.DivInteger;
  1101. // break;
  1102. // }
  1103. //
  1104. //
  1105. //
  1106. // if (operatorDeclaration.IsConversionOperator) {
  1107. // outputFormatter.PrintToken(Tokens.CType);
  1108. // } else {
  1109. // if(op != -1) outputFormatter.PrintToken(op);
  1110. // }
  1111. //
  1112. // PrintTemplates(operatorDeclaration.Templates);
  1113. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  1114. // AppendCommaSeparatedList(operatorDeclaration.Parameters);
  1115. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  1116. // if (!operatorDeclaration.TypeReference.IsNull) {
  1117. // outputFormatter.Space();
  1118. // outputFormatter.PrintToken(Tokens.As);
  1119. // outputFormatter.Space();
  1120. // VisitReturnTypeAttributes(operatorDeclaration.Attributes, data);
  1121. // TrackedVisit(operatorDeclaration.TypeReference, data);
  1122. // }
  1123. //
  1124. // outputFormatter.NewLine();
  1125. //
  1126. // ++outputFormatter.IndentationLevel;
  1127. // TrackedVisit(operatorDeclaration.Body, data);
  1128. // --outputFormatter.IndentationLevel;
  1129. //
  1130. // outputFormatter.Indent();
  1131. // outputFormatter.PrintToken(Tokens.End);
  1132. // outputFormatter.Space();
  1133. // outputFormatter.PrintToken(Tokens.Operator);
  1134. // outputFormatter.NewLine();
  1135. //
  1136. // return null;
  1137. // }
  1138. //
  1139. // public override object TrackedVisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data)
  1140. // {
  1141. // VisitAttributes(declareDeclaration.Attributes, data);
  1142. // outputFormatter.Indent();
  1143. // OutputModifier(declareDeclaration.Modifier);
  1144. // outputFormatter.PrintToken(Tokens.Declare);
  1145. // outputFormatter.Space();
  1146. //
  1147. // switch (declareDeclaration.Charset) {
  1148. // case CharsetModifier.Auto:
  1149. // outputFormatter.PrintToken(Tokens.Auto);
  1150. // outputFormatter.Space();
  1151. // break;
  1152. // case CharsetModifier.Unicode:
  1153. // outputFormatter.PrintToken(Tokens.Unicode);
  1154. // outputFormatter.Space();
  1155. // break;
  1156. // case CharsetModifier.Ansi:
  1157. // outputFormatter.PrintToken(Tokens.Ansi);
  1158. // outputFormatter.Space();
  1159. // break;
  1160. // }
  1161. //
  1162. // bool isVoid = declareDeclaration.TypeReference.IsNull || declareDeclaration.TypeReference.Type == "System.Void";
  1163. // if (isVoid) {
  1164. // outputFormatter.PrintToken(Tokens.Sub);
  1165. // } else {
  1166. // outputFormatter.PrintToken(Tokens.Function);
  1167. // }
  1168. // outputFormatter.Space();
  1169. //
  1170. // outputFormatter.PrintIdentifier(declareDeclaration.Name);
  1171. //
  1172. // outputFormatter.Space();
  1173. // outputFormatter.PrintToken(Tokens.Lib);
  1174. // outputFormatter.Space();
  1175. // outputFormatter.PrintText(ConvertString(declareDeclaration.Library));
  1176. // outputFormatter.Space();
  1177. //
  1178. // if (declareDeclaration.Alias.Length > 0) {
  1179. // outputFormatter.PrintToken(Tokens.Alias);
  1180. // outputFormatter.Space();
  1181. // outputFormatter.PrintText(ConvertString(declareDeclaration.Alias));
  1182. // outputFormatter.Space();
  1183. // }
  1184. //
  1185. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  1186. // AppendCommaSeparatedList(declareDeclaration.Parameters);
  1187. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  1188. //
  1189. // if (!isVoid) {
  1190. // outputFormatter.Space();
  1191. // outputFormatter.PrintToken(Tokens.As);
  1192. // outputFormatter.Space();
  1193. // VisitReturnTypeAttributes(declareDeclaration.Attributes, data);
  1194. // TrackedVisit(declareDeclaration.TypeReference, data);
  1195. // }
  1196. //
  1197. // outputFormatter.NewLine();
  1198. //
  1199. // return null;
  1200. // }
  1201. // #endregion
  1202. //
  1203. // #region Statements
  1204. // public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
  1205. // {
  1206. // if (blockStatement.Parent is BlockStatement) {
  1207. // outputFormatter.Indent();
  1208. // outputFormatter.PrintText("If True Then");
  1209. // outputFormatter.NewLine();
  1210. // outputFormatter.IndentationLevel += 1;
  1211. // }
  1212. // VisitStatementList(blockStatement.Children);
  1213. // if (blockStatement.Parent is BlockStatement) {
  1214. // outputFormatter.IndentationLevel -= 1;
  1215. // outputFormatter.Indent();
  1216. // outputFormatter.PrintText("End If");
  1217. // outputFormatter.NewLine();
  1218. // }
  1219. // return null;
  1220. // }
  1221. //
  1222. // void PrintIndentedBlock(Statement stmt)
  1223. // {
  1224. // outputFormatter.IndentationLevel += 1;
  1225. // if (stmt is BlockStatement) {
  1226. // TrackedVisit(stmt, null);
  1227. // } else {
  1228. // outputFormatter.Indent();
  1229. // TrackedVisit(stmt, null);
  1230. // outputFormatter.NewLine();
  1231. // }
  1232. // outputFormatter.IndentationLevel -= 1;
  1233. // }
  1234. //
  1235. // void PrintIndentedBlock(IEnumerable statements)
  1236. // {
  1237. // outputFormatter.IndentationLevel += 1;
  1238. // VisitStatementList(statements);
  1239. // outputFormatter.IndentationLevel -= 1;
  1240. // }
  1241. //
  1242. // void VisitStatementList(IEnumerable statements)
  1243. // {
  1244. // foreach (Statement stmt in statements) {
  1245. // if (stmt is BlockStatement) {
  1246. // TrackedVisit(stmt, null);
  1247. // } else {
  1248. // outputFormatter.Indent();
  1249. // TrackedVisit(stmt, null);
  1250. // outputFormatter.NewLine();
  1251. // }
  1252. // }
  1253. // }
  1254. //
  1255. // public override object TrackedVisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data)
  1256. // {
  1257. // outputFormatter.PrintToken(Tokens.AddHandler);
  1258. // outputFormatter.Space();
  1259. // TrackedVisit(addHandlerStatement.EventExpression, data);
  1260. // outputFormatter.PrintToken(Tokens.Comma);
  1261. // outputFormatter.Space();
  1262. // TrackedVisit(addHandlerStatement.HandlerExpression, data);
  1263. // return null;
  1264. // }
  1265. //
  1266. // public override object TrackedVisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data)
  1267. // {
  1268. // outputFormatter.PrintToken(Tokens.RemoveHandler);
  1269. // outputFormatter.Space();
  1270. // TrackedVisit(removeHandlerStatement.EventExpression, data);
  1271. // outputFormatter.PrintToken(Tokens.Comma);
  1272. // outputFormatter.Space();
  1273. // TrackedVisit(removeHandlerStatement.HandlerExpression, data);
  1274. // return null;
  1275. // }
  1276. //
  1277. // public override object TrackedVisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data)
  1278. // {
  1279. // outputFormatter.PrintToken(Tokens.RaiseEvent);
  1280. // outputFormatter.Space();
  1281. // outputFormatter.PrintIdentifier(raiseEventStatement.EventName);
  1282. // outputFormatter.PrintToken(Tokens.OpenParenthesis);
  1283. // AppendCommaSeparatedList(raiseEventStatement.Arguments);
  1284. // outputFormatter.PrintToken(Tokens.CloseParenthesis);
  1285. // return null;
  1286. // }
  1287. //
  1288. // public override object TrackedVisitEraseStatement(EraseStatement eraseStatement, object data)
  1289. // {
  1290. // outputFormatter.PrintToken(Tokens.Erase);
  1291. // outputFormatter.Space();
  1292. // AppendCommaSeparatedList(eraseStatement.Expressions);
  1293. // return null;
  1294. // }
  1295. //
  1296. // public override object TrackedVisitErrorStatement(ErrorStatement errorStatement, object data)
  1297. // {
  1298. // outputFormatter.PrintToken(Tokens.Error);
  1299. // outputFormatter.Space();
  1300. // TrackedVisit(errorStatement.Expression, data);
  1301. // return null;
  1302. // }
  1303. //
  1304. // public override object TrackedVisitOnErrorStatement(OnErrorStatement onErrorStatement, object data)
  1305. // {
  1306. // outputFormatter.PrintToken(Tokens.On);
  1307. // outputFormatter.Space();
  1308. // outputFormatter.PrintToken(Tokens.Error);
  1309. // outputFormatter.Space();
  1310. // TrackedVisit(onErrorStatement.EmbeddedStatement, data);
  1311. // return null;
  1312. // }
  1313. //
  1314. // public override object TrackedVisitReDimStatement(ReDimStatement reDimStatement, object data)
  1315. // {
  1316. // outputFormatter.PrintToken(Tokens.ReDim);
  1317. // outputFormatter.Space();
  1318. // if (reDimStatement.IsPreserve) {
  1319. // outputFormatter.PrintToken(Tokens.Preserve);
  1320. // outputFormatter.Space();
  1321. // }
  1322. //
  1323. // AppendCommaSeparatedList(reDimStatement.ReDimClauses);
  1324. // return null;
  1325. // }
  1326. //
  1327. // public override object TrackedVisitExpressionStatement(ExpressionStatement expressionStatement, object data)
  1328. // {
  1329. // TrackedVisit(expressionStatement.Expression, data);
  1330. // return null;
  1331. // }
  1332. //
  1333. // public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
  1334. // {
  1335. // if (localVariableDeclaration.Modifier != Modifiers.None) {
  1336. // OutputModifier(localVariableDeclaration.Modifier & ~Modifiers.Dim);
  1337. // }
  1338. // if (!isUsingResourceAcquisition) {
  1339. // if ((localVariableDeclaration.Modifier & Modifiers.Const) == 0) {
  1340. // outputFormatter.PrintToken(Tokens.Dim);
  1341. // }
  1342. // outputFormatter.Space();
  1343. // }
  1344. // currentVariableType = localVariableDeclaration.TypeReference;
  1345. //
  1346. // AppendCommaSeparatedList(localVariableDeclaration.Variables);
  1347. // currentVariableType = null;
  1348. //
  1349. // return null;
  1350. // }
  1351. //
  1352. // public override object TrackedVisitReturnStatement(ReturnStatement returnStatement, object data)
  1353. // {
  1354. // outputFormatter.PrintToken(Tokens.Return);
  1355. // if (!returnStatement.Expression.IsNull) {
  1356. // outputFormatter.Space();
  1357. // TrackedVisit(returnStatement.Expression, data);
  1358. // }
  1359. // return null;
  1360. // }
  1361. //
  1362. // public override object TrackedVisitIfElseStatement(IfElseStatement ifElseStatement, object data)
  1363. // {
  1364. // outputFormatter.PrintToken(Tokens.If);
  1365. // outputFormatter.Space();
  1366. // TrackedVisit(ifElseStatement.Condition, data);
  1367. // outputFormatter.Space();
  1368. // outputFormatter.PrintToken(Tokens.Then);
  1369. // outputFormatter.NewLine();
  1370. //
  1371. // PrintIndentedBlock(ifElseStatement.TrueStatement);
  1372. //
  1373. // foreach (ElseIfSection elseIfSection in ifElseStatement.ElseIfSections) {
  1374. // TrackedVisit(elseIfSection, data);
  1375. // }
  1376. //
  1377. // if (ifElseStatement.HasElseStatements) {
  1378. // outputFormatter.Indent();
  1379. // outputFormatter.PrintToken(Tokens.Else);
  1380. // outputFormatter.NewLine();
  1381. // PrintIndentedBlock(ifElseStatement.FalseStatement);
  1382. // }
  1383. //
  1384. // outputFormatter.Indent();
  1385. // outputFormatter.PrintToken(Tokens.End);
  1386. // outputFormatter.Space();
  1387. // outputFormatter.PrintToken(Tokens.If);
  1388. // return null;
  1389. // }
  1390. //
  1391. // public override object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data)
  1392. // {
  1393. // outputFormatter.Indent();
  1394. // outputFormatter.PrintToken(Tokens.ElseIf);
  1395. // outputFormatter.Space();
  1396. // TrackedVisit(elseIfSection.Condition, data);
  1397. // outputFormatter.Space();
  1398. // outputFormatter.PrintToken(Tokens.Then);
  1399. // outputFormatter.NewLine();
  1400. // PrintIndentedBlock(elseIfSection.EmbeddedStatement);
  1401. // return null;
  1402. // }
  1403. //
  1404. // public override object TrackedVisitLabelStatement(LabelStatement labelStatement, object data)
  1405. // {
  1406. // outputFormatter.PrintIdentifier(labelStatement.Label);
  1407. // outputFormatter.PrintToken(Tokens.Colon);
  1408. // return null;
  1409. // }
  1410. //
  1411. // public override object TrackedVisitGotoStatement(GotoStatement gotoStatement, object data)
  1412. // {
  1413. // outputFormatter.PrintToken(Tokens.GoTo);
  1414. // outputFormatter.Space();
  1415. // outputFormatter.PrintIdentifier(gotoStatement.Label);
  1416. // return null;
  1417. // }
  1418. //
  1419. // public override object TrackedVisitSwitchStatement(SwitchStatement switchStatement, object data)
  1420. // {
  1421. // exitTokenStack.Push(Tokens.Select);
  1422. // outputFormatter.PrintToken(Tokens.Select);
  1423. // outputFormatter.Space();
  1424. // outputFormatter.PrintToken(Tokens.Case);
  1425. // outputFormatter.Space();
  1426. // TrackedVisit(switchStatement.SwitchExpression, data);
  1427. // outputFormatter.NewLine();
  1428. // ++outputFormatter.IndentationLevel;
  1429. // foreach…