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 std::string docu_comment;
173 std::vector<Parameter> parameters;
176 class Field : public ClassMember {
180 has_const_value = false;
184 std::string docu_comment;
186 bool has_const_value;
189 float const_float_value;
192 std::string const_string_value;
195 class Class : public AtomicType {
198 for(std::vector<ClassMember*>::iterator i = members.begin();
199 i != members.end(); ++i)
203 std::vector<ClassMember*> members;
204 std::vector<Class*> super_classes;
205 std::vector<Class*> sub_classes;
206 std::string docu_comment;
214 virtual ~Namespace() {
215 for(std::vector<Function*>::iterator i = functions.begin();
216 i != functions.end(); ++i)
218 for(std::vector<AtomicType*>::iterator i = types.begin();
219 i != types.end(); ++i)
221 for(std::vector<Namespace*>::iterator i = namespaces.begin();
222 i != namespaces.end(); ++i)
225 void add_type(AtomicType* type)
227 types.push_back(type);
230 void add_namespace(Namespace* ns)
232 namespaces.push_back(ns);
235 AtomicType* _findType(const std::string& name, bool godown = false) {
236 for(std::vector<AtomicType*>::iterator i = types.begin();
237 i != types.end(); ++i) {
238 AtomicType* type = *i;
239 if(type->name == name)
243 return parent->_findType(name, true);
248 Namespace* _findNamespace(const std::string& name, bool godown = false) {
249 for(std::vector<Namespace*>::iterator i = namespaces.begin();
250 i != namespaces.end(); ++i) {
256 return parent->_findNamespace(name, true);
261 Namespace* findNamespace(const std::string& name, bool godown = false) {
262 Namespace* ret = _findNamespace(name, godown);
264 std::ostringstream msg;
265 msg << "Couldn't find namespace '" << name << "'.";
266 throw std::runtime_error(msg.str());
272 std::vector<Function*> functions;
273 std::vector<Field*> fields;
274 std::vector<AtomicType*> types;
275 std::vector<Namespace*> namespaces;
281 class CompilationUnit : public Namespace {