Update release

This commit is contained in:
vczh
2023-01-19 01:07:59 -08:00
parent 19cbd6156b
commit 773f0bc2d4
7 changed files with 262 additions and 151 deletions
+29 -19
View File
@@ -33509,6 +33509,31 @@ Native Window Provider
{ {
currentController=controller; currentController=controller;
} }
/***********************************************************************
Helper Functions
***********************************************************************/
INativeCursor* GetCursorFromHitTest(INativeWindowListener::HitTestResult hitTestResult, INativeResourceService* resourceService)
{
switch (hitTestResult)
{
case INativeWindowListener::BorderLeft:
case INativeWindowListener::BorderRight:
return resourceService->GetSystemCursor(INativeCursor::SizeWE);
case INativeWindowListener::BorderTop:
case INativeWindowListener::BorderBottom:
return resourceService->GetSystemCursor(INativeCursor::SizeNS);
case INativeWindowListener::BorderLeftTop:
case INativeWindowListener::BorderRightBottom:
return resourceService->GetSystemCursor(INativeCursor::SizeNWSE);
case INativeWindowListener::BorderRightTop:
case INativeWindowListener::BorderLeftBottom:
return resourceService->GetSystemCursor(INativeCursor::SizeNESW);
default:
return nullptr;
}
}
} }
} }
@@ -34138,27 +34163,12 @@ GuiHostedController::INativeWindowListener (PreAction)
auto x = info.x.value - hoveringWindow->wmWindow.bounds.x1.value; auto x = info.x.value - hoveringWindow->wmWindow.bounds.x1.value;
auto y = info.y.value - hoveringWindow->wmWindow.bounds.y1.value; auto y = info.y.value - hoveringWindow->wmWindow.bounds.y1.value;
auto hitTestResult = PerformHitTest(From(hoveringWindow->listeners), { {x},{y} }); auto hitTestResult = PerformHitTest(From(hoveringWindow->listeners), { {x},{y} });
switch (hitTestResult) auto cursor = GetCursorFromHitTest(hitTestResult, ResourceService());
if (cursor == nullptr)
{ {
case INativeWindowListener::BorderLeft: cursor = hoveringWindow->GetWindowCursor();
case INativeWindowListener::BorderRight:
nativeWindow->SetWindowCursor(ResourceService()->GetSystemCursor(INativeCursor::SizeWE));
break;
case INativeWindowListener::BorderTop:
case INativeWindowListener::BorderBottom:
nativeWindow->SetWindowCursor(ResourceService()->GetSystemCursor(INativeCursor::SizeNS));
break;
case INativeWindowListener::BorderLeftTop:
case INativeWindowListener::BorderRightBottom:
nativeWindow->SetWindowCursor(ResourceService()->GetSystemCursor(INativeCursor::SizeNWSE));
break;
case INativeWindowListener::BorderRightTop:
case INativeWindowListener::BorderLeftBottom:
nativeWindow->SetWindowCursor(ResourceService()->GetSystemCursor(INativeCursor::SizeNESW));
break;
default:
nativeWindow->SetWindowCursor(hoveringWindow->GetWindowCursor());
} }
nativeWindow->SetWindowCursor(cursor);
} }
if (wmWindow) if (wmWindow)
+8
View File
@@ -3280,6 +3280,14 @@ Native Window Controller
/// <param name="controller">The global native system service controller.</param> /// <param name="controller">The global native system service controller.</param>
extern void SetCurrentController(INativeController* controller); extern void SetCurrentController(INativeController* controller);
/// <summary>
/// Get a cursor according to the hit test result.
/// </summary>
/// <param name="hitTestResult">The hit test result.</param>
/// <param name="resourceService">The resource service to get cursors.</param>
/// <returns>Returns the cursor according to the hit test result. It could return nullptr when the cursor is not defined.</returns>
extern INativeCursor* GetCursorFromHitTest(INativeWindowListener::HitTestResult hitTestResult, INativeResourceService* resourceService);
/// <summary> /// <summary>
/// A helper function calling multiple <see cref="INativeWindowListener::HitTest"/>. /// A helper function calling multiple <see cref="INativeWindowListener::HitTest"/>.
/// </summary> /// </summary>
+1 -1
View File
@@ -10950,7 +10950,7 @@ GuiWorkflowSharedManagerPlugin
{ {
if (!workflowManager) if (!workflowManager)
{ {
workflowManager = Ptr(new WfLexicalScopeManager(workflowParser)); workflowManager = Ptr(new WfLexicalScopeManager(workflowParser, WfCpuArchitecture::AsExecutable));
} }
return workflowManager.Obj(); return workflowManager.Obj();
} }
+3 -17
View File
@@ -1217,12 +1217,6 @@ UnitTest
namespace execution_impl namespace execution_impl
{ {
struct UnitTestLink
{
const char* fileName;
UnitTestFileProc testProc = nullptr;
UnitTestLink* next = nullptr;
};
UnitTestLink* testHead = nullptr; UnitTestLink* testHead = nullptr;
UnitTestLink** testTail = &testHead; UnitTestLink** testTail = &testHead;
@@ -1383,10 +1377,6 @@ UnitTest
} }
{ {
auto current = testHead;
testHead = nullptr;
testTail = nullptr;
UnitTestContext context; UnitTestContext context;
testContext = &context; testContext = &context;
totalFiles = 0; totalFiles = 0;
@@ -1403,18 +1393,17 @@ UnitTest
PrintMessage(L"Failures are not suppressed.", MessageKind::Info); PrintMessage(L"Failures are not suppressed.", MessageKind::Info);
} }
auto current = testHead;
while (current) while (current)
{ {
context.failed = false; context.failed = false;
PrintMessage(atow(current->fileName), MessageKind::File); PrintMessage(atow(AString::Unmanaged(current->fileName)), MessageKind::File);
context.indentation = L" "; context.indentation = L" ";
ExecuteAndSuppressFailure(current->testProc); ExecuteAndSuppressFailure(current->testProc);
if (!testContext->failed) passedFiles++; if (!testContext->failed) passedFiles++;
totalFiles++; totalFiles++;
context.indentation = L""; context.indentation = L"";
auto temp = current;
current = current->next; current = current->next;
delete temp;
} }
bool passed = totalFiles == passedFiles; bool passed = totalFiles == passedFiles;
@@ -1464,11 +1453,8 @@ UnitTest
} }
} }
void UnitTest::RegisterTestFile(const char* fileName, UnitTestFileProc testProc) void UnitTest::RegisterTestFile(UnitTestLink* link)
{ {
auto link = new UnitTestLink;
link->fileName = fileName;
link->testProc = testProc;
*testTail = link; *testTail = link;
testTail = &link->next; testTail = &link->next;
} }
+90 -24
View File
@@ -7080,36 +7080,90 @@ Quick Sort
template<typename T, typename F> template<typename T, typename F>
void SortLambda(T* items, vint length, F orderer) void SortLambda(T* items, vint length, F orderer)
{ {
if (length == 0) return; while (true)
vint pivot = 0;
vint left = 0;
vint right = 0;
bool flag = false;
while (left + right + 1 != length)
{ {
vint& mine = (flag ? left : right); if (length == 0) return;
vint& theirs = (flag ? right : left); vint pivot = 0;
vint candidate = (flag ? left : length - right - 1); vint left = 0;
vint factor = (flag ? -1 : 1); vint right = 0;
if (orderer(items[pivot], items[candidate]) * factor <= 0)
{ {
mine++; bool flag = false;
while (left + right + 1 != length)
{
vint& mine = (flag ? left : right);
vint& theirs = (flag ? right : left);
vint candidate = (flag ? left : length - right - 1);
vint factor = (flag ? -1 : 1);
if (orderer(items[pivot], items[candidate]) * factor <= 0)
{
mine++;
}
else
{
theirs++;
T temp = items[pivot];
items[pivot] = items[candidate];
items[candidate] = temp;
pivot = candidate;
flag = !flag;
}
}
}
{
vint reading = left - 1;
vint writing = reading;
while (reading >= 0)
{
if (orderer(items[pivot], items[reading]) == 0)
{
if (reading != writing)
{
T temp = items[reading];
items[reading] = items[writing];
items[writing] = temp;
}
writing--;
}
reading--;
}
left = writing + 1;
}
{
vint reading = length - right;
vint writing = reading;
while (reading < length)
{
if (orderer(items[pivot], items[reading]) == 0)
{
if (reading != writing)
{
T temp = items[reading];
items[reading] = items[writing];
items[writing] = temp;
}
writing++;
}
reading++;
}
right = length - writing;
}
if (left < right)
{
SortLambda(items, left, orderer);
items += length - right;
length = right;
} }
else else
{ {
theirs++; SortLambda(items + length - right, right, orderer);
T temp = items[pivot]; length = left;
items[pivot] = items[candidate];
items[candidate] = temp;
pivot = candidate;
flag = !flag;
} }
} }
SortLambda(items, left, orderer);
SortLambda(items + left + 1, right, orderer);
} }
/// <summary>Quick sort.</summary> /// <summary>Quick sort.</summary>
@@ -8503,6 +8557,13 @@ namespace vl
{ {
using UnitTestFileProc = void(*)(); using UnitTestFileProc = void(*)();
struct UnitTestLink
{
const char* fileName = nullptr;
UnitTestFileProc testProc = nullptr;
UnitTestLink* next = nullptr;
};
/// <summary> /// <summary>
/// <p>Unit test framework.</p> /// <p>Unit test framework.</p>
/// <p> /// <p>
@@ -8615,17 +8676,22 @@ namespace vl
/// <param name="argv">Accept the second argument of the main function.</param> /// <param name="argv">Accept the second argument of the main function.</param>
static int RunAndDisposeTests(int argc, char* argv[]); static int RunAndDisposeTests(int argc, char* argv[]);
static void RegisterTestFile(const char* fileName, UnitTestFileProc testProc); static void RegisterTestFile(UnitTestLink* link);
static void RunCategoryOrCase(const WString& description, bool isCategory, Func<void()>&& callback); static void RunCategoryOrCase(const WString& description, bool isCategory, Func<void()>&& callback);
static void EnsureLegalToAssert(); static void EnsureLegalToAssert();
}; };
class UnitTestFile class UnitTestFile
{ {
protected:
UnitTestLink link;
public: public:
UnitTestFile(const char* fileName, UnitTestFileProc testProc) UnitTestFile(const char* fileName, UnitTestFileProc testProc)
{ {
UnitTest::RegisterTestFile(fileName, testProc); link.fileName = fileName;
link.testProc = testProc;
UnitTest::RegisterTestFile(&link);
} }
}; };
+111 -88
View File
@@ -259,16 +259,26 @@ CheckScopes_CycleDependency
}) })
); );
switch (tds[0]->GetTypeDescriptorFlags()) auto selectedTd = tds[0];
for (auto candidateTd : From(tds).Skip(1))
{
auto selectedRange = visitor.depItems[selectedTd]->codeRange;
auto candidateRange = visitor.depItems[candidateTd]->codeRange;
if (candidateRange.codeIndex > selectedRange.codeIndex) { selectedTd = candidateTd; continue; }
if (candidateRange.start > selectedRange.start) { selectedTd = candidateTd; continue; }
}
switch (selectedTd->GetTypeDescriptorFlags())
{ {
case TypeDescriptorFlags::Struct: case TypeDescriptorFlags::Struct:
manager->errors.Add(WfErrors::StructRecursivelyIncludeItself(dynamic_cast<WfStructDeclaration*>(visitor.depItems[tds[0]]), tds)); manager->errors.Add(WfErrors::StructRecursivelyIncludeItself(dynamic_cast<WfStructDeclaration*>(visitor.depItems[selectedTd]), tds));
break; break;
case TypeDescriptorFlags::Class: case TypeDescriptorFlags::Class:
manager->errors.Add(WfErrors::ClassRecursiveInheritance(dynamic_cast<WfClassDeclaration*>(visitor.depItems[tds[0]]), tds)); manager->errors.Add(WfErrors::ClassRecursiveInheritance(dynamic_cast<WfClassDeclaration*>(visitor.depItems[selectedTd]), tds));
break; break;
case TypeDescriptorFlags::Interface: case TypeDescriptorFlags::Interface:
manager->errors.Add(WfErrors::InterfaceRecursiveInheritance(dynamic_cast<WfClassDeclaration*>(visitor.depItems[tds[0]]), tds)); manager->errors.Add(WfErrors::InterfaceRecursiveInheritance(dynamic_cast<WfClassDeclaration*>(visitor.depItems[selectedTd]), tds));
break; break;
default:; default:;
} }
@@ -668,8 +678,9 @@ ResolveExpressionResult
WfLexicalScopeManager WfLexicalScopeManager
***********************************************************************/ ***********************************************************************/
WfLexicalScopeManager::WfLexicalScopeManager(workflow::Parser& _workflowParser) WfLexicalScopeManager::WfLexicalScopeManager(workflow::Parser& _workflowParser, WfCpuArchitecture _cpuArchitecture)
:workflowParser(_workflowParser) :workflowParser(_workflowParser)
, cpuArchitecture(_cpuArchitecture)
{ {
workflowParserHandler = glr::InstallDefaultErrorMessageGenerator(workflowParser, errors); workflowParserHandler = glr::InstallDefaultErrorMessageGenerator(workflowParser, errors);
attributes.Add({ L"cpp", L"File" }, TypeInfoRetriver<WString>::CreateTypeInfo()); attributes.Add({ L"cpp", L"File" }, TypeInfoRetriver<WString>::CreateTypeInfo());
@@ -677,6 +688,28 @@ WfLexicalScopeManager
attributes.Add({ L"cpp", L"Private" }, TypeInfoRetriver<void>::CreateTypeInfo()); attributes.Add({ L"cpp", L"Private" }, TypeInfoRetriver<void>::CreateTypeInfo());
attributes.Add({ L"cpp", L"Protected" }, TypeInfoRetriver<void>::CreateTypeInfo()); attributes.Add({ L"cpp", L"Protected" }, TypeInfoRetriver<void>::CreateTypeInfo());
attributes.Add({ L"cpp", L"Friend" }, TypeInfoRetriver<ITypeDescriptor*>::CreateTypeInfo()); attributes.Add({ L"cpp", L"Friend" }, TypeInfoRetriver<ITypeDescriptor*>::CreateTypeInfo());
switch (cpuArchitecture)
{
case WfCpuArchitecture::x86:
cputdSInt = reflection::description::GetTypeDescriptor<vint32_t>();
cputdUInt = reflection::description::GetTypeDescriptor<vuint32_t>();
cputiSInt = reflection::description::TypeInfoRetriver<vint32_t>::CreateTypeInfo();
cputiUInt = reflection::description::TypeInfoRetriver<vuint32_t>::CreateTypeInfo();
break;
case WfCpuArchitecture::x64:
cputdSInt = reflection::description::GetTypeDescriptor<vint64_t>();
cputdUInt = reflection::description::GetTypeDescriptor<vuint64_t>();
cputiSInt = reflection::description::TypeInfoRetriver<vint64_t>::CreateTypeInfo();
cputiUInt = reflection::description::TypeInfoRetriver<vuint64_t>::CreateTypeInfo();
break;
case WfCpuArchitecture::AsExecutable:
cputdSInt = reflection::description::GetTypeDescriptor<vint>();
cputdUInt = reflection::description::GetTypeDescriptor<vuint>();
cputiSInt = reflection::description::TypeInfoRetriver<vint>::CreateTypeInfo();
cputiUInt = reflection::description::TypeInfoRetriver<vuint>::CreateTypeInfo();
break;
}
} }
WfLexicalScopeManager::~WfLexicalScopeManager() WfLexicalScopeManager::~WfLexicalScopeManager()
@@ -2553,7 +2586,22 @@ CheckScopes_SymbolType
bool CheckScopes_SymbolType(WfLexicalScopeManager* manager) bool CheckScopes_SymbolType(WfLexicalScopeManager* manager)
{ {
vint errorCount = manager->errors.Count(); vint errorCount = manager->errors.Count();
for (auto scope : manager->nodeScopes.Values()) for (auto scope : From(manager->nodeScopes)
.OrderBy([](auto&& a, auto&& b)
{
auto rangeA = a.key->codeRange;
auto rangeB = b.key->codeRange;
if (rangeA.codeIndex != rangeB.codeIndex)
{
return rangeA.codeIndex - rangeB.codeIndex;
}
else
{
return glr::ParsingTextPos::Compare(rangeA.start, rangeB.start);
}
})
.Select([](auto&& pair) { return pair.value; })
)
{ {
if (!manager->checkedScopes_SymbolType.Contains(scope.Obj())) if (!manager->checkedScopes_SymbolType.Contains(scope.Obj()))
{ {
@@ -2768,7 +2816,7 @@ CompleteScopeForClassMember
} }
auto& smInfo = manager->stateMachineInfos[node]; auto& smInfo = manager->stateMachineInfos[node];
smInfo->createCoroutineMethod->AddParameter(Ptr(new ParameterInfoImpl(smInfo->createCoroutineMethod.Obj(), L"<state>startState", TypeInfoRetriver<vint>::CreateTypeInfo()))); smInfo->createCoroutineMethod->AddParameter(Ptr(new ParameterInfoImpl(smInfo->createCoroutineMethod.Obj(), L"<state>startState", manager->cputiSInt)));
smInfo->createCoroutineMethod->SetReturn(TypeInfoRetriver<void>::CreateTypeInfo()); smInfo->createCoroutineMethod->SetReturn(TypeInfoRetriver<void>::CreateTypeInfo());
} }
@@ -3587,6 +3635,21 @@ namespace vl
return { node, node->codeRange, message }; return { node, node->codeRange, message };
} }
template<typename T, typename F>
WString ListToErrorMessage(List<T>& items, F&& f)
{
WString description;
for (auto friendlyName : From(items)
.Select(f)
.OrderBy([](auto&& a, auto&& b) { return WString::Compare(a, b); })
)
{
description += L"\r\n\t";
description += friendlyName;
}
return description;
}
/*********************************************************************** /***********************************************************************
WfErrors WfErrors
***********************************************************************/ ***********************************************************************/
@@ -3788,12 +3851,7 @@ WfErrors
glr::ParsingError WfErrors::CannotPickOverloadedFunctions(glr::ParsingAstBase* node, collections::List<ResolveExpressionResult>& results) glr::ParsingError WfErrors::CannotPickOverloadedFunctions(glr::ParsingAstBase* node, collections::List<ResolveExpressionResult>& results)
{ {
WString description; auto description = ListToErrorMessage(results, [](auto&& result) { return result.GetFriendlyName(); });
for (auto [result, index] : indexed(results))
{
description += L"\r\n\t";
description += result.GetFriendlyName();
}
return MakeParsingError(node, L"A22: Cannot decide which function to call in multiple targets: " + description + L"."); return MakeParsingError(node, L"A22: Cannot decide which function to call in multiple targets: " + description + L".");
} }
@@ -3967,12 +4025,7 @@ WfErrors
glr::ParsingError WfErrors::CoProviderNotExists(WfCoProviderStatement* node, collections::List<WString>& candidates) glr::ParsingError WfErrors::CoProviderNotExists(WfCoProviderStatement* node, collections::List<WString>& candidates)
{ {
WString description; auto description = ListToErrorMessage(candidates, [](auto&& candidate) { return candidate; });
for (auto candidate : candidates)
{
description += L"\r\n\t";
description += candidate;
}
if (node->name.value == L"") if (node->name.value == L"")
{ {
return MakeParsingError(node, L"C9: Cannot find a coroutine provider based on the function return type, all of the following types do not exist: " + description + L"."); return MakeParsingError(node, L"C9: Cannot find a coroutine provider based on the function return type, all of the following types do not exist: " + description + L".");
@@ -4015,12 +4068,7 @@ WfErrors
} }
else else
{ {
WString description; auto description = ListToErrorMessage(types, [](auto&& type) { return type->GetTypeFriendlyName(); });
for (auto type : types)
{
description += L"\r\n\t";
description += type->GetTypeFriendlyName();
}
return MakeParsingError(node, L"C11: Failed to resolve the result type of coroutine operator \"" + operatorName + L"\", no appropriate static function \"CastResult\" is found in the following types. It requires exactly one argument of type \"object\" with a return type which is not \"void\": " + description + L"."); return MakeParsingError(node, L"C11: Failed to resolve the result type of coroutine operator \"" + operatorName + L"\", no appropriate static function \"CastResult\" is found in the following types. It requires exactly one argument of type \"object\" with a return type which is not \"void\": " + description + L".");
} }
} }
@@ -4148,12 +4196,7 @@ WfErrors
glr::ParsingError WfErrors::CannotPickOverloadedInterfaceMethods(WfExpression* node, collections::List<ResolveExpressionResult>& results) glr::ParsingError WfErrors::CannotPickOverloadedInterfaceMethods(WfExpression* node, collections::List<ResolveExpressionResult>& results)
{ {
WString description; auto description = ListToErrorMessage(results, [](auto&& result) { return result.GetFriendlyName(); });
for (auto result : results)
{
description += L"\r\n\t";
description += result.GetFriendlyName();
}
return MakeParsingError(node, L"D5: Cannot decide which function to implement in multiple targets:" + description + L"."); return MakeParsingError(node, L"D5: Cannot decide which function to implement in multiple targets:" + description + L".");
} }
@@ -4224,12 +4267,7 @@ WfErrors
glr::ParsingError WfErrors::StructRecursivelyIncludeItself(WfStructDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds) glr::ParsingError WfErrors::StructRecursivelyIncludeItself(WfStructDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds)
{ {
WString description; auto description = ListToErrorMessage(tds, [](auto&& td) { return td->GetTypeName(); });
for (auto td : tds)
{
description += L"\r\n\t";
description += td->GetTypeName();
}
return MakeParsingError(node, L"D13: Recursive references are found in these struct definitions:" + description + L"."); return MakeParsingError(node, L"D13: Recursive references are found in these struct definitions:" + description + L".");
} }
@@ -4285,12 +4323,7 @@ WfErrors
glr::ParsingError WfErrors::TooManyTargets(glr::ParsingAstBase* node, collections::List<ResolveExpressionResult>& results, const WString& name) glr::ParsingError WfErrors::TooManyTargets(glr::ParsingAstBase* node, collections::List<ResolveExpressionResult>& results, const WString& name)
{ {
WString description; auto description = ListToErrorMessage(results, [](auto&& result) { return result.GetFriendlyName(); });
for (auto [result, index] : indexed(results))
{
description += L"\r\n\t";
description += result.GetFriendlyName();
}
return MakeParsingError(node, L"F3: Symbol \"" + name + L"\" references to too many targets: " + description + L"."); return MakeParsingError(node, L"F3: Symbol \"" + name + L"\" references to too many targets: " + description + L".");
} }
@@ -4412,23 +4445,13 @@ WfErrors
glr::ParsingError WfErrors::ClassRecursiveInheritance(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds) glr::ParsingError WfErrors::ClassRecursiveInheritance(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds)
{ {
WString description; auto description = ListToErrorMessage(tds, [](auto&& td) { return td->GetTypeName(); });
for (auto td : tds)
{
description += L"\r\n\t";
description += td->GetTypeName();
}
return MakeParsingError(node, L"G10: Recursive inheriting are found in these class definitions:" + description + L"."); return MakeParsingError(node, L"G10: Recursive inheriting are found in these class definitions:" + description + L".");
} }
glr::ParsingError WfErrors::InterfaceRecursiveInheritance(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds) glr::ParsingError WfErrors::InterfaceRecursiveInheritance(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds)
{ {
WString description; auto description = ListToErrorMessage(tds, [](auto&& td) { return td->GetTypeName(); });
for (auto td : tds)
{
description += L"\r\n\t";
description += td->GetTypeName();
}
return MakeParsingError(node, L"G10: Recursive inheriting are found in these interface definitions:" + description + L"."); return MakeParsingError(node, L"G10: Recursive inheriting are found in these interface definitions:" + description + L".");
} }
@@ -4459,23 +4482,13 @@ WfErrors
glr::ParsingError WfErrors::CppUnableToDecideClassOrder(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds) glr::ParsingError WfErrors::CppUnableToDecideClassOrder(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds)
{ {
WString description; auto description = ListToErrorMessage(tds, [](auto&& td) { return td->GetTypeName(); });
for (auto td : tds)
{
description += L"\r\n\t";
description += td->GetTypeName();
}
return MakeParsingError(node, L"CPP1: (C++ Code Generation) Cannot decide order of the following classes. It is probably caused by inheritance relationships of internal classes inside these classes:" + description + L"."); return MakeParsingError(node, L"CPP1: (C++ Code Generation) Cannot decide order of the following classes. It is probably caused by inheritance relationships of internal classes inside these classes:" + description + L".");
} }
glr::ParsingError WfErrors::CppUnableToSeparateCustomFile(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds) glr::ParsingError WfErrors::CppUnableToSeparateCustomFile(WfClassDeclaration* node, collections::List<reflection::description::ITypeDescriptor*>& tds)
{ {
WString description; auto description = ListToErrorMessage(tds, [](auto&& td) { return td->GetTypeName(); });
for (auto td : tds)
{
description += L"\r\n\t";
description += td->GetTypeName();
}
return MakeParsingError(node, L"CPP2: (C++ Code Generation) @cpp:File atrribute values for these classes are invalid. Generating classes to source files specified by these attribute values will create source files which do not compile. It is probably caused by inheritance relationships of internal classes inside these classes:" + description + L"."); return MakeParsingError(node, L"CPP2: (C++ Code Generation) @cpp:File atrribute values for these classes are invalid. Generating classes to source files specified by these attribute values will create source files which do not compile. It is probably caused by inheritance relationships of internal classes inside these classes:" + description + L".");
} }
} }
@@ -7461,7 +7474,7 @@ ExpandNewCoroutineExpression
auto varDecl = Ptr(new WfVariableDeclaration); auto varDecl = Ptr(new WfVariableDeclaration);
newExpr->declarations.Add(varDecl); newExpr->declarations.Add(varDecl);
varDecl->name.value = L"<co-state>"; varDecl->name.value = L"<co-state>";
varDecl->type = GetTypeFromTypeInfo(TypeInfoRetriver<vint>::CreateTypeInfo().Obj()); varDecl->type = GetTypeFromTypeInfo(manager->cputiSInt.Obj());
auto stateExpr = Ptr(new WfIntegerExpression); auto stateExpr = Ptr(new WfIntegerExpression);
stateExpr->value.value = L"0"; stateExpr->value.value = L"0";
@@ -7476,7 +7489,7 @@ ExpandNewCoroutineExpression
auto varDecl = Ptr(new WfVariableDeclaration); auto varDecl = Ptr(new WfVariableDeclaration);
newExpr->declarations.Add(varDecl); newExpr->declarations.Add(varDecl);
varDecl->name.value = L"<co-state-before-pause>"; varDecl->name.value = L"<co-state-before-pause>";
varDecl->type = GetTypeFromTypeInfo(TypeInfoRetriver<vint>::CreateTypeInfo().Obj()); varDecl->type = GetTypeFromTypeInfo(manager->cputiSInt.Obj());
varDecl->expression = GenerateCoroutineInvalidId(); varDecl->expression = GenerateCoroutineInvalidId();
} }
@@ -10289,10 +10302,10 @@ CreateTypeInfoFromType
typeDescriptor = description::GetTypeDescriptor<IDescriptable>(); typeDescriptor = description::GetTypeDescriptor<IDescriptable>();
break; break;
case WfPredefinedTypeName::Int: case WfPredefinedTypeName::Int:
typeDescriptor = description::GetTypeDescriptor<vint>(); typeDescriptor = scope->FindManager()->cputdSInt;
break; break;
case WfPredefinedTypeName::UInt: case WfPredefinedTypeName::UInt:
typeDescriptor = description::GetTypeDescriptor<vuint>(); typeDescriptor = scope->FindManager()->cputdUInt;
break; break;
case WfPredefinedTypeName::Float: case WfPredefinedTypeName::Float:
typeDescriptor = description::GetTypeDescriptor<float>(); typeDescriptor = description::GetTypeDescriptor<float>();
@@ -12497,11 +12510,7 @@ ValidateSemantic(Expression)
auto typeDescriptor = expectedType ? expectedType->GetTypeDescriptor() : nullptr; auto typeDescriptor = expectedType ? expectedType->GetTypeDescriptor() : nullptr;
if (!typeDescriptor || typeDescriptor->GetTypeDescriptorFlags() == TypeDescriptorFlags::Object || typeDescriptor==description::GetTypeDescriptor<WString>()) if (!typeDescriptor || typeDescriptor->GetTypeDescriptorFlags() == TypeDescriptorFlags::Object || typeDescriptor==description::GetTypeDescriptor<WString>())
{ {
#ifdef VCZH_64 typeDescriptor = manager->cputdSInt;
typeDescriptor = description::GetTypeDescriptor<vint64_t>();
#else
typeDescriptor = description::GetTypeDescriptor<vint32_t>();
#endif
} }
if (auto serializableType = typeDescriptor->GetSerializableType()) if (auto serializableType = typeDescriptor->GetSerializableType())
@@ -12608,24 +12617,24 @@ ValidateSemantic(Expression)
ITypeInfo* classType = genericType->GetElementType(); ITypeInfo* classType = genericType->GetElementType();
if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueReadonlyList>()) if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueReadonlyList>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = CopyTypeInfo(genericType->GetGenericArgument(0)); resultType = CopyTypeInfo(genericType->GetGenericArgument(0));
} }
else if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueArray>()) else if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueArray>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = CopyTypeInfo(genericType->GetGenericArgument(0)); resultType = CopyTypeInfo(genericType->GetGenericArgument(0));
leftValue = true; leftValue = true;
} }
else if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueList>()) else if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueList>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = CopyTypeInfo(genericType->GetGenericArgument(0)); resultType = CopyTypeInfo(genericType->GetGenericArgument(0));
leftValue = true; leftValue = true;
} }
else if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueObservableList>()) else if (classType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueObservableList>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = CopyTypeInfo(genericType->GetGenericArgument(0)); resultType = CopyTypeInfo(genericType->GetGenericArgument(0));
leftValue = true; leftValue = true;
} }
@@ -12649,24 +12658,24 @@ ValidateSemantic(Expression)
{ {
if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueReadonlyList>()) if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueReadonlyList>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = TypeInfoRetriver<Value>::CreateTypeInfo(); resultType = TypeInfoRetriver<Value>::CreateTypeInfo();
} }
else if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueArray>()) else if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueArray>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = TypeInfoRetriver<Value>::CreateTypeInfo(); resultType = TypeInfoRetriver<Value>::CreateTypeInfo();
leftValue = true; leftValue = true;
} }
else if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueList>()) else if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueList>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = TypeInfoRetriver<Value>::CreateTypeInfo(); resultType = TypeInfoRetriver<Value>::CreateTypeInfo();
leftValue = true; leftValue = true;
} }
else if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueObservableList>()) else if (genericType->GetTypeDescriptor() == description::GetTypeDescriptor<IValueObservableList>())
{ {
indexType = TypeInfoRetriver<vint>::CreateTypeInfo(); indexType = manager->cputiSInt;
resultType = TypeInfoRetriver<Value>::CreateTypeInfo(); resultType = TypeInfoRetriver<Value>::CreateTypeInfo();
leftValue = true; leftValue = true;
} }
@@ -24394,9 +24403,9 @@ Compile
return GenerateAssembly(manager); return GenerateAssembly(manager);
} }
Ptr<runtime::WfAssembly> Compile(workflow::Parser& workflowParser, collections::List<WString>& moduleCodes, collections::List<glr::ParsingError>& errors) Ptr<runtime::WfAssembly> Compile(workflow::Parser& workflowParser, analyzer::WfCpuArchitecture cpuArchitecture, collections::List<WString>& moduleCodes, collections::List<glr::ParsingError>& errors)
{ {
WfLexicalScopeManager manager(workflowParser); WfLexicalScopeManager manager(workflowParser, cpuArchitecture);
return Compile(&manager, moduleCodes, errors); return Compile(&manager, moduleCodes, errors);
} }
} }
@@ -25630,17 +25639,31 @@ GenerateInstructions(Expression)
auto elementType = Ptr(result.type->GetElementType()->GetGenericArgument(0)); auto elementType = Ptr(result.type->GetElementType()->GetGenericArgument(0));
auto type = GetInstructionTypeArgument(elementType); auto type = GetInstructionTypeArgument(elementType);
WfRuntimeValue one;
switch (context.manager->cpuArchitecture)
{
case WfCpuArchitecture::x86:
one = {(vint32_t)1};
break;
case WfCpuArchitecture::x64:
one = { (vint64_t)1 };
break;
default:
one = { (vint)1 };
break;
}
GenerateExpressionInstructions(context, node->begin, elementType); GenerateExpressionInstructions(context, node->begin, elementType);
if (node->beginBoundary == WfRangeBoundary::Exclusive) if (node->beginBoundary == WfRangeBoundary::Exclusive)
{ {
INSTRUCTION(Ins::LoadValue({ (vint)1 })); INSTRUCTION(Ins::LoadValue(one));
INSTRUCTION(Ins::OpAdd(type)); INSTRUCTION(Ins::OpAdd(type));
} }
GenerateExpressionInstructions(context, node->end, elementType); GenerateExpressionInstructions(context, node->end, elementType);
if (node->endBoundary == WfRangeBoundary::Exclusive) if (node->endBoundary == WfRangeBoundary::Exclusive)
{ {
INSTRUCTION(Ins::LoadValue({ (vint)1 })); INSTRUCTION(Ins::LoadValue(one));
INSTRUCTION(Ins::OpSub(type)); INSTRUCTION(Ins::OpSub(type));
} }
+20 -2
View File
@@ -5046,6 +5046,16 @@ Scope Manager
collections::Dictionary<WString, vint> stateIds; collections::Dictionary<WString, vint> stateIds;
}; };
/// <summary>
/// CPU architecture
/// </summary>
enum class WfCpuArchitecture
{
x86,
x64,
AsExecutable,
};
/// <summary>Scope manager for storing all information generated from Workflow modules during compiling.</summary> /// <summary>Scope manager for storing all information generated from Workflow modules during compiling.</summary>
class WfLexicalScopeManager : public Object class WfLexicalScopeManager : public Object
{ {
@@ -5089,6 +5099,12 @@ Scope Manager
vint usedCodeIndex = 0; vint usedCodeIndex = 0;
public: public:
WfCpuArchitecture cpuArchitecture = WfCpuArchitecture::AsExecutable;
ITypeDescriptor* cputdSInt = nullptr;
ITypeDescriptor* cputdUInt = nullptr;
Ptr<ITypeInfo> cputiSInt;
Ptr<ITypeInfo> cputiUInt;
workflow::Parser& workflowParser; workflow::Parser& workflowParser;
Ptr<EventHandler> workflowParserHandler; Ptr<EventHandler> workflowParserHandler;
AttributeTypeMap attributes; AttributeTypeMap attributes;
@@ -5122,7 +5138,8 @@ Scope Manager
/// <summary>Create a Workflow compiler.</summary> /// <summary>Create a Workflow compiler.</summary>
/// <param name="_parsingTable">The workflow parser table. It can be retrived from [M:vl.workflow.WfLoadTable].</param> /// <param name="_parsingTable">The workflow parser table. It can be retrived from [M:vl.workflow.WfLoadTable].</param>
WfLexicalScopeManager(workflow::Parser& _workflowParser); /// <param name="_cpuArchitecture">The target CPU architecture.</param>
WfLexicalScopeManager(workflow::Parser& _workflowParser, WfCpuArchitecture _cpuArchitecture);
~WfLexicalScopeManager(); ~WfLexicalScopeManager();
/// <summary>Add a Workflow module. Syntax errors can be found at <see cref="errors"/>.</summary> /// <summary>Add a Workflow module. Syntax errors can be found at <see cref="errors"/>.</summary>
@@ -5695,9 +5712,10 @@ Code Generation
/// <summary>Compile a Workflow program. Use the other one whenever possible, which alloes reusing <see cref="analyzer::WfLexicalScopeManager"/> to improve performance.</summary> /// <summary>Compile a Workflow program. Use the other one whenever possible, which alloes reusing <see cref="analyzer::WfLexicalScopeManager"/> to improve performance.</summary>
/// <returns>The generated assembly. Return nullptr if failed to compile.</returns> /// <returns>The generated assembly. Return nullptr if failed to compile.</returns>
/// <param name="workflowParser">The generated parser class.</param> /// <param name="workflowParser">The generated parser class.</param>
/// <param name="cpuArchitecture">The target CPU architecture.</param>
/// <param name="moduleCodes">All workflow module codes.</param> /// <param name="moduleCodes">All workflow module codes.</param>
/// <param name="errors">Container to get all errors generated during compiling.</param> /// <param name="errors">Container to get all errors generated during compiling.</param>
extern Ptr<runtime::WfAssembly> Compile(workflow::Parser& workflowParser, collections::List<WString>& moduleCodes, collections::List<glr::ParsingError>& errors); extern Ptr<runtime::WfAssembly> Compile(workflow::Parser& workflowParser, analyzer::WfCpuArchitecture cpuArchitecture, collections::List<WString>& moduleCodes, collections::List<glr::ParsingError>& errors);
} }
} }
} }