5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2008 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
14 using System
.Collections
.Generic
;
19 public MemberInfo Parent
;
23 public bool IsPrivate
;
24 public bool IsProtected
;
26 private string header
; // The .h file where the member is defined
27 private Members children
;
28 private Annotations annotations
;
29 private string fullname
;
30 private string managed_fullname
;
31 private Nullable
<int> silverlight_version
;
32 private string managed_name
;
34 public GlobalInfo GlobalInfo
{
36 GlobalInfo result
= Parent
as GlobalInfo
;
42 return this as GlobalInfo
;
44 return Parent
.GlobalInfo
;
48 public string ManagedName
{
50 if (managed_name
== null) {
51 managed_name
= Annotations
.GetValue ("ManagedName");
52 if (string.IsNullOrEmpty (managed_name
))
59 public TypeInfo ParentType
{
61 return (TypeInfo
) Parent
;
65 public void WriteVersionIf (StringBuilder text
, bool end
)
67 if (SilverlightVersion
> 1) {
69 text
.AppendLine ("#if ");
70 Helper
.WriteVersion (text
, SilverlightVersion
);
72 text
.AppendLine ("#endif");
77 public bool IsPluginMember
{
79 if (Header
== null || Header
== string.Empty
)
82 return Path
.GetFileName (Path
.GetDirectoryName (Header
)) == "plugin";
86 public bool IsSrcMember
{
88 if (Header
== null || Header
== string.Empty
)
91 return Path
.GetFileName (Path
.GetDirectoryName (Header
)) == "src";
95 public virtual string Signature
{
99 public Members Children
{
101 if (children
== null)
102 children
= new Members (this);
107 public Annotations Annotations
{
109 if (annotations
== null)
110 annotations
= new Annotations ();
118 public string Header
{
120 if (header
== null) {
122 header
= Parent
.Header
;
124 header
= string.Empty
;
133 public string FullName
{
135 if (fullname
== null) {
136 if (Parent
!= null && !string.IsNullOrEmpty (Parent
.FullName
)) {
137 fullname
= Parent
.FullName
+ "." + Name
;
146 public string ManagedFullName
{
148 if (managed_fullname
== null) {
149 if (Parent
!= null && !string.IsNullOrEmpty (Parent
.ManagedFullName
)) {
150 managed_fullname
= Parent
.ManagedFullName
+ "." + Name
;
151 } else if (Namespace
!= null) {
152 managed_fullname
= Namespace
+ "." + FullName
;
154 managed_fullname
= FullName
;
157 return managed_fullname
;
161 public string Namespace
{
162 get { return Annotations.GetValue ("Namespace"); }
165 public int SilverlightVersion
{
169 if (!silverlight_version
.HasValue
) {
170 if (Annotations
.TryGetValue ("Version", out property
)) {
171 value = property
.Value
;
172 } else if (Annotations
.TryGetValue ("SilverlightVersion", out property
)) {
173 value = property
.Value
;
178 silverlight_version
= new Nullable
<int> (Parent
.SilverlightVersion
);
180 silverlight_version
= new Nullable
<int> (1);
182 if (value == "\"2\"" || value == "2" || value == "2.0")
183 silverlight_version
= new Nullable
<int> (2);
184 else if (value == "\"1\"" || value == "1" || value == "1.0")
185 silverlight_version
= new Nullable
<int> (1);
187 throw new Exception (string.Format ("Invalid Version/SilverlightVersion: '{0}'", value));
191 return silverlight_version
.Value
;
195 public void Dump (int ident
)
197 if (annotations
!= null)
199 Console
.Write (new string ('\t', ident
));
200 Console
.WriteLine ("{0} {1}", FullName
, Header
);
201 if (children
!= null)
202 foreach (MemberInfo info
in children
.Values
)
203 info
.Dump (ident
+ 1);
208 class Members
: Dictionary
<string, MemberInfo
>{
209 private MemberInfo
[] sorted
;
210 private MemberInfo
[] sorted_by_kind
;
211 private List
<TypeInfo
> sorted_types_by_kind
;
212 private StringBuilder kinds_for_enum
;
213 private MemberInfo parent
;
215 public Members (MemberInfo Parent
) : base (StringComparer
.Ordinal
)
220 class TypeSortedByKind
: IComparer
<TypeInfo
> {
221 public int Compare (TypeInfo a
, TypeInfo b
)
223 return string.Compare (a
.KindName
, b
.KindName
);
227 public class MembersSortedByName
<T
> : IComparer
<T
> where T
: MemberInfo
{
228 public int Compare (T a
, T b
)
230 return string.Compare (a
.Name
, b
.Name
);
234 public class MembersSortedByFullName
<T
> : IComparer
<T
> where T
: MemberInfo
{
235 public int Compare (T a
, T b
)
237 return string.Compare (a
.FullName
, b
.FullName
);
241 public class MembersSortedByManagedFullName
<T
> : IComparer
<T
> where T
: MemberInfo
{
242 public int Compare (T a
, T b
)
244 int result
= string.Compare (a
.Namespace
, b
.Namespace
);
247 return string.Compare (a
.ManagedName
, b
.ManagedName
);
251 public IEnumerable
<TypeInfo
> SortedTypesByKind
{
253 if (sorted_types_by_kind
== null) {
254 sorted_types_by_kind
= new List
<TypeInfo
> ();
255 foreach (MemberInfo member
in this.Values
) {
256 TypeInfo type
= member
as TypeInfo
;
258 sorted_types_by_kind
.Add (type
);
260 sorted_types_by_kind
.Sort (new TypeSortedByKind ());
262 return sorted_types_by_kind
;
266 public IEnumerable
<MemberInfo
> SortedList
{
268 if (sorted
== null) {
270 sorted
= new MemberInfo
[Count
];
271 foreach (MemberInfo type
in this.Values
)
273 Array
.Sort (sorted
, delegate (MemberInfo x
, MemberInfo y
) {
274 return string.Compare (x
.FullName
, y
.FullName
);
280 public IEnumerable
<MemberInfo
> SortedByKindList
{
282 if (sorted_by_kind
== null) {
284 sorted_by_kind
= new MemberInfo
[Count
];
285 foreach (MemberInfo type
in this.Values
) {
286 if (!(type
is TypeInfo
))
290 sorted_by_kind
[i
++] = type
;
293 Array
.Sort (sorted_by_kind
, delegate (MemberInfo x
, MemberInfo y
) {
294 if (x
== null && y
!= null)
296 else if (x
!= null && y
== null)
298 else if (x
== null && y
== null)
301 return string.Compare ((x
as TypeInfo
).KindName
, (y
as TypeInfo
).KindName
);
304 return sorted_by_kind
;
308 public MemberInfo
Add (MemberInfo
value)
311 string signature
= value.Signature
;
313 if (!base.ContainsKey (signature
)) {
314 base.Add (signature
, value);
315 } else if (value.Name
== "<anonymous>") {
318 tmp
= "<anonymous>" + counter
.ToString ();
320 } while (base.ContainsKey (tmp
));
322 base.Add (value.Name
, value);
324 Console
.WriteLine (string.Format ("Could not add the member: {0}.{1} in parent {3}: There already is a member with the same signature ({2}).", parent
.Name
, value.Name
, signature
, parent
.GetType ().FullName
));
329 public StringBuilder
GetKindsForEnum ()
331 if (kinds_for_enum
== null) {
332 kinds_for_enum
= new StringBuilder ();
333 foreach (MemberInfo info
in SortedByKindList
) {
334 TypeInfo type
= info
as TypeInfo
;
339 if (!type
.Annotations
.ContainsKey ("IncludeInKinds")) {
343 kinds_for_enum
.Append ("\t\t");
344 kinds_for_enum
.Append (type
.KindName
);
345 kinds_for_enum
.Append (",");
346 if (type
.Annotations
.ContainsKey ("SilverlightVersion"))// && type.Annotations ["SilverlightVersion"].Value == "\"2\"")
347 kinds_for_enum
.Append ("// Silverlight 2.0 only");
348 kinds_for_enum
.AppendLine ();
351 return kinds_for_enum
;