Eliminated copy/paste
parent
77935bd631
commit
9b9d9a6b54
|
@ -65,12 +65,12 @@ typedef rule<BOOST_SPIRIT_CLASSIC_NS::phrase_scanner_t> Rule;
|
||||||
// If a number of template arguments were given, generate a number of expanded
|
// If a number of template arguments were given, generate a number of expanded
|
||||||
// class names, e.g., PriorFactor -> PriorFactorPose2, and add those classes
|
// class names, e.g., PriorFactor -> PriorFactorPose2, and add those classes
|
||||||
static void handle_possible_template(vector<Class>& classes, const Class& cls,
|
static void handle_possible_template(vector<Class>& classes, const Class& cls,
|
||||||
const string& templateArgument, const vector<Qualified>& instantiations) {
|
const string& templateArgName, const vector<Qualified>& instantiations) {
|
||||||
if (instantiations.empty()) {
|
if (instantiations.empty()) {
|
||||||
classes.push_back(cls);
|
classes.push_back(cls);
|
||||||
} else {
|
} else {
|
||||||
vector<Class> classInstantiations = //
|
vector<Class> classInstantiations = //
|
||||||
cls.expandTemplate(templateArgument, instantiations);
|
cls.expandTemplate(templateArgName, instantiations);
|
||||||
BOOST_FOREACH(const Class& c, classInstantiations)
|
BOOST_FOREACH(const Class& c, classInstantiations)
|
||||||
classes.push_back(c);
|
classes.push_back(c);
|
||||||
}
|
}
|
||||||
|
@ -99,11 +99,10 @@ Module::Module(const string& interfacePath,
|
||||||
void Module::parseMarkup(const std::string& data) {
|
void Module::parseMarkup(const std::string& data) {
|
||||||
// these variables will be imperatively updated to gradually build [cls]
|
// these variables will be imperatively updated to gradually build [cls]
|
||||||
// The one with postfix 0 are used to reset the variables after parse.
|
// The one with postfix 0 are used to reset the variables after parse.
|
||||||
string methodName;
|
|
||||||
bool isConst, isConst0 = false;
|
bool isConst, isConst0 = false;
|
||||||
ReturnValue retVal0, retVal;
|
ReturnValue retVal0, retVal;
|
||||||
Argument arg0, arg;
|
Argument arg0, arg;
|
||||||
ArgumentList args0, args;
|
ArgumentList args;
|
||||||
vector<string> arg_dup; ///keep track of duplicates
|
vector<string> arg_dup; ///keep track of duplicates
|
||||||
Constructor constructor0(verbose), constructor(verbose);
|
Constructor constructor0(verbose), constructor(verbose);
|
||||||
Deconstructor deconstructor0(verbose), deconstructor(verbose);
|
Deconstructor deconstructor0(verbose), deconstructor(verbose);
|
||||||
|
@ -165,49 +164,30 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
*(namespace_name_p[push_back_a(cls.qualifiedParent.namespaces)] >> str_p("::")) >>
|
*(namespace_name_p[push_back_a(cls.qualifiedParent.namespaces)] >> str_p("::")) >>
|
||||||
className_p[assign_a(cls.qualifiedParent.name)];
|
className_p[assign_a(cls.qualifiedParent.name)];
|
||||||
|
|
||||||
// TODO: get rid of copy/paste below?
|
// parse "gtsam::Pose2" and add to templateArgValues
|
||||||
|
Qualified templateArgValue;
|
||||||
// parse "gtsam::Pose2" and add to templateInstantiations
|
vector<Qualified> templateArgValues;
|
||||||
Qualified argValue;
|
Rule templateArgValue_p =
|
||||||
vector<Qualified> templateInstantiations;
|
(*(namespace_name_p[push_back_a(templateArgValue.namespaces)] >> str_p("::")) >>
|
||||||
Rule templateInstantiation_p =
|
className_p[assign_a(templateArgValue.name)])
|
||||||
(*(namespace_name_p[push_back_a(argValue.namespaces)] >> str_p("::")) >>
|
[push_back_a(templateArgValues, templateArgValue)]
|
||||||
className_p[assign_a(argValue.name)])
|
[clear_a(templateArgValue)];
|
||||||
[push_back_a(templateInstantiations, argValue)]
|
|
||||||
[clear_a(argValue)];
|
|
||||||
|
|
||||||
// template<CALIBRATION = {gtsam::Cal3DS2}>
|
// template<CALIBRATION = {gtsam::Cal3DS2}>
|
||||||
string templateArgument;
|
string templateArgName;
|
||||||
Rule templateInstantiations_p =
|
Rule templateArgValues_p =
|
||||||
(str_p("template") >>
|
(str_p("template") >>
|
||||||
'<' >> name_p[assign_a(templateArgument)] >> '=' >> '{' >>
|
'<' >> name_p[assign_a(templateArgName)] >> '=' >>
|
||||||
!(templateInstantiation_p >> *(',' >> templateInstantiation_p)) >>
|
'{' >> !(templateArgValue_p >> *(',' >> templateArgValue_p)) >> '}' >>
|
||||||
'}' >> '>')
|
'>');
|
||||||
[push_back_a(cls.templateArgs, templateArgument)];
|
|
||||||
|
|
||||||
// parse "gtsam::Pose2" and add to methodInstantiations
|
|
||||||
vector<Qualified> methodInstantiations;
|
|
||||||
Rule methodInstantiation_p =
|
|
||||||
(*(namespace_name_p[push_back_a(argValue.namespaces)] >> str_p("::")) >>
|
|
||||||
className_p[assign_a(argValue.name)])
|
|
||||||
[push_back_a(methodInstantiations, argValue)]
|
|
||||||
[clear_a(argValue)];
|
|
||||||
|
|
||||||
// template<CALIBRATION = {gtsam::Cal3DS2}>
|
|
||||||
string methodArgument;
|
|
||||||
Rule methodInstantiations_p =
|
|
||||||
(str_p("template") >>
|
|
||||||
'<' >> name_p[assign_a(methodArgument)] >> '=' >> '{' >>
|
|
||||||
!(methodInstantiation_p >> *(',' >> methodInstantiation_p)) >>
|
|
||||||
'}' >> '>');
|
|
||||||
|
|
||||||
// parse "gtsam::Pose2" and add to singleInstantiation.typeList
|
// parse "gtsam::Pose2" and add to singleInstantiation.typeList
|
||||||
TemplateInstantiationTypedef singleInstantiation;
|
TemplateInstantiationTypedef singleInstantiation;
|
||||||
Rule templateSingleInstantiationArg_p =
|
Rule templateSingleInstantiationArg_p =
|
||||||
(*(namespace_name_p[push_back_a(argValue.namespaces)] >> str_p("::")) >>
|
(*(namespace_name_p[push_back_a(templateArgValue.namespaces)] >> str_p("::")) >>
|
||||||
className_p[assign_a(argValue.name)])
|
className_p[assign_a(templateArgValue.name)])
|
||||||
[push_back_a(singleInstantiation.typeList, argValue)]
|
[push_back_a(singleInstantiation.typeList, templateArgValue)]
|
||||||
[clear_a(argValue)];
|
[clear_a(templateArgValue)];
|
||||||
|
|
||||||
// typedef gtsam::RangeFactor<gtsam::Pose2, gtsam::Point2> RangeFactorPosePoint2;
|
// typedef gtsam::RangeFactor<gtsam::Pose2, gtsam::Point2> RangeFactorPosePoint2;
|
||||||
TemplateInstantiationTypedef singleInstantiation0;
|
TemplateInstantiationTypedef singleInstantiation0;
|
||||||
|
@ -242,7 +222,7 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
Rule constructor_p =
|
Rule constructor_p =
|
||||||
(className_p >> '(' >> argumentList_p >> ')' >> ';' >> !comments_p)
|
(className_p >> '(' >> argumentList_p >> ')' >> ';' >> !comments_p)
|
||||||
[push_back_a(constructor.args_list, args)]
|
[push_back_a(constructor.args_list, args)]
|
||||||
[assign_a(args,args0)];
|
[clear_a(args)];
|
||||||
//[assign_a(constructor.args,args)]
|
//[assign_a(constructor.args,args)]
|
||||||
//[assign_a(constructor.name,cls.name)]
|
//[assign_a(constructor.name,cls.name)]
|
||||||
//[push_back_a(cls.constructors, constructor)]
|
//[push_back_a(cls.constructors, constructor)]
|
||||||
|
@ -281,21 +261,19 @@ 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 | '_')];
|
||||||
|
|
||||||
// gtsam::Values retract(const gtsam::VectorValues& delta) const;
|
// gtsam::Values retract(const gtsam::VectorValues& delta) const;
|
||||||
|
string methodName;
|
||||||
|
vector<Qualified> methodInstantiations;
|
||||||
Rule method_p =
|
Rule method_p =
|
||||||
!methodInstantiations_p >>
|
!templateArgValues_p
|
||||||
|
[assign_a(methodInstantiations,templateArgValues)][clear_a(templateArgValues)] >>
|
||||||
(returnType_p >> methodName_p[assign_a(methodName)] >>
|
(returnType_p >> methodName_p[assign_a(methodName)] >>
|
||||||
'(' >> argumentList_p >> ')' >>
|
'(' >> argumentList_p >> ')' >>
|
||||||
!str_p("const")[assign_a(isConst,true)] >> ';' >> *comments_p)
|
!str_p("const")[assign_a(isConst,true)] >> ';' >> *comments_p)
|
||||||
[bl::bind(&Method::addOverload,
|
[bl::bind(&Method::addOverload,
|
||||||
bl::var(cls.methods)[bl::var(methodName)],
|
bl::var(cls.methods)[bl::var(methodName)], verbose,
|
||||||
verbose,
|
bl::var(isConst), bl::var(methodName), bl::var(args), bl::var(retVal))]
|
||||||
bl::var(isConst),
|
|
||||||
bl::var(methodName),
|
|
||||||
bl::var(args),
|
|
||||||
bl::var(retVal))]
|
|
||||||
[assign_a(isConst,isConst0)]
|
[assign_a(isConst,isConst0)]
|
||||||
[clear_a(methodName)]
|
[clear_a(args)]
|
||||||
[assign_a(args,args0)]
|
|
||||||
[assign_a(retVal,retVal0)];
|
[assign_a(retVal,retVal0)];
|
||||||
|
|
||||||
Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
||||||
|
@ -309,15 +287,19 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
bl::var(methodName),
|
bl::var(methodName),
|
||||||
bl::var(args),
|
bl::var(args),
|
||||||
bl::var(retVal))]
|
bl::var(retVal))]
|
||||||
[clear_a(methodName)]
|
[clear_a(args)]
|
||||||
[assign_a(args,args0)]
|
|
||||||
[assign_a(retVal,retVal0)];
|
[assign_a(retVal,retVal0)];
|
||||||
|
|
||||||
Rule functions_p = constructor_p | method_p | static_method_p;
|
Rule functions_p = constructor_p | method_p | static_method_p;
|
||||||
|
|
||||||
|
vector<Qualified> templateInstantiations;
|
||||||
Rule class_p =
|
Rule class_p =
|
||||||
(str_p("")[assign_a(cls,cls0)])
|
(str_p("")[assign_a(cls,cls0)])
|
||||||
>> (!(templateInstantiations_p | templateList_p)
|
>> (!(templateArgValues_p
|
||||||
|
[push_back_a(cls.templateArgs, templateArgName)]
|
||||||
|
[assign_a(templateInstantiations,templateArgValues)]
|
||||||
|
[clear_a(templateArgValues)]
|
||||||
|
| templateList_p)
|
||||||
>> !(str_p("virtual")[assign_a(cls.isVirtual, true)])
|
>> !(str_p("virtual")[assign_a(cls.isVirtual, true)])
|
||||||
>> str_p("class")
|
>> str_p("class")
|
||||||
>> className_p[assign_a(cls.name)]
|
>> className_p[assign_a(cls.name)]
|
||||||
|
@ -329,11 +311,11 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
[assign_a(cls.namespaces, namespaces)]
|
[assign_a(cls.namespaces, namespaces)]
|
||||||
[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(templateArgName), bl::var(templateInstantiations))]
|
||||||
[assign_a(deconstructor,deconstructor0)]
|
[assign_a(deconstructor,deconstructor0)]
|
||||||
[assign_a(constructor, constructor0)]
|
[assign_a(constructor, constructor0)]
|
||||||
[assign_a(cls,cls0)]
|
[assign_a(cls,cls0)]
|
||||||
[clear_a(templateArgument)]
|
|
||||||
[clear_a(templateInstantiations)];
|
[clear_a(templateInstantiations)];
|
||||||
|
|
||||||
Qualified globalFunction;
|
Qualified globalFunction;
|
||||||
|
@ -348,7 +330,7 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
bl::var(args),
|
bl::var(args),
|
||||||
bl::var(retVal))]
|
bl::var(retVal))]
|
||||||
[clear_a(globalFunction)]
|
[clear_a(globalFunction)]
|
||||||
[assign_a(args,args0)]
|
[clear_a(args)]
|
||||||
[assign_a(retVal,retVal0)];
|
[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('>');
|
||||||
|
|
Loading…
Reference in New Issue