4 using System.Reflection;
5 using System.Reflection.Emit;
6 using System.Collections;
8 public class Constant : Expression {
13 public Attributes OptAttributes;
15 public const int AllowedModifiers =
22 public Constant (string constant_type, string name, Expression expr, int mod_flags, Attributes attrs)
24 this.constant_type = constant_type;
27 this.mod_flags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE);
28 OptAttributes = attrs;
37 public string ConstantType {
43 public Expression Expr {
49 public FieldAttributes FieldAttr {
51 return FieldAttributes.Literal | Modifiers.FieldAttr (mod_flags) ;
55 public override Expression DoResolve (EmitContext ec)
61 public override void Emit (EmitContext ec)
63 throw new Exception ("Unimplemented");
67 // Defines the constant in the @parent
69 public void EmitConstant (RootContext rc, TypeContainer parent)
75 t = rc.LookupType (parent, constant_type);
79 tc = System.Type.GetTypeCode (t);
81 if ((tc == TypeCode.SByte) || (tc == TypeCode.Byte) ||
82 (tc == TypeCode.Int16) || (tc == TypeCode.UInt16) ||
83 (tc == TypeCode.Int32) || (tc == TypeCode.Int64) ||
84 (tc == TypeCode.UInt32) || (tc == TypeCode.UInt64)) {
86 } else if ((tc == TypeCode.Double) || (tc == TypeCode.Single)) {
88 } else if (tc == TypeCode.Char) {
89 } else if (tc == TypeCode.Decimal) {
91 } else if (t.IsSubclassOf (typeof (System.String))) {
93 } else if (t.IsSubclassOf (typeof (System.Enum))) {
96 Report.Error (-3, "Constant type is not valid (only system types are allowed");
100 fb = parent.TypeBuilder.DefineField (name, t, FieldAttr);