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 {
164 std::string docu_comment;
167 std::vector<Parameter> parameters;
170 class Field : public ClassMember {
174 has_const_value = false;
178 std::string docu_comment;
180 bool has_const_value;
183 float const_float_value;
186 std::string const_string_value;
189 class Class : public AtomicType {
192 for(std::vector<ClassMember*>::iterator i = members.begin();
193 i != members.end(); ++i)
197 std::vector<ClassMember*> members;
198 std::string docu_comment;
206 virtual ~Namespace() {
207 for(std::vector<Function*>::iterator i = functions.begin();
208 i != functions.end(); ++i)
210 for(std::vector<AtomicType*>::iterator i = types.begin();
211 i != types.end(); ++i)
213 for(std::vector<Namespace*>::iterator i = namespaces.begin();
214 i != namespaces.end(); ++i)
217 void add_type(AtomicType* type)
219 types.push_back(type);
222 void add_namespace(Namespace* ns)
224 namespaces.push_back(ns);
227 AtomicType* _findType(const std::string& name, bool godown = false) {
228 for(std::vector<AtomicType*>::iterator i = types.begin();
229 i != types.end(); ++i) {
230 AtomicType* type = *i;
231 if(type->name == name)
235 return parent->_findType(name, true);
240 Namespace* _findNamespace(const std::string& name, bool godown = false) {
241 for(std::vector<Namespace*>::iterator i = namespaces.begin();
242 i != namespaces.end(); ++i) {
248 return parent->_findNamespace(name, true);
253 Namespace* findNamespace(const std::string& name, bool godown = false) {
254 Namespace* ret = _findNamespace(name, godown);
256 std::ostringstream msg;
257 msg << "Couldn't find namespace '" << name << "'.";
258 throw std::runtime_error(msg.str());
264 std::vector<Function*> functions;
265 std::vector<Field*> fields;
266 std::vector<AtomicType*> types;
267 std::vector<Namespace*> namespaces;
273 class CompilationUnit : public Namespace {