Skip to content

Commit

Permalink
Couple of adjustments from #188.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasfertig committed Aug 12, 2019
1 parent 108c6d3 commit c061d79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 19 additions & 8 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1845,12 +1845,18 @@ void CodeGenerator::InsertCXXMethodHeader(const CXXMethodDecl* stmt, OutputForma
codeGenerator.InsertCurlysIfRequired(init->getInit());
} else {
const auto* inlineInit = init->getInit();
bool useCurlies{false};

if(const auto* cxxInheritedCtorInitExpr = dyn_cast_or_null<CXXInheritedCtorInitExpr>(inlineInit)) {
cxxInheritedCtorDecl = cxxInheritedCtorInitExpr->getConstructor();

// Insert the base class name only, if it is not a CXXContructorExpr which already carries the type.
} else if(init->isBaseInitializer() && not isa<CXXConstructExpr>(inlineInit)) {
initOutputFormatHelper.Append(GetName(QualType(init->getBaseClass(), 0)));
useCurlies = true;
}

codeGenerator.InsertArg(inlineInit);
codeGenerator.WrapInCurliesIfNeeded(useCurlies, [&] { codeGenerator.InsertArg(inlineInit); });
}
}
}
Expand Down Expand Up @@ -2088,13 +2094,7 @@ void CodeGenerator::PrintNamespace(const NestedNameSpecifier* stmt)
case NestedNameSpecifier::TypeSpec: {

mOutputFormatHelper.Append(GetUnqualifiedScopelessName(stmt->getAsType()));

// XXX: Leave this for now, it inserts a second pair of <...> which seems to be not required.
// if(const auto* tmplSpecType = dyn_cast<TemplateSpecializationType>(type)) {
// InsertTemplateArgs(tmplSpecType->template_arguments());
// // } else if(const auto* subs = dyn_cast_or_null<SubstTemplateTypeParmType>(T)) {
// // mOutputFormatHelper.Append(GetName(subs->getReplacementType()));
//}
// The template parameters are already contained in the type we inserted above.
} break;

default: break;
Expand Down Expand Up @@ -3086,6 +3086,17 @@ void CodeGenerator::WrapInParensIfNeeded(bool needsParens, T&& lambda, const Add
}
//-----------------------------------------------------------------------------

template<typename T>
void CodeGenerator::WrapInCurliesIfNeeded(bool needsParens, T&& lambda, const AddSpaceAtTheEnd addSpaceAtTheEnd)
{
if(needsParens) {
WrapInParensOrCurlys(BraceKind::Curlys, std::forward<T>(lambda), addSpaceAtTheEnd);
} else {
lambda();
}
}
//-----------------------------------------------------------------------------

template<typename T>
void CodeGenerator::WrapInCurlys(T&& lambda, const AddSpaceAtTheEnd addSpaceAtTheEnd)
{
Expand Down
4 changes: 4 additions & 0 deletions CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ class CodeGenerator
void
WrapInParensIfNeeded(bool needsParens, T&& lambda, const AddSpaceAtTheEnd addSpaceAtTheEnd = AddSpaceAtTheEnd::No);

template<typename T>
void
WrapInCurliesIfNeeded(bool needsParens, T&& lambda, const AddSpaceAtTheEnd addSpaceAtTheEnd = AddSpaceAtTheEnd::No);

template<typename T>
void WrapInCurlys(T&& lambda, const AddSpaceAtTheEnd addSpaceAtTheEnd = AddSpaceAtTheEnd::No);

Expand Down

0 comments on commit c061d79

Please sign in to comment.