~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/ConvertVisitor.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
using Boo.Lang.Compiler.Steps;
 
7
using ICSharpCode.Core;
 
8
using ICSharpCode.SharpDevelop.Dom;
 
9
using AST = Boo.Lang.Compiler.Ast;
 
10
 
 
11
namespace Grunwald.BooBinding.CodeCompletion
 
12
{
 
13
        public class ConvertVisitor : AbstractVisitorCompilerStep
 
14
        {
 
15
                int[] _lineLength;
 
16
                
 
17
                public ConvertVisitor(int[] _lineLength, IProjectContent pc)
 
18
                {
 
19
                        this._lineLength = _lineLength;
 
20
                        this._cu = new DefaultCompilationUnit(pc);
 
21
                }
 
22
                
 
23
                DefaultCompilationUnit _cu;
 
24
 
 
25
                public DefaultCompilationUnit Cu {
 
26
                        get {
 
27
                                return _cu;
 
28
                        }
 
29
                }
 
30
                
 
31
                Stack<DefaultClass> _currentClass = new Stack<DefaultClass>();
 
32
                bool _firstModule = true;
 
33
                
 
34
                public override void Run()
 
35
                {
 
36
                        try {
 
37
                                _cu.Tag = CompileUnit;
 
38
                                Visit(CompileUnit);
 
39
                        } catch (Exception ex) {
 
40
                                MessageService.ShowException(ex);
 
41
                        }
 
42
                }
 
43
                
 
44
                protected override void OnError(AST.Node node, Exception error)
 
45
                {
 
46
                        MessageService.ShowException(error, "error processing " + node.ToCodeString());
 
47
                }
 
48
                
 
49
                private ModifierEnum GetModifier(AST.TypeMember m)
 
50
                {
 
51
                        ModifierEnum r = ModifierEnum.None;
 
52
                        if (m.IsPublic)    r |= ModifierEnum.Public;
 
53
                        if (m.IsProtected) r |= ModifierEnum.Protected;
 
54
                        if (m.IsPrivate)   r |= ModifierEnum.Private;
 
55
                        if (m.IsInternal)  r |= ModifierEnum.Internal;
 
56
                        if (!m.IsVisibilitySet) {
 
57
                                if (IsStrictMode(_cu.ProjectContent))
 
58
                                        r |= ModifierEnum.Private;
 
59
                                else if (m is AST.Field)
 
60
                                        r |= ModifierEnum.Protected;
 
61
                                else
 
62
                                        r |= ModifierEnum.Public;
 
63
                        }
 
64
                        
 
65
                        if (m.IsStatic) r |= ModifierEnum.Static;
 
66
                        if (m is AST.Field) {
 
67
                                if (m.IsFinal) r |= ModifierEnum.Readonly;
 
68
                        } else {
 
69
                                if (m.IsFinal) r |= ModifierEnum.Sealed;
 
70
                        }
 
71
                        if (m.IsAbstract)  r |= ModifierEnum.Abstract;
 
72
                        if (m.IsOverride)  r |= ModifierEnum.Override;
 
73
                        if (m.IsSynthetic) r |= ModifierEnum.Synthetic;
 
74
                        if (m.IsPartial)   r |= ModifierEnum.Partial;
 
75
                        
 
76
                        if (m.LexicalInfo.IsValid && m.DeclaringType != null
 
77
                            && m.LexicalInfo.Line < m.DeclaringType.LexicalInfo.Line)
 
78
                        { // member added through attribute
 
79
                                r |= ModifierEnum.Synthetic;
 
80
                        }
 
81
                        return r;
 
82
                }
 
83
                
 
84
                public static AST.TypeMemberModifiers ConvertVisibilityBack(ModifierEnum modifier)
 
85
                {
 
86
                        AST.TypeMemberModifiers r = AST.TypeMemberModifiers.None;
 
87
                        if ((modifier & ModifierEnum.Public) == ModifierEnum.Public)
 
88
                                r |= AST.TypeMemberModifiers.Public;
 
89
                        if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected)
 
90
                                r |= AST.TypeMemberModifiers.Protected;
 
91
                        if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal)
 
92
                                r |= AST.TypeMemberModifiers.Internal;
 
93
                        if ((modifier & ModifierEnum.Private) == ModifierEnum.Private)
 
94
                                r |= AST.TypeMemberModifiers.Private;
 
95
                        return r;
 
96
                }
 
