]> git.buserror.net Git - polintos/scott/priv.git/blob - idlcomp/cdl.h
Add first draft of marshalling spec
[polintos/scott/priv.git] / idlcomp / cdl.h
1 // Types which are only used when compiling CDL files
2 //
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
4 // 
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
8 // 
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
14
15
16 #ifndef CDL_H
17 #define CDL_H
18
19 #include <idlc.h>
20
21 class Class;
22 typedef Ref<Class> ClassRef;
23
24 extern list<ClassRef> classes;
25
26 class Class : public NameSpace {
27         list<InterfaceRef> ifaces;
28
29 public:
30         struct ParamInfo : public RefCountable<ParamInfo> {
31                 bool copy;
32         };
33
34         typedef Ref<ParamInfo> ParamInfoRef;
35
36 private:
37         // C++ associative arrays are much more of a 
38         // pain to use than they should be.
39
40         typedef map<ParamRef, ParamInfoRef> params_map_type;
41         typedef params_map_type::value_type params_valtype;
42         typedef params_map_type::const_iterator params_iter;
43
44 public:
45         struct MethodInfo : public RefCountable<MethodInfo> {
46                 StrListRef implname;
47                 bool copy_params; // True if at least one parameter
48                                   // has the copy attribute.
49
50         private:
51                 params_map_type params;
52         
53         public:
54                 ParamInfo *get_param(Param *p)
55                 {
56                         params_iter ret = params.find(p);
57                         
58                         if (ret != params.end())
59                                 return (*ret).second;
60                         
61                         return NULL;
62                 }
63                 
64                 ParamInfo *add_param(Param *p)
65                 {
66                         ParamInfo *pi = get_param(p);
67                 
68                         if (!pi) {
69                                 pi = new ParamInfo;
70                                 pi->copy = false;
71                                 
72                                 pair<params_iter, bool> ret = 
73                                         params.insert(params_valtype(p, pi));
74         
75                                 assert(ret.second);
76                         }
77                 
78                         return pi;
79                 }
80         };
81
82         typedef Ref<MethodInfo> MethodInfoRef;
83
84 private:
85         typedef map<MethodRef, MethodInfoRef> method_map_type;
86         typedef method_map_type::value_type methods_valtype;
87         typedef method_map_type::const_iterator methods_iter;
88
89         method_map_type methods;
90
91 public:
92         InterfaceRef concrete_iface;
93
94         Class(const String *name) :
95         Symbol(name), concrete_iface(new Interface(new String("<anon>")))
96         {
97                 classes.push_back(this);
98         }
99         
100         void add_iface(Interface *iface)
101         {
102                 ifaces.push_back(iface);
103                 concrete_iface->add_super(iface);
104         }
105         
106         MethodInfo *get_method(Method *m)
107         {
108                 methods_iter ret = methods.find(m);
109                 
110                 if (ret != methods.end())
111                         return (*ret).second;
112                 
113                 return NULL;
114         }
115         
116         MethodInfo *add_method(Method *m)
117         {
118                 MethodInfo *mi = get_method(m);
119
120                 if (!mi) {
121                         mi = new MethodInfo;
122                         mi->copy_params = false;
123                         
124                         pair<methods_iter, bool> ret = 
125                                 methods.insert(methods_valtype(m, mi));
126
127                         assert(ret.second);
128                 }
129                 
130                 return mi;
131         }
132
133         typedef list<InterfaceRef>::const_iterator ifaces_iterator;
134
135         ifaces_iterator ifaces_begin()
136         {
137                 return ifaces.begin();
138         }
139
140         ifaces_iterator ifaces_end()
141         {
142                 return ifaces.end();
143         }
144         
145         // FIXME: check for duplicate method implementation names.
146         void finalize()
147         {
148                 concrete_iface->finalize_class_iface();
149         }
150 };
151
152 #endif