Using TemplateGrammar
parent
32852eeec7
commit
8eb6393c92
|
@ -43,7 +43,8 @@ void Class::assignParent(const Qualified& parent) {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
boost::optional<string> Class::qualifiedParent() const {
|
boost::optional<string> Class::qualifiedParent() const {
|
||||||
boost::optional<string> result = boost::none;
|
boost::optional<string> result = boost::none;
|
||||||
if (parentClass) result = parentClass->qualifiedName("::");
|
if (parentClass)
|
||||||
|
result = parentClass->qualifiedName("::");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ Method& Class::mutableMethod(Str key) {
|
||||||
try {
|
try {
|
||||||
return methods_.at(key);
|
return methods_.at(key);
|
||||||
} catch (const out_of_range& oor) {
|
} catch (const out_of_range& oor) {
|
||||||
handleException(oor,methods_);
|
handleException(oor, methods_);
|
||||||
throw runtime_error("Internal error in wrap");
|
throw runtime_error("Internal error in wrap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +72,7 @@ const Method& Class::method(Str key) const {
|
||||||
try {
|
try {
|
||||||
return methods_.at(key);
|
return methods_.at(key);
|
||||||
} catch (const out_of_range& oor) {
|
} catch (const out_of_range& oor) {
|
||||||
handleException(oor,methods_);
|
handleException(oor, methods_);
|
||||||
throw runtime_error("Internal error in wrap");
|
throw runtime_error("Internal error in wrap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,13 +317,13 @@ vector<Class> Class::expandTemplate(Str templateArg,
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::addMethod(bool verbose, bool is_const, Str methodName,
|
void Class::addMethod(bool verbose, bool is_const, Str methodName,
|
||||||
const ArgumentList& argumentList, const ReturnValue& returnValue,
|
const ArgumentList& argumentList, const ReturnValue& returnValue,
|
||||||
Str templateArgName, const vector<Qualified>& templateArgValues) {
|
const Template& tmplate) {
|
||||||
// Check if templated
|
// Check if templated
|
||||||
if (!templateArgName.empty() && templateArgValues.size() > 0) {
|
if (!tmplate.argName.empty() && tmplate.argValues.size() > 0) {
|
||||||
// Create method to expand
|
// Create method to expand
|
||||||
// For all values of the template argument, create a new method
|
// For all values of the template argument, create a new method
|
||||||
BOOST_FOREACH(const Qualified& instName, templateArgValues) {
|
BOOST_FOREACH(const Qualified& instName, tmplate.argValues) {
|
||||||
const TemplateSubstitution ts(templateArgName, instName, *this);
|
const TemplateSubstitution ts(tmplate.argName, instName, *this);
|
||||||
// substitute template in arguments
|
// substitute template in arguments
|
||||||
ArgumentList expandedArgs = argumentList.expandTemplate(ts);
|
ArgumentList expandedArgs = argumentList.expandTemplate(ts);
|
||||||
// do the same for return type
|
// do the same for return type
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Template.h"
|
||||||
#include "Constructor.h"
|
#include "Constructor.h"
|
||||||
#include "Deconstructor.h"
|
#include "Deconstructor.h"
|
||||||
#include "Method.h"
|
#include "Method.h"
|
||||||
|
@ -95,7 +96,7 @@ public:
|
||||||
/// Add potentially overloaded, potentially templated method
|
/// Add potentially overloaded, potentially templated method
|
||||||
void addMethod(bool verbose, bool is_const, Str methodName,
|
void addMethod(bool verbose, bool is_const, Str methodName,
|
||||||
const ArgumentList& argumentList, const ReturnValue& returnValue,
|
const ArgumentList& argumentList, const ReturnValue& returnValue,
|
||||||
Str templateArgName, const std::vector<Qualified>& templateArgValues);
|
const Template& tmplate);
|
||||||
|
|
||||||
/// Post-process classes for serialization markers
|
/// Post-process classes for serialization markers
|
||||||
void erase_serialization(); // non-const !
|
void erase_serialization(); // non-const !
|
||||||
|
|
|
@ -114,15 +114,6 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
// TODO, do we really need cls here? Non-local
|
// TODO, do we really need cls here? Non-local
|
||||||
Class cls0(verbose),cls(verbose);
|
Class cls0(verbose),cls(verbose);
|
||||||
|
|
||||||
// template<CALIBRATION = {gtsam::Cal3DS2}>
|
|
||||||
string templateArgName;
|
|
||||||
vector<Qualified> templateArgValues;
|
|
||||||
TypeListGrammar<'{','}'> templateArgValues_g(templateArgValues);
|
|
||||||
Rule templateArgValues_p =
|
|
||||||
(str_p("template") >>
|
|
||||||
'<' >> basic.name_p[assign_a(templateArgName)] >> '=' >>
|
|
||||||
templateArgValues_g >> '>');
|
|
||||||
|
|
||||||
// parse "gtsam::Pose2" and add to singleInstantiation.typeList
|
// parse "gtsam::Pose2" and add to singleInstantiation.typeList
|
||||||
TemplateInstantiationTypedef singleInstantiation, singleInstantiation0;
|
TemplateInstantiationTypedef singleInstantiation, singleInstantiation0;
|
||||||
TypeListGrammar<'<','>'> typelist_g(singleInstantiation.typeList);
|
TypeListGrammar<'<','>'> typelist_g(singleInstantiation.typeList);
|
||||||
|
@ -164,20 +155,24 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
|
|
||||||
Rule methodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
Rule methodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
||||||
|
|
||||||
|
// template<CALIBRATION = {gtsam::Cal3DS2}>
|
||||||
|
Template methodTemplate;
|
||||||
|
TemplateGrammar methodTemplate_g(methodTemplate);
|
||||||
|
|
||||||
// gtsam::Values retract(const gtsam::VectorValues& delta) const;
|
// gtsam::Values retract(const gtsam::VectorValues& delta) const;
|
||||||
string methodName;
|
string methodName;
|
||||||
bool isConst, isConst0 = false;
|
bool isConst, isConst0 = false;
|
||||||
Rule method_p =
|
Rule method_p =
|
||||||
!templateArgValues_p >>
|
!methodTemplate_g >>
|
||||||
(returnValue_g >> methodName_p[assign_a(methodName)] >>
|
(returnValue_g >> methodName_p[assign_a(methodName)] >>
|
||||||
argumentList_g >>
|
argumentList_g >>
|
||||||
!str_p("const")[assign_a(isConst,true)] >> ';' >> *basic.comments_p)
|
!str_p("const")[assign_a(isConst,true)] >> ';' >> *basic.comments_p)
|
||||||
[bl::bind(&Class::addMethod, bl::var(cls), verbose, bl::var(isConst),
|
[bl::bind(&Class::addMethod, bl::var(cls), verbose, bl::var(isConst),
|
||||||
bl::var(methodName), bl::var(args), bl::var(retVal),
|
bl::var(methodName), bl::var(args), bl::var(retVal),
|
||||||
bl::var(templateArgName), bl::var(templateArgValues))]
|
bl::var(methodTemplate))]
|
||||||
[assign_a(retVal,retVal0)]
|
[assign_a(retVal,retVal0)]
|
||||||
[clear_a(args)]
|
[clear_a(args)]
|
||||||
[clear_a(templateArgValues)]
|
[clear_a(methodTemplate)]
|
||||||
[assign_a(isConst,isConst0)];
|
[assign_a(isConst,isConst0)];
|
||||||
|
|
||||||
Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
||||||
|
@ -193,17 +188,19 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
|
|
||||||
Rule functions_p = constructor_p | method_p | static_method_p;
|
Rule functions_p = constructor_p | method_p | static_method_p;
|
||||||
|
|
||||||
|
// template<CALIBRATION = {gtsam::Cal3DS2}>
|
||||||
|
Template classTemplate;
|
||||||
|
TemplateGrammar classTemplate_g(classTemplate);
|
||||||
|
|
||||||
|
// Parent class
|
||||||
Qualified possibleParent;
|
Qualified possibleParent;
|
||||||
TypeGrammar classParent_p(possibleParent);
|
TypeGrammar classParent_p(possibleParent);
|
||||||
|
|
||||||
// parse a full class
|
// parse a full class
|
||||||
vector<Qualified> templateInstantiations;
|
|
||||||
Rule class_p =
|
Rule class_p =
|
||||||
eps_p[assign_a(cls,cls0)]
|
eps_p[assign_a(cls,cls0)]
|
||||||
>> (!(templateArgValues_p
|
>> (!(classTemplate_g
|
||||||
[push_back_a(cls.templateArgs, templateArgName)]
|
[push_back_a(cls.templateArgs, classTemplate.argName)]
|
||||||
[assign_a(templateInstantiations,templateArgValues)]
|
|
||||||
[clear_a(templateArgValues)]
|
|
||||||
| templateList_p)
|
| templateList_p)
|
||||||
>> !(str_p("virtual")[assign_a(cls.isVirtual, true)])
|
>> !(str_p("virtual")[assign_a(cls.isVirtual, true)])
|
||||||
>> str_p("class")
|
>> str_p("class")
|
||||||
|
@ -219,8 +216,8 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
[assign_a(cls.namespaces_, namespaces)]
|
[assign_a(cls.namespaces_, namespaces)]
|
||||||
[assign_a(cls.deconstructor.name,cls.name_)]
|
[assign_a(cls.deconstructor.name,cls.name_)]
|
||||||
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls),
|
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls),
|
||||||
bl::var(templateInstantiations))]
|
bl::var(classTemplate.argValues))]
|
||||||
[clear_a(templateInstantiations)]
|
[clear_a(classTemplate)]
|
||||||
[assign_a(constructor, constructor0)]
|
[assign_a(constructor, constructor0)]
|
||||||
[assign_a(cls,cls0)];
|
[assign_a(cls,cls0)];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue