~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SystemTypes.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
 
 
7
namespace ICSharpCode.SharpDevelop.Dom
 
8
{
 
9
        public class SystemTypes
 
10
        {
 
11
                public readonly IReturnType Void;
 
12
                public readonly IReturnType Object;
 
13
                public readonly IReturnType Delegate;
 
14
                public readonly IReturnType MulticastDelegate;
 
15
                public readonly IReturnType ValueType;
 
16
                public readonly IReturnType Enum;
 
17
                
 
18
                public readonly IReturnType Boolean;
 
19
                public readonly IReturnType Int32;
 
20
                public readonly IReturnType String;
 
21
                
 
22
                public readonly IReturnType Array;
 
23
                public readonly IReturnType Attribute;
 
24
                public readonly IReturnType Type;
 
25
                
 
26
                public readonly IReturnType Exception;
 
27
                public readonly IReturnType AsyncCallback;
 
28
                public readonly IReturnType IAsyncResult;
 
29
                public readonly IReturnType IDisposable;
 
30
                
 
31
                IProjectContent pc;
 
32
                
 
33
                public SystemTypes(IProjectContent pc)
 
34
                {
 
35
                        this.pc = pc;
 
36
                        Void      = new VoidReturnType(pc);
 
37
                        Object    = CreateFromName("System.Object");
 
38
                        Delegate  = CreateFromName("System.Delegate");
 
39
                        MulticastDelegate = CreateFromName("System.MulticastDelegate");
 
40
                        ValueType = CreateFromName("System.ValueType");
 
41
                        Enum      = CreateFromName("System.Enum");
 
42
                        
 
43
                        Boolean = CreateFromName("System.Boolean");
 
44
                        Int32   = CreateFromName("System.Int32");
 
45
                        String  = CreateFromName("System.String");
 
46
                        
 
47
                        Array     = CreateFromName("System.Array");
 
48
                        Attribute = CreateFromName("System.Attribute");
 
49
                        Type      = CreateFromName("System.Type");
 
50
                        
 
51
                        Exception     = CreateFromName("System.Exception");
 
52
                        AsyncCallback = CreateFromName("System.AsyncCallback");
 
53
                        IAsyncResult  = CreateFromName("System.IAsyncResult");
 
54
                        IDisposable = CreateFromName("System.IDisposable");
 
55
                }
 
56
                
 
57
                IReturnType CreateFromName(string name)
 
58
                {
 
59
                        IClass c = pc.GetClass(name, 0);
 
60
                        if (c != null) {
 
61
                                return c.DefaultReturnType;
 
62
                        } else {
 
63
                                LoggingService.Warn("SystemTypes.CreateFromName could not find " + name);
 
64
                                return Void;
 
65
                        }
 
66
                }
 
67
                
 
68
                /// <summary>
 
69
                /// Creates the return type for a primitive system type.
 
70
                /// </summary>
 
71
                public IReturnType CreatePrimitive(Type type)
 
72
                {
 
73
                        if (type.HasElementType || type.ContainsGenericParameters) {
 
74
                                throw new ArgumentException("Only primitive types are supported.");
 
75
                        }
 
76
                        return CreateFromName(type.FullName);
 
77
                }
 
78
        }
 
79
        
 
80
        public sealed class VoidClass : DefaultClass
 
81
        {
 
82
                internal static readonly string VoidName = typeof(void).FullName;
 
83
                
 
84
                public VoidClass(IProjectContent pc)
 
85
                        : base(new DefaultCompilationUnit(pc), VoidName)
 
86
                {
 
87
                        this.ClassType = ClassType.Struct;
 
88
                        this.Modifiers = ModifierEnum.Public | ModifierEnum.Sealed;
 
89
                        Freeze();
 
90
                }
 
91
                
 
92
                protected override IReturnType CreateDefaultReturnType()
 
93
                {
 
94
                        return ProjectContent.SystemTypes.Void;
 
95
                }
 
96
        }
 
97
        
 
98
        public sealed class VoidReturnType : AbstractReturnType
 
99
        {
 
100
                IProjectContent pc;
 
101
                
 
102
                public VoidReturnType(IProjectContent pc)
 
103
                {
 
104
                        if (pc == null)
 
105
                                throw new ArgumentNullException("pc");
 
106
                        this.pc = pc;
 
107
                        FullyQualifiedName = VoidClass.VoidName;
 
108
                }
 
109
                
 
110
                public override IClass GetUnderlyingClass()
 
111
                {
 
112
                        return pc.GetClass("System.Void", 0, LanguageProperties.CSharp, GetClassOptions.LookInReferences);
 
113
                }
 
114
                
 
115
                public override List<IMethod> GetMethods()
 
116
                {
 
117
                        return new List<IMethod>();
 
118
                }
 
119
                
 
120
                public override List<IProperty> GetProperties()
 
121
                {
 
122
                        return new List<IProperty>();
 
123
                }
 
124
                
 
125
                public override List<IField> GetFields()
 
126
                {
 
127
                        return new List<IField>();
 
128
                }
 
129
                
 
130
                public override List<IEvent> GetEvents()
 
131
                {
 
132
                        return new List<IEvent>();
 
133
                }
 
134
        }
 
135
}