Adding support for global functions - parsing works
parent
46b2971e45
commit
26fce2d400
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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<std::string> StrVec;
|
||||||
|
|
||||||
|
bool verbose_;
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
// each overload, regardless of namespace
|
||||||
|
std::vector<ArgumentList> argLists; ///< arugments for each overload
|
||||||
|
std::vector<ReturnValue> returnVals; ///< returnVals for each overload
|
||||||
|
std::vector<StrVec> 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,10 +79,10 @@ Module::Module(const string& interfacePath,
|
||||||
vector<string> arg_dup; ///keep track of duplicates
|
vector<string> arg_dup; ///keep track of duplicates
|
||||||
Constructor constructor0(enable_verbose), constructor(enable_verbose);
|
Constructor constructor0(enable_verbose), constructor(enable_verbose);
|
||||||
Deconstructor deconstructor0(enable_verbose), deconstructor(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);
|
StaticMethod static_method0(enable_verbose), static_method(enable_verbose);
|
||||||
Class cls0(enable_verbose),cls(enable_verbose);
|
Class cls0(enable_verbose),cls(enable_verbose);
|
||||||
ForwardDeclaration fwDec0, fwDec;
|
GlobalFunction globalFunc0(enable_verbose), globalFunc(enable_verbose);
|
||||||
|
ForwardDeclaration fwDec0, fwDec;
|
||||||
vector<string> namespaces, /// current namespace tag
|
vector<string> namespaces, /// current namespace tag
|
||||||
namespaces_return, /// namespace for current return type
|
namespaces_return, /// namespace for current return type
|
||||||
using_namespace_current; /// All namespaces from "using" declarations
|
using_namespace_current; /// All namespaces from "using" declarations
|
||||||
|
@ -261,12 +261,12 @@ Module::Module(const string& interfacePath,
|
||||||
>> ((':' >> classParent_p >> '{') | '{')
|
>> ((':' >> classParent_p >> '{') | '{')
|
||||||
>> *(functions_p | comments_p)
|
>> *(functions_p | comments_p)
|
||||||
>> str_p("};"))
|
>> str_p("};"))
|
||||||
[assign_a(constructor.name, cls.name)]
|
[assign_a(constructor.name, cls.name)]
|
||||||
[assign_a(cls.constructor, constructor)]
|
[assign_a(cls.constructor, constructor)]
|
||||||
[assign_a(cls.namespaces, namespaces)]
|
[assign_a(cls.namespaces, namespaces)]
|
||||||
[assign_a(cls.using_namespaces, using_namespace_current)]
|
[assign_a(cls.using_namespaces, using_namespace_current)]
|
||||||
[assign_a(deconstructor.name,cls.name)]
|
[assign_a(deconstructor.name,cls.name)]
|
||||||
[assign_a(cls.deconstructor, deconstructor)]
|
[assign_a(cls.deconstructor, deconstructor)]
|
||||||
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls), bl::var(templateArgument), bl::var(templateInstantiations))]
|
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls), bl::var(templateArgument), bl::var(templateInstantiations))]
|
||||||
[assign_a(deconstructor,deconstructor0)]
|
[assign_a(deconstructor,deconstructor0)]
|
||||||
[assign_a(constructor, constructor0)]
|
[assign_a(constructor, constructor0)]
|
||||||
|
@ -274,6 +274,20 @@ Module::Module(const string& interfacePath,
|
||||||
[clear_a(templateArgument)]
|
[clear_a(templateArgument)]
|
||||||
[clear_a(templateInstantiations)];
|
[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 include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>');
|
||||||
|
|
||||||
Rule namespace_def_p =
|
Rule namespace_def_p =
|
||||||
|
@ -281,7 +295,7 @@ Module::Module(const string& interfacePath,
|
||||||
>> namespace_name_p[push_back_a(namespaces)]
|
>> namespace_name_p[push_back_a(namespaces)]
|
||||||
>> ch_p('{')
|
>> ch_p('{')
|
||||||
>> *(include_p | class_p | templateSingleInstantiation_p | namespace_def_p | comments_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)
|
>> !namespace_name_p)
|
||||||
[pop_a(namespaces)];
|
[pop_a(namespaces)];
|
||||||
|
|
||||||
|
@ -297,7 +311,7 @@ Module::Module(const string& interfacePath,
|
||||||
[push_back_a(forward_declarations, fwDec)]
|
[push_back_a(forward_declarations, fwDec)]
|
||||||
[assign_a(fwDec, fwDec0)];
|
[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;
|
Rule module_p = *module_content_p >> !end_p;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "Class.h"
|
#include "Class.h"
|
||||||
|
#include "GlobalFunction.h"
|
||||||
#include "TemplateInstantiationTypedef.h"
|
#include "TemplateInstantiationTypedef.h"
|
||||||
#include "ForwardDeclaration.h"
|
#include "ForwardDeclaration.h"
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ namespace wrap {
|
||||||
*/
|
*/
|
||||||
struct Module {
|
struct Module {
|
||||||
|
|
||||||
|
typedef std::map<std::string, GlobalFunction> GlobalFunctions;
|
||||||
|
|
||||||
std::string name; ///< module name
|
std::string name; ///< module name
|
||||||
std::vector<Class> classes; ///< list of classes
|
std::vector<Class> classes; ///< list of classes
|
||||||
std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations
|
std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations
|
||||||
|
@ -40,6 +43,7 @@ struct Module {
|
||||||
// std::vector<std::string> using_namespaces; ///< all default namespaces
|
// std::vector<std::string> using_namespaces; ///< all default namespaces
|
||||||
std::vector<ForwardDeclaration> forward_declarations;
|
std::vector<ForwardDeclaration> forward_declarations;
|
||||||
std::vector<std::string> includes; ///< Include statements
|
std::vector<std::string> includes; ///< Include statements
|
||||||
|
GlobalFunctions global_functions;
|
||||||
|
|
||||||
/// constructor that parses interface file
|
/// constructor that parses interface file
|
||||||
Module(const std::string& interfacePath,
|
Module(const std::string& interfacePath,
|
||||||
|
|
|
@ -82,6 +82,9 @@ class Test {
|
||||||
// even more comments at the end!
|
// even more comments at the end!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Vector aGlobalFunction();
|
||||||
|
|
||||||
// comments at the end!
|
// comments at the end!
|
||||||
|
|
||||||
// even more comments at the end!
|
// even more comments at the end!
|
||||||
|
|
Loading…
Reference in New Issue