1 // Types which are only used when compiling CDL files
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following condition:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
30 typedef Ref<Class> ClassRef;
32 extern list<ClassRef> classes;
34 class Class : public NameSpace {
35 list<InterfaceRef> ifaces;
38 struct ParamInfo : public RefCountable<ParamInfo> {
42 typedef Ref<ParamInfo> ParamInfoRef;
45 // C++ associative arrays are much more of a
46 // pain to use than they should be.
48 typedef map<ParamRef, ParamInfoRef> params_map_type;
49 typedef params_map_type::value_type params_valtype;
50 typedef params_map_type::const_iterator params_iter;
53 struct MethodInfo : public RefCountable<MethodInfo> {
55 bool copy_params; // True if at least one parameter
56 // has the copy attribute.
59 params_map_type params;
62 ParamInfo *get_param(Param *p)
64 params_iter ret = params.find(p);
66 if (ret != params.end())
72 ParamInfo *add_param(Param *p)
74 ParamInfo *pi = get_param(p);
80 pair<params_iter, bool> ret =
81 params.insert(params_valtype(p, pi));
90 typedef Ref<MethodInfo> MethodInfoRef;
93 typedef map<MethodRef, MethodInfoRef> method_map_type;
94 typedef method_map_type::value_type methods_valtype;
95 typedef method_map_type::const_iterator methods_iter;
97 method_map_type methods;
100 InterfaceRef concrete_iface;
102 Class(const String *name) :
103 Symbol(name), concrete_iface(new Interface(new String("<anon>")))
105 classes.push_back(this);
108 void add_iface(Interface *iface)
110 ifaces.push_back(iface);
111 concrete_iface->add_super(iface);
114 MethodInfo *get_method(Method *m)
116 methods_iter ret = methods.find(m);
118 if (ret != methods.end())
119 return (*ret).second;
124 MethodInfo *add_method(Method *m)
126 MethodInfo *mi = get_method(m);
130 mi->copy_params = false;
132 pair<methods_iter, bool> ret =
133 methods.insert(methods_valtype(m, mi));
141 typedef list<InterfaceRef>::const_iterator ifaces_iterator;
143 ifaces_iterator ifaces_begin()
145 return ifaces.begin();
148 ifaces_iterator ifaces_end()
153 // FIXME: check for duplicate method implementation names.
156 concrete_iface->finalize_class_iface();