MCPcopy Create free account
hub / github.com/andreasfertig/cppinsights / WrapInCompoundIfNeeded

Method WrapInCompoundIfNeeded

CodeGenerator.cpp:5176–5208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5174//-----------------------------------------------------------------------------
5175
5176void CodeGenerator::WrapInCompoundIfNeeded(const Stmt* stmt, const AddNewLineAfter addNewLineAfter)
5177{
5178 const bool hasNoCompoundStmt = not(isa<CompoundStmt>(stmt) or isa<AttributedStmt>(stmt));
5179
5180 if(hasNoCompoundStmt) {
5181 mOutputFormatHelper.OpenScope();
5182 }
5183
5184 if(not isa<NullStmt>(stmt)) {
5185 InsertArg(stmt);
5186
5187 const bool isAttrWithCompound{[&] {
5188 auto* attrStmt = dyn_cast_or_null<AttributedStmt>(stmt);
5189 return attrStmt and isa<CompoundStmt>(attrStmt->getSubStmt());
5190 }()};
5191
5192 // Add semi-colon if necessary. A do{} while does already add one.
5193 if(IsStmtRequiringSemi<IfStmt, CompoundStmt, NullStmt, WhileStmt, DoStmt>(stmt) and not isAttrWithCompound) {
5194 mOutputFormatHelper.AppendSemiNewLine();
5195 }
5196 }
5197
5198 if(hasNoCompoundStmt) {
5199 mOutputFormatHelper.CloseScope(OutputFormatHelper::NoNewLineBefore::Yes);
5200 }
5201
5202 const bool addNewLine = (AddNewLineAfter::Yes == addNewLineAfter);
5203 if(addNewLine or (hasNoCompoundStmt and addNewLine)) {
5204 mOutputFormatHelper.AppendNewLine();
5205 } else if(not addNewLine or (hasNoCompoundStmt and not addNewLine)) {
5206 mOutputFormatHelper.Append(' ');
5207 }
5208}
5209//-----------------------------------------------------------------------------
5210
5211void CodeGenerator::WrapInParens(void_func_ref lambda, const AddSpaceAtTheEnd addSpaceAtTheEnd)

Callers

nothing calls this directly

Calls 5

OpenScopeMethod · 0.80
AppendSemiNewLineMethod · 0.80
CloseScopeMethod · 0.80
AppendNewLineMethod · 0.80
AppendMethod · 0.80

Tested by

no test coverage detected