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), _const(false), _static(false), pointer(0), ref(0)
54 void write_c_type(std::ostream& out)
60 atomic_type->write_c(out);
61 for(int i = 0; i < pointer; ++i)
63 for(int i = 0; i < ref; ++i)
69 if(atomic_type == &BasicType::VOID && pointer == 0)
74 AtomicType* atomic_type;
77 // number of '*' in the type declaration...
79 // number of '&' in the type declaration...
83 class StringType : public AtomicType {
87 this->name = "string";
88 assert(_instance == 0);
93 assert(_instance == this);
97 static StringType* instance()
102 virtual void write_c(std::ostream& out)
104 out << "std::string";
108 static StringType* _instance;
119 virtual ~ClassMember()
127 Visbility visibility;
130 class Function : public ClassMember {
140 std::vector<Parameter> parameters;
143 class Class : public AtomicType {
146 for(std::vector<ClassMember*>::iterator i = members.begin();
147 i != members.end(); ++i)
151 std::vector<ClassMember*> members;
159 virtual ~Namespace() {
160 for(std::vector<Function*>::iterator i = functions.begin();
161 i != functions.end(); ++i)
163 for(std::vector<AtomicType*>::iterator i = types.begin();
164 i != types.end(); ++i)
166 for(std::vector<Namespace*>::iterator i = namespaces.begin();
167 i != namespaces.end(); ++i)
170 void add_type(AtomicType* type)
172 types.push_back(type);
175 void add_namespace(Namespace* ns)
177 namespaces.push_back(ns);
180 Namespace* _findNamespace(const std::string& name, bool godown = false) {
181 for(std::vector<Namespace*>::iterator i = namespaces.begin();
182 i != namespaces.end(); ++i) {
188 return parent->_findNamespace(name, true);
193 Namespace* findNamespace(const std::string& name, bool godown = false) {
194 Namespace* ret = _findNamespace(name, godown);
196 std::ostringstream msg;
197 msg << "Couldn't find namespace '" << name << "'.";
198 throw std::runtime_error(msg.str());
204 std::vector<Function*> functions;
205 std::vector<AtomicType*> types;
206 std::vector<Namespace*> namespaces;
212 class CompilationUnit : public Namespace {