just kick off another build
[moon.git] / tools / generators / GlobalInfo.cs
blob122ac1e4c3398fe3e9505361e8e81d0764455f1d
1 /*
2 * GlobalInfo.cs.
4 * Contact:
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.
13 using System;
14 using System.Collections.Generic;
15 using System.IO;
16 using System.Text;
18 class GlobalInfo : MemberInfo {
19 private List<FieldInfo> dependency_properties;
20 private List<MethodInfo> cppmethods_to_bind;
21 private List<MethodInfo> jsmethods_to_bind;
22 private List<TypeInfo> dependency_objects;
24 /// <value>
25 /// A list of all the types that inherits from DependencyObject
26 /// </value>
27 public List<TypeInfo> GetDependencyObjects () {
28 if (dependency_objects == null) {
29 dependency_objects = new List<TypeInfo> ();
31 foreach (MemberInfo member in Children.Values) {
32 TypeInfo type = member as TypeInfo;
33 TypeInfo current, parent;
34 bool is_do = false;
35 int limit = 20;
37 if (type == null)
38 continue;
40 if (type.IsEnum || type.IsStruct)
41 continue;
43 current = type;
45 while (limit-- > 0) {
47 if (current.Base == null || string.IsNullOrEmpty (current.Base.Value))
48 break;
50 if (!Children.ContainsKey (current.Base.Value))
51 continue;
53 parent = Children [current.Base.Value] as TypeInfo;
55 if (parent == null)
56 break;
58 if (parent.Name == "DependencyObject") {
59 is_do = true;
60 break;
63 current = parent;
66 // if (limit <= 0)
67 // throw new Exception (string.Format ("Infinite loop while checking if '{0}' inherits from DependencyObject.", type.FullName));
69 if (is_do)
70 dependency_objects.Add (type);
73 dependency_objects.Sort (new Members.MembersSortedByManagedFullName <TypeInfo> ());
75 return dependency_objects;
78 public List<FieldInfo> DependencyProperties {
79 get {
80 if (dependency_properties == null) {
81 // Check annotations against a list of known properties
82 // to catch typos (DefaulValue, etc).
83 Dictionary<string, string> known_annotations = new Dictionary <string, string> ();
85 known_annotations.Add ("ReadOnly", null);
86 known_annotations.Add ("AlwaysChange", null);
87 known_annotations.Add ("Version", null);
88 known_annotations.Add ("PropertyType", null);
89 known_annotations.Add ("AutoCreateValue", null);
90 known_annotations.Add ("DefaultValue", null);
91 known_annotations.Add ("Access", null);
92 known_annotations.Add ("ManagedAccess", null);
93 known_annotations.Add ("Nullable", null);
94 known_annotations.Add ("Attached", null);
95 known_annotations.Add ("ManagedDeclaringType", null);
96 known_annotations.Add ("ManagedPropertyType", null);
97 known_annotations.Add ("ManagedFieldAccess", null);
98 known_annotations.Add ("ManagedAccessorAccess", null);
99 known_annotations.Add ("ManagedGetterAccess", null);
100 known_annotations.Add ("ManagedSetterAccess", null);
101 known_annotations.Add ("GenerateGetter", null);
102 known_annotations.Add ("GenerateSetter", null);
103 known_annotations.Add ("GenerateAccessors", null);
104 known_annotations.Add ("GenerateManagedDP", null);
105 known_annotations.Add ("GenerateManagedAccessors", null);
106 known_annotations.Add ("Validator", null);
107 known_annotations.Add ("AutoCreator", null);
108 known_annotations.Add ("IsCustom", null);
110 dependency_properties = new List<FieldInfo> ();
111 foreach (MemberInfo member in Children.Values) {
112 TypeInfo type = member as TypeInfo;
114 if (type == null)
115 continue;
117 foreach (MemberInfo member2 in member.Children.Values) {
118 FieldInfo field = member2 as FieldInfo;
120 if (field == null)
121 continue;
123 if (field.FieldType == null || field.FieldType.Value != "int")
124 continue;
126 if (!field.IsStatic)
127 continue;
129 if (!field.Name.EndsWith ("Property"))
130 continue;
132 dependency_properties.Add (field);
134 foreach (Annotation p in field.Annotations.Values) {
135 if (!known_annotations.ContainsKey (p.Name))
136 Console.WriteLine ("The field {0} in {3} has an unknown property: '{1}' = '{2}'", field.FullName, p.Name, p.Value, Path.GetFileName (field.Header));
140 dependency_properties.Sort (new Members.MembersSortedByFullName <FieldInfo> ());
142 return dependency_properties;
147 public List<MethodInfo> CPPMethodsToBind {
148 get {
149 if (cppmethods_to_bind == null) {
150 cppmethods_to_bind = new List<MethodInfo> ();
151 foreach (MemberInfo member1 in Children.Values) {
152 TypeInfo type = member1 as TypeInfo;
153 if (type == null)
154 continue;
156 foreach (MemberInfo member2 in type.Children.Values) {
157 MethodInfo method = member2 as MethodInfo;
158 if (method == null)
159 continue;
160 if (method.Parent == null) {
161 Console.WriteLine ("The method {0} in type {1} does not have its parent set.", method.Name, type.Name);
162 continue;
164 if (!method.Annotations.ContainsKey ("GenerateCBinding"))
165 continue;
166 cppmethods_to_bind.Add (method);
169 cppmethods_to_bind.Sort (new Members.MembersSortedByFullName <MethodInfo> ());
171 return cppmethods_to_bind;
175 public List<MethodInfo> JSMethodsToBind {
176 get {
177 if (jsmethods_to_bind == null) {
178 jsmethods_to_bind = new List<MethodInfo> ();
179 foreach (MemberInfo member1 in Children.Values) {
180 TypeInfo type = member1 as TypeInfo;
181 if (type == null)
182 continue;
184 foreach (MemberInfo member2 in type.Children.Values) {
185 MethodInfo method = member2 as MethodInfo;
186 if (method == null)
187 continue;
188 if (method.Parent == null) {
189 Console.WriteLine ("The method {0} in type {1} does not have its parent set.", method.Name, type.Name);
190 continue;
192 if (!method.Annotations.ContainsKey ("GenerateJSBinding"))
193 continue;
195 jsmethods_to_bind.Add (method);
198 jsmethods_to_bind.Sort (new Members.MembersSortedByFullName <MethodInfo> ());
200 return jsmethods_to_bind;
204 public bool IsEnum (string type)
206 MemberInfo member;
207 TypeInfo tp;
209 type = type.Replace ("*", "");
211 if (!Children.TryGetValue (type, out member)) {
212 if (type.Contains ("::")) {
213 string parent = type.Substring (0, type.IndexOf ("::"));
214 string child = type.Substring (type.IndexOf ("::") + 2);
216 if (!Children.TryGetValue (parent, out member))
217 return false;
219 if (!member.Children.TryGetValue (child, out member))
220 return false;
222 } else {
223 return false;
227 tp = member as TypeInfo;
229 if (tp == null)
230 return false;
232 return tp.IsEnum;