X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=tools%2Fminiswig%2Ftree.h;h=b6f85546670cbe5538439a13cb8e22d5e85e7f54;hb=864c93e01ec366f730b3ebad08d5c52d6a9363b6;hp=4b9485c1a3ecad938eeacf57d2aa9bf55fedc57f;hpb=0b585f0dc8e185bcf1a7e281108281f5b2b96706;p=supertux.git diff --git a/tools/miniswig/tree.h b/tools/miniswig/tree.h index 4b9485c1a..b6f855466 100644 --- a/tools/miniswig/tree.h +++ b/tools/miniswig/tree.h @@ -4,10 +4,17 @@ #include #include #include +#include +#include +#include + +class Namespace; class AtomicType { public: - std::string name; + AtomicType() + : parent(0) + { } virtual ~AtomicType() { } @@ -15,6 +22,9 @@ public: { out << name; } + + std::string name; + Namespace* parent; }; class BasicType : public AtomicType { @@ -38,7 +48,8 @@ private: class Type { public: Type() - : atomic_type(0), _const(false), _static(false), pointer(0), ref(0) + : atomic_type(0), _unsigned(false), _const(false), _static(false), + pointer(0), ref(0) { } void write_c_type(std::ostream& out) @@ -56,12 +67,15 @@ public: bool is_void() const { + if(atomic_type == 0) + return true; if(atomic_type == &BasicType::VOID && pointer == 0) return true; return false; } AtomicType* atomic_type; + bool _unsigned; bool _const; bool _static; // number of '*' in the type declaration... @@ -143,12 +157,10 @@ public: class Namespace { public: - std::string name; -}; - -class CompilationUnit { -public: - ~CompilationUnit() { + Namespace() { + parent = 0; + } + virtual ~Namespace() { for(std::vector::iterator i = functions.begin(); i != functions.end(); ++i) delete *i; @@ -159,10 +171,50 @@ public: i != namespaces.end(); ++i) delete *i; } - + void add_type(AtomicType* type) + { + types.push_back(type); + type->parent = this; + } + void add_namespace(Namespace* ns) + { + namespaces.push_back(ns); + ns->parent = this; + } + Namespace* _findNamespace(const std::string& name, bool godown = false) { + for(std::vector::iterator i = namespaces.begin(); + i != namespaces.end(); ++i) { + Namespace* ns = *i; + if(ns->name == name) + return ns; + } + if(godown && parent) + return parent->_findNamespace(name, true); + + return 0; + } + + Namespace* findNamespace(const std::string& name, bool godown = false) { + Namespace* ret = _findNamespace(name, godown); + if(!ret) { + std::ostringstream msg; + msg << "Couldn't find namespace '" << name << "'."; + throw std::runtime_error(msg.str()); + } + + return ret; + } + std::vector functions; std::vector types; std::vector namespaces; + + Namespace* parent; + std::string name; +}; + +class CompilationUnit : public Namespace { +public: }; #endif