-#include "tree.h"
+#include "tree.hpp"
#include <iostream>
#include <sstream>
#include <stdexcept>
-#include "create_docu.h"
-#include "globals.h"
+#include "create_docu.hpp"
+#include "globals.hpp"
void
DocuCreator::create_docu(Namespace* ns)
+++ /dev/null
-#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
--- /dev/null
+#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
-#include "tree.h"
+#include "tree.hpp"
#include <iostream>
#include <sstream>
#include <stdexcept>
-#include "create_wrapper.h"
-#include "globals.h"
+#include "create_wrapper.hpp"
+#include "globals.hpp"
void
WrapperCreator::create_wrapper(Namespace* ns)
+++ /dev/null
-#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
-
--- /dev/null
+#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
+
+++ /dev/null
-#ifndef __GLOBALS_H__
-#define __GLOBALS_H__
-
-#include "tree.h"
-#include <iostream>
-
-// 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
-
--- /dev/null
+#ifndef __GLOBALS_H__
+#define __GLOBALS_H__
+
+#include "tree.hpp"
+#include <iostream>
+
+// 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
+
#include <stdlib.h>
#include <string.h>
#include <iostream>
-#include "tree.h"
+#include "tree.hpp"
#include "parser.hpp"
-#include "globals.h"
+#include "globals.hpp"
#define YY_DECL int yylex(YYSTYPE* yylval)
#include <fstream>
#include <vector>
#include <string>
-#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();
#include <iostream>
#include <sstream>
#include <stdexcept>
-#include "tree.h"
-#include "globals.h"
+#include "tree.hpp"
+#include "globals.hpp"
%}
-#include "tree.h"
+#include "tree.hpp"
BasicType BasicType::VOID("void");
BasicType BasicType::BOOL("bool");
+++ /dev/null
-#ifndef __TREE_H__
-#define __TREE_H__
-
-#include <vector>
-#include <string>
-#include <iostream>
-#include <sstream>
-#include <stdexcept>
-#include <assert.h>
-
-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<Parameter> parameters;
-};
-
-class Class : public AtomicType {
-public:
- ~Class() {
- for(std::vector<ClassMember*>::iterator i = members.begin();
- i != members.end(); ++i)
- delete *i;
- }
-
- std::vector<ClassMember*> members;
- std::string docu_comment;
-};
-
-class Namespace {
-public:
- Namespace() {
- parent = 0;
- }
- virtual ~Namespace() {
- for(std::vector<Function*>::iterator i = functions.begin();
- i != functions.end(); ++i)
- delete *i;
- for(std::vector<AtomicType*>::iterator i = types.begin();
- i != types.end(); ++i)
- delete *i;
- for(std::vector<Namespace*>::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<AtomicType*>::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<Namespace*>::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<Function*> functions;
- std::vector<AtomicType*> types;
- std::vector<Namespace*> namespaces;
-
- Namespace* parent;
- std::string name;
-};
-
-class CompilationUnit : public Namespace {
-public:
-};
-
-#endif
-
--- /dev/null
+#ifndef __TREE_H__
+#define __TREE_H__
+
+#include <vector>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <stdexcept>
+#include <assert.h>
+
+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<Parameter> parameters;
+};
+
+class Class : public AtomicType {
+public:
+ ~Class() {
+ for(std::vector<ClassMember*>::iterator i = members.begin();
+ i != members.end(); ++i)
+ delete *i;
+ }
+
+ std::vector<ClassMember*> members;
+ std::string docu_comment;
+};
+
+class Namespace {
+public:
+ Namespace() {
+ parent = 0;
+ }
+ virtual ~Namespace() {
+ for(std::vector<Function*>::iterator i = functions.begin();
+ i != functions.end(); ++i)
+ delete *i;
+ for(std::vector<AtomicType*>::iterator i = types.begin();
+ i != types.end(); ++i)
+ delete *i;
+ for(std::vector<Namespace*>::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<AtomicType*>::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<Namespace*>::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<Function*> functions;
+ std::vector<AtomicType*> types;
+ std::vector<Namespace*> namespaces;
+
+ Namespace* parent;
+ std::string name;
+};
+
+class CompilationUnit : public Namespace {
+public:
+};
+
+#endif
+
#include <stdexcept>
#include <sstream>
-#include "xmlwriter.h"
+#include "xmlwriter.hpp"
XmlWriter::XmlWriter(std::ostream& outstream)
: out(outstream), indent(0)
+++ /dev/null
-#ifndef __XMLWRITER_H__
-#define __XMLWRITER_H__
-
-#include <iostream>
-#include <vector>
-#include <string>
-
-/** 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:
- * <world name="foo">
- * <bar/>
- * <baz name="boo" style="old">text</baz>
- * </world>
- */
-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 <class T>
- void comment(const T& outp)
- { // This routine writes just about anything as an XML comment.
- newLine();
- out << "<!-- " << outp ;
- closetag = " -->";
- }
-
-
- template<class T>
- void write(const T& text)
- {
- if (closetag[0]=='>') {
- out << ">";
- closetag = "";
- } else if (closetag[0]=='/') {
- out << ">"; // eventually we should place a \n here
- closetag = "</";
- closetag += lasttag;
- closetag += ">";
- }
- out << text;
- }
-
- template<class T>
- 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<std::string> sections;
-};
-
-#endif
-
--- /dev/null
+#ifndef __XMLWRITER_H__
+#define __XMLWRITER_H__
+
+#include <iostream>
+#include <vector>
+#include <string>
+
+/** 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:
+ * <world name="foo">
+ * <bar/>
+ * <baz name="boo" style="old">text</baz>
+ * </world>
+ */
+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 <class T>
+ void comment(const T& outp)
+ { // This routine writes just about anything as an XML comment.
+ newLine();
+ out << "<!-- " << outp ;
+ closetag = " -->";
+ }
+
+
+ template<class T>
+ void write(const T& text)
+ {
+ if (closetag[0]=='>') {
+ out << ">";
+ closetag = "";
+ } else if (closetag[0]=='/') {
+ out << ">"; // eventually we should place a \n here
+ closetag = "</";
+ closetag += lasttag;
+ closetag += ">";
+ }
+ out << text;
+ }
+
+ template<class T>
+ 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<std::string> sections;
+};
+
+#endif
+