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 Visibility 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 parameter_spec;
197 std::string docu_comment;
200 std::vector<Parameter> parameters;
203 class Field : public ClassMember {
207 has_const_value = false;
211 std::string docu_comment;
213 bool has_const_value;
216 float const_float_value;
219 std::string const_string_value;
222 class Class : public AtomicType {
225 for(std::vector<ClassMember*>::iterator i = members.begin();
226 i != members.end(); ++i)
230 std::vector<ClassMember*> members;
231 std::vector<Class*> super_classes;
232 std::vector<Class*> sub_classes;
233 std::string docu_comment;
241 virtual ~Namespace() {
242 for(std::vector<Function*>::iterator i = functions.begin();
243 i != functions.end(); ++i)
245 for(std::vector<AtomicType*>::iterator i = types.begin();
246 i != types.end(); ++i)
248 for(std::vector<Namespace*>::iterator i = namespaces.begin();
249 i != namespaces.end(); ++i)
252 void add_type(AtomicType* type)
254 types.push_back(type);
257 void add_namespace(Namespace* ns)
259 namespaces.push_back(ns);
262 AtomicType* _findType(const std::string& name, bool godown = false) {
263 for(std::vector<AtomicType*>::iterator i = types.begin();
264 i != types.end(); ++i) {
265 AtomicType* type = *i;
266 if(type->name == name)
270 return parent->_findType(name, true);
275 Namespace* _findNamespace(const std::string& name, bool godown = false) {
276 for(std::vector<Namespace*>::iterator i = namespaces.begin();
277 i != namespaces.end(); ++i) {
283 return parent->_findNamespace(name, true);
288 Namespace* findNamespace(const std::string& name, bool godown = false) {
289 Namespace* ret = _findNamespace(name, godown);
291 std::ostringstream msg;
292 msg << "Couldn't find namespace '" << name << "'.";
293 throw std::runtime_error(msg.str());
299 std::vector<Function*> functions;
300 std::vector<Field*> fields;
301 std::vector<AtomicType*> types;
302 std::vector<Namespace*> namespaces;
308 class CompilationUnit : public Namespace {