diff --git a/wrap/Argument.h b/wrap/Argument.h index 5a4f08a25..729792eb8 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -45,6 +45,13 @@ struct Argument { /// MATLAB code generation, MATLAB to C++ void matlab_unwrap(FileWriter& file, const std::string& matlabName) const; + + friend std::ostream& operator<<(std::ostream& os, const Argument& arg) { + os << (arg.is_const ? "const " : "") << arg.type << (arg.is_ptr ? "*" : "") + << (arg.is_ref ? "&" : ""); + return os; + } + }; /// Argument list is just a container with Arguments @@ -100,6 +107,19 @@ struct ArgumentList: public std::vector { void emit_conditional_call(FileWriter& proxyFile, const ReturnValue& returnVal, const std::string& wrapperName, int id, bool staticMethod = false) const; + + friend std::ostream& operator<<(std::ostream& os, + const ArgumentList& argList) { + os << "("; + if (argList.size() > 0) + os << argList.front(); + if (argList.size() > 1) + for (size_t i = 1; i < argList.size(); i++) + os << ", " << argList[i]; + os << ")"; + return os; + } + }; template @@ -108,7 +128,7 @@ inline void verifyArguments(const std::vector& validArgs, typedef typename std::map::value_type NamedMethod; BOOST_FOREACH(const NamedMethod& namedMethod, vt) { const T& t = namedMethod.second; - t.verifyArguments(validArgs,t.name_); + t.verifyArguments(validArgs, t.name_); } } diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 5da9d8bd0..7ab618f0f 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -247,6 +247,7 @@ Class Class::expandTemplate(const TemplateSubstitution& ts) const { inst.constructor.args_list = inst.constructor.expandArgumentListsTemplate(ts); inst.constructor.name = inst.name; inst.deconstructor.name = inst.name; + cout << inst << endl; return inst; } @@ -254,10 +255,12 @@ Class Class::expandTemplate(const TemplateSubstitution& ts) const { vector Class::expandTemplate(Str templateArg, const vector& instantiations) const { vector result; + cout << *this << endl; BOOST_FOREACH(const Qualified& instName, instantiations) { Qualified expandedClass = (Qualified) (*this); expandedClass.name += instName.name; const TemplateSubstitution ts(templateArg, instName, expandedClass); + cout << ts << endl; Class inst = expandTemplate(ts); inst.name = expandedClass.name; inst.templateArgs.clear(); @@ -274,12 +277,10 @@ void Class::addMethod(bool verbose, bool is_const, Str methodName, Str templateArgName, const vector& templateArgValues) { // Check if templated if (!templateArgName.empty() && templateArgValues.size() > 0) { - cout << methodName << endl; // Create method to expand // For all values of the template argument, create a new method BOOST_FOREACH(const Qualified& instName, templateArgValues) { const TemplateSubstitution ts(templateArgName, instName, this->name); - cout << ts << endl; // substitute template in arguments ArgumentList expandedArgs = argumentList.expandTemplate(ts); // do the same for return type diff --git a/wrap/Class.h b/wrap/Class.h index 809f40049..2c2de49fc 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -19,15 +19,18 @@ #pragma once -#include -#include - #include "Constructor.h" #include "Deconstructor.h" #include "Method.h" #include "StaticMethod.h" #include "TypeAttributesTable.h" +#include +#include + +#include +#include + namespace wrap { /// Class has name, constructors, methods @@ -108,6 +111,14 @@ public: void deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, Str wrapperName, std::vector& functionNames) const; + friend std::ostream& operator<<(std::ostream& os, const Class& cls) { + os << "class " << cls.name << "{\n"; + BOOST_FOREACH(const Method& m, cls.methods | boost::adaptors::map_values) + os << m << ";\n"; + os << "};" << std::endl; + return os; + } + private: void pointer_constructor_fragments(FileWriter& proxyFile, diff --git a/wrap/Function.h b/wrap/Function.h index d175fe145..a06f35145 100644 --- a/wrap/Function.h +++ b/wrap/Function.h @@ -93,6 +93,13 @@ public: } } + friend std::ostream& operator<<(std::ostream& os, + const ArgumentOverloads& overloads) { + BOOST_FOREACH(const ArgumentList& argList, overloads.argLists_) + os << argList << std::endl; + return os; + } + }; /** @@ -168,6 +175,13 @@ public: } } + friend std::ostream& operator<<(std::ostream& os, + const SignatureOverloads& overloads) { + for (size_t i = 0; i < overloads.nrOverloads(); i++) + os << overloads.returnVals_[i] << overloads.argLists_[i] << std::endl; + return os; + } + }; // Templated checking functions diff --git a/wrap/Method.h b/wrap/Method.h index d1e382a13..be3e1c97f 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -41,6 +41,12 @@ struct Method: public StaticMethod { const ArgumentList& args, const ReturnValue& retVal, const Qualified& instName = Qualified()); + friend std::ostream& operator<<(std::ostream& os, const Method& m) { + for (size_t i = 0; i < m.nrOverloads(); i++) + os << m.returnVals_[i] << " " << m.name_ << m.argLists_[i]; + return os; + } + private: // Emit method header diff --git a/wrap/Qualified.h b/wrap/Qualified.h index def2343cd..b23e9020d 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -45,7 +45,7 @@ struct Qualified { } bool operator!=(const Qualified& other) const { - return other.name!=name || other.namespaces != namespaces; + return other.name != name || other.namespaces != namespaces; } /// Return a qualified string using given delimiter @@ -66,6 +66,11 @@ struct Qualified { return result; } + friend std::ostream& operator<<(std::ostream& os, const Qualified& q) { + os << q.qualifiedName("::"); + return os; + } + }; } // \namespace wrap diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index 993760e81..54e585cad 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -18,7 +18,8 @@ using namespace wrap; ReturnValue ReturnValue::expandTemplate(const TemplateSubstitution& ts) const { ReturnValue instRetVal = *this; instRetVal.type1 = ts(type1); - if (isPair) instRetVal.type2 = ts(type2); + if (isPair) + instRetVal.type2 = ts(type2); return instRetVal; } diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index e7206b494..abfcec2b0 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -49,6 +49,14 @@ struct ReturnValue { void emit_matlab(FileWriter& proxyFile) const; + friend std::ostream& operator<<(std::ostream& os, const ReturnValue& r) { + if (!r.isPair && r.type1.category == ReturnType::VOID) + os << "void"; + else + os << r.return_type(true); + return os; + } + }; } // \namespace wrap diff --git a/wrap/TemplateSubstitution.h b/wrap/TemplateSubstitution.h index fd031024e..4e9b43f3d 100644 --- a/wrap/TemplateSubstitution.h +++ b/wrap/TemplateSubstitution.h @@ -51,7 +51,7 @@ public: // Substitute if needed ReturnType operator()(const ReturnType& type) const { - ReturnType instType; + ReturnType instType = type; if (type.name == templateArg_ && type.namespaces.empty()) instType.rename(qualifiedType_); else if (type.name == "This")