2010-04-01 Jb Evain <jbevain@novell.com>
[mcs.git] / ilasm / codegen / ParamDef.cs
blobede5bec5036dd277e80d952fd6ef31ad86b83d63
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 //
11 using System;
12 using System.Collections;
15 namespace Mono.ILASM {
17 /// <summary>
18 /// Definition of a parameter passed to a method
19 /// </summary>
20 public class ParamDef : ICustomAttrTarget {
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;
31 public static readonly ParamDef Ellipsis = new ParamDef (new PEAPI.ParamAttr (), "ELLIPSIS", null);
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;
42 public void AddDefaultValue (PEAPI.Constant cVal)
44 defval = cVal;
47 public void AddCustomAttribute (CustomAttr customattr)
49 if (customattr_list == null)
50 customattr_list = new ArrayList ();
52 customattr_list.Add (customattr);
55 public void AddMarshalInfo (PEAPI.NativeType native_type)
57 this.native_type = native_type;
60 public BaseTypeRef Type {
61 get { return typeref; }
64 public string TypeName {
65 get { return typeref.FullName; }
68 public string Name {
69 get { return name; }
72 public PEAPI.Param PeapiParam {
73 get { return peapi_param; }
76 public bool IsSentinel ()
78 return (typeref is SentinelTypeRef && this != Ellipsis);
81 public void Define (CodeGen code_gen)
83 if (is_defined)
84 return;
86 typeref.Resolve (code_gen);
88 peapi_param = new PEAPI.Param (attr,
89 name, typeref.PeapiType);
90 if (defval != null) {
91 peapi_param.AddDefaultValue (defval);
94 if (customattr_list != null)
95 foreach (CustomAttr customattr in customattr_list)
96 customattr.AddTo (code_gen, peapi_param);
98 if (native_type != null)
99 peapi_param.AddMarshallInfo (native_type);
101 is_defined = true;