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 Class : public AtomicType {
173 for(std::vector<ClassMember*>::iterator i = members.begin();
174 i != members.end(); ++i)
178 std::vector<ClassMember*> members;
179 std::string docu_comment;
187 virtual ~Namespace() {
188 for(std::vector<Function*>::iterator i = functions.begin();
189 i != functions.end(); ++i)
191 for(std::vector<AtomicType*>::iterator i = types.begin();
192 i != types.end(); ++i)
194 for(std::vector<Namespace*>::iterator i = namespaces.begin();
195 i != namespaces.end(); ++i)
198 void add_type(AtomicType* type)
200 types.push_back(type);
203 void add_namespace(Namespace* ns)
205 namespaces.push_back(ns);
208 AtomicType* _findType(const std::string& name, bool godown = false) {
209 for(std::vector<AtomicType*>::iterator i = types.begin();
210 i != types.end(); ++i) {
211 AtomicType* type = *i;
212 if(type->name == name)
216 return parent->_findType(name, true);
221 Namespace* _findNamespace(const std::string& name, bool godown = false) {
222 for(std::vector<Namespace*>::iterator i = namespaces.begin();
223 i != namespaces.end(); ++i) {
229 return parent->_findNamespace(name, true);
234 Namespace* findNamespace(const std::string& name, bool godown = false) {
235 Namespace* ret = _findNamespace(name, godown);
237 std::ostringstream msg;
238 msg << "Couldn't find namespace '" << name << "'.";
239 throw std::runtime_error(msg.str());
245 std::vector<Function*> functions;
246 std::vector<AtomicType*> types;
247 std::vector<Namespace*> namespaces;
253 class CompilationUnit : public Namespace {