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 SQIntegerType : public AtomicType {
91 this->name = "SQInteger";
92 assert(_instance == 0);
95 virtual ~SQIntegerType()
97 assert(_instance == this);
101 static SQIntegerType* instance()
106 static SQIntegerType* _instance;
109 class HSQUIRRELVMType : public AtomicType {
113 this->name = "HSQUIRRELVM";
114 assert(_instance == 0);
117 virtual ~HSQUIRRELVMType()
119 assert(_instance == this);
123 static HSQUIRRELVMType* instance()
128 static HSQUIRRELVMType* _instance;
131 class StringType : public AtomicType {
135 this->name = "string";
136 assert(_instance == 0);
139 virtual ~StringType()
141 assert(_instance == this);
145 static StringType* instance()
150 virtual void write_c(std::ostream& out)
152 out << "std::string";
156 static StringType* _instance;
167 virtual ~ClassMember()
175 Visbility visibility;
178 class Function : public ClassMember {
192 /// function should suspend squirrel VM after execution
194 /// a custom wrapper (just pass along HSQUIRRELVM)
196 std::string docu_comment;
199 std::vector<Parameter> parameters;
202 class Field : public ClassMember {
206 has_const_value = false;
210 std::string docu_comment;
212 bool has_const_value;
215 float const_float_value;
218 std::string const_string_value;
221 class Class : public AtomicType {
224 for(std::vector<ClassMember*>::iterator i = members.begin();
225 i != members.end(); ++i)
229 std::vector<ClassMember*> members;
230 std::vector<Class*> super_classes;
231 std::vector<Class*> sub_classes;
232 std::string docu_comment;
240 virtual ~Namespace() {
241 for(std::vector<Function*>::iterator i = functions.begin();
242 i != functions.end(); ++i)
244 for(std::vector<AtomicType*>::iterator i = types.begin();
245 i != types.end(); ++i)
247 for(std::vector<Namespace*>::iterator i = namespaces.begin();
248 i != namespaces.end(); ++i)
251 void add_type(AtomicType* type)
253 types.push_back(type);
256 void add_namespace(Namespace* ns)
258 namespaces.push_back(ns);
261 AtomicType* _findType(const std::string& name, bool godown = false) {
262 for(std::vector<AtomicType*>::iterator i = types.begin();
263 i != types.end(); ++i) {
264 AtomicType* type = *i;
265 if(type->name == name)
269 return parent->_findType(name, true);
274 Namespace* _findNamespace(const std::string& name, bool godown = false) {
275 for(std::vector<Namespace*>::iterator i = namespaces.begin();
276 i != namespaces.end(); ++i) {
282 return parent->_findNamespace(name, true);
287 Namespace* findNamespace(const std::string& name, bool godown = false) {
288 Namespace* ret = _findNamespace(name, godown);
290 std::ostringstream msg;
291 msg << "Couldn't find namespace '" << name << "'.";
292 throw std::runtime_error(msg.str());
298 std::vector<Function*> functions;
299 std::vector<Field*> fields;
300 std::vector<AtomicType*> types;
301 std::vector<Namespace*> namespaces;
307 class CompilationUnit : public Namespace {