diff --git a/wrap/GlobalFunction.cpp b/wrap/GlobalFunction.cpp new file mode 100644 index 000000000..e20a1f2f2 --- /dev/null +++ b/wrap/GlobalFunction.cpp @@ -0,0 +1,29 @@ +/** + * @file GlobalFunction.cpp + * + * @date Jul 22, 2012 + * @author Alex Cunningham + */ + +#include "GlobalFunction.h" + +namespace wrap { + +/* ************************************************************************* */ +void GlobalFunction::addOverload(bool verbose, const std::string& name, + const ArgumentList& args, const ReturnValue& retVal, const StrVec& ns_stack) { + this->verbose_ = verbose; + this->name = name; + this->argLists.push_back(args); + this->returnVals.push_back(retVal); + this->namespaces.push_back(ns_stack); +} + +/* ************************************************************************* */ + + +} // \namespace wrap + + + + diff --git a/wrap/GlobalFunction.h b/wrap/GlobalFunction.h new file mode 100644 index 000000000..0899bbdc9 --- /dev/null +++ b/wrap/GlobalFunction.h @@ -0,0 +1,42 @@ +/** + * @file GlobalFunction.h + * + * @brief Implements codegen for a global function wrapped in matlab + * + * @date Jul 22, 2012 + * @author Alex Cunningham + */ + +#pragma once + +#include "Argument.h" +#include "ReturnValue.h" + +namespace wrap { + +struct GlobalFunction { + + typedef std::vector StrVec; + + bool verbose_; + std::string name; + + // each overload, regardless of namespace + std::vector argLists; ///< arugments for each overload + std::vector returnVals; ///< returnVals for each overload + std::vector namespaces; ///< Stack of namespaces + + // Constructor only used in Module + GlobalFunction(bool verbose = true) : verbose_(verbose) {} + + // adds an overloaded version of this function + void addOverload(bool verbose, const std::string& name, + const ArgumentList& args, const ReturnValue& retVal, const StrVec& ns_stack); + +}; + +} // \namespace wrap + + + + diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 1f077b31f..786a4de78 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -79,10 +79,10 @@ Module::Module(const string& interfacePath, vector arg_dup; ///keep track of duplicates Constructor constructor0(enable_verbose), constructor(enable_verbose); Deconstructor deconstructor0(enable_verbose), deconstructor(enable_verbose); - //Method method0(enable_verbose), method(enable_verbose); StaticMethod static_method0(enable_verbose), static_method(enable_verbose); Class cls0(enable_verbose),cls(enable_verbose); - ForwardDeclaration fwDec0, fwDec; + GlobalFunction globalFunc0(enable_verbose), globalFunc(enable_verbose); + ForwardDeclaration fwDec0, fwDec; vector namespaces, /// current namespace tag namespaces_return, /// namespace for current return type using_namespace_current; /// All namespaces from "using" declarations @@ -261,12 +261,12 @@ Module::Module(const string& interfacePath, >> ((':' >> classParent_p >> '{') | '{') >> *(functions_p | comments_p) >> str_p("};")) - [assign_a(constructor.name, cls.name)] - [assign_a(cls.constructor, constructor)] + [assign_a(constructor.name, cls.name)] + [assign_a(cls.constructor, constructor)] [assign_a(cls.namespaces, namespaces)] - [assign_a(cls.using_namespaces, using_namespace_current)] - [assign_a(deconstructor.name,cls.name)] - [assign_a(cls.deconstructor, deconstructor)] + [assign_a(cls.using_namespaces, using_namespace_current)] + [assign_a(deconstructor.name,cls.name)] + [assign_a(cls.deconstructor, deconstructor)] [bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls), bl::var(templateArgument), bl::var(templateInstantiations))] [assign_a(deconstructor,deconstructor0)] [assign_a(constructor, constructor0)] @@ -274,6 +274,20 @@ Module::Module(const string& interfacePath, [clear_a(templateArgument)] [clear_a(templateInstantiations)]; + Rule global_function_p = + (returnType_p >> staticMethodName_p[assign_a(methodName)] >> + '(' >> argumentList_p >> ')' >> ';' >> *comments_p) + [bl::bind(&GlobalFunction::addOverload, + bl::var(global_functions)[bl::var(methodName)], + verbose, + bl::var(methodName), + bl::var(args), + bl::var(retVal), + bl::var(namespaces))] + [assign_a(methodName,methodName0)] + [assign_a(args,args0)] + [assign_a(retVal,retVal0)]; + Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>'); Rule namespace_def_p = @@ -281,7 +295,7 @@ Module::Module(const string& interfacePath, >> namespace_name_p[push_back_a(namespaces)] >> ch_p('{') >> *(include_p | class_p | templateSingleInstantiation_p | namespace_def_p | comments_p) - >> str_p("}///\\namespace") // end namespace, avoid confusion with classes + >> str_p("}///\\namespace") // end namespace, avoid confusion with classes // FIXME: check for absense of semicolon to disambiguate >> !namespace_name_p) [pop_a(namespaces)]; @@ -297,7 +311,7 @@ Module::Module(const string& interfacePath, [push_back_a(forward_declarations, fwDec)] [assign_a(fwDec, fwDec0)]; - Rule module_content_p = comments_p | using_namespace_p | include_p | class_p | templateSingleInstantiation_p | forward_declaration_p | namespace_def_p ; + Rule module_content_p = comments_p | using_namespace_p | include_p | class_p | templateSingleInstantiation_p | forward_declaration_p | global_function_p | namespace_def_p; Rule module_p = *module_content_p >> !end_p; diff --git a/wrap/Module.h b/wrap/Module.h index ce1a87969..a2c77bc9e 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -23,6 +23,7 @@ #include #include "Class.h" +#include "GlobalFunction.h" #include "TemplateInstantiationTypedef.h" #include "ForwardDeclaration.h" @@ -33,6 +34,8 @@ namespace wrap { */ struct Module { + typedef std::map GlobalFunctions; + std::string name; ///< module name std::vector classes; ///< list of classes std::vector templateInstantiationTypedefs; ///< list of template instantiations @@ -40,6 +43,7 @@ struct Module { // std::vector using_namespaces; ///< all default namespaces std::vector forward_declarations; std::vector includes; ///< Include statements + GlobalFunctions global_functions; /// constructor that parses interface file Module(const std::string& interfacePath, diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index 5dfe07b8d..2e92043b2 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -82,6 +82,9 @@ class Test { // even more comments at the end! }; + +Vector aGlobalFunction(); + // comments at the end! // even more comments at the end!