21 virtual void write_c(std::ostream& out)
30 class BasicType : public AtomicType {
32 static BasicType VOID;
33 static BasicType BOOL;
34 static BasicType CHAR;
35 static BasicType SHORT;
37 static BasicType LONG;
38 static BasicType FLOAT;
39 static BasicType DOUBLE;
42 BasicType(const std::string& name)
51 : atomic_type(0), _unsigned(false), _const(false), _static(false),
55 void write_c_type(std::ostream& out)
61 atomic_type->write_c(out);
62 for(int i = 0; i < pointer; ++i)
64 for(int i = 0; i < ref; ++i)
72 if(atomic_type == &BasicType::VOID && pointer == 0)
77 AtomicType* atomic_type;
81 // number of '*' in the type declaration...
83 // number of '&' in the type declaration...
87 class HSQUIRRELVMType : public AtomicType {
91 this->name = "HSQUIRRELVM";
92 assert(_instance == 0);
95 virtual ~HSQUIRRELVMType()
97 assert(_instance == this);
101 static HSQUIRRELVMType* instance()
106 static HSQUIRRELVMType* _instance;
109 class StringType : public AtomicType {
113 this->name = "string";
114 assert(_instance == 0);
117 virtual ~StringType()
119 assert(_instance == this);
123 static StringType* instance()
128 virtual void write_c(std::ostream& out)
130 out << "std::string";
134 static StringType* _instance;
145 virtual ~ClassMember()
153 Visbility visibility;
156 class Function : public ClassMember {
170 /// function should suspend squirrel VM after execution
172 /// a custom wrapper (just pass along HSQUIRRELVM)
174 std::string docu_comment;
177 std::vector<Parameter> parameters;
180 class Field : public ClassMember {
184 has_const_value = false;
188 std::string docu_comment;
190 bool has_const_value;
193 float const_float_value;
196 std::string const_string_value;
199 class Class : public AtomicType {
202 for(std::vector<ClassMember*>::iterator i = members.begin();
203 i != members.end(); ++i)
207 std::vector<ClassMember*> members;
208 std::vector<Class*> super_classes;
209 std::vector<Class*> sub_classes;
210 std::string docu_comment;
218 virtual ~Namespace() {
219 for(std::vector<Function*>::iterator i = functions.begin();
220 i != functions.end(); ++i)
222 for(std::vector<AtomicType*>::iterator i = types.begin();
223 i != types.end(); ++i)
225 for(std::vector<Namespace*>::iterator i = namespaces.begin();
226 i != namespaces.end(); ++i)
229 void add_type(AtomicType* type)
231 types.push_back(type);
234 void add_namespace(Namespace* ns)
236 namespaces.push_back(ns);
239 AtomicType* _findType(const std::string& name, bool godown = false) {
240 for(std::vector<AtomicType*>::iterator i = types.begin();
241 i != types.end(); ++i) {
242 AtomicType* type = *i;
243 if(type->name == name)
247 return parent->_findType(name, true);
252 Namespace* _findNamespace(const std::string& name, bool godown = false) {
253 for(std::vector<Namespace*>::iterator i = namespaces.begin();
254 i != namespaces.end(); ++i) {
260 return parent->_findNamespace(name, true);
265 Namespace* findNamespace(const std::string& name, bool godown = false) {
266 Namespace* ret = _findNamespace(name, godown);
268 std::ostringstream msg;
269 msg << "Couldn't find namespace '" << name << "'.";
270 throw std::runtime_error(msg.str());
276 std::vector<Function*> functions;
277 std::vector<Field*> fields;
278 std::vector<AtomicType*> types;
279 std::vector<Namespace*> namespaces;
285 class CompilationUnit : public Namespace {