1 // Types which are only used when compiling CDL files
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
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.
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.
22 typedef Ref<Class> ClassRef;
24 extern list<ClassRef> classes;
26 class Class : public NameSpace {
27 list<InterfaceRef> ifaces;
30 struct ParamInfo : public RefCountable<ParamInfo> {
34 typedef Ref<ParamInfo> ParamInfoRef;
37 // C++ associative arrays are much more of a
38 // pain to use than they should be.
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;
45 struct MethodInfo : public RefCountable<MethodInfo> {
47 bool copy_params; // True if at least one parameter
48 // has the copy attribute.
51 params_map_type params;
54 ParamInfo *get_param(Param *p)
56 params_iter ret = params.find(p);
58 if (ret != params.end())
64 ParamInfo *add_param(Param *p)
66 ParamInfo *pi = get_param(p);
72 pair<params_iter, bool> ret =
73 params.insert(params_valtype(p, pi));
82 typedef Ref<MethodInfo> MethodInfoRef;
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;
89 method_map_type methods;
92 InterfaceRef concrete_iface;
94 Class(const String *name) :
95 Symbol(name), concrete_iface(new Interface(new String("<anon>")))
97 classes.push_back(this);
100 void add_iface(Interface *iface)
102 ifaces.push_back(iface);
103 concrete_iface->add_super(iface);
106 MethodInfo *get_method(Method *m)
108 methods_iter ret = methods.find(m);
110 if (ret != methods.end())
111 return (*ret).second;
116 MethodInfo *add_method(Method *m)
118 MethodInfo *mi = get_method(m);
122 mi->copy_params = false;
124 pair<methods_iter, bool> ret =
125 methods.insert(methods_valtype(m, mi));
133 typedef list<InterfaceRef>::const_iterator ifaces_iterator;
135 ifaces_iterator ifaces_begin()
137 return ifaces.begin();
140 ifaces_iterator ifaces_end()
145 // FIXME: check for duplicate method implementation names.
148 concrete_iface->finalize_class_iface();