Merge pull request #1981 from akoeplinger/ilasm
[mono.git] / mcs / ilasm / codegen / ParamDef.cs
1 //
2 // Mono.ILASM.ParamDef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10
11 using System;
12 using System.Collections;
13
14
15 namespace Mono.ILASM {
16
17         /// <summary>
18         ///  Definition of a parameter passed to a method
19         /// </summary>
20         public class ParamDef : ICustomAttrTarget {
21
22                 private PEAPI.ParamAttr attr;
23                 private string name;
24                 private BaseTypeRef typeref;
25                 private bool is_defined;
26                 private PEAPI.Param peapi_param;
27                 private PEAPI.Constant defval;
28                 private ArrayList customattr_list;
29                 private PEAPI.NativeType native_type;
30
31                 public static readonly ParamDef Ellipsis = new ParamDef (new PEAPI.ParamAttr (), "ELLIPSIS", null);
32
33                 public ParamDef (PEAPI.ParamAttr attr, string name,
34                                 BaseTypeRef typeref) {
35                         this.attr = attr;
36                         this.name = name;
37                         this.typeref = typeref;
38                         is_defined = false;
39                         defval = null;
40                 }
41
42                 public void AddDefaultValue (PEAPI.Constant cVal)
43                 {
44                         defval = cVal;
45                 }
46
47                 public void AddCustomAttribute (CustomAttr customattr)
48                 {
49                         if (customattr_list == null)
50                                 customattr_list = new ArrayList ();
51
52                         customattr_list.Add (customattr);
53                 }
54
55                 public void AddMarshalInfo (PEAPI.NativeType native_type)
56                 {
57                         this.native_type = native_type;
58                 }
59
60                 public BaseTypeRef Type {
61                         get { return typeref; }
62                 }
63
64                 public string TypeName {
65                         get { return typeref.FullName; }
66                 }
67
68                 public string Name {
69                         get { return name; }
70                 }
71
72                 public PEAPI.Param PeapiParam {
73                         get { return peapi_param; }
74                 }
75
76                 public bool IsSentinel ()
77                 {
78                         return (typeref is SentinelTypeRef && this != Ellipsis);
79                 }
80
81                 public void Define (CodeGen code_gen)
82                 {
83                         if (is_defined)
84                                 return;
85
86                         typeref.Resolve (code_gen);
87
88                         peapi_param = new PEAPI.Param (attr,
89                                         name, typeref.PeapiType);
90                         if (defval != null) {
91                                 peapi_param.AddDefaultValue (defval);
92                         }
93
94                         if (customattr_list != null)
95                                 foreach (CustomAttr customattr in customattr_list)
96                                         customattr.AddTo (code_gen, peapi_param);
97
98                         if (native_type != null)
99                                 peapi_param.AddMarshallInfo (native_type);
100
101                         is_defined = true;
102                 }
103         }
104
105 }
106