PageRenderTime 88ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Languages/Ruby/ClassInitGenerator/Generator.cs

https://github.com/jdhardy/ironpython
C# | 85 lines | 64 code | 7 blank | 14 comment | 12 complexity | d7d9a325ad24bbd9a9859c7f730cd95d MD5 | raw file
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. #if FEATURE_CORE_DLR
  16. using MSA = System.Linq.Expressions;
  17. #else
  18. using MSA = Microsoft.Scripting.Ast;
  19. #endif
  20. using System;
  21. using System.Collections.Generic;
  22. using System.IO;
  23. using Microsoft.Scripting.Utils;
  24. internal class Generator {
  25. static void Main(string[]/*!*/ args) {
  26. var list = new List<string>(args);
  27. if (list.IndexOf("/refcache") >= 0 || list.IndexOf("-refcache") >= 0) {
  28. ReflectionCacheGenerator.Create(args).Generate();
  29. } else {
  30. var generator = InitGenerator.Create(args);
  31. if (generator == null) {
  32. Environment.ExitCode = -1;
  33. return;
  34. }
  35. generator.Generate();
  36. }
  37. }
  38. internal void WriteLicenseStatement(TextWriter/*!*/ writer) {
  39. writer.Write(
  40. @"/* ****************************************************************************
  41. *
  42. * Copyright (c) Microsoft Corporation.
  43. *
  44. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  45. * copy of the license can be found in the License.html file at the root of this distribution. If
  46. * you cannot locate the Apache License, Version 2.0, please send an email to
  47. * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  48. * by the terms of the Apache License, Version 2.0.
  49. *
  50. * You must not remove this notice, or any other, from this software.
  51. *
  52. *
  53. * ***************************************************************************/
  54. ");
  55. }
  56. internal static KeyValuePair<string/*!*/, string/*!*/> ToNameValue(string/*!*/ arg) {
  57. if (arg.StartsWith("/") || arg.StartsWith("-")) {
  58. int colon = arg.IndexOf(':');
  59. if (colon >= 0) {
  60. return new KeyValuePair<string, string>(arg.Substring(1, colon - 1), arg.Substring(colon + 1));
  61. } else {
  62. return new KeyValuePair<string, string>(arg.Substring(1), String.Empty);
  63. }
  64. } else {
  65. return new KeyValuePair<string, string>(String.Empty, arg);
  66. }
  67. }
  68. internal static string/*!*/ TypeNameDispenser(Type/*!*/ type) {
  69. return
  70. type == typeof(MSA.Expression) ||
  71. type.FullName.StartsWith(typeof(Action).Namespace + ".Action") ||
  72. type.FullName.StartsWith(typeof(Action<>).Namespace + ".Action`") ||
  73. type.FullName.StartsWith(typeof(Func<>).Namespace + ".Func`") ||
  74. type.FullName == "System.Runtime.InteropServices.DefaultParameterValueAttribute" ?
  75. type.Name : type.FullName;
  76. }
  77. }