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 StringType : public AtomicType {
91 this->name = "string";
92 assert(_instance == 0);
97 assert(_instance == this);
101 static StringType* instance()
106 virtual void write_c(std::ostream& out)
108 out << "std::string";
112 static StringType* _instance;
123 virtual ~ClassMember()
131 Visbility visibility;
134 class Function : public ClassMember {
144 std::vector<Parameter> parameters;
147 class Class : public AtomicType {
150 for(std::vector<ClassMember*>::iterator i = members.begin();
151 i != members.end(); ++i)
155 std::vector<ClassMember*> members;
163 virtual ~Namespace() {
164 for(std::vector<Function*>::iterator i = functions.begin();
165 i != functions.end(); ++i)
167 for(std::vector<AtomicType*>::iterator i = types.begin();
168 i != types.end(); ++i)
170 for(std::vector<Namespace*>::iterator i = namespaces.begin();
171 i != namespaces.end(); ++i)
174 void add_type(AtomicType* type)
176 types.push_back(type);
179 void add_namespace(Namespace* ns)
181 namespaces.push_back(ns);
184 Namespace* _findNamespace(const std::string& name, bool godown = false) {
185 for(std::vector<Namespace*>::iterator i = namespaces.begin();
186 i != namespaces.end(); ++i) {
192 return parent->_findNamespace(name, true);
197 Namespace* findNamespace(const std::string& name, bool godown = false) {
198 Namespace* ret = _findNamespace(name, godown);
200 std::ostringstream msg;
201 msg << "Couldn't find namespace '" << name << "'.";
202 throw std::runtime_error(msg.str());
208 std::vector<Function*> functions;
209 std::vector<AtomicType*> types;
210 std::vector<Namespace*> namespaces;
216 class CompilationUnit : public Namespace {