Merge pull request #1931 from kasthack/system.web-fixes
[mono.git] / mcs / ilasm / codegen / EventDef.cs
1 //
2 // Mono.ILASM.EventDef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All right reserved
8 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class EventDef : ICustomAttrTarget {
17
18                 private FeatureAttr attr;
19                 private string name;
20                 private BaseTypeRef type;
21                 private PEAPI.Event event_def;
22                 private bool is_resolved;
23                 private ArrayList customattr_list;
24
25                 private MethodRef addon;
26                 private MethodRef fire;
27                 private ArrayList other_list;
28                 private MethodRef removeon;
29
30                 public EventDef (FeatureAttr attr, BaseTypeRef type, string name)
31                 {
32                         this.attr = attr;
33                         this.name = name;
34                         this.type = type;
35                         is_resolved = false;
36                 }
37
38                 public void AddCustomAttribute (CustomAttr customattr)
39                 {
40                         if (customattr_list == null)
41                                 customattr_list = new ArrayList ();
42
43                         customattr_list.Add (customattr);
44                 }
45
46                 public PEAPI.Event Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
47                 {
48                         if (is_resolved)
49                                 return event_def;
50
51                         type.Resolve (code_gen);
52                         event_def = classdef.AddEvent (name, type.PeapiType);
53
54                         if ((attr & FeatureAttr.Rtspecialname) != 0)
55                                 event_def.SetRTSpecialName ();
56
57                         if ((attr & FeatureAttr.Specialname) != 0)
58                                 event_def.SetSpecialName ();
59                         
60                         if (customattr_list != null)
61                                 foreach (CustomAttr customattr in customattr_list)
62                                         customattr.AddTo (code_gen, event_def);
63
64                         is_resolved = true;
65
66                         return event_def;
67                 }
68
69                 private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
70                 {
71                         PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
72                         if (methoddef == null)
73                                 Report.Error (type + " method of event " + name + " not found");
74                         return methoddef;
75                 }
76
77                 public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
78                 {
79                         if (!is_resolved)
80                                 Resolve (code_gen, classdef);
81
82                         if (addon != null) {
83                                 addon.Resolve (code_gen);
84                                 event_def.AddAddon (AsMethodDef (addon.PeapiMethod, "addon"));
85                         }
86
87                         if (fire != null) {
88                                 fire.Resolve (code_gen);
89                                 event_def.AddFire (AsMethodDef (fire.PeapiMethod, "fire"));
90                         }
91
92                         if (other_list != null) {
93                                 foreach (MethodRef otherm in other_list) {
94                                         otherm.Resolve (code_gen);
95                                         event_def.AddOther (AsMethodDef (otherm.PeapiMethod, "other"));
96                                 }
97                         }
98
99                         if (removeon != null) {
100                                 removeon.Resolve (code_gen);
101                                 event_def.AddRemoveOn (AsMethodDef (removeon.PeapiMethod, "removeon"));
102                         }
103                 }
104
105                 public void AddAddon (MethodRef method_ref)
106                 {
107                         addon = method_ref;
108                 }
109
110                 public void AddFire (MethodRef method_ref)
111                 {
112                         fire = method_ref;
113                 }
114
115                 public void AddOther (MethodRef method_ref)
116                 {
117                         if (other_list == null)
118                                 other_list = new ArrayList ();
119                         other_list.Add (method_ref);
120                 }
121
122                 public void AddRemoveon (MethodRef method_ref)
123                 {
124                         removeon = method_ref;
125                 }
126
127         }
128
129 }
130