2
// DomCecilCompilationUnit.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using System.Collections.Generic;
31
using MonoDevelop.Projects.Dom;
34
namespace MonoDevelop.Projects.Dom
36
public class DomCecilCompilationUnit : CompilationUnit
38
AssemblyDefinition assemblyDefinition;
40
public AssemblyDefinition AssemblyDefinition {
42
return assemblyDefinition;
46
public DomCecilCompilationUnit (AssemblyDefinition assemblyDefinition) : this (true, true, assemblyDefinition)
50
public DomCecilCompilationUnit (bool keepDefinitions, bool loadInternals, AssemblyDefinition assemblyDefinition) : base (assemblyDefinition.Name.FullName)
53
this.assemblyDefinition = assemblyDefinition;
54
foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules) {
55
AddModuleDefinition (keepDefinitions, loadInternals, moduleDefinition);
60
public void CleanCecilDefinitions ()
62
assemblyDefinition = null;
63
foreach (IType type in Types) {
64
DomCecilType cecilType = type as DomCecilType;
65
if (cecilType != null)
66
cecilType.CleanCecilDefinitions ();
71
public static DomCecilCompilationUnit Load (string fileName)
73
return Load (fileName, true);
75
public static DomCecilCompilationUnit Load (string fileName, bool keepDefinitions)
77
return Load (fileName, true, true);
80
public static DomCecilCompilationUnit Load (string fileName, bool keepDefinitions, bool loadInternals)
82
if (String.IsNullOrEmpty (fileName))
84
DomCecilCompilationUnit result = new DomCecilCompilationUnit (keepDefinitions, loadInternals, AssemblyFactory.GetAssembly (fileName));
85
result.fileName = fileName;
89
public static bool IsInternal (MonoDevelop.Projects.Dom.Modifiers mods)
91
return (mods & MonoDevelop.Projects.Dom.Modifiers.Internal) == MonoDevelop.Projects.Dom.Modifiers.Internal ||
92
(mods & MonoDevelop.Projects.Dom.Modifiers.Private) == MonoDevelop.Projects.Dom.Modifiers.Private
94
(mods & MonoDevelop.Projects.Dom.Modifiers.ProtectedOrInternal) == MonoDevelop.Projects.Dom.Modifiers.ProtectedOrInternal ||
95
(mods & MonoDevelop.Projects.Dom.Modifiers.SpecialName) == MonoDevelop.Projects.Dom.Modifiers.SpecialName*/;
98
void AddModuleDefinition (bool keepDefinitions, bool loadInternal, ModuleDefinition moduleDefinition)
100
InstantiatedParamResolver resolver = new InstantiatedParamResolver ();
101
foreach (TypeDefinition type in moduleDefinition.Types) {
102
// filter nested types, they're handled in DomCecilType.
103
if ((type.Attributes & TypeAttributes.NestedPublic) == TypeAttributes.NestedPublic ||
104
(type.Attributes & TypeAttributes.NestedFamily) == TypeAttributes.NestedFamily ||
105
(type.Attributes & TypeAttributes.NestedAssembly) == TypeAttributes.NestedAssembly ||
106
(type.Attributes & TypeAttributes.NestedPrivate) == TypeAttributes.NestedPrivate ||
107
(type.Attributes & TypeAttributes.NestedFamANDAssem) == TypeAttributes.NestedFamANDAssem)
109
if (!loadInternal && IsInternal (DomCecilType.GetModifiers (type.Attributes)))
111
// if (type.Name == "SimplePropertyDescriptor")
112
// System.Console.WriteLine(type.Attributes + "/" + DomCecilType.GetModifiers (type.Attributes) + "/" + IsInternal (DomCecilType.GetModifiers (type.Attributes)));
113
DomCecilType loadType = new DomCecilType (keepDefinitions, loadInternal, type);
115
Add ((IType)resolver.Visit (loadType, null));
119
class InstantiatedParamResolver: CopyDomVisitor<object>
121
Dictionary<string, IType> argTypes;
123
public override IDomVisitable Visit (IType type, object data)
125
if (type.TypeParameters.Count > 0) {
126
var oldTypes = argTypes;
127
if (oldTypes != null)
128
argTypes = new Dictionary<string, IType> (oldTypes);
130
argTypes = new Dictionary<string, IType> ();
132
foreach (TypeParameter p in type.TypeParameters)
133
argTypes [p.Name] = type;
135
IDomVisitable res = base.Visit (type, data);
139
return base.Visit (type, data);
143
public override IDomVisitable Visit (IReturnType type, object data)
145
if (argTypes != null) {
147
if (argTypes.TryGetValue (type.FullName, out res)) {
148
DomReturnType rt = new DomReturnType (res);
149
rt.Parts.Add (new ReturnTypePart (type.FullName, null));
153
return base.Visit (type, data);