97
                
 
98
                private int GetLineEnd(int line)
 
99
                {
 
100
                        if (_lineLength == null || line < 1 || line > _lineLength.Length)
 
101
                                return 0;
 
102
                        else
 
103
                                return _lineLength[line - 1] + 1;
 
104
                }
 
105
                
 
106
                private DomRegion GetRegion(AST.Node m)
 
107
                {
 
108
                        AST.LexicalInfo l = m.LexicalInfo;
 
109
                        if (l.Line < 0)
 
110
                                return DomRegion.Empty;
 
111
                        else
 
112
                                return new DomRegion(l.Line, 0 /*l.Column*/, l.Line, GetLineEnd(l.Line));
 
113
                }
 
114
                
 
115
                private DomRegion GetClientRegion(AST.Node m)
 
116
                {
 
117
                        AST.LexicalInfo l = m.LexicalInfo;
 
118
                        if (l.Line < 0)
 
119
                                return DomRegion.Empty;
 
120
                        AST.SourceLocation l2;
 
121
                        if (m is AST.Method) {
 
122
                                l2 = ((AST.Method)m).Body.EndSourceLocation;
 
123
                        } else if (m is AST.Property) {
 
124
                                AST.Property p = (AST.Property)m;
 
125
                                if (p.Getter != null && p.Getter.Body != null) {
 
126
                                        l2 = p.Getter.Body.EndSourceLocation;
 
127
                                        if (p.Setter != null && p.Setter.Body != null) {
 
128
                                                if (p.Setter.Body.EndSourceLocation.Line > l2.Line)
 
129
                                                        l2 = p.Setter.Body.EndSourceLocation;
 
130
                                        }
 
131
                                } else if (p.Setter != null && p.Setter.Body != null) {
 
132
                                        l2 = p.Setter.Body.EndSourceLocation;
 
133
                                } else {
 
134
                                        l2 = p.EndSourceLocation;
 
135
                                }
 
136
                        } else {
 
137
                                l2 = m.EndSourceLocation;
 
138
                        }
 
139
                        if (l2 == null || l2.Line < 0 || l.Line == l2.Line)
 
140
                                return DomRegion.Empty;
 
141
                        // TODO: use l.Column / l2.Column when the tab-bug has been fixed
 
142
                        return new DomRegion(l.Line, GetLineEnd(l.Line), l2.Line, GetLineEnd(l2.Line));
 
143
                }
 
144
                
 
145
                public override void OnImport(AST.Import p)
 
146
                {
 
147
                        DefaultUsing u = new DefaultUsing(_cu.ProjectContent);
 
148
                        if (p.Alias == null)
 
149
                                u.Usings.Add(p.Namespace);
 
150
                        else
 
151
                                u.AddAlias(p.Alias.Name, new GetClassReturnType(_cu.ProjectContent, p.Namespace, 0));
 
152
                        _cu.UsingScope.Usings.Add(u);
 
153
                }
 
154
                
 
155
                private IClass OuterClass {
 
156
                        get {
 
157
                                if (_currentClass.Count > 0)
 
158
                                        return _currentClass.Peek();
 
159
                                else
 
160
                                        return null;
 
161
                        }
 
162
                }
 
163
                
 
164
                void ConvertTemplates(AST.Node node, DefaultClass c)
 
165
                {
 
166
                        c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
 
167
                }
 
168
                
 
169
                void ConvertTemplates(AST.Node node, DefaultMethod m)
 
170
                {
 
171
                        m.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
 
172
                }
 
173
                
 
174
                void ConvertAttributes(AST.TypeMember node, AbstractEntity to)
 
