]> git.buserror.net Git - polintos/scott/priv.git/blob - idlcomp/cdl.h
Initial checkin from Perforce.
[polintos/scott/priv.git] / idlcomp / cdl.h
1 #ifndef CDL_H
2 #define CDL_H
3
4 #include <idlc.h>
5
6 class Class;
7 typedef Ref<Class> ClassRef;
8
9 extern list<ClassRef> classes;
10
11 class Class : public NameSpace {
12         list<InterfaceRef> ifaces;
13
14 public:
15         struct ParamInfo : public RefCountable<ParamInfo> {
16                 bool copy;
17         };
18
19         typedef Ref<ParamInfo> ParamInfoRef;
20
21 private:
22         // C++ associative arrays are much more of a 
23         // pain to use than they should be.
24
25         typedef map<ParamRef, ParamInfoRef> params_map_type;
26         typedef params_map_type::value_type params_valtype;
27         typedef params_map_type::const_iterator params_iter;
28
29 public:
30         struct MethodInfo : public RefCountable<MethodInfo> {
31                 StrListRef implname;
32                 bool copy_params; // True if at least one parameter
33                                   // has the copy attribute.
34
35         private:
36                 params_map_type params;
37         
38         public:
39                 ParamInfo *get_param(Param *p)
40                 {
41                         params_iter ret = params.find(p);
42                         
43                         if (ret != params.end())
44                                 return (*ret).second;
45                         
46                         return NULL;
47                 }
48                 
49                 ParamInfo *add_param(Param *p)
50                 {
51                         ParamInfo *pi = get_param(p);
52                 
53                         if (!pi) {
54                                 pi = new ParamInfo;
55                                 pi->copy = false;
56                                 
57                                 pair<params_iter, bool> ret = 
58                                         params.insert(params_valtype(p, pi));
59         
60                                 assert(ret.second);
61                         }
62                 
63                         return pi;
64                 }
65         };
66
67         typedef Ref<MethodInfo> MethodInfoRef;
68
69 private:
70         typedef map<MethodRef, MethodInfoRef> method_map_type;
71         typedef method_map_type::value_type methods_valtype;
72         typedef method_map_type::const_iterator methods_iter;
73
74         method_map_type methods;
75
76 public:
77         InterfaceRef concrete_iface;
78
79         Class(const String *name) :
80         Symbol(name), concrete_iface(new Interface(new String("<anon>")))
81         {
82                 classes.push_back(this);
83         }
84         
85         void add_iface(Interface *iface)
86         {
87                 ifaces.push_back(iface);
88                 concrete_iface->add_super(iface);
89         }
90         
91         MethodInfo *get_method(Method *m)
92         {
93                 methods_iter ret = methods.find(m);
94                 
95                 if (ret != methods.end())
96                         return (*ret).second;
97                 
98                 return NULL;
99         }
100         
101         MethodInfo *add_method(Method *m)
102         {
103                 MethodInfo *mi = get_method(m);
104
105                 if (!mi) {
106                         mi = new MethodInfo;
107                         mi->copy_params = false;
108                         
109                         pair<methods_iter, bool> ret = 
110                                 methods.insert(methods_valtype(m, mi));
111
112                         assert(ret.second);
113                 }
114                 
115                 return mi;
116         }
117
118         typedef list<InterfaceRef>::const_iterator ifaces_iterator;
119
120         ifaces_iterator ifaces_begin()
121         {
122                 return ifaces.begin();
123         }
124
125         ifaces_iterator ifaces_end()
126         {
127                 return ifaces.end();
128         }
129         
130         // FIXME: check for duplicate method implementation names.
131         void finalize()
132         {
133                 concrete_iface->finalize_class_iface();
134         }
135 };
136
137 #endif