-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ut for property #1233
add ut for property #1233
Changes from all commits
0d6c602
8b96ee5
8e91e60
4aa527f
1623eaf
5d650a7
408d28d
4623f38
d552e2e
abc1f30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ | |||||||
using System.Linq; | ||||||||
using System.Runtime.CompilerServices; | ||||||||
using System.Text; | ||||||||
using Akka.Util.Internal; | ||||||||
using Diagnostic = Microsoft.CodeAnalysis.Diagnostic; | ||||||||
using ECPoint = Neo.Cryptography.ECC.ECPoint; | ||||||||
|
||||||||
|
@@ -72,6 +73,9 @@ public class CompilationContext | |||||||
internal int StaticFieldCount => _staticFields.Count + _anonymousStaticFields.Count + _vtables.Count; | ||||||||
private byte[] Script => _script ??= GetInstructions().Select(p => p.ToArray()).SelectMany(p => p).ToArray(); | ||||||||
|
||||||||
// Define a tuple array to store both field symbols and their semantic models | ||||||||
internal (IFieldSymbol Field, SemanticModel Model)[] ContractFields = []; | ||||||||
internal SemanticModel ContractSemanticModel { get; set; } | ||||||||
|
||||||||
/// <summary> | ||||||||
/// Specify the contract to be compiled. | ||||||||
|
@@ -372,6 +376,8 @@ private void ProcessClass(SemanticModel model, INamedTypeSymbol symbol) | |||||||
return; | ||||||||
} | ||||||||
|
||||||||
ContractSemanticModel = model; | ||||||||
|
||||||||
foreach (var attribute in symbol.GetAttributesWithInherited()) | ||||||||
{ | ||||||||
if (attribute.AttributeClass!.IsSubclassOf(nameof(ManifestExtraAttribute))) | ||||||||
|
@@ -416,6 +422,25 @@ private void ProcessClass(SemanticModel model, INamedTypeSymbol symbol) | |||||||
} | ||||||||
_className = symbol.Name; | ||||||||
} | ||||||||
// Get all fields and their corresponding semantic models | ||||||||
ContractFields = symbol.GetAllMembers() | ||||||||
.OfType<IFieldSymbol>() | ||||||||
.Select(field => | ||||||||
{ | ||||||||
// Try to get the syntax reference for the field | ||||||||
var syntaxRef = field.DeclaringSyntaxReferences.FirstOrDefault(); | ||||||||
// If the field has a syntax reference, get its semantic model | ||||||||
// Otherwise, use the current model (for metadata fields) | ||||||||
var fieldModel = syntaxRef != null | ||||||||
? ((ISourceAssemblySymbol)field.ContainingAssembly).Compilation.GetSemanticModel(syntaxRef.SyntaxTree) | ||||||||
: model; | ||||||||
return (Field: field, Model: fieldModel); | ||||||||
}) | ||||||||
.ToArray(); | ||||||||
|
||||||||
// Process each field using its symbol | ||||||||
ContractFields.ForEach(f => AddStaticField(f.Field)); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. array.ForEach is using Akka.Util.Internal, and is harder to debug |
||||||||
|
||||||||
Dictionary<(string, int), IMethodSymbol> export = new(); | ||||||||
// export methods `new`ed in child class, not those hidden in parent class | ||||||||
foreach (ISymbol member in symbol.GetAllMembers()) | ||||||||
|
@@ -514,7 +539,6 @@ private void ProcessMethod(SemanticModel model, IMethodSymbol symbol, bool expor | |||||||
throw new CompilationException(symbol, DiagnosticId.SyntaxNotSupported, $"Unsupported syntax: Can not set contract interface {symbol.Name} as inline."); | ||||||||
return; | ||||||||
} | ||||||||
|
||||||||
MethodConvert convert = ConvertMethod(model, symbol); | ||||||||
if (export && MethodConvert.NeedInstanceConstructor(symbol)) | ||||||||
{ | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
using System.Linq; | ||
using System.Numerics; | ||
using System.Runtime.InteropServices; | ||
using Neo.VM.Types; | ||
using Array = System.Array; | ||
|
||
namespace Neo.Compiler | ||
{ | ||
|
@@ -243,12 +245,43 @@ private void ProcessFieldInitializer(SemanticModel model, IFieldSymbol field, Ac | |
syntaxNode = syntax; | ||
initializer = syntax.Initializer; | ||
} | ||
if (initializer is null) return; | ||
model = model.Compilation.GetSemanticModel(syntaxNode.SyntaxTree); | ||
|
||
if (initializer is null) | ||
{ | ||
if(_context.ContractFields.Any(f => | ||
SymbolEqualityComparer.Default.Equals(f.Field, field)) && | ||
(field.Type.GetStackItemType() == StackItemType.Integer || field.Type.GetStackItemType() == StackItemType.Integer)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. f.Field.Type😰? |
||
{ | ||
var index = _context.AddStaticField(field); | ||
PushDefault(field.Type); | ||
AccessSlot(OpCode.STSFLD, index); | ||
} | ||
return; | ||
} | ||
|
||
using (InsertSequencePoint(syntaxNode)) | ||
{ | ||
preInitialize?.Invoke(); | ||
ConvertExpression(model, initializer.Value, syntaxNode); | ||
// We must process contract fields separately, they may not belong to the current semantic model | ||
// And they may also not belong to the semantic model of the contract, but the parent class semantic model | ||
if (_context.ContractFields.Any(f => | ||
SymbolEqualityComparer.Default.Equals(f.Field, field))) | ||
{ | ||
// Try to get the syntax reference for the field | ||
var syntaxRef = field.DeclaringSyntaxReferences.FirstOrDefault(); | ||
// If the field has a syntax reference, get its semantic model | ||
// Otherwise, use the current model (for metadata fields) | ||
var fieldModel = syntaxRef != null | ||
? ((ISourceAssemblySymbol)field.ContainingAssembly).Compilation.GetSemanticModel(syntaxRef.SyntaxTree) | ||
: _context.ContractSemanticModel; | ||
|
||
ConvertExpression( fieldModel.Compilation.GetSemanticModel(syntaxNode.SyntaxTree), initializer.Value, syntaxNode); | ||
} | ||
else | ||
{ | ||
model = model.Compilation.GetSemanticModel(syntaxNode.SyntaxTree); | ||
ConvertExpression(model, initializer.Value, syntaxNode); | ||
} | ||
postInitialize?.Invoke(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.