175
                {
 
176
                        if (node.Attributes.Count == 0) {
 
177
                                to.Attributes = DefaultAttribute.EmptyAttributeList;
 
178
                        } else {
 
179
                                ClassFinder context;
 
180
                                if (to is IClass) {
 
181
                                        context = new ClassFinder((IClass)to, node.LexicalInfo.Line, node.LexicalInfo.Column);
 
182
                                } else {
 
183
                                        context = new ClassFinder(to.DeclaringType, node.LexicalInfo.Line, node.LexicalInfo.Column);
 
184
                                }
 
185
                                foreach (AST.Attribute a in node.Attributes) {
 
186
                                        to.Attributes.Add(new DefaultAttribute(new AttributeReturnType(context, a.Name)) {
 
187
                                                                CompilationUnit = _cu,
 
188
                                                                Region = GetRegion(a)
 
189
                                                          });
 
190
                                }
 
191
                        }
 
192
                        to.Documentation = node.Documentation;
 
193
                }
 
194
                
 
195
                void ConvertParameters(AST.ParameterDeclarationCollection parameters, DefaultMethod m)
 
196
                {
 
197
                        if (parameters == null || parameters.Count == 0) {
 
198
                                m.Parameters = DefaultParameter.EmptyParameterList;
 
199
                        } else {
 
200
                                AddParameters(parameters, m.Parameters, m, m.DeclaringType);
 
201
                        }
 
202
                }
 
203
                void ConvertParameters(AST.ParameterDeclarationCollection parameters, DefaultProperty p)
 
204
                {
 
205
                        if (parameters == null || parameters.Count == 0) {
 
206
                                p.Parameters = DefaultParameter.EmptyParameterList;
 
207
                        } else {
 
208
                                AddParameters(parameters, p.Parameters, p, p.DeclaringType);
 
209
                        }
 
210
                }
 
211
                internal static void AddParameters(AST.ParameterDeclarationCollection parameters, IList<IParameter> output, IMethodOrProperty method, IClass c)
 
212
                {
 
213
                        if (c == null) throw new ArgumentNullException("c");
 
214
                        DefaultParameter p = null;
 
215
                        foreach (AST.ParameterDeclaration par in parameters) {
 
216
                                p = new DefaultParameter(par.Name,
 
217
                                                         CreateReturnType(par.Type, c, method as IMethod, c.Region.BeginLine + 1, 1, c.ProjectContent),
 
218
                                                         new DomRegion(par.LexicalInfo.Line, par.LexicalInfo.Column));
 
219
                                if (par.IsByRef) p.Modifiers |= ParameterModifiers.Ref;
 
220
                                output.Add(p);
 
221
                        }
 
222
                        if (parameters.HasParamArray) {
 
223
                                p.Modifiers |= ParameterModifiers.Params;
 
224
                        }
 
225
                }
 
226
                
 
227
                IReturnType CreateReturnType(AST.TypeReference reference, IMethod method)
 
228
                {
 
229
                        IClass c = OuterClass;
 
230
                        if (c == null) {
 
231
                                return CreateReturnType(reference, new DefaultClass(_cu, "___DummyClass"), method, 1, 1, _cu.ProjectContent);
 
232
                        } else {
 
233
                                return CreateReturnType(reference, c, method, c.Region.BeginLine + 1, 1, _cu.ProjectContent);
 
234
                        }
 
235
                }
 
236
                
 
237
                internal static bool IsStrictMode(IProjectContent projectContent)
 
238
                {
 
239
                        BooProject project = projectContent.Project as BooProject;
 
240
                        if (project != null)
 
241
                                return project.Strict;
 
242
                        else
 
243
                                return false;
 
244
                }
 
245
                
 
246
                internal static IReturnType GetDefaultReturnType(IProjectContent projectContent)
 
247
                {
 
248
                        BooProject project = projectContent.Project as BooProject;
 
249
                        if (project != null && project.Ducky)
 
250
                                return new BooResolver.DuckClass(new DefaultCompilationUnit(projectContent)).DefaultReturnType;
 
251
                        else
 
252
                                return projectContent.SystemTypes.Object;
 
253
                }
 
