2019-08-23 11:56:54 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BfSystem.h"
|
|
|
|
#include "BfAst.h"
|
|
|
|
#include "BfParser.h"
|
|
|
|
|
|
|
|
NS_BF_BEGIN
|
|
|
|
|
|
|
|
class BfFixitFinder : public BfElementVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static int FindLineStartAfter(BfSourceData* source, int idx)
|
|
|
|
{
|
|
|
|
bool hadBr = false;
|
|
|
|
while (idx < source->mSrcLength)
|
|
|
|
{
|
|
|
|
char c = source->mSrc[idx];
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
break;
|
2022-07-26 13:27:03 -04:00
|
|
|
}
|
2019-08-23 11:56:54 -07:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FindLineStartAfter(BfAstNode* node)
|
|
|
|
{
|
|
|
|
return FindLineStartAfter(node->GetSourceData(), node->GetSrcEnd());
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FindLineStartBefore(BfSourceData* source, int idx)
|
|
|
|
{
|
|
|
|
bool hadBr = false;
|
|
|
|
while (idx >= 0)
|
|
|
|
{
|
|
|
|
char c = source->mSrc[idx];
|
|
|
|
if (c == '\n')
|
2022-07-26 13:27:03 -04:00
|
|
|
{
|
2019-08-23 11:56:54 -07:00
|
|
|
idx++;
|
|
|
|
break;
|
2022-07-26 13:27:03 -04:00
|
|
|
}
|
2019-08-23 11:56:54 -07:00
|
|
|
idx--;
|
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FindLineStartBefore(BfAstNode* node)
|
|
|
|
{
|
|
|
|
return FindLineStartBefore(node->GetSourceData(), node->GetSrcStart());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BfUsingFinder : public BfFixitFinder
|
|
|
|
{
|
|
|
|
public:
|
2022-06-01 16:36:58 -07:00
|
|
|
int mFromIdx;
|
2019-08-23 11:56:54 -07:00
|
|
|
int mLastIdx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BfUsingFinder()
|
|
|
|
{
|
|
|
|
mLastIdx = 0;
|
2022-06-01 16:36:58 -07:00
|
|
|
mFromIdx = -1;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
2022-06-01 16:36:58 -07:00
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
virtual void Visit(BfUsingDirective* usingDirective) override
|
|
|
|
{
|
2022-07-26 13:27:03 -04:00
|
|
|
mLastIdx = FindLineStartAfter(usingDirective->GetSourceData(), usingDirective->GetSrcEnd());
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
2022-06-01 16:36:58 -07:00
|
|
|
|
|
|
|
virtual void Visit(BfNamespaceDeclaration* namespaceDecl) override
|
|
|
|
{
|
|
|
|
if (mFromIdx != -1)
|
2022-07-26 13:27:03 -04:00
|
|
|
{
|
2022-06-01 16:36:58 -07:00
|
|
|
if ((mFromIdx < namespaceDecl->mSrcStart) || (mFromIdx >= namespaceDecl->mSrcEnd))
|
|
|
|
{
|
|
|
|
// Not inside
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BfFixitFinder::Visit(namespaceDecl);
|
|
|
|
}
|
2019-08-23 11:56:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_BF_END
|