Skip to content

Commit

Permalink
Supporting using const fields in hardware entry types (since they don…
Browse files Browse the repository at this point in the history
…'t do anything on the hardware)
  • Loading branch information
Piedone committed Sep 21, 2023
1 parent 62cf446 commit 196ba40
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ private void VerifyHardwareEntryPoints(SyntaxTree syntaxTree, ITypeDeclarationLo
{
var unsupportedMembers = type
.Members
.Where(member => member is FieldDeclaration || member is PropertyDeclaration || member.GetFullName().IsConstructorName());
.Where(member =>
(member is FieldDeclaration or PropertyDeclaration && !member.HasModifier(Modifiers.Const)) ||
member.GetFullName().IsConstructorName());
if (unsupportedMembers.Any())
{
throw new NotSupportedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ protected override void VisitChildren(AstNode node)
}
}

// Is this a const? Then we can just substitute it directly.
// Is this a const expression? Then we can just substitute it directly.
var resolveResult = node.GetResolveResult();
if (resolveResult?.IsCompileTimeConstant == true &&
if (node is Expression &&
resolveResult?.IsCompileTimeConstant == true &&
resolveResult.ConstantValue != null &&
node is not PrimitiveExpression)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public Task StaticTestInputAssemblyMatchesApproved() =>
new[] { typeof(ArrayUsingCases).Assembly },
configuration =>
{
configuration.TransformerConfiguration().UseSimpleMemory = false;
var transformerConfiguration = configuration.TransformerConfiguration();
transformerConfiguration.UseSimpleMemory = false;
transformerConfiguration.ArrayLengths.Add(
"System.Int32 Hast.TestInputs.Static.ArrayUsingCases+<>c::<PassArrayToTask>b__1_0(System.Object).arrayObject",
ArrayUsingCases.TaskArrayLength);
configuration
.TransformerConfiguration()
Expand Down
Loading

0 comments on commit 196ba40

Please sign in to comment.