254
                
 
255
                public static IReturnType CreateReturnType(AST.TypeReference reference, IClass callingClass,
 
256
                                                           IMethodOrProperty callingMember, int caretLine, int caretColumn,
 
257
                                                           IProjectContent projectContent)
 
258
                {
 
259
                        System.Diagnostics.Debug.Assert(projectContent != null);
 
260
                        if (reference == null) {
 
261
                                return GetDefaultReturnType(projectContent);
 
262
                        }
 
263
                        if (reference is AST.ArrayTypeReference) {
 
264
                                AST.ArrayTypeReference arr = (AST.ArrayTypeReference)reference;
 
265
                                return new ArrayReturnType(projectContent,
 
266
                                                           CreateReturnType(arr.ElementType, callingClass, callingMember,
 
267
                                                                            caretLine, caretColumn, projectContent),
 
268
                                                           (arr.Rank != null) ? (int)arr.Rank.Value : 1);
 
269
                        } else if (reference is AST.SimpleTypeReference) {
 
270
                                string name = ((AST.SimpleTypeReference)reference).Name;
 
271
                                IReturnType rt;
 
272
                                int typeParameterCount = (reference is AST.GenericTypeReference) ? ((AST.GenericTypeReference)reference).GenericArguments.Count : 0;
 
273
                                if (name == "duck")
 
274
                                        rt = new BooResolver.DuckClass(new DefaultCompilationUnit(projectContent)).DefaultReturnType;
 
275
                                else if (BooAmbience.ReverseTypeConversionTable.ContainsKey(name))
 
276
                                        rt = new GetClassReturnType(projectContent, BooAmbience.ReverseTypeConversionTable[name], typeParameterCount);
 
277
                                else if (callingClass == null)
 
278
                                        rt = new GetClassReturnType(projectContent, name, typeParameterCount);
 
279
                                else
 
280
                                        rt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn,
 
281
                                                                       name, typeParameterCount);
 
282
                                if (typeParameterCount > 0) {
 
283
                                        AST.TypeReferenceCollection arguments = ((AST.GenericTypeReference)reference).GenericArguments;
 
284
                                        // GenericTypeReference derives from SimpleTypeReference
 
285
                                        IReturnType[] typeArguments = new IReturnType[arguments.Count];
 
286
                                        for (int i = 0; i < typeArguments.Length; i++) {
 
287
                                                typeArguments[i] = CreateReturnType(arguments[i], callingClass, callingMember, caretLine, caretColumn,
 
288
                                                                                    projectContent);
 
289
                                        }
 
290
                                        rt = new ConstructedReturnType(rt, typeArguments);
 
291
                                }
 
292
                                return rt;
 
293
                        } else if (reference is AST.CallableTypeReference) {
 
294
                                AST.CallableTypeReference ctr = (AST.CallableTypeReference)reference;
 
295
                                AnonymousMethodReturnType amrt = new AnonymousMethodReturnType(new DefaultCompilationUnit(projectContent));
 
296
                                if (ctr.ReturnType != null) {
 
297
                                        amrt.MethodReturnType = CreateReturnType(ctr.ReturnType, callingClass, callingMember, caretLine, caretColumn, projectContent);
 
298
                                }
 
299
                                amrt.MethodParameters = new List<IParameter>();
 
300
                                AddParameters(ctr.Parameters, amrt.MethodParameters, callingMember, callingClass ?? new DefaultClass(new DefaultCompilationUnit(projectContent), "__Dummy"));
 
301
                                return amrt;
 
302
                        } else {
 
303
                                throw new NotSupportedException("unknown reference type: " + reference.ToString());
 
304
                        }
 
305
                }
 
306
                IReturnType CreateReturnType(AST.TypeReference reference)
 
307
                {
 
308
                        return CreateReturnType(reference, null);
 
309
                }
 
310
                IReturnType CreateReturnType(AST.Field field)
 
