Browse Source

Formatting fix for inline types with interleaved member access/attribute

Brian Fiete 3 months ago
parent
commit
2c48f26536
2 changed files with 44 additions and 6 deletions
  1. 31 6
      IDEHelper/Compiler/BfPrinter.cpp
  2. 13 0
      IDEHelper/Compiler/BfPrinter.h

+ 31 - 6
IDEHelper/Compiler/BfPrinter.cpp

@@ -209,14 +209,39 @@ void BfPrinter::FlushVisitChild()
 
 	std::stable_sort(nodeQueue.begin(), nodeQueue.end(), CompareNodeStart);
 
-	for (auto& node : nodeQueue)
-	{
-		mNextStateModify = node;
+	ChildQueueState childQueueState;
+	childQueueState.mQueue = &nodeQueue;	
+	mActiveChildQueues.Add(&childQueueState);	
+
+	auto _HandleStateNotify = [&](StateModify node)
+		{
+			mNextStateModify = node;
 
-		VisitChild(node.mQueuedNode);
-		if (mVirtualNewLineIdx == mNextStateModify.mWantNewLineIdx)
-			mVirtualNewLineIdx = node.mWantNewLineIdx;
+			VisitChild(node.mQueuedNode);
+			if (mVirtualNewLineIdx == mNextStateModify.mWantNewLineIdx)
+				mVirtualNewLineIdx = node.mWantNewLineIdx;
+		};
+
+	while (childQueueState.mIdx < childQueueState.mQueue->mSize)
+	{
+		auto node = (*childQueueState.mQueue)[childQueueState.mIdx++];		
+		if (mActiveChildQueues.mSize > 1)
+		{
+			// Check for nodes in the prev queue that are actual inside the new queue (can happen with inline type declarations)
+			auto prevQueue = mActiveChildQueues[mActiveChildQueues.mSize - 2];
+			while (true)
+			{
+				auto prevQueueNode = (*prevQueue->mQueue)[prevQueue->mIdx];
+				if (prevQueueNode.mQueuedNode->mSrcStart >= node.mQueuedNode->mSrcStart)
+					break;
+				prevQueue->mIdx++;
+				_HandleStateNotify(prevQueueNode);				
+			}
+		}	
+		_HandleStateNotify(node);		
 	}
+
+	mActiveChildQueues.pop_back();
 }
 
 void BfPrinter::VisitChildWithPrecedingSpace(BfAstNode* bfAstNode)

+ 13 - 0
IDEHelper/Compiler/BfPrinter.h

@@ -49,6 +49,18 @@ public:
 		}
 	};
 
+	struct ChildQueueState
+	{
+		Array<StateModify>* mQueue;
+		int mIdx;
+
+		ChildQueueState()
+		{
+			mQueue = NULL;
+			mIdx = 0;
+		}
+	};
+
 	BfSourceData* mSource;
 	BfParserData* mParser;
 
@@ -62,6 +74,7 @@ public:
 
 	int mTriviaIdx;
 	int mCurSrcIdx;
+	Array<ChildQueueState*> mActiveChildQueues;
 	Array<StateModify> mChildNodeQueue;
 	int mFormatStart;
 	int mFormatEnd;