mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 15:24:10 +02:00
Initial checkin
This commit is contained in:
parent
c74712dad9
commit
078564ac9e
3242 changed files with 1616395 additions and 0 deletions
650
IDE/src/Compiler/BfCompiler.bf
Normal file
650
IDE/src/Compiler/BfCompiler.bf
Normal file
|
@ -0,0 +1,650 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using Beefy.widgets;
|
||||
using Beefy;
|
||||
using Beefy.utils;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
//public class Bf
|
||||
|
||||
public class BfCompiler : CompilerBase
|
||||
{
|
||||
enum OptionFlags : int32
|
||||
{
|
||||
EmitDebugInfo = 1,
|
||||
EmitLineInfo = 2,
|
||||
WriteIR = 4,
|
||||
GenerateOBJ = 8,
|
||||
NoFramePointerElim = 0x10,
|
||||
ClearLocalVars = 0x20,
|
||||
RuntimeChecks = 0x40,
|
||||
EmitDynamicCastCheck = 0x80,
|
||||
EnableObjectDebugFlags = 0x100,
|
||||
EmitObjectAccessCheck = 0x200,
|
||||
EnableCustodian = 0x400,
|
||||
EnableRealtimeLeakCheck = 0x800,
|
||||
EnableSideStack = 0x1000,
|
||||
EnableHotSwapping = 0x2000,
|
||||
IncrementalBuild = 0x4000,
|
||||
DebugAlloc = 0x8000
|
||||
}
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfCompiler_Compile(void* bfCompiler, void* bfPassInstance, char8* outputDirectory);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfCompiler_ClearResults(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfCompiler_VerifyTypeName(void* bfCompiler, char8* typeName, int32 cursorPos);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfCompiler_ClassifySource(void* bfCompiler, void* bfPassInstance, void* bfParser, void* bfResolvePassData, void* char8Data);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetAutocompleteInfo(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetSymbolReferences(void* bfCompiler, void* bfPassInstance, void* bfResolvePassData);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_Cancel(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_ClearCompletionPercentage(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern float BfCompiler_GetCompletionPercentage(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern int32 BfCompiler_GetCompileRevision(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_Delete(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_ClearBuildCache(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetOutputFileNames(void* bfCompiler, void* bfProject, out bool hadOutputChanges);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetUsedOutputFileNames(void* bfCompiler, void* bfProject, bool flushQueuedHotFiles, out bool hadOutputChanges);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetTypeDefList(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetTypeDefMatches(void* bfCompiler, char8* searchStr);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_GetTypeDefInfo(void* bfCompiler, char8* typeDefName);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_SetOptions(void* bfCompiler,
|
||||
void* hotProject, int32 hotIdx, int32 machineType, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads,
|
||||
OptionFlags optionsFlags, char8* mallocName, char8* freeName);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_ForceRebuild(void* bfCompiler);
|
||||
|
||||
public enum HotTypeFlags
|
||||
{
|
||||
None = 0,
|
||||
UserNotUsed = 1,
|
||||
UserUsed = 2,
|
||||
Heap = 4,
|
||||
};
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfCompiler_GetHasHotPendingDataChanges(void* bfCompiler);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_HotCommit(void* bfCompiler);
|
||||
|
||||
public enum HotResolveFlags
|
||||
{
|
||||
None = 0,
|
||||
HadDataChanges = 1
|
||||
}
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_HotResolve_Start(void* bfCompiler, int32 flags);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_HotResolve_AddActiveMethod(void* bfCompiler, char8* methodName);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_HotResolve_AddDelegateMethod(void* bfCompiler, char8* methodName);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_HotResolve_ReportType(void* bfCompiler, int typeId, int usageKind);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfCompiler_HotResolve_ReportTypeRange(void* bfCompiler, char8* typeName, int usageKind);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfCompiler_HotResolve_Finish(void* bfCompiler);
|
||||
|
||||
class SetPassInstanceCommand : Command
|
||||
{
|
||||
public BfPassInstance mPassInstance;
|
||||
}
|
||||
|
||||
class SetupProjectSettingsCommand : Command
|
||||
{
|
||||
public Project mProject;
|
||||
}
|
||||
|
||||
class DeleteBfProjectCommand : Command
|
||||
{
|
||||
public BfProject mBfProject;
|
||||
}
|
||||
|
||||
class RefreshViewCommand : Command
|
||||
{
|
||||
}
|
||||
|
||||
class SetWorkspaceOptionsCommand : Command
|
||||
{
|
||||
public BfProject mHotBfProject;
|
||||
public int32 mHotIdx;
|
||||
}
|
||||
|
||||
public void* mNativeBfCompiler;
|
||||
public bool mIsResolveOnly;
|
||||
public BfSystem mBfSystem;
|
||||
bool mWantsRemoveOldData;
|
||||
|
||||
public this(void* nativeBfCompiler)
|
||||
{
|
||||
mNativeBfCompiler = nativeBfCompiler;
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
BfCompiler_Delete(mNativeBfCompiler);
|
||||
mNativeBfCompiler = null;
|
||||
|
||||
if (mCommandQueue.Count > 0)
|
||||
{
|
||||
NOP!();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Compile(BfPassInstance passInstance, String outputDirectory)
|
||||
{
|
||||
bool success = BfCompiler_Compile(mNativeBfCompiler, passInstance.mNativeBfPassInstance, outputDirectory);
|
||||
passInstance.mCompileSucceeded = success;
|
||||
passInstance.mDidCompile = true;
|
||||
return success;
|
||||
}
|
||||
|
||||
public void ClearResults()
|
||||
{
|
||||
BfCompiler_ClearResults(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public bool ClassifySource(BfPassInstance bfPassInstance, BfParser parser, BfResolvePassData resolvePassData, EditWidgetContent.CharData[] char8Data)
|
||||
{
|
||||
void* nativeResolvePassData = null;
|
||||
if (resolvePassData != null)
|
||||
nativeResolvePassData = resolvePassData.mNativeResolvePassData;
|
||||
EditWidgetContent.CharData* char8DataPtr = (char8Data != null) ? char8Data.CArray() : null;
|
||||
return BfCompiler_ClassifySource(mNativeBfCompiler, bfPassInstance.mNativeBfPassInstance, (parser != null) ? parser.mNativeBfParser : null, nativeResolvePassData, char8DataPtr);
|
||||
}
|
||||
|
||||
public bool VerifyTypeName(String typeName, int cursorPos)
|
||||
{
|
||||
return BfCompiler_VerifyTypeName(mNativeBfCompiler, typeName, (.)cursorPos);
|
||||
}
|
||||
|
||||
public void GetAutocompleteInfo(String outAutocompleteInfo)
|
||||
{
|
||||
char8* result = BfCompiler_GetAutocompleteInfo(mNativeBfCompiler);
|
||||
scope String(result).MoveTo(outAutocompleteInfo);
|
||||
}
|
||||
|
||||
public void GetSymbolReferences(BfPassInstance passInstance, BfResolvePassData resolvePassData, String outSymbolReferences)
|
||||
{
|
||||
char8* result = BfCompiler_GetSymbolReferences(mNativeBfCompiler, passInstance.mNativeBfPassInstance, resolvePassData.mNativeResolvePassData);
|
||||
scope String(result).MoveTo(outSymbolReferences);
|
||||
}
|
||||
|
||||
/*public void UpdateRenameSymbols(BfPassInstance passInstance, BfResolvePassData resolvePassData)
|
||||
{
|
||||
BfCompiler_UpdateRenameSymbols(mNativeBfCompiler, passInstance.mNativeBfPassInstance, resolvePassData.mNativeResolvePassData);
|
||||
}*/
|
||||
|
||||
public void GetOutputFileNames(BfProject project, bool flushQueuedHotFiles, out bool hadOutputChanges, List<String> outFileNames)
|
||||
{
|
||||
char8* result = BfCompiler_GetUsedOutputFileNames(mNativeBfCompiler, project.mNativeBfProject, flushQueuedHotFiles, out hadOutputChanges);
|
||||
if (result == null)
|
||||
return;
|
||||
String fileNamesStr = scope String();
|
||||
fileNamesStr.Append(result);
|
||||
if (fileNamesStr.Length == 0)
|
||||
return;
|
||||
List<StringView> stringViews = scope List<StringView>(fileNamesStr.Split('\n'));
|
||||
for (var strView in stringViews)
|
||||
outFileNames.Add(new String(strView));
|
||||
}
|
||||
|
||||
public void SetOptions(BfProject hotProject, int32 hotIdx,
|
||||
int32 machineType, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads,
|
||||
OptionFlags optionFlags, String mallocFuncName, String freeFuncName)
|
||||
{
|
||||
BfCompiler_SetOptions(mNativeBfCompiler,
|
||||
(hotProject != null) ? hotProject.mNativeBfProject : null, hotIdx,
|
||||
machineType, toolsetType, simdSetting, allocStackCount, maxWorkerThreads, optionFlags, mallocFuncName, freeFuncName);
|
||||
}
|
||||
|
||||
public void ForceRebuild()
|
||||
{
|
||||
BfCompiler_ForceRebuild(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public void QueueSetPassInstance(BfPassInstance passInstance)
|
||||
{
|
||||
SetPassInstanceCommand command = new SetPassInstanceCommand();
|
||||
command.mPassInstance = passInstance;
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public void QueueSetupProjectSettings(Project project)
|
||||
{
|
||||
SetupProjectSettingsCommand command = new SetupProjectSettingsCommand();
|
||||
command.mProject = project;
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public void QueueDeleteBfProject(BfProject bfProject)
|
||||
{
|
||||
DeleteBfProjectCommand command = new DeleteBfProjectCommand();
|
||||
command.mBfProject = bfProject;
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public void QueueRefreshViewCommand()
|
||||
{
|
||||
QueueCommand(new RefreshViewCommand());
|
||||
}
|
||||
|
||||
public void QueueSetWorkspaceOptions(Project hotProject, int32 hotIdx)
|
||||
{
|
||||
BfProject hotBfProject = null;
|
||||
if (hotProject != null)
|
||||
hotBfProject = mBfSystem.GetBfProject(hotProject);
|
||||
var command = new SetWorkspaceOptionsCommand();
|
||||
command.mHotBfProject = hotBfProject;
|
||||
command.mHotIdx = hotIdx;
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
protected override void DoProcessQueue()
|
||||
{
|
||||
BfPassInstance passInstance = null;
|
||||
bool didPassInstanceAlloc = false;
|
||||
|
||||
mBfSystem.Lock(0);
|
||||
|
||||
//Debug.WriteLine("Starting Beef Thread {0}", Thread.CurrentThread.Id);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Command command = null;
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
if (mCommandQueue.Count == 0)
|
||||
break;
|
||||
command = mCommandQueue[0];
|
||||
}
|
||||
|
||||
if (command is SetPassInstanceCommand)
|
||||
{
|
||||
var setPassInstanceCommand = (SetPassInstanceCommand)command;
|
||||
passInstance = setPassInstanceCommand.mPassInstance;
|
||||
}
|
||||
else if (passInstance == null)
|
||||
{
|
||||
passInstance = mBfSystem.CreatePassInstance("ProcessQueue");
|
||||
didPassInstanceAlloc = true;
|
||||
}
|
||||
|
||||
if (command is SetupProjectSettingsCommand)
|
||||
{
|
||||
var setupProjectSettingsCommand = (SetupProjectSettingsCommand)command;
|
||||
gApp.SetupBeefProjectSettings(mBfSystem, this, setupProjectSettingsCommand.mProject);
|
||||
}
|
||||
|
||||
if (command is DeleteBfProjectCommand)
|
||||
{
|
||||
var deleteBfProjectCommand = (DeleteBfProjectCommand)command;
|
||||
deleteBfProjectCommand.mBfProject.Dispose();
|
||||
delete deleteBfProjectCommand.mBfProject;
|
||||
}
|
||||
|
||||
if (command is ProjectSourceCommand)
|
||||
ProjectSourceCommandBlock:
|
||||
{
|
||||
var projectSourceCommand = (ProjectSourceCommand)command;
|
||||
bool worked = true;
|
||||
String sourceFilePath = scope String();
|
||||
var projectSource = projectSourceCommand.mProjectSource;
|
||||
if (projectSource.mIncludeKind != .Ignore)
|
||||
{
|
||||
using (projectSource.mProject.mMonitor.Enter())
|
||||
{
|
||||
projectSourceCommand.mProjectSource.GetFullImportPath(sourceFilePath);
|
||||
}
|
||||
|
||||
bool canMoveSourceString = true;
|
||||
IdSpan char8IdData = projectSourceCommand.mSourceCharIdData;
|
||||
String data = projectSourceCommand.mSourceString;
|
||||
if (char8IdData.IsEmpty)
|
||||
{
|
||||
data = scope:ProjectSourceCommandBlock String();
|
||||
if (gApp.LoadTextFile(sourceFilePath, data) case .Err)
|
||||
data = null;
|
||||
if (data != null)
|
||||
{
|
||||
data.EnsureNullTerminator();
|
||||
char8IdData = IdSpan.GetDefault((int32)data.Length);
|
||||
defer:ProjectSourceCommandBlock char8IdData.Dispose();
|
||||
var editData = gApp.GetEditData(projectSource, false);
|
||||
using (gApp.mMonitor.Enter())
|
||||
{
|
||||
editData.SetSavedData(data, char8IdData);
|
||||
}
|
||||
canMoveSourceString = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
String msg = new String();
|
||||
msg.AppendF("FAILED TO LOAD FILE: {0}", sourceFilePath);
|
||||
mQueuedOutput.Add(msg);
|
||||
passInstance.mFailed = true;
|
||||
}
|
||||
|
||||
if ((!mIsResolveOnly) && (data != null))
|
||||
IDEApp.sApp.mWorkspace.ProjectSourceCompiled(projectSource, data, char8IdData, canMoveSourceString);
|
||||
|
||||
var bfParser = mBfSystem.CreateParser(projectSourceCommand.mProjectSource);
|
||||
if (data != null)
|
||||
bfParser.SetSource(data, sourceFilePath);
|
||||
else
|
||||
bfParser.SetSource("", sourceFilePath);
|
||||
bfParser.SetCharIdData(ref char8IdData);
|
||||
worked &= bfParser.Parse(passInstance, false);
|
||||
worked &= bfParser.Reduce(passInstance);
|
||||
worked &= bfParser.BuildDefs(passInstance, null, false);
|
||||
|
||||
// Do this to make sure we re-trigger errors in parse/reduce/builddefs
|
||||
if (!worked)
|
||||
projectSource.HasChangedSinceLastCompile = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (command is ProjectSourceRemovedCommand)
|
||||
{
|
||||
var fileRemovedCommand = (ProjectSourceRemovedCommand)command;
|
||||
var bfParser = mBfSystem.FileRemoved(fileRemovedCommand.mProjectSource);
|
||||
if (bfParser != null)
|
||||
{
|
||||
bfParser.RemoveDefs();
|
||||
delete bfParser;
|
||||
mWantsRemoveOldData = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (command is CompileCommand)
|
||||
{
|
||||
var compileCommand = (CompileCommand)command;
|
||||
Compile(passInstance, compileCommand.mOutputDirectory);
|
||||
mBfSystem.RemoveOldParsers();
|
||||
mBfSystem.RemoveOldData();
|
||||
}
|
||||
|
||||
if (command is ResolveAllCommand)
|
||||
{
|
||||
var resolvePassData = BfResolvePassData.Create(ResolveType.Classify);
|
||||
// If we get canceled then try again after waiting a couple updates
|
||||
if (!ClassifySource(passInstance, null, resolvePassData, null))
|
||||
QueueDeferredResolveAll();
|
||||
delete resolvePassData;
|
||||
mBfSystem.RemoveOldParsers();
|
||||
mBfSystem.RemoveOldData();
|
||||
}
|
||||
|
||||
if (command is SetWorkspaceOptionsCommand)
|
||||
{
|
||||
var setWorkspaceOptionsCommand = (SetWorkspaceOptionsCommand)command;
|
||||
var workspace = IDEApp.sApp.mWorkspace;
|
||||
using (workspace.mMonitor.Enter())
|
||||
{
|
||||
HandleOptions(setWorkspaceOptionsCommand.mHotBfProject, setWorkspaceOptionsCommand.mHotIdx);
|
||||
}
|
||||
}
|
||||
|
||||
if (command is RefreshViewCommand)
|
||||
{
|
||||
mWantsActiveViewRefresh = true;
|
||||
}
|
||||
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
delete command;
|
||||
if (!mShuttingDown)
|
||||
{
|
||||
var poppedCmd = mCommandQueue.PopFront();
|
||||
Debug.Assert(poppedCmd == command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mBfSystem.Unlock();
|
||||
|
||||
if (didPassInstanceAlloc)
|
||||
delete passInstance;
|
||||
}
|
||||
|
||||
void HandleOptions(BfProject hotBfProject, int32 hotIdx)
|
||||
{
|
||||
//Debug.WriteLine("HandleOptions");
|
||||
|
||||
var options = IDEApp.sApp.GetCurWorkspaceOptions();
|
||||
|
||||
bool enableObjectDebugFlags = options.mEnableObjectDebugFlags;
|
||||
bool emitObjectAccessCheck = options.mEmitObjectAccessCheck && enableObjectDebugFlags;
|
||||
|
||||
OptionFlags optionFlags = default;
|
||||
void SetOpt(bool val, OptionFlags optionFlag)
|
||||
{
|
||||
if (val)
|
||||
optionFlags |= optionFlag;
|
||||
//Debug.WriteLine(" SetOpt {0:X} {1:X}", (int)optionFlags, (int)optionFlag);
|
||||
}
|
||||
|
||||
SetOpt(options.mIncrementalBuild, .IncrementalBuild);
|
||||
SetOpt(options.mEmitDebugInfo == .Yes, .EmitDebugInfo);
|
||||
SetOpt((options.mEmitDebugInfo == .Yes) || (options.mEmitDebugInfo == .LinesOnly), .EmitLineInfo);
|
||||
if (gApp.mConfig_NoIR)
|
||||
{
|
||||
SetOpt(true, .GenerateOBJ);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetOpt((options.mIntermediateType == .IRCode) || (options.mIntermediateType == .ObjectAndIRCode), .WriteIR);
|
||||
SetOpt((options.mIntermediateType == .Object) || (options.mIntermediateType == .ObjectAndIRCode), .GenerateOBJ);
|
||||
}
|
||||
SetOpt(options.mNoOmitFramePointers, .NoFramePointerElim);
|
||||
SetOpt(options.mInitLocalVariables, .ClearLocalVars);
|
||||
SetOpt(options.mRuntimeChecks, .RuntimeChecks);
|
||||
SetOpt(options.mEmitDynamicCastCheck, .EmitDynamicCastCheck);
|
||||
SetOpt(enableObjectDebugFlags, .EnableObjectDebugFlags);
|
||||
SetOpt(emitObjectAccessCheck, .EmitObjectAccessCheck);
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
SetOpt(options.mEnableRealtimeLeakCheck, .EnableRealtimeLeakCheck);
|
||||
#endif
|
||||
SetOpt(options.mEnableSideStack, .EnableSideStack);
|
||||
#if !CLI
|
||||
SetOpt(options.mAllowHotSwapping, .EnableHotSwapping);
|
||||
#endif
|
||||
|
||||
String mallocLinkName;
|
||||
String freeLinkName;
|
||||
switch (options.mAllocType)
|
||||
{
|
||||
case .Debug:
|
||||
optionFlags |= .DebugAlloc;
|
||||
mallocLinkName = "";
|
||||
freeLinkName = "";
|
||||
case .CRT:
|
||||
mallocLinkName = "malloc";
|
||||
freeLinkName = "free";
|
||||
case .JEMalloc:
|
||||
mallocLinkName = "je_malloc";
|
||||
freeLinkName = "je_free";
|
||||
case .TCMalloc:
|
||||
mallocLinkName = "tcmalloc";
|
||||
freeLinkName = "tcfree";
|
||||
case .Custom:
|
||||
mallocLinkName = options.mAllocMalloc;
|
||||
freeLinkName = options.mAllocFree;
|
||||
}
|
||||
|
||||
//Debug.WriteLine("HandleOptions SetOptions:{0:X}", (int)optionFlags);
|
||||
|
||||
SetOptions(hotBfProject, hotIdx,
|
||||
(int32)options.mMachineType, (int32)options.mToolsetType, (int32)options.mBfSIMDSetting, (int32)options.mAllocStackTraceDepth, (int32)gApp.mSettings.mCompilerSettings.mWorkerThreads,
|
||||
optionFlags, mallocLinkName, freeLinkName);
|
||||
|
||||
if (!mIsResolveOnly)
|
||||
{
|
||||
for (let typeOption in gApp.mWorkspace.mBeefGlobalOptions.mDistinctBuildOptions)
|
||||
mBfSystem.AddTypeOptions(typeOption);
|
||||
for (let typeOption in options.mDistinctBuildOptions)
|
||||
mBfSystem.AddTypeOptions(typeOption);
|
||||
}
|
||||
}
|
||||
|
||||
public override void StartQueueProcessThread()
|
||||
{
|
||||
// This causes the current view to do a full refresh every keystroke.
|
||||
// I think it's not needed...
|
||||
//mWantsActiveViewRefresh = true;
|
||||
base.StartQueueProcessThread();
|
||||
}
|
||||
|
||||
public override void RequestCancelBackground()
|
||||
{
|
||||
if ([Friend]mThreadWorker.mThreadRunning)
|
||||
{
|
||||
/*if (gApp.mMainWindow.IsKeyDown(.Control))
|
||||
{
|
||||
NOP!();
|
||||
}*/
|
||||
if (mNativeBfCompiler != null)
|
||||
BfCompiler_Cancel(mNativeBfCompiler);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearCompletionPercentage()
|
||||
{
|
||||
BfCompiler_ClearCompletionPercentage(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public float GetCompletionPercentage()
|
||||
{
|
||||
return BfCompiler_GetCompletionPercentage(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public int32 GetCompileRevision()
|
||||
{
|
||||
return BfCompiler_GetCompileRevision(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public void GetTypeDefList(String outStr)
|
||||
{
|
||||
outStr.Append(BfCompiler_GetTypeDefList(mNativeBfCompiler));
|
||||
}
|
||||
|
||||
public void GetTypeDefMatches(String searchStr, String outStr)
|
||||
{
|
||||
outStr.Append(BfCompiler_GetTypeDefMatches(mNativeBfCompiler, searchStr));
|
||||
}
|
||||
|
||||
public void GetTypeDefInfo(String typeDefName, String outStr)
|
||||
{
|
||||
outStr.Append(BfCompiler_GetTypeDefInfo(mNativeBfCompiler, typeDefName));
|
||||
}
|
||||
|
||||
public void ClearBuildCache()
|
||||
{
|
||||
BfCompiler_ClearBuildCache(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public bool GetHasHotPendingDataChanges()
|
||||
{
|
||||
return BfCompiler_GetHasHotPendingDataChanges(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public void HotCommit()
|
||||
{
|
||||
BfCompiler_HotCommit(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public void HotResolve_Start(HotResolveFlags flags)
|
||||
{
|
||||
BfCompiler_HotResolve_Start(mNativeBfCompiler, (.)flags);
|
||||
}
|
||||
|
||||
public void HotResolve_AddActiveMethod(char8* methodName)
|
||||
{
|
||||
BfCompiler_HotResolve_AddActiveMethod(mNativeBfCompiler, methodName);
|
||||
}
|
||||
|
||||
public void HotResolve_AddDelegateMethod(char8* methodName)
|
||||
{
|
||||
BfCompiler_HotResolve_AddDelegateMethod(mNativeBfCompiler, methodName);
|
||||
}
|
||||
|
||||
public void HotResolve_ReportType(int typeId, HotTypeFlags flags)
|
||||
{
|
||||
BfCompiler_HotResolve_ReportType(mNativeBfCompiler, typeId, (int32)flags);
|
||||
}
|
||||
|
||||
public void HotResolve_ReportTypeRange(char8* typeName, HotTypeFlags flags)
|
||||
{
|
||||
BfCompiler_HotResolve_ReportTypeRange(mNativeBfCompiler, typeName, (int32)flags);
|
||||
}
|
||||
|
||||
public void HotResolve_Finish(String result)
|
||||
{
|
||||
char8* resultCStr = BfCompiler_HotResolve_Finish(mNativeBfCompiler);
|
||||
result.Append(resultCStr);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (!ThreadRunning)
|
||||
{
|
||||
if (mWantsRemoveOldData)
|
||||
{
|
||||
mBfSystem.RemoveOldData();
|
||||
mWantsRemoveOldData = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
352
IDE/src/Compiler/BfParser.bf
Normal file
352
IDE/src/Compiler/BfParser.bf
Normal file
|
@ -0,0 +1,352 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using Beefy.widgets;
|
||||
using Beefy.utils;
|
||||
using IDE.ui;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public enum BfSourceElementType : uint8
|
||||
{
|
||||
Normal,
|
||||
Keyword,
|
||||
Literal,
|
||||
Identifier,
|
||||
Type,
|
||||
Comment,
|
||||
Method,
|
||||
TypeRef
|
||||
}
|
||||
|
||||
public enum ResolveType
|
||||
{
|
||||
None,
|
||||
Classify,
|
||||
ClassifyFullRefresh,
|
||||
Autocomplete,
|
||||
Autocomplete_HighPri,
|
||||
GoToDefinition,
|
||||
GetSymbolInfo,
|
||||
RenameSymbol,
|
||||
ShowFileSymbolReferences,
|
||||
GetNavigationData,
|
||||
GetCurrentLocation,
|
||||
GetFixits,
|
||||
GetTypeDefList,
|
||||
GetTypeDefInto,
|
||||
GetVarType
|
||||
}
|
||||
|
||||
public class ResolveParams
|
||||
{
|
||||
public ResolveType mResolveType;
|
||||
public int32 mOverrideCursorPos = -1;
|
||||
public bool mInDeferredList;
|
||||
|
||||
public int32 mLocalId = -1;
|
||||
public String mReplaceStr ~ delete _;
|
||||
public String mTypeDef ~ delete _;
|
||||
public int32 mFieldIdx = -1;
|
||||
public int32 mMethodIdx = -1;
|
||||
public int32 mPropertyIdx = -1;
|
||||
public int32 mTypeGenericParamIdx = -1;
|
||||
public int32 mMethodGenericParamIdx = -1;
|
||||
|
||||
public String mOutFileName ~ delete _;
|
||||
public int32 mOutLine;
|
||||
public int32 mOutLineChar;
|
||||
public String mNavigationData ~ delete _;
|
||||
public String mAutocompleteInfo ~ delete _;
|
||||
public WaitEvent mWaitEvent ~ delete _;
|
||||
|
||||
public BfPassInstance mPassInstance ~ delete _;
|
||||
public EditWidgetContent.CharData[] mCharData ~ delete _;
|
||||
public IdSpan mCharIdSpan ~ _.Dispose();
|
||||
public BfParser mParser;
|
||||
public String mDocumentationName ~ delete _;
|
||||
public bool mCancelled;
|
||||
public int32 mTextVersion = -1;
|
||||
public bool mIsUserRequested;
|
||||
}
|
||||
|
||||
public class BfParser : ILeakIdentifiable
|
||||
{
|
||||
static int32 sIdx;
|
||||
public int32 mIdx = sIdx++;
|
||||
public void ToLeakString(String str)
|
||||
{
|
||||
str.AppendF("Idx:{0}", mIdx);
|
||||
}
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_DeleteParser(void* bfSystem, void* bfParser);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_SetSource(void* bfParser, char8* data, int32 length, char8* fileName);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_SetCharIdData(void* bfParser, uint8* data, int32 length);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_SetNextRevision(void* bfParser, void* nextParser);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfParser_SetCursorIdx(void* bfParser, int32 cursorIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfParser_SetAutocomplete(void* bfParser, int32 cursorIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfParser_SetIsClassifying(void* bfParser);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfParser_Parse(void* bfParser, void* bfPassInstance, bool compatMode);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfParser_Reduce(void* bfParser, void* bfPassInstance);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfParser_Format(void* bfParser, int32 formatEnd, int32 formatStart, out int32* outCharMapping);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfParser_GetDebugExpressionAt(void* bfParser, int32 cursorIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfParser_CreateResolvePassData(void* bfSystem, int32 resolveType);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfParser_BuildDefs(void* bfParser, void* bfPassInstance, void* bfResolvePassData, bool fullRefresh);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_RemoveDefs(void* bfParser);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_ClassifySource(void* bfParser, void* elementTypeArray, bool preserveFlags);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_GenerateAutoCompletionFrom(void* bfParser, int32 srcPosition);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfParser_SetCompleteParse(void* bfParser);
|
||||
|
||||
public BfSystem mSystem;
|
||||
public void* mNativeBfParser;
|
||||
public bool mIsUsed;
|
||||
public String mFileName ~ delete _;
|
||||
public ProjectSource mProjectSource;
|
||||
|
||||
public this(void* nativeBfParser)
|
||||
{
|
||||
mNativeBfParser = nativeBfParser;
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
if (mNativeBfParser != null)
|
||||
BfSystem_DeleteParser(mSystem.mNativeBfSystem, mNativeBfParser);
|
||||
}
|
||||
|
||||
public void Detach()
|
||||
{
|
||||
mNativeBfParser = null;
|
||||
}
|
||||
|
||||
public void SetSource(String data, String fileName)
|
||||
{
|
||||
if (fileName.Contains("main4.cs"))
|
||||
{
|
||||
}
|
||||
|
||||
Debug.Assert(!mIsUsed);
|
||||
mIsUsed = true;
|
||||
BfParser_SetSource(mNativeBfParser, data, (int32)data.Length, fileName);
|
||||
}
|
||||
|
||||
public void SetCharIdData(ref IdSpan char8IdData)
|
||||
{
|
||||
char8IdData.Prepare();
|
||||
uint8* data = char8IdData.mData.CArray();
|
||||
BfParser_SetCharIdData(mNativeBfParser, data, char8IdData.mLength);
|
||||
}
|
||||
|
||||
public void SetCursorIdx(int cursorIdx)
|
||||
{
|
||||
BfParser_SetCursorIdx(mNativeBfParser, (int32)cursorIdx);
|
||||
}
|
||||
|
||||
public void SetAutocomplete(int cursorIdx)
|
||||
{
|
||||
BfParser_SetAutocomplete(mNativeBfParser, (int32)cursorIdx);
|
||||
}
|
||||
|
||||
public void SetIsClassifying()
|
||||
{
|
||||
BfParser_SetIsClassifying(mNativeBfParser);
|
||||
}
|
||||
|
||||
public bool Parse(BfPassInstance passInstance, bool compatMode)
|
||||
{
|
||||
return BfParser_Parse(mNativeBfParser, passInstance.mNativeBfPassInstance, compatMode);
|
||||
}
|
||||
|
||||
public bool Reduce(BfPassInstance passInstance)
|
||||
{
|
||||
return BfParser_Reduce(mNativeBfParser, passInstance.mNativeBfPassInstance);
|
||||
}
|
||||
|
||||
public void Reformat(int formatStart, int formatEnd, out int32[] char8Mapping, String str)
|
||||
{
|
||||
int32* char8MappingPtr;
|
||||
var stringPtr = BfParser_Format(mNativeBfParser, (int32)formatStart, (int32)formatEnd, out char8MappingPtr);
|
||||
str.Append(stringPtr);
|
||||
|
||||
char8Mapping = new int32[str.Length];
|
||||
for (int32 i = 0; i < char8Mapping.Count; i++)
|
||||
char8Mapping[i] = char8MappingPtr[i];
|
||||
}
|
||||
|
||||
public bool GetDebugExpressionAt(int cursorIdx, String outExpr)
|
||||
{
|
||||
var stringPtr = BfParser_GetDebugExpressionAt(mNativeBfParser, (int32)cursorIdx);
|
||||
if (stringPtr == null)
|
||||
return false;
|
||||
outExpr.Append(stringPtr);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool BuildDefs(BfPassInstance bfPassInstance, BfResolvePassData resolvePassData, bool fullRefresh)
|
||||
{
|
||||
void* nativeResolvePassData = null;
|
||||
if (resolvePassData != null)
|
||||
nativeResolvePassData = resolvePassData.mNativeResolvePassData;
|
||||
return BfParser_BuildDefs(mNativeBfParser, bfPassInstance.mNativeBfPassInstance, nativeResolvePassData, fullRefresh);
|
||||
}
|
||||
|
||||
public void RemoveDefs()
|
||||
{
|
||||
BfParser_RemoveDefs(mNativeBfParser);
|
||||
}
|
||||
|
||||
public void ClassifySource(EditWidgetContent.CharData[] char8Data, bool preserveFlags)
|
||||
{
|
||||
EditWidgetContent.CharData* char8DataPtr = char8Data.CArray();
|
||||
BfParser_ClassifySource(mNativeBfParser, char8DataPtr, preserveFlags);
|
||||
}
|
||||
|
||||
public void SetNextRevision(BfParser nextRevision)
|
||||
{
|
||||
BfParser_SetNextRevision(mNativeBfParser, nextRevision.mNativeBfParser);
|
||||
}
|
||||
|
||||
public void GenerateAutoCompletionFrom(int32 srcPosition)
|
||||
{
|
||||
BfParser_GenerateAutoCompletionFrom(mNativeBfParser, srcPosition);
|
||||
}
|
||||
|
||||
public BfResolvePassData CreateResolvePassData(ResolveType resolveType = ResolveType.Autocomplete)
|
||||
{
|
||||
var resolvePassData = new BfResolvePassData();
|
||||
resolvePassData.mNativeResolvePassData = BfParser_CreateResolvePassData(mNativeBfParser, (int32)resolveType);
|
||||
return resolvePassData;
|
||||
}
|
||||
|
||||
public void ReformatInto(SourceEditWidget editWidget, int formatStart, int formatEnd, uint8 orFlags = 0)
|
||||
{
|
||||
var editWidgetContent = (SourceEditWidgetContent)editWidget.Content;
|
||||
|
||||
/*let origText = scope String();
|
||||
editWidget.GetText(origText);
|
||||
File.WriteAllText(@"c:\temp\orig.txt", origText);*/
|
||||
|
||||
int32[] char8Mapping;
|
||||
String newText = scope String();
|
||||
Reformat(formatStart, formatEnd, out char8Mapping, newText);
|
||||
defer delete char8Mapping;
|
||||
|
||||
//File.WriteAllText(@"c:\temp\new.txt", newText);
|
||||
|
||||
SourceEditBatchHelper sourceEditBatchHelper = scope SourceEditBatchHelper(editWidget, "format");
|
||||
|
||||
int32 insertCount = 0;
|
||||
int32 deleteCount = 0;
|
||||
|
||||
int32 insertChars = 0;
|
||||
int32 deleteChars = 0;
|
||||
|
||||
int32 insertStartIdx = -1;
|
||||
int32 expectedOldIdx = 0;
|
||||
for (int32 i = 0; i < char8Mapping.Count; i++)
|
||||
{
|
||||
int32 oldIdx = (int32)char8Mapping[i];
|
||||
|
||||
if ((oldIdx != -1) && (insertStartIdx != -1))
|
||||
{
|
||||
// Finish inserting
|
||||
editWidgetContent.CursorTextPos = insertStartIdx;
|
||||
|
||||
String insertString = scope String();
|
||||
//newText.Substring(insertStartIdx, i - insertStartIdx, insertString);
|
||||
insertString.Append(newText, insertStartIdx, i - insertStartIdx);
|
||||
var insertTextAction = new EditWidgetContent.InsertTextAction(editWidgetContent, insertString, .None);
|
||||
insertTextAction.mMoveCursor = false;
|
||||
editWidgetContent.mData.mUndoManager.Add(insertTextAction);
|
||||
|
||||
editWidgetContent.PhysInsertAtCursor(insertString, false);
|
||||
|
||||
if (orFlags != 0)
|
||||
{
|
||||
for (int32 idx = insertStartIdx; idx < i; idx++)
|
||||
editWidgetContent.mData.mText[idx].mDisplayFlags |= orFlags;
|
||||
}
|
||||
|
||||
insertStartIdx = -1;
|
||||
insertCount++;
|
||||
insertChars += (int32)insertString.Length;
|
||||
}
|
||||
|
||||
if (oldIdx == expectedOldIdx)
|
||||
{
|
||||
expectedOldIdx++;
|
||||
continue;
|
||||
}
|
||||
else if (oldIdx == -1)
|
||||
{
|
||||
if (insertStartIdx == -1)
|
||||
insertStartIdx = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(oldIdx > expectedOldIdx); // This fails if we have the same ID occur multiple times, or we reorder nodes
|
||||
if (oldIdx <= expectedOldIdx)
|
||||
break; // Error - abort
|
||||
|
||||
int32 charsToDelete = oldIdx - expectedOldIdx;
|
||||
editWidgetContent.CursorTextPos = i;
|
||||
var deleteCharAction = new EditWidgetContent.DeleteCharAction(editWidgetContent, 0, charsToDelete);
|
||||
deleteCharAction.mMoveCursor = false;
|
||||
editWidgetContent.mData.mUndoManager.Add(deleteCharAction);
|
||||
editWidgetContent.PhysDeleteChars(0, charsToDelete);
|
||||
expectedOldIdx = oldIdx + 1;
|
||||
deleteCount++;
|
||||
deleteChars += charsToDelete;
|
||||
}
|
||||
}
|
||||
|
||||
editWidgetContent.ContentChanged();
|
||||
Debug.WriteLine("Reformat {0} inserts, total of {1} chars. {2} deletes, total of {3} chars.", insertCount, insertChars, deleteCount, deleteChars);
|
||||
|
||||
sourceEditBatchHelper.Finish();
|
||||
}
|
||||
|
||||
public void SetCompleteParse()
|
||||
{
|
||||
BfParser_SetCompleteParse(mNativeBfParser);
|
||||
}
|
||||
}
|
||||
}
|
145
IDE/src/Compiler/BfPassInstance.bf
Normal file
145
IDE/src/Compiler/BfPassInstance.bf
Normal file
|
@ -0,0 +1,145 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using Beefy.utils;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public class BfPassInstance
|
||||
{
|
||||
[StdCall, CLink]
|
||||
static extern void BfPassInstance_Delete(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfPassInstance_PopOutString(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfPassInstance_SetClassifierPassId(void* bfResolvePassData, uint8 classifierPassId);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern int32 BfPassInstance_GetErrorCount(void* mNativeResolvePassData);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfPassInstance_GetErrorData(void* mNativeResolvePassData, int32 errorIdx, out bool isWarning,
|
||||
out bool isAfter, out bool isDeferred, out bool isWhileSpecializing,
|
||||
out bool isPersistent, out int32 srcStart, out int32 srcEnd, out int32 moreInfoCount);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfPassInstance_Error_GetMoreInfoData(void* mNativeResolvePassData, int32 errorIdx, int32 moreInfoIdx, out char8* fileName, out int32 srcStart, out int32 srcEnd);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern bool BfPassInstance_HadSignatureChanges(void* mNativeResolvePassData);
|
||||
|
||||
public class BfError
|
||||
{
|
||||
public bool mIsWarning;
|
||||
public bool mIsAfter;
|
||||
public bool mIsDeferred;
|
||||
public bool mIsWhileSpecializing;
|
||||
public bool mIsPersistent;
|
||||
public String mError ~ delete _;
|
||||
public int32 mSrcStart;
|
||||
public int32 mSrcEnd;
|
||||
public int32 mMoreInfoCount;
|
||||
public bool mOwnsSpan;
|
||||
public IdSpan mIdSpan ~ { if (mOwnsSpan) _.Dispose(); };
|
||||
public int32 mErrorIdx = -1;
|
||||
public String mFileName ~ delete _;
|
||||
public List<BfError> mMoreInfo ~ DeleteContainerAndItems!(_);
|
||||
}
|
||||
|
||||
static public List<BfPassInstance> sPassInstances = new List<BfPassInstance>() ~ delete _;
|
||||
static Monitor sMonitor = new Monitor() ~ delete _;
|
||||
static int32 sCurId;
|
||||
|
||||
public void* mNativeBfPassInstance;
|
||||
public bool mDidCompile;
|
||||
public bool mCompileSucceeded;
|
||||
public bool mIsDisposed;
|
||||
public bool mFailed;
|
||||
|
||||
public int32 mId = sCurId++;
|
||||
internal String mDbgStr ~ delete _;
|
||||
|
||||
public this(void* nativePassInstance)
|
||||
{
|
||||
mNativeBfPassInstance = nativePassInstance;
|
||||
|
||||
using (sMonitor.Enter())
|
||||
{
|
||||
sPassInstances.Add(this);
|
||||
}
|
||||
|
||||
//Debug.Assert(sPassInstances.Count <= 5);
|
||||
Debug.Assert(sPassInstances.Count <= 4);
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
Debug.Assert(!mIsDisposed);
|
||||
|
||||
using (sMonitor.Enter())
|
||||
{
|
||||
sPassInstances.Remove(this);
|
||||
}
|
||||
|
||||
mIsDisposed = true;
|
||||
BfPassInstance_Delete(mNativeBfPassInstance);
|
||||
mNativeBfPassInstance = null;
|
||||
|
||||
if (mFailed)
|
||||
{
|
||||
NOP!();
|
||||
}
|
||||
}
|
||||
|
||||
public bool PopOutString(String outStr)
|
||||
{
|
||||
char8* strVal = BfPassInstance_PopOutString(mNativeBfPassInstance);
|
||||
if (strVal == null)
|
||||
return false;
|
||||
outStr.Append(strVal);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetClassifierPassId(uint8 classifierPassId)
|
||||
{
|
||||
BfPassInstance_SetClassifierPassId(mNativeBfPassInstance, classifierPassId);
|
||||
}
|
||||
|
||||
public int32 GetErrorCount()
|
||||
{
|
||||
return BfPassInstance_GetErrorCount(mNativeBfPassInstance);
|
||||
}
|
||||
|
||||
public void GetErrorData(int32 errorIdx, BfError bfError)
|
||||
{
|
||||
Debug.Assert(bfError.mError == null);
|
||||
bfError.mErrorIdx = errorIdx;
|
||||
bfError.mError = new String(BfPassInstance_GetErrorData(mNativeBfPassInstance, errorIdx, out bfError.mIsWarning, out bfError.mIsAfter, out bfError.mIsDeferred,
|
||||
out bfError.mIsWhileSpecializing, out bfError.mIsPersistent, out bfError.mSrcStart, out bfError.mSrcEnd, out bfError.mMoreInfoCount));
|
||||
}
|
||||
|
||||
public void GetMoreInfoErrorData(int32 errorIdx, int32 moreInfoIdx, BfError bfError)
|
||||
{
|
||||
char8* fileName = null;
|
||||
char8* errorStr = BfPassInstance_Error_GetMoreInfoData(mNativeBfPassInstance, errorIdx, moreInfoIdx, out fileName, out bfError.mSrcStart, out bfError.mSrcEnd);
|
||||
Debug.Assert(bfError.mFileName == null);
|
||||
if (fileName != null)
|
||||
bfError.mFileName = new String(fileName);
|
||||
if (bfError.mError == null)
|
||||
bfError.mError = new String(errorStr);
|
||||
else
|
||||
bfError.mError.Append(errorStr);
|
||||
}
|
||||
|
||||
public bool HadSignatureChanges()
|
||||
{
|
||||
return BfPassInstance_HadSignatureChanges(mNativeBfPassInstance);
|
||||
}
|
||||
}
|
||||
}
|
62
IDE/src/Compiler/BfProject.bf
Normal file
62
IDE/src/Compiler/BfProject.bf
Normal file
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public class BfProject
|
||||
{
|
||||
[StdCall, CLink]
|
||||
extern static void BfProject_Delete(void* nativeBfProject);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfProject_ClearDependencies(void* nativeBfProject);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfProject_AddDependency(void* nativeBfProject, void* nativeDepProject);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfProject_SetDisabled(void* nativeBfProject, bool disabled);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfProject_SetOptions(void* nativeBfProject, int32 targetType, char8* startupObject, char8* preprocessorMacros,
|
||||
int32 optLevel, int32 ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP);
|
||||
|
||||
public void* mNativeBfProject;
|
||||
public bool mDisabled;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
BfProject_Delete(mNativeBfProject);
|
||||
}
|
||||
|
||||
public void ClearDependencies()
|
||||
{
|
||||
BfProject_ClearDependencies(mNativeBfProject);
|
||||
}
|
||||
|
||||
public void AddDependency(BfProject depProject)
|
||||
{
|
||||
BfProject_AddDependency(mNativeBfProject, depProject.mNativeBfProject);
|
||||
}
|
||||
|
||||
public void SetDisabled(bool disabled)
|
||||
{
|
||||
mDisabled = disabled;
|
||||
BfProject_SetDisabled(mNativeBfProject, disabled);
|
||||
}
|
||||
|
||||
public void SetOptions(Project.TargetType targetType, String startupObject, List<String> preprocessorMacros,
|
||||
BuildOptions.BfOptimizationLevel optLevel, BuildOptions.LTOType ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP)
|
||||
{
|
||||
String macrosStr = scope String();
|
||||
macrosStr.Join("\n", preprocessorMacros.GetEnumerator());
|
||||
BfProject_SetOptions(mNativeBfProject, (int32)targetType, startupObject, macrosStr,
|
||||
(int32)optLevel, (int32)ltoType, mergeFunctions, combineLoads, vectorizeLoops, vectorizeSLP);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
129
IDE/src/Compiler/BfResolveHelper.bf
Normal file
129
IDE/src/Compiler/BfResolveHelper.bf
Normal file
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Beefy;
|
||||
using IDE.ui;
|
||||
using System.IO;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public class BfResolveHelper
|
||||
{
|
||||
class DeferredReparseEntry
|
||||
{
|
||||
public int32 mWaitTicks;
|
||||
public String mFilePath ~ delete _;
|
||||
public SourceViewPanel mExludeSourceViewPanel;
|
||||
}
|
||||
|
||||
List<DeferredReparseEntry> mDeferredReparses = new List<DeferredReparseEntry>() ~ DeleteContainerAndItems!(_);
|
||||
int32 mVisibleViewRefreshWaitTicks;
|
||||
SourceViewPanel mVisibleViewRefreshExcludeSourceView;
|
||||
|
||||
public void SourceViewPanelClosed(SourceViewPanel sourceViewPanel)
|
||||
{
|
||||
if (mVisibleViewRefreshExcludeSourceView == sourceViewPanel)
|
||||
mVisibleViewRefreshExcludeSourceView = null;
|
||||
|
||||
for (var entry in mDeferredReparses)
|
||||
{
|
||||
if (entry.mExludeSourceViewPanel == sourceViewPanel)
|
||||
entry.mExludeSourceViewPanel = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ProjectSourceRemoved(ProjectSource projectSource)
|
||||
{
|
||||
// Don't need to do anything
|
||||
}
|
||||
|
||||
public void DeferRefreshVisibleViews(SourceViewPanel sourceViewPanel)
|
||||
{
|
||||
if (mVisibleViewRefreshWaitTicks == 0)
|
||||
{
|
||||
mVisibleViewRefreshWaitTicks = 30;
|
||||
mVisibleViewRefreshExcludeSourceView = sourceViewPanel;
|
||||
}
|
||||
else
|
||||
{
|
||||
mVisibleViewRefreshWaitTicks = 30;
|
||||
if (mVisibleViewRefreshExcludeSourceView != sourceViewPanel)
|
||||
{
|
||||
// We already had another soruceView that queued up a refresh
|
||||
// so remove the exclusion
|
||||
mVisibleViewRefreshExcludeSourceView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeferReparse(String fileName, SourceViewPanel excludeSourceVewPanel)
|
||||
{
|
||||
DeferRefreshVisibleViews(excludeSourceVewPanel);
|
||||
|
||||
for (var entry in mDeferredReparses)
|
||||
{
|
||||
if (Path.Equals(entry.mFilePath, fileName))
|
||||
{
|
||||
if (entry.mExludeSourceViewPanel != excludeSourceVewPanel)
|
||||
entry.mExludeSourceViewPanel = null; // Reparse them all
|
||||
entry.mWaitTicks = 30;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var newEntry = new DeferredReparseEntry();
|
||||
newEntry.mFilePath = new String(fileName);
|
||||
newEntry.mExludeSourceViewPanel = excludeSourceVewPanel;
|
||||
newEntry.mWaitTicks = 30;
|
||||
mDeferredReparses.Add(newEntry);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
var app = IDEApp.sApp;
|
||||
|
||||
if ((mVisibleViewRefreshWaitTicks > 0) && (--mVisibleViewRefreshWaitTicks == 0))
|
||||
{
|
||||
if (!app.mBfResolveCompiler.IsPerformingBackgroundOperation())
|
||||
{
|
||||
app.RefreshVisibleViews(mVisibleViewRefreshExcludeSourceView);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try again next tick
|
||||
mVisibleViewRefreshWaitTicks = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mDeferredReparses.Count > 0)
|
||||
{
|
||||
var entry = mDeferredReparses[0];
|
||||
if ((--entry.mWaitTicks <= 0) && (!app.mBfResolveCompiler.IsPerformingBackgroundOperation()))
|
||||
{
|
||||
bool needsResolveAll = false;
|
||||
app.mWorkspace.WithProjectItems(scope [&] (projectItem) =>
|
||||
{
|
||||
var projectSource = projectItem as ProjectSource;
|
||||
if ((projectSource != null) &&
|
||||
((entry.mExludeSourceViewPanel == null) || (projectSource != entry.mExludeSourceViewPanel.mProjectSource)))
|
||||
{
|
||||
var fullPath = scope String();
|
||||
projectSource.GetFullImportPath(fullPath);
|
||||
if (Path.Equals(fullPath, entry.mFilePath))
|
||||
{
|
||||
app.mBfResolveCompiler.QueueProjectSource(projectSource);
|
||||
needsResolveAll = true;
|
||||
DeferRefreshVisibleViews(entry.mExludeSourceViewPanel);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (needsResolveAll)
|
||||
app.mBfResolveCompiler.QueueDeferredResolveAll();
|
||||
mDeferredReparses.RemoveAt(0);
|
||||
delete entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
97
IDE/src/Compiler/BfResolvePassData.bf
Normal file
97
IDE/src/Compiler/BfResolvePassData.bf
Normal file
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public class BfResolvePassData
|
||||
{
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_Delete(void* bfResolvePassData);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetLocalId(void* bfResolvePassData, int32 localId);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetTypeGenericParamIdx(void* resolvePassData, int typeGenericParamIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetMethodGenericParamIdx(void* resolvePassData, int typeGenericParamIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetSymbolReferenceTypeDef(void* bfResolvePassData, char8* replaceStr);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetSymbolReferenceFieldIdx(void* bfResolvePassData, int32 fieldIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetSymbolReferenceMethodIdx(void* bfResolvePassData, int32 methodIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetSymbolReferencePropertyIdx(void* bfResolvePassData, int32 propertyIdx);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfResolvePassData_SetDocumentationRequest(void* bfResolvePassData, char8* entryName);
|
||||
|
||||
//
|
||||
|
||||
//[StdCall, CLink]
|
||||
//static extern void* BfParser_CreateResolvePassData(void* bfSystem, int32 resolveType);
|
||||
|
||||
public void* mNativeResolvePassData;
|
||||
|
||||
public ~this()
|
||||
{
|
||||
BfResolvePassData_Delete(mNativeResolvePassData);
|
||||
}
|
||||
|
||||
public void SetLocalId(int32 localId)
|
||||
{
|
||||
BfResolvePassData_SetLocalId(mNativeResolvePassData, localId);
|
||||
}
|
||||
|
||||
public void SetTypeGenericParamIdx(int32 genericParamIdx)
|
||||
{
|
||||
BfResolvePassData_SetTypeGenericParamIdx(mNativeResolvePassData, genericParamIdx);
|
||||
}
|
||||
|
||||
public void SetMethodGenericParamIdx(int32 genericParamIdx)
|
||||
{
|
||||
BfResolvePassData_SetMethodGenericParamIdx(mNativeResolvePassData, genericParamIdx);
|
||||
}
|
||||
|
||||
public void SetSymbolReferenceTypeDef(String typeDefName)
|
||||
{
|
||||
BfResolvePassData_SetSymbolReferenceTypeDef(mNativeResolvePassData, typeDefName);
|
||||
}
|
||||
|
||||
public void SetSymbolReferenceFieldIdx(int32 fieldIdx)
|
||||
{
|
||||
BfResolvePassData_SetSymbolReferenceFieldIdx(mNativeResolvePassData, fieldIdx);
|
||||
}
|
||||
|
||||
public void SetSymbolReferenceMethodIdx(int32 methodIdx)
|
||||
{
|
||||
BfResolvePassData_SetSymbolReferenceMethodIdx(mNativeResolvePassData, methodIdx);
|
||||
}
|
||||
|
||||
public void SetSymbolReferencePropertyIdx(int32 propertyIdx)
|
||||
{
|
||||
BfResolvePassData_SetSymbolReferencePropertyIdx(mNativeResolvePassData, propertyIdx);
|
||||
}
|
||||
|
||||
public void SetDocumentationRequest(String entryName)
|
||||
{
|
||||
BfResolvePassData_SetDocumentationRequest(mNativeResolvePassData, entryName);
|
||||
}
|
||||
|
||||
public static BfResolvePassData Create(ResolveType resolveType = ResolveType.Autocomplete)
|
||||
{
|
||||
var resolvePassData = new BfResolvePassData();
|
||||
resolvePassData.mNativeResolvePassData = BfParser.[Friend]BfParser_CreateResolvePassData(null, (int32)resolveType);
|
||||
return resolvePassData;
|
||||
}
|
||||
}
|
||||
}
|
365
IDE/src/Compiler/BfSystem.bf
Normal file
365
IDE/src/Compiler/BfSystem.bf
Normal file
|
@ -0,0 +1,365 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public class BfSystem
|
||||
{
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_CheckLock(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_Create();
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_Delete(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_ReportMemory(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_Update(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_CreatePassInstance(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern char8* BfSystem_GetNamespaceSearch(void* bfSystem, char8* typeName, void* project);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_CreateProject(void* bfSystem, char8* projectName);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_ClearTypeOptions(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void BfSystem_AddTypeOptions(void* bfSystem, char8* filter, int32 simdSetting, int32 optimizationLevel, int32 emitDebugInfo, int32 runtimeChecks,
|
||||
int32 initLocalVariables, int32 emitDynamicCastCheck, int32 emitObjectAccessCheck, int32 allocStackTraceDepth);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_CreateParser(void* bfSystem, void* bfProject);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_CreateCompiler(void* bfSystem, bool isResolveOnly = false);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_RemoveDeletedParsers(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_RemoveOldParsers(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_RemoveOldData(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_NotifyWillRequestLock(void* bfSystem, int32 priority);
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_Lock(void* bfSystem, int32 priority);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfSystem_PerfZoneStart(char8* name);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfSystem_PerfZoneEnd();
|
||||
|
||||
[StdCall, CLink]
|
||||
static extern void* BfSystem_Unlock(void* bfSystem);
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfSystem_StartTiming();
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfSystem_StopTiming();
|
||||
|
||||
[StdCall, CLink]
|
||||
extern static void BfSystem_DbgPrintTimings();
|
||||
|
||||
public void* mNativeBfSystem;
|
||||
public bool mIsTiming;
|
||||
public Monitor mMonitor = new Monitor() ~ delete _;
|
||||
|
||||
public Dictionary<ProjectSource, BfParser> mParserMap = new Dictionary<ProjectSource, BfParser>() ~ delete _;
|
||||
public Dictionary<Project, BfProject> mProjectMap = new Dictionary<Project, BfProject>() ~ delete _;
|
||||
|
||||
public this()
|
||||
{
|
||||
mNativeBfSystem = BfSystem_Create();
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
for (var parser in mParserMap.Values)
|
||||
delete parser;
|
||||
for (var bfProject in mProjectMap.Values)
|
||||
delete bfProject;
|
||||
BfSystem_Delete(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void CheckLock()
|
||||
{
|
||||
BfSystem_CheckLock(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
BfSystem_Update(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void ReportMemory()
|
||||
{
|
||||
BfSystem_ReportMemory(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void AddProject(Project project)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
var bfProject = CreateProject(project.mProjectName);
|
||||
mProjectMap[project] = bfProject;
|
||||
}
|
||||
}
|
||||
|
||||
public BfProject GetBfProject(Project project)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
return mProjectMap[project];
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveBfProject(Project project)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
mProjectMap.Remove(project);
|
||||
}
|
||||
}
|
||||
|
||||
public BfPassInstance CreatePassInstance(String dbgStr = null)
|
||||
{
|
||||
void* nativePassInstance = BfSystem_CreatePassInstance(mNativeBfSystem);
|
||||
BfPassInstance passInstance = new BfPassInstance(nativePassInstance);
|
||||
if (dbgStr != null)
|
||||
passInstance.mDbgStr = new String(dbgStr);
|
||||
return passInstance;
|
||||
}
|
||||
|
||||
public BfParser CreateEmptyParser(BfProject bfProject)
|
||||
{
|
||||
void* nativeBfProject = (bfProject == null) ? null : bfProject.mNativeBfProject;
|
||||
void* nativeBfParser = BfSystem_CreateParser(mNativeBfSystem, nativeBfProject);
|
||||
BfParser parser = new BfParser(nativeBfParser);
|
||||
parser.mSystem = this;
|
||||
return parser;
|
||||
}
|
||||
|
||||
public void GetNamespaceSearch(String typeName, String outNamespaceSearch, BfProject project)
|
||||
{
|
||||
char8* namespaceSearch = BfSystem_GetNamespaceSearch(mNativeBfSystem, typeName, project.mNativeBfProject);
|
||||
if (namespaceSearch != null)
|
||||
outNamespaceSearch.Append(namespaceSearch);
|
||||
}
|
||||
|
||||
public BfProject CreateProject(String projectName)
|
||||
{
|
||||
BfProject project = new BfProject();
|
||||
project.mNativeBfProject = BfSystem_CreateProject(mNativeBfSystem, projectName);
|
||||
return project;
|
||||
}
|
||||
|
||||
/*public bool HasParser(string fileName)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
return mParserMap.ContainsKey(fileName);
|
||||
}
|
||||
}*/
|
||||
|
||||
public BfParser CreateParser(ProjectSource projectSource, bool useMap = true)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
BfParser parser;
|
||||
if (!useMap)
|
||||
{
|
||||
parser = CreateEmptyParser(mProjectMap[projectSource.mProject]);
|
||||
parser.mProjectSource = projectSource;
|
||||
parser.mFileName = new String();
|
||||
projectSource.GetFullImportPath(parser.mFileName);
|
||||
return parser;
|
||||
}
|
||||
|
||||
BfParser prevParser;
|
||||
mParserMap.TryGetValue(projectSource, out prevParser);
|
||||
|
||||
parser = CreateEmptyParser(mProjectMap[projectSource.mProject]);
|
||||
parser.mSystem = this;
|
||||
parser.mProjectSource = projectSource;
|
||||
parser.mFileName = new String();
|
||||
projectSource.GetFullImportPath(parser.mFileName);
|
||||
mParserMap[projectSource] = parser;
|
||||
if (prevParser != null)
|
||||
{
|
||||
prevParser.SetNextRevision(parser);
|
||||
prevParser.Detach();
|
||||
delete prevParser;
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
}
|
||||
|
||||
public BfParser CreateNewParserRevision(BfParser prevParser)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
BfParser parser = CreateEmptyParser(mProjectMap[prevParser.mProjectSource.mProject]);
|
||||
parser.mFileName = new String(prevParser.mFileName);
|
||||
parser.mProjectSource = prevParser.mProjectSource;
|
||||
mParserMap[parser.mProjectSource] = parser;
|
||||
if (prevParser != null)
|
||||
{
|
||||
prevParser.SetNextRevision(parser);
|
||||
prevParser.Detach();
|
||||
delete prevParser;
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
}
|
||||
|
||||
public void FileRenamed(ProjectSource projectSource, String oldFileName, String newFileName)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
BfParser prevParser;
|
||||
if (mParserMap.TryGetValue(projectSource, out prevParser))
|
||||
{
|
||||
prevParser.mFileName.Set(newFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BfParser FileRemoved(ProjectSource projectSource)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
BfParser prevParser = null;
|
||||
if (mParserMap.TryGetValue(projectSource, out prevParser))
|
||||
{
|
||||
//DeleteParser(prevParser);
|
||||
mParserMap.Remove(projectSource);
|
||||
}
|
||||
return prevParser;
|
||||
}
|
||||
}
|
||||
|
||||
public BfParser FindParser(ProjectSource projectSource)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
BfParser prevParser;
|
||||
mParserMap.TryGetValue(projectSource, out prevParser);
|
||||
return prevParser;
|
||||
}
|
||||
}
|
||||
|
||||
public BfCompiler CreateCompiler(bool isResolveOnly)
|
||||
{
|
||||
void* nativeBfCompiler = BfSystem_CreateCompiler(mNativeBfSystem, isResolveOnly);
|
||||
var bfCompiler = new BfCompiler(nativeBfCompiler);
|
||||
bfCompiler.mIsResolveOnly = isResolveOnly;
|
||||
bfCompiler.mBfSystem = this;
|
||||
return bfCompiler;
|
||||
}
|
||||
|
||||
public void RemoveDeletedParsers()
|
||||
{
|
||||
BfSystem_RemoveDeletedParsers(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void RemoveOldParsers()
|
||||
{
|
||||
BfSystem_RemoveOldParsers(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void RemoveOldData()
|
||||
{
|
||||
BfSystem_RemoveOldData(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void NotifyWillRequestLock(int32 priority)
|
||||
{
|
||||
BfSystem_NotifyWillRequestLock(mNativeBfSystem, priority);
|
||||
}
|
||||
|
||||
public void Lock(int32 priority)
|
||||
{
|
||||
BfSystem_Lock(mNativeBfSystem, priority);
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
BfSystem_Unlock(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void StartTiming()
|
||||
{
|
||||
mIsTiming = true;
|
||||
BfSystem_StartTiming();
|
||||
}
|
||||
|
||||
public void PerfZoneStart(String name)
|
||||
{
|
||||
BfSystem_PerfZoneStart(name);
|
||||
}
|
||||
|
||||
public void PerfZoneEnd()
|
||||
{
|
||||
BfSystem_PerfZoneEnd();
|
||||
}
|
||||
|
||||
public void StopTiming()
|
||||
{
|
||||
mIsTiming = false;
|
||||
BfSystem_StopTiming();
|
||||
}
|
||||
|
||||
public void DbgPrintTimings()
|
||||
{
|
||||
BfSystem_DbgPrintTimings();
|
||||
}
|
||||
|
||||
public void ClearTypeOptions()
|
||||
{
|
||||
BfSystem_ClearTypeOptions(mNativeBfSystem);
|
||||
}
|
||||
|
||||
public void AddTypeOptions(String filter, BuildOptions.SIMDSetting? simdSetting, BuildOptions.BfOptimizationLevel? optimizationLevel, BuildOptions.EmitDebugInfo? emitDebugInfo, bool? runtimeChecks,
|
||||
bool? initLocalVariables, bool? emitDynamicCastCheck, bool? emitObjectAccessCheck, int32? allocStackTraceDepth)
|
||||
{
|
||||
int32 simdSettingInt = (simdSetting == null) ? -1 : (int32)simdSetting.Value;
|
||||
int32 optimizationLevelInt = (optimizationLevel == null) ? -1 : (int32)optimizationLevel.Value;
|
||||
int32 emitDebugInfoInt = (emitDebugInfo == null) ? -1 : (int32)emitDebugInfo.Value;
|
||||
int32 runtimeChecksInt = (runtimeChecks == null) ? -1 : runtimeChecks.Value ? 1 : 0;
|
||||
int32 initLocalVariablesInt = (initLocalVariables == null) ? -1 : initLocalVariables.Value ? 1 : 0;
|
||||
int32 emitDynamicCastCheckInt = (emitDynamicCastCheck == null) ? -1 : emitDynamicCastCheck.Value ? 1 : 0;
|
||||
int32 emitObjectAccessCheckInt = (emitObjectAccessCheck == null) ? -1 : emitObjectAccessCheck.Value ? 1 : 0;
|
||||
int32 allocStackTraceDepthInt = (allocStackTraceDepth == null) ? -1 : allocStackTraceDepth.Value;
|
||||
BfSystem_AddTypeOptions(mNativeBfSystem, filter, simdSettingInt, optimizationLevelInt, emitDebugInfoInt, runtimeChecksInt,
|
||||
initLocalVariablesInt, emitDynamicCastCheckInt, emitObjectAccessCheckInt, allocStackTraceDepthInt);
|
||||
}
|
||||
|
||||
public void AddTypeOptions(DistinctBuildOptions typeOption)
|
||||
{
|
||||
AddTypeOptions(typeOption.mFilter, typeOption.mBfSIMDSetting, typeOption.mBfOptimizationLevel, typeOption.mEmitDebugInfo, typeOption.mRuntimeChecks,
|
||||
typeOption.mInitLocalVariables, typeOption.mEmitDynamicCastCheck, typeOption.mEmitObjectAccessCheck, typeOption.mAllocStackTraceDepth);
|
||||
}
|
||||
}
|
||||
}
|
210
IDE/src/Compiler/CompilerBase.bf
Normal file
210
IDE/src/Compiler/CompilerBase.bf
Normal file
|
@ -0,0 +1,210 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using Beefy.utils;
|
||||
using Beefy;
|
||||
using System.IO;
|
||||
|
||||
namespace IDE.Compiler
|
||||
{
|
||||
public abstract class CompilerBase : CommandQueueManager
|
||||
{
|
||||
public int32 mResolveAllWait;
|
||||
protected List<String> mQueuedOutput = new List<String>() ~ DeleteContainerAndItems!(_);
|
||||
public bool mWantsActiveViewRefresh;
|
||||
|
||||
public volatile int32 mThreadYieldCount = 0; // Whether our thread wants to be yielded to, and for how many ticks
|
||||
|
||||
protected class ResolveAllCommand : Command
|
||||
{
|
||||
}
|
||||
|
||||
protected class ProjectSourceRemovedCommand : Command
|
||||
{
|
||||
public ProjectSource mProjectSource;
|
||||
public ~this()
|
||||
{
|
||||
mProjectSource.ReleaseRef();
|
||||
}
|
||||
}
|
||||
|
||||
protected class ProjectSourceCommand : Command
|
||||
{
|
||||
public ProjectSource mProjectSource;
|
||||
public IdSpan mSourceCharIdData ~ _.Dispose();
|
||||
public String mSourceString ~ delete _;
|
||||
}
|
||||
|
||||
protected class CompileCommand : Command
|
||||
{
|
||||
public String mOutputDirectory ~ delete _;
|
||||
}
|
||||
|
||||
public void QueueCompile(String outputDirectory)
|
||||
{
|
||||
CompileCommand command = new CompileCommand();
|
||||
command.mOutputDirectory = new String(outputDirectory);
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public void QueueDeferredResolveAll()
|
||||
{
|
||||
/*if (gApp.mMainWindow.IsKeyDown(.Control))
|
||||
{
|
||||
NOP!();
|
||||
}*/
|
||||
|
||||
mResolveAllWait = 2;
|
||||
}
|
||||
|
||||
public virtual void QueueProjectSource(ProjectSource projectSource)
|
||||
{
|
||||
ProjectSourceCommand command = new ProjectSourceCommand();
|
||||
command.mProjectSource = projectSource;
|
||||
command.mSourceString = new String();
|
||||
IDEApp.sApp.FindProjectSourceContent(projectSource, out command.mSourceCharIdData, false, command.mSourceString);
|
||||
if (gApp.mBfBuildCompiler == this)
|
||||
{
|
||||
if (gApp.mDbgVersionedCompileDir != null)
|
||||
{
|
||||
String fileName = scope .();
|
||||
projectSource.GetFullImportPath(fileName);
|
||||
|
||||
String baseSrcDir = scope .();
|
||||
baseSrcDir.Append(projectSource.mProject.mProjectDir);
|
||||
baseSrcDir.Append(@"\src\");
|
||||
|
||||
if (fileName.StartsWith(baseSrcDir, .OrdinalIgnoreCase))
|
||||
{
|
||||
fileName.Remove(0, baseSrcDir.Length - 1);
|
||||
fileName.Insert(0, projectSource.mProject.mProjectName);
|
||||
}
|
||||
//Console.WriteLine("Hey!");
|
||||
fileName.Replace('\\', '_');
|
||||
fileName.Replace('/', '_');
|
||||
|
||||
String path = scope .();
|
||||
path.Append(gApp.mDbgVersionedCompileDir);
|
||||
path.Append(fileName);
|
||||
//Utils.WriteTextFile(path, command.mSourceString);
|
||||
|
||||
var filePath = scope String();
|
||||
projectSource.GetFullImportPath(filePath);
|
||||
|
||||
String contents = scope .();
|
||||
contents.AppendF("//@{}|{}\n", filePath, File.GetLastWriteTime(filePath).GetValueOrDefault().ToFileTime());
|
||||
contents.Append(command.mSourceString);
|
||||
File.WriteAllText(path, contents);
|
||||
}
|
||||
}
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public virtual void ClearQueuedProjectSource()
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
// Don't remove the head of the queue because we may already be processing it
|
||||
for (int32 i = 1; i < mCommandQueue.Count; i++)
|
||||
{
|
||||
if (mCommandQueue[i] is ProjectSourceCommand)
|
||||
{
|
||||
mCommandQueue.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void QueueProjectSourceRemoved(ProjectSource projectSource)
|
||||
{
|
||||
ProjectSourceRemovedCommand command = new ProjectSourceRemovedCommand();
|
||||
command.mProjectSource = projectSource;
|
||||
projectSource.AddRef();
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public bool HasResolvedAll()
|
||||
{
|
||||
return (!HasQueuedCommands()) && (mResolveAllWait == 0);
|
||||
}
|
||||
|
||||
public void QueueResolveCommand()
|
||||
{
|
||||
/*if (gApp.mMainWindow.IsKeyDown(.Control))
|
||||
{
|
||||
NOP!();
|
||||
}*/
|
||||
|
||||
ResolveAllCommand command = new ResolveAllCommand();
|
||||
QueueCommand(command);
|
||||
}
|
||||
|
||||
public override void ProcessQueue()
|
||||
{
|
||||
mThreadYieldCount = 0;
|
||||
DoProcessQueue();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (!ThreadRunning)
|
||||
{
|
||||
CheckThreadDone();
|
||||
|
||||
if (mWantsActiveViewRefresh)
|
||||
{
|
||||
IDEApp.sApp.RefreshVisibleViews();
|
||||
mWantsActiveViewRefresh = false;
|
||||
}
|
||||
|
||||
if (mThreadYieldCount > 0)
|
||||
{
|
||||
mThreadYieldCount--;
|
||||
}
|
||||
else if (mAllowThreadStart)
|
||||
{
|
||||
if (mResolveAllWait > 0)
|
||||
{
|
||||
if (--mResolveAllWait == 0)
|
||||
{
|
||||
QueueResolveCommand();
|
||||
}
|
||||
}
|
||||
|
||||
if (mCommandQueue.Count > 0)
|
||||
{
|
||||
StartQueueProcessThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PopMessage(String outMessage)
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
if (mQueuedOutput.Count > 0)
|
||||
{
|
||||
String msg = mQueuedOutput[0];
|
||||
mQueuedOutput.RemoveAt(0);
|
||||
msg.MoveTo(outMessage);
|
||||
delete msg;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ClearMessages()
|
||||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
ClearAndDeleteItems(mQueuedOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue