Initial import of the Generic MCS tree.
[mono.git] / mcs / gmcs / generic.cs
1 //
2 // generic.cs: Support classes for generics
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc.
8 //
9 using System;
10 using System.Collections;
11
12 namespace Mono.CSharp {
13
14         //
15         // Tracks the constraints for a type parameter
16         //
17         class Constraints {
18                 string type_parameter;
19                 ArrayList constraints;
20                 
21                 //
22                 // type_parameter is the identifier, constraints is an arraylist of
23                 // Expressions (with types) or `true' for the constructor constraint.
24                 // 
25                 public Constraints (string type_parameter, ArrayList constraints)
26                 {
27                         this.type_parameter = type_parameter;
28                         this.constraints = constraints;
29                 }
30         }
31
32         //
33         // This type represents a generic type parameter reference.
34         //
35         // These expressions are born in a fully resolved state.
36         //
37         public class TypeParameterExpr : TypeExpr {
38                 string type_parameter;
39
40                 public string Name {
41                         get {
42                                 return type_parameter;
43                         }
44                 }
45                 
46                 public TypeParameterExpr (string type_parameter, Location l)
47                         : base (typeof (object), l)
48                 {
49                         this.type_parameter = type_parameter;
50                 }
51
52                 public override string ToString ()
53                 {
54                         return "TypeParameter[" + type_parameter + "]";
55                 }
56
57                 public void Error_CannotUseAsUnmanagedType (Location loc)
58                 {
59                         Report.Error (-203, loc, "Can not use type parameter as unamanged type");
60                 }
61         }
62
63         public class TypeArguments {
64                 ArrayList args;
65                 
66                 public TypeArguments ()
67                 {
68                         args = new ArrayList ();
69                 }
70
71                 public void Add (Expression type)
72                 {
73                         args.Add (type);
74                 }
75         }
76         
77         public class ConstructedType : Expression {
78                 Expression container_type;
79                 string name;
80                 TypeArguments args;
81                 
82                 public ConstructedType (Expression container_type, string name, TypeArguments args, Location l)
83                 {
84                         loc = l;
85                         this.container_type = container_type;
86                         this.name = name;
87                         this.args = args;
88                 }
89
90                 public override Expression DoResolve (EmitContext ec)
91                 {
92                         throw new Exception ("IMPLEMENT ME");
93                 }
94
95                 public override void Emit (EmitContext ec)
96                 {
97                         throw new Exception ("IMPLEMENT ME");
98                 }
99         }
100 }