20 virtual void write_c(std::ostream& out)
29 class BasicType : public AtomicType {
31 static BasicType VOID;
32 static BasicType BOOL;
33 static BasicType CHAR;
34 static BasicType SHORT;
36 static BasicType LONG;
37 static BasicType FLOAT;
38 static BasicType DOUBLE;
41 BasicType(const std::string& name)
50 : atomic_type(0), _const(false), _static(false), pointer(0), ref(0)
53 void write_c_type(std::ostream& out)
59 atomic_type->write_c(out);
60 for(int i = 0; i < pointer; ++i)
62 for(int i = 0; i < ref; ++i)
68 if(atomic_type == &BasicType::VOID && pointer == 0)
73 AtomicType* atomic_type;
76 // number of '*' in the type declaration...
78 // number of '&' in the type declaration...
82 class StringType : public AtomicType {
86 this->name = "string";
87 assert(_instance == 0);
92 assert(_instance == this);
96 static StringType* instance()
101 virtual void write_c(std::ostream& out)
103 out << "std::string";
107 static StringType* _instance;
118 virtual ~ClassMember()
126 Visbility visibility;
129 class Function : public ClassMember {
139 std::vector<Parameter> parameters;
142 class Class : public AtomicType {
145 for(std::vector<ClassMember*>::iterator i = members.begin();
146 i != members.end(); ++i)
150 std::vector<ClassMember*> members;
158 virtual ~Namespace() {
159 for(std::vector<Function*>::iterator i = functions.begin();
160 i != functions.end(); ++i)
162 for(std::vector<AtomicType*>::iterator i = types.begin();
163 i != types.end(); ++i)
165 for(std::vector<Namespace*>::iterator i = namespaces.begin();
166 i != namespaces.end(); ++i)
169 void add_type(AtomicType* type)
171 types.push_back(type);
174 void add_namespace(Namespace* ns)
176 namespaces.push_back(ns);
179 Namespace* _findNamespace(const std::string& name, bool godown = false) {
180 for(std::vector<Namespace*>::iterator i = namespaces.begin();
181 i != namespaces.end(); ++i) {
187 return parent->_findNamespace(name, true);
192 Namespace* findNamespace(const std::string& name, bool godown = false) {
193 Namespace* ret = _findNamespace(name, godown);
195 std::ostringstream msg;
196 msg << "Couldn't find namespace '" << name << "'.";
197 throw std::runtime_error(msg.str());
203 std::vector<Function*> functions;
204 std::vector<AtomicType*> types;
205 std::vector<Namespace*> namespaces;
211 class CompilationUnit : public Namespace {