From: Matthias Braun Date: Sun, 26 Jun 2005 13:41:26 +0000 (+0000) Subject: also rename .h to .hpp in miniswig dir X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=74863ab9562536398b7f15861f30075758ab4285;p=supertux.git also rename .h to .hpp in miniswig dir SVN-Revision: 2643 --- diff --git a/tools/miniswig/create_docu.cpp b/tools/miniswig/create_docu.cpp index b1e172217..3310e48d2 100644 --- a/tools/miniswig/create_docu.cpp +++ b/tools/miniswig/create_docu.cpp @@ -1,9 +1,9 @@ -#include "tree.h" +#include "tree.hpp" #include #include #include -#include "create_docu.h" -#include "globals.h" +#include "create_docu.hpp" +#include "globals.hpp" void DocuCreator::create_docu(Namespace* ns) diff --git a/tools/miniswig/create_docu.h b/tools/miniswig/create_docu.h deleted file mode 100644 index 1f679b53b..000000000 --- a/tools/miniswig/create_docu.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __CREATE_DOCU_H__ -#define __CREATE_DOCU_H__ - -#include "tree.h" -#include "xmlwriter.h" - -class DocuCreator -{ -public: - const char* ind; - std::ostream& out; - XmlWriter writer; - - DocuCreator(std::ostream& _out = std::cout) - : out(_out), writer(out) - { - ind = " "; - } - - void create_docu(Namespace* ns); - void create_class_docu(Class* _class); - void create_function_docu(Class* _class, Function* function); - std::string get_type(const Type& type); -}; - -#endif diff --git a/tools/miniswig/create_docu.hpp b/tools/miniswig/create_docu.hpp new file mode 100644 index 000000000..0345de44f --- /dev/null +++ b/tools/miniswig/create_docu.hpp @@ -0,0 +1,26 @@ +#ifndef __CREATE_DOCU_H__ +#define __CREATE_DOCU_H__ + +#include "tree.hpp" +#include "xmlwriter.hpp" + +class DocuCreator +{ +public: + const char* ind; + std::ostream& out; + XmlWriter writer; + + DocuCreator(std::ostream& _out = std::cout) + : out(_out), writer(out) + { + ind = " "; + } + + void create_docu(Namespace* ns); + void create_class_docu(Class* _class); + void create_function_docu(Class* _class, Function* function); + std::string get_type(const Type& type); +}; + +#endif diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index 330792d2a..7eae391b4 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -1,9 +1,9 @@ -#include "tree.h" +#include "tree.hpp" #include #include #include -#include "create_wrapper.h" -#include "globals.h" +#include "create_wrapper.hpp" +#include "globals.hpp" void WrapperCreator::create_wrapper(Namespace* ns) diff --git a/tools/miniswig/create_wrapper.h b/tools/miniswig/create_wrapper.h deleted file mode 100644 index 359c1edbc..000000000 --- a/tools/miniswig/create_wrapper.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __CREATE_WRAPPER_H__ -#define __CREATE_WRAPPER_H__ - -#include "tree.h" - -class WrapperCreator -{ -public: - /// this is used for indentation - const char* ind; - // output stream - std::ostream& out; - std::ostream& hppout; - - WrapperCreator(std::ostream& _out = std::cout, std::ostream& _hppout = std::cout) - : out(_out), hppout(_hppout) - { - ind = " "; - } - - void create_wrapper(Namespace* ns); - void create_class_wrapper(Class* _class); - void create_class_release_hook(Class* _class); - void create_function_wrapper(Class* _class, Function* function); - void prepare_argument(const Type& type, size_t idx, const std::string& var); - void push_to_stack(const Type& type, const std::string& var); -}; - -#endif - diff --git a/tools/miniswig/create_wrapper.hpp b/tools/miniswig/create_wrapper.hpp new file mode 100644 index 000000000..97c14df44 --- /dev/null +++ b/tools/miniswig/create_wrapper.hpp @@ -0,0 +1,30 @@ +#ifndef __CREATE_WRAPPER_H__ +#define __CREATE_WRAPPER_H__ + +#include "tree.hpp" + +class WrapperCreator +{ +public: + /// this is used for indentation + const char* ind; + // output stream + std::ostream& out; + std::ostream& hppout; + + WrapperCreator(std::ostream& _out = std::cout, std::ostream& _hppout = std::cout) + : out(_out), hppout(_hppout) + { + ind = " "; + } + + void create_wrapper(Namespace* ns); + void create_class_wrapper(Class* _class); + void create_class_release_hook(Class* _class); + void create_function_wrapper(Class* _class, Function* function); + void prepare_argument(const Type& type, size_t idx, const std::string& var); + void push_to_stack(const Type& type, const std::string& var); +}; + +#endif + diff --git a/tools/miniswig/globals.h b/tools/miniswig/globals.h deleted file mode 100644 index 51cef65f9..000000000 --- a/tools/miniswig/globals.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __GLOBALS_H__ -#define __GLOBALS_H__ - -#include "tree.h" -#include - -// parsing -extern CompilationUnit* unit; -extern bool search_down; -extern Namespace* search_namespace; -extern Namespace* current_namespace; -extern std::string last_docucomment; -// the first file indicated by # 1 "..." -// (this is what the C preprocessor outputs so that you know which was the -// original file before preprocessing -extern std::string original_file; -// the filename where the current fragment came from (before it was included by -// the preprocessor) -extern std::string current_file; -// get line number inside the current_file -int getCurrentLine(); - -// config/output -extern std::istream* input; -extern std::string inputfile; -extern std::string modulename; -extern std::string selected_namespace; - -#endif - diff --git a/tools/miniswig/globals.hpp b/tools/miniswig/globals.hpp new file mode 100644 index 000000000..9f6f65d46 --- /dev/null +++ b/tools/miniswig/globals.hpp @@ -0,0 +1,30 @@ +#ifndef __GLOBALS_H__ +#define __GLOBALS_H__ + +#include "tree.hpp" +#include + +// parsing +extern CompilationUnit* unit; +extern bool search_down; +extern Namespace* search_namespace; +extern Namespace* current_namespace; +extern std::string last_docucomment; +// the first file indicated by # 1 "..." +// (this is what the C preprocessor outputs so that you know which was the +// original file before preprocessing +extern std::string original_file; +// the filename where the current fragment came from (before it was included by +// the preprocessor) +extern std::string current_file; +// get line number inside the current_file +int getCurrentLine(); + +// config/output +extern std::istream* input; +extern std::string inputfile; +extern std::string modulename; +extern std::string selected_namespace; + +#endif + diff --git a/tools/miniswig/lexer.ll b/tools/miniswig/lexer.ll index 21b13f4e9..ccaf06712 100644 --- a/tools/miniswig/lexer.ll +++ b/tools/miniswig/lexer.ll @@ -3,9 +3,9 @@ #include #include #include -#include "tree.h" +#include "tree.hpp" #include "parser.hpp" -#include "globals.h" +#include "globals.hpp" #define YY_DECL int yylex(YYSTYPE* yylval) diff --git a/tools/miniswig/main.cpp b/tools/miniswig/main.cpp index 0140a8585..2655a6462 100644 --- a/tools/miniswig/main.cpp +++ b/tools/miniswig/main.cpp @@ -2,10 +2,10 @@ #include #include #include -#include "tree.h" -#include "globals.h" -#include "create_wrapper.h" -#include "create_docu.h" +#include "tree.hpp" +#include "globals.hpp" +#include "create_wrapper.hpp" +#include "create_docu.hpp" extern int yyparse(); extern int yylex(); diff --git a/tools/miniswig/parser.yy b/tools/miniswig/parser.yy index 4875401b7..1aae8ce04 100644 --- a/tools/miniswig/parser.yy +++ b/tools/miniswig/parser.yy @@ -3,8 +3,8 @@ #include #include #include -#include "tree.h" -#include "globals.h" +#include "tree.hpp" +#include "globals.hpp" %} diff --git a/tools/miniswig/tree.cpp b/tools/miniswig/tree.cpp index e26452da7..3d5413e38 100644 --- a/tools/miniswig/tree.cpp +++ b/tools/miniswig/tree.cpp @@ -1,4 +1,4 @@ -#include "tree.h" +#include "tree.hpp" BasicType BasicType::VOID("void"); BasicType BasicType::BOOL("bool"); diff --git a/tools/miniswig/tree.h b/tools/miniswig/tree.h deleted file mode 100644 index 2e7149c3f..000000000 --- a/tools/miniswig/tree.h +++ /dev/null @@ -1,258 +0,0 @@ -#ifndef __TREE_H__ -#define __TREE_H__ - -#include -#include -#include -#include -#include -#include - -class Namespace; - -class AtomicType { -public: - AtomicType() - : parent(0) - { } - virtual ~AtomicType() - { } - - virtual void write_c(std::ostream& out) - { - out << name; - } - - std::string name; - Namespace* parent; -}; - -class BasicType : public AtomicType { -public: - static BasicType VOID; - static BasicType BOOL; - static BasicType CHAR; - static BasicType SHORT; - static BasicType INT; - static BasicType LONG; - static BasicType FLOAT; - static BasicType DOUBLE; - -private: - BasicType(const std::string& name) - { - this->name = name; - } -}; - -class Type { -public: - Type() - : atomic_type(0), _unsigned(false), _const(false), _static(false), - pointer(0), ref(0) - { } - - void write_c_type(std::ostream& out) - { - if(_static) - out << "static "; - if(_const) - out << "const "; - atomic_type->write_c(out); - for(int i = 0; i < pointer; ++i) - out << "*"; - for(int i = 0; i < ref; ++i) - out << "&"; - } - - 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... - int pointer; - // number of '&' in the type declaration... - int ref; -}; - -class HSQUIRRELVMType : public AtomicType { -public: - HSQUIRRELVMType() - { - this->name = "HSQUIRRELVM"; - assert(_instance == 0); - _instance = this; - } - virtual ~HSQUIRRELVMType() - { - assert(_instance == this); - _instance = 0; - } - - static HSQUIRRELVMType* instance() - { - return _instance; - } -private: - static HSQUIRRELVMType* _instance; -}; - -class StringType : public AtomicType { -public: - StringType() - { - this->name = "string"; - assert(_instance == 0); - _instance = this; - } - virtual ~StringType() - { - assert(_instance == this); - _instance = 0; - } - - static StringType* instance() - { - return _instance; - } - - virtual void write_c(std::ostream& out) - { - out << "std::string"; - } - -private: - static StringType* _instance; -}; - -class Parameter { -public: - std::string name; - Type type; -}; - -class ClassMember { -public: - virtual ~ClassMember() - { } - - enum Visbility { - PUBLIC, - PROTECTED, - PRIVATE - }; - Visbility visibility; -}; - -class Function : public ClassMember { -public: - enum FuncType { - FUNCTION, - CONSTRUCTOR, - DESTRUCTOR - }; - FuncType type; - std::string docu_comment; - std::string name; - Type return_type; - std::vector parameters; -}; - -class Class : public AtomicType { -public: - ~Class() { - for(std::vector::iterator i = members.begin(); - i != members.end(); ++i) - delete *i; - } - - std::vector members; - std::string docu_comment; -}; - -class Namespace { -public: - Namespace() { - parent = 0; - } - virtual ~Namespace() { - for(std::vector::iterator i = functions.begin(); - i != functions.end(); ++i) - delete *i; - for(std::vector::iterator i = types.begin(); - i != types.end(); ++i) - delete *i; - for(std::vector::iterator i = namespaces.begin(); - 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; - } - AtomicType* _findType(const std::string& name, bool godown = false) { - for(std::vector::iterator i = types.begin(); - i != types.end(); ++i) { - AtomicType* type = *i; - if(type->name == name) - return type; - } - if(godown && parent) - return parent->_findType(name, true); - - return 0; - } - - 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 - diff --git a/tools/miniswig/tree.hpp b/tools/miniswig/tree.hpp new file mode 100644 index 000000000..2e7149c3f --- /dev/null +++ b/tools/miniswig/tree.hpp @@ -0,0 +1,258 @@ +#ifndef __TREE_H__ +#define __TREE_H__ + +#include +#include +#include +#include +#include +#include + +class Namespace; + +class AtomicType { +public: + AtomicType() + : parent(0) + { } + virtual ~AtomicType() + { } + + virtual void write_c(std::ostream& out) + { + out << name; + } + + std::string name; + Namespace* parent; +}; + +class BasicType : public AtomicType { +public: + static BasicType VOID; + static BasicType BOOL; + static BasicType CHAR; + static BasicType SHORT; + static BasicType INT; + static BasicType LONG; + static BasicType FLOAT; + static BasicType DOUBLE; + +private: + BasicType(const std::string& name) + { + this->name = name; + } +}; + +class Type { +public: + Type() + : atomic_type(0), _unsigned(false), _const(false), _static(false), + pointer(0), ref(0) + { } + + void write_c_type(std::ostream& out) + { + if(_static) + out << "static "; + if(_const) + out << "const "; + atomic_type->write_c(out); + for(int i = 0; i < pointer; ++i) + out << "*"; + for(int i = 0; i < ref; ++i) + out << "&"; + } + + 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... + int pointer; + // number of '&' in the type declaration... + int ref; +}; + +class HSQUIRRELVMType : public AtomicType { +public: + HSQUIRRELVMType() + { + this->name = "HSQUIRRELVM"; + assert(_instance == 0); + _instance = this; + } + virtual ~HSQUIRRELVMType() + { + assert(_instance == this); + _instance = 0; + } + + static HSQUIRRELVMType* instance() + { + return _instance; + } +private: + static HSQUIRRELVMType* _instance; +}; + +class StringType : public AtomicType { +public: + StringType() + { + this->name = "string"; + assert(_instance == 0); + _instance = this; + } + virtual ~StringType() + { + assert(_instance == this); + _instance = 0; + } + + static StringType* instance() + { + return _instance; + } + + virtual void write_c(std::ostream& out) + { + out << "std::string"; + } + +private: + static StringType* _instance; +}; + +class Parameter { +public: + std::string name; + Type type; +}; + +class ClassMember { +public: + virtual ~ClassMember() + { } + + enum Visbility { + PUBLIC, + PROTECTED, + PRIVATE + }; + Visbility visibility; +}; + +class Function : public ClassMember { +public: + enum FuncType { + FUNCTION, + CONSTRUCTOR, + DESTRUCTOR + }; + FuncType type; + std::string docu_comment; + std::string name; + Type return_type; + std::vector parameters; +}; + +class Class : public AtomicType { +public: + ~Class() { + for(std::vector::iterator i = members.begin(); + i != members.end(); ++i) + delete *i; + } + + std::vector members; + std::string docu_comment; +}; + +class Namespace { +public: + Namespace() { + parent = 0; + } + virtual ~Namespace() { + for(std::vector::iterator i = functions.begin(); + i != functions.end(); ++i) + delete *i; + for(std::vector::iterator i = types.begin(); + i != types.end(); ++i) + delete *i; + for(std::vector::iterator i = namespaces.begin(); + 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; + } + AtomicType* _findType(const std::string& name, bool godown = false) { + for(std::vector::iterator i = types.begin(); + i != types.end(); ++i) { + AtomicType* type = *i; + if(type->name == name) + return type; + } + if(godown && parent) + return parent->_findType(name, true); + + return 0; + } + + 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 + diff --git a/tools/miniswig/xmlwriter.cpp b/tools/miniswig/xmlwriter.cpp index 1a85247ec..b44635f17 100644 --- a/tools/miniswig/xmlwriter.cpp +++ b/tools/miniswig/xmlwriter.cpp @@ -2,7 +2,7 @@ #include #include -#include "xmlwriter.h" +#include "xmlwriter.hpp" XmlWriter::XmlWriter(std::ostream& outstream) : out(outstream), indent(0) diff --git a/tools/miniswig/xmlwriter.h b/tools/miniswig/xmlwriter.h deleted file mode 100644 index 97e43445a..000000000 --- a/tools/miniswig/xmlwriter.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __XMLWRITER_H__ -#define __XMLWRITER_H__ - -#include -#include -#include - -/** This class is a class which helps printing formated xml output. - * Example: - * This sequence: - * xml.openTag("world"); - * xml.writeAttribute("name", "foo"); - * xml.writeTag("bar"); - * xml.writeTag("baz"); - * xml.writeAttribute("name", "boo"); - * xml.writeAttribute("style", "old"); - * xml.write("text"); - * xml.closeTag("world"); - * results in this output: - * - * - * text - * - */ -class XmlWriter { -public: - XmlWriter(std::ostream& out); - ~XmlWriter(); - - /** Start a xml tag which contains subtags */ - void openTag(const char* name); - /** Closes an xml tag with subtags */ - void closeTag(const char* name); - - void writeTag(const char* name); - - template - void comment(const T& outp) - { // This routine writes just about anything as an XML comment. - newLine(); - out << ""; - } - - - template - void write(const T& text) - { - if (closetag[0]=='>') { - out << ">"; - closetag = ""; - } else if (closetag[0]=='/') { - out << ">"; // eventually we should place a \n here - closetag = ""; - } - out << text; - } - - template - void writeAttribute(const char* name, T value) - { - out << " " << name << "=\"" << value << "\""; - } - -private: - void newLine(); - void closeTag(); - - std::ostream& out; - int indent; - std::string closetag; - std::string lasttag; - std::vector sections; -}; - -#endif - diff --git a/tools/miniswig/xmlwriter.hpp b/tools/miniswig/xmlwriter.hpp new file mode 100644 index 000000000..97e43445a --- /dev/null +++ b/tools/miniswig/xmlwriter.hpp @@ -0,0 +1,79 @@ +#ifndef __XMLWRITER_H__ +#define __XMLWRITER_H__ + +#include +#include +#include + +/** This class is a class which helps printing formated xml output. + * Example: + * This sequence: + * xml.openTag("world"); + * xml.writeAttribute("name", "foo"); + * xml.writeTag("bar"); + * xml.writeTag("baz"); + * xml.writeAttribute("name", "boo"); + * xml.writeAttribute("style", "old"); + * xml.write("text"); + * xml.closeTag("world"); + * results in this output: + * + * + * text + * + */ +class XmlWriter { +public: + XmlWriter(std::ostream& out); + ~XmlWriter(); + + /** Start a xml tag which contains subtags */ + void openTag(const char* name); + /** Closes an xml tag with subtags */ + void closeTag(const char* name); + + void writeTag(const char* name); + + template + void comment(const T& outp) + { // This routine writes just about anything as an XML comment. + newLine(); + out << ""; + } + + + template + void write(const T& text) + { + if (closetag[0]=='>') { + out << ">"; + closetag = ""; + } else if (closetag[0]=='/') { + out << ">"; // eventually we should place a \n here + closetag = ""; + } + out << text; + } + + template + void writeAttribute(const char* name, T value) + { + out << " " << name << "=\"" << value << "\""; + } + +private: + void newLine(); + void closeTag(); + + std::ostream& out; + int indent; + std::string closetag; + std::string lasttag; + std::vector sections; +}; + +#endif +