311
                {
 
312
                        if (field.Type == null) {
 
313
                                if (field.Initializer != null)
 
314
                                        return new BooInferredReturnType(field.Initializer, OuterClass);
 
315
                                else
 
316
                                        return GetDefaultReturnType(_cu.ProjectContent);
 
317
                        } else {
 
318
                                return CreateReturnType(field.Type);
 
319
                        }
 
320
                }
 
321
                IReturnType CreateReturnType(AST.Method node, IMethod method)
 
322
                {
 
323
                        if (node.ReturnType == null)
 
324
                                return new BooInferredReturnType(node.Body, OuterClass, false);
 
325
                        return CreateReturnType(node.ReturnType, method);
 
326
                }
 
327
                IReturnType CreateReturnType(AST.Property property)
 
328
                {
 
329
                        if (property.Type == null && property.Getter != null && property.Getter.Body != null)
 
330
                                return new BooInferredReturnType(property.Getter.Body, OuterClass, false);
 
331
                        return CreateReturnType(property.Type);
 
332
                }
 
333
                
 
334
                public override void OnCallableDefinition(AST.CallableDefinition node)
 
335
                {
 
336
                        LoggingService.Debug("OnCallableDefinition: " + node.FullName);
 
337
                        DomRegion region = GetRegion(node);
 
338
                        DefaultClass c = new DefaultClass(_cu, ClassType.Delegate, GetModifier(node), region, OuterClass);
 
339
                        ConvertAttributes(node, c);
 
340
                        c.BaseTypes.Add(c.ProjectContent.SystemTypes.Delegate);
 
341
                        c.FullyQualifiedName = node.FullName;
 
342
                        if (_currentClass.Count > 0) {
 
343
                                OuterClass.InnerClasses.Add(c);
 
344
                        } else {
 
345
                                _cu.Classes.Add(c);
 
346
                        }
 
347
                        _currentClass.Push(c); // necessary for CreateReturnType
 
348
                        ConvertTemplates(node, c);
 
349
                        IReturnType returnType = CreateReturnType(node.ReturnType);
 
350
                        DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
 
351
                        ConvertParameters(node.Parameters, invokeMethod);
 
352
                        c.Methods.Add(invokeMethod);
 
353
                        invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
 
354
                        ConvertParameters(node.Parameters, invokeMethod);
 
355
                        if (invokeMethod.Parameters == DefaultParameter.EmptyParameterList) {
 
356
                                invokeMethod.Parameters = new List<IParameter>();
 
357
                        }
 
358
                        invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
 
359
                        invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
 
360
                        c.Methods.Add(invokeMethod);
 
361
                        invokeMethod = new DefaultMethod("EndInvoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
 
362
                        invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
 
363
                        c.Methods.Add(invokeMethod);
 
364
                        _currentClass.Pop();
 
365
                }
 
366
                
 
367
                public override bool EnterClassDefinition(AST.ClassDefinition node)
 
368
                {
 
369
                        EnterTypeDefinition(node, ClassType.Class);
 
370
                        return base.EnterClassDefinition(node);
 
371
                }
 
372
                
 
373
                public override bool EnterInterfaceDefinition(AST.InterfaceDefinition node)
 
374
                {
 
375
                        EnterTypeDefinition(node, ClassType.Interface);
 
376
                        return base.EnterInterfaceDefinition(node);
 
377
                }
 
378
                
 
379
                public override bool EnterEnumDefinition(AST.EnumDefinition node)
 
380
                {
 
381
                        EnterTypeDefinition(node, ClassType.Enum);
 
382
                        return base.EnterEnumDefinition(node);
 
383
                }
 
384
                
 
385
                // cannot override OnNamespaceDeclaration - it's visited too late (after the type definitions)
 
386
                void HandleNamespaceDeclaration(AST.NamespaceDeclaration node)
 
387
                {
 
388
                        if (node == null)
 
389
                                return;
 
390
                        string[] namespaceName = node.Name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
 
391
                        foreach (string namePart in namespaceName) {
 
392
                                _cu.UsingScope = new DefaultUsingScope {
 
393
                                        NamespaceName = PrependCurrentNamespace(namePart),
 
394
                                        Parent = _cu.UsingScope
 
395
                                };
 
396
                        }
 
397
                }
 
398
                
 
399
                public override bool EnterModule(AST.Module node)
 
400
                {
 
401
                        HandleNamespaceDeclaration(node.Namespace);
 
402
                        if (!_firstModule && node.Members.Count > 0) {
 
403
                                EnterTypeDefinition(node, ClassType.Module);
 
404
                        }
 
405
                        _firstModule = false;
 
406
                        return base.EnterModule(node);
 
407
                }
 
408
                
 
409
                private void EnterTypeDefinition(AST.TypeDefinition node, ClassType classType)
 
410
                {
 
411
                        //LoggingService.Debug("Enter " + node.GetType().Name + " (" + node.FullName + ")");
 
412
                        foreach (AST.Attribute att in node.Attributes) {
 
413
                                if (att.Name == "Boo.Lang.ModuleAttribute")
 
414
                                        classType = ClassType.Module;
 
415
                        }
 
416
                        DomRegion region = GetClientRegion(node);
 
417
                        DefaultClass c = new DefaultClass(_cu, classType, GetModifier(node), region, OuterClass);
 
418
                        c.FullyQualifiedName = node.FullName;
 
419
                        if (_currentClass.Count > 0)
 
420
                                _currentClass.Peek().InnerClasses.Add(c);
 
421
                        else
 
422
                                _cu.Classes.Add(c);
 
423
                        _currentClass.Push(c);
 
424
                        ConvertAttributes(node, c);
 
425
                        ConvertTemplates(node, c);
 
426
                        if (node.BaseTypes != null) {
 
427
                                foreach (AST.TypeReference r in node.BaseTypes) {
 
428
                                        c.BaseTypes.Add(CreateReturnType(r));
 
429
                                }
 
430
                        }
 
431
                }
 
432
                
 
433
                public override void LeaveClassDefinition(AST.ClassDefinition node)
 
434
                {
 
435
                        LeaveTypeDefinition(node);
 
436
                        base.LeaveClassDefinition(node);
 
437
                }
 
438
                
 
439
                public override void LeaveInterfaceDefinition(AST.InterfaceDefinition node)
 
440
                {
 
441
                        LeaveTypeDefinition(node);
 
442
                        base.LeaveInterfaceDefinition(node);
 
443
                }
 
444
                
 
445
                public override void LeaveEnumDefinition(AST.EnumDefinition node)
 
446
                {
 
447
                        LeaveTypeDefinition(node);
 
448
                        base.LeaveEnumDefinition(node);
 
449
                }
 
450
                
 
451
                public override void LeaveModule(AST.Module node)
 
452
                {
 
453
                        if (_currentClass.Count != 0) LeaveTypeDefinition(node);
 
454
                        base.LeaveModule(node);
 
455
                }
 
456
                
 
457
                private void LeaveTypeDefinition(AST.TypeDefinition node)
 
458
                {
 
459
                        DefaultClass c = _currentClass.Pop();
 
460
                        foreach (AST.Attribute att in node.Attributes) {
 
461
                                if (att.Name == "System.Reflection.DefaultMemberAttribute" && att.Arguments.Count == 1) {
 
462
                                        AST.StringLiteralExpression sle = att.Arguments[0] as AST.StringLiteralExpression;
 
463
                                        if (sle != null) {
 
464
                                                foreach (DefaultProperty p in c.Properties) {
 
465
                                                        if (p.Name == sle.Value) {
 
466
                                                                p.IsIndexer = true;
 
467
                                                        }
 
468
                                                }
 
469
                                        }
 
470
                                }
 
471
                        }
 
472
                        //LoggingService.Debug("Leave "+node.GetType().Name+" "+node.FullName+" (Class = "+c.FullyQualifiedName+")");
 
473
                }
 
474
                
 
475
                public override void OnMethod(AST.Method node)
 
476
                {
 
477
                        //LoggingService.Debug("Method: " + node.FullName + " (" + node.Modifiers + ")");
 
478
                        DefaultMethod method = new DefaultMethod(node.Name, null, GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass);
 
479
                        
 
480
                        foreach (AST.Attribute a in node.Attributes) {
 
481
                                if (a.Name == "Extension" || a.Name == "Boo.Lang.Extension"
 
482
                                    || a.Name == "ExtensionAttribute" || a.Name == "Boo.Lang.ExtensionAttribute")
 
483
                                {
 
484
                                        method.IsExtensionMethod = true;
 
485
                                }
 
486
                        }
 
487
                        
 
488
                        ConvertAttributes(node, method);
 
489
                        ConvertTemplates(node, method);
 
490
                        // return type must be assigned AFTER ConvertTemplates
 
491
                        method.ReturnType = CreateReturnType(node, method);
 
492
                        ConvertParameters(node.Parameters, method);
 
493
                        _currentClass.Peek().Methods.Add(method);
 
494
                        method.UserData = node;
 
495
                }
 
496
                
 
497
                public override void OnConstructor(AST.Constructor node)
 
498
                {
 
499
                        if (node.IsSynthetic && node.Parameters.Count == 0) return;
 
500
                        Constructor ctor = new Constructor(GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass);
 
501
                        ConvertAttributes(node, ctor);
 
502
                        ConvertParameters(node.Parameters, ctor);
 
503
                        _currentClass.Peek().Methods.Add(ctor);
 
504
                        ctor.UserData = node;
 
505
                }
 
506
                
 
507
                public override void OnEnumMember(AST.EnumMember node)
 
508
                {
 
509
                        DefaultField field = new DefaultField(OuterClass.DefaultReturnType, node.Name, ModifierEnum.Const | ModifierEnum.Public, GetRegion(node), OuterClass);
 
510
                        ConvertAttributes(node, field);
 
511
                        OuterClass.Fields.Add(field);
 
512
                }
 
513
                
 
514
                public override void OnField(AST.Field node)
 
515
                {
 
516
                        DefaultField field = new DefaultField(CreateReturnType(node), node.Name, GetModifier(node), GetRegion(node), OuterClass);
 
517
                        ConvertAttributes(node, field);
 
518
                        OuterClass.Fields.Add(field);
 
519
                }
 
520
                
 
521
                public override void OnEvent(AST.Event node)
 
522
                {
 
523
                        DomRegion region = GetRegion(node);
 
524
                        DefaultEvent e = new DefaultEvent(node.Name, CreateReturnType(node.Type), GetModifier(node), region, region, OuterClass);
 
525
                        ConvertAttributes(node, e);
 
526
                        OuterClass.Events.Add(e);
 
527
                }
 
528
                
 
529
                public override void OnProperty(AST.Property node)
 
530
                {
 
531
                        DefaultProperty property = new DefaultProperty(node.Name, CreateReturnType(node), GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass);
 
532
                        ConvertAttributes(node, property);
 
533
                        ConvertParameters(node.Parameters, property);
 
534
                        if (node.Getter != null && node.Getter.Body != null) {
 
535
                                property.GetterRegion = GetClientRegion(node.Getter);
 
536
                        }
 
537
                        if (node.Setter != null && node.Setter.Body != null) {
 
538
                                property.SetterRegion = GetClientRegion(node.Setter);
 
539
                        }
 
540
                        property.IsIndexer = (node.Name == "self");
 
541
                        OuterClass.Properties.Add(property);
 
542
                        property.UserData = node;
 
543
                }
 
544
                
 
545
                string PrependCurrentNamespace(string name)
 
546
                {
 
547
                        if (string.IsNullOrEmpty(_cu.UsingScope.NamespaceName))
 
548
                                return name;
 
549
                        else
 
550
                                return _cu.UsingScope.NamespaceName + "." + name;
 
551
                }
 
552
        }
 
553
}