mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Comment formatting fixes
This commit is contained in:
parent
1155bd9600
commit
c06b4eb946
1 changed files with 22 additions and 6 deletions
|
@ -300,11 +300,8 @@ int BfPrinter::CalcOrigLineSpacing(BfAstNode* bfAstNode, int* lineStartIdx)
|
||||||
|
|
||||||
void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
||||||
{
|
{
|
||||||
if ((!mOutString.IsEmpty()) && (!isspace((uint8)mOutString[mOutString.mLength - 1])))
|
bool startsWithSpace = false;
|
||||||
{
|
|
||||||
Write(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wasExpectingNewLine = mExpectingNewLine;
|
bool wasExpectingNewLine = mExpectingNewLine;
|
||||||
|
|
||||||
mTriviaIdx = std::max(mTriviaIdx, node->GetTriviaStart());
|
mTriviaIdx = std::max(mTriviaIdx, node->GetTriviaStart());
|
||||||
|
@ -315,12 +312,17 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
||||||
for (int i = mTriviaIdx; i < srcEnd; i++)
|
for (int i = mTriviaIdx; i < srcEnd; i++)
|
||||||
{
|
{
|
||||||
char c = astNodeSrc->mSrc[i];
|
char c = astNodeSrc->mSrc[i];
|
||||||
|
if ((i == mTriviaIdx) && (isspace((uint8)c)))
|
||||||
|
startsWithSpace = true;
|
||||||
|
|
||||||
if ((c == '\n') && (i < node->GetSrcStart()))
|
if ((c == '\n') && (i < node->GetSrcStart()))
|
||||||
crCount++;
|
crCount++;
|
||||||
if (((c != ' ') && (c != '\t')) || (!mReformatting))
|
if (((c != ' ') && (c != '\t')) || (!mReformatting))
|
||||||
endIdx = i + 1;
|
endIdx = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wantsPrefixSpace = (!mOutString.IsEmpty()) && (!isspace((uint8)mOutString[mOutString.mLength - 1]));
|
||||||
|
|
||||||
bool expectingNewLine = mNextStateModify.mWantNewLineIdx != mVirtualNewLineIdx;
|
bool expectingNewLine = mNextStateModify.mWantNewLineIdx != mVirtualNewLineIdx;
|
||||||
|
|
||||||
int startIdx = mTriviaIdx;
|
int startIdx = mTriviaIdx;
|
||||||
|
@ -333,7 +335,10 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
||||||
if ((origLineSpacing != -1) && (lineStart != -1))
|
if ((origLineSpacing != -1) && (lineStart != -1))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < crCount; i++)
|
for (int i = 0; i < crCount; i++)
|
||||||
|
{
|
||||||
Write("\n");
|
Write("\n");
|
||||||
|
wantsPrefixSpace = false;
|
||||||
|
}
|
||||||
startIdx = node->GetSrcStart();
|
startIdx = node->GetSrcStart();
|
||||||
// Leave left-aligned preprocessor nodes
|
// Leave left-aligned preprocessor nodes
|
||||||
if ((node->GetSourceData()->mSrc[node->GetSrcStart()] != '#') || (origLineSpacing > 0))
|
if ((node->GetSourceData()->mSrc[node->GetSrcStart()] != '#') || (origLineSpacing > 0))
|
||||||
|
@ -439,6 +444,10 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
||||||
bool emitChar = true;
|
bool emitChar = true;
|
||||||
|
|
||||||
char c = astNodeSrc->mSrc[srcIdx];
|
char c = astNodeSrc->mSrc[srcIdx];
|
||||||
|
|
||||||
|
if ((wantsPrefixSpace) && (isspace((uint8)c)))
|
||||||
|
wantsPrefixSpace = false;
|
||||||
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
isNewLine = true;
|
isNewLine = true;
|
||||||
|
@ -592,7 +601,12 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FlushIndent();
|
if (wantsPrefixSpace)
|
||||||
|
{
|
||||||
|
mQueuedSpaceCount++;
|
||||||
|
wantsPrefixSpace = false;
|
||||||
|
}
|
||||||
|
FlushIndent();
|
||||||
|
|
||||||
for (int idx = startIdx; idx <= BF_MIN(srcIdx, endIdx - 1); idx++)
|
for (int idx = startIdx; idx <= BF_MIN(srcIdx, endIdx - 1); idx++)
|
||||||
{
|
{
|
||||||
|
@ -1038,6 +1052,8 @@ void BfPrinter::Visit(BfLabelableStatement* labelableStmt)
|
||||||
void BfPrinter::Visit(BfCommentNode* commentNode)
|
void BfPrinter::Visit(BfCommentNode* commentNode)
|
||||||
{
|
{
|
||||||
WriteIgnoredNode(commentNode);
|
WriteIgnoredNode(commentNode);
|
||||||
|
if (commentNode->mCommentKind == BfCommentKind_Line)
|
||||||
|
ExpectNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfPrinter::Visit(BfPreprocesorIgnoredSectionNode* preprocesorIgnoredSection)
|
void BfPrinter::Visit(BfPreprocesorIgnoredSectionNode* preprocesorIgnoredSection)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue