You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/Neo.Compiler.CSharp/MethodConvert/Expression/AnonymousObjectCreationExpression.cs
+15
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,21 @@ namespace Neo.Compiler;
18
18
19
19
partialclassMethodConvert
20
20
{
21
+
/// <summary>
22
+
/// Methods for converting the creation of an object of an anonymous type into a series of instructions.
23
+
/// </summary>
24
+
/// <param name="model">The semantic model providing context and information about the anonymous object creation.</param>
25
+
/// <param name="expression">The syntax representation of the anonymous object creation statement being converted.</param>
26
+
/// <remarks>
27
+
/// Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.
28
+
/// The type name is generated by the compiler and is not available at the source code level.
29
+
/// The type of each property is inferred by the compiler.
30
+
/// </remarks>
31
+
/// <example>
32
+
/// The following example shows an anonymous type that is initialized with two properties named Amount and Message.
33
+
/// <c>var v = new { Amount = 108, Message = "Hello" };</c>
Copy file name to clipboardexpand all lines: src/Neo.Compiler.CSharp/MethodConvert/Expression/ArrayCreationExpression.cs
+19
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,25 @@ namespace Neo.Compiler;
19
19
20
20
partialclassMethodConvert
21
21
{
22
+
/// <summary>
23
+
/// Converts the code for constructing arrays and initializing arrays into OpCodes.
24
+
/// This method includes analyzing the array length, array type, array dimension and initial data.
25
+
/// </summary>
26
+
/// <param name="model">The semantic model providing context and information about the array creation.</param>
27
+
/// <param name="expression">The syntax representation of the array creation statement being converted.</param>
28
+
/// <exception cref="CompilationException">Only one-dimensional arrays are supported, otherwise an exception is thrown.</exception>
29
+
/// <remarks>
30
+
/// When the array is initialized to null, this code converts it to "array length" + OpCode.NEWBUFFER (only for byte[]) or OpCode.NEWARRAY_T.
31
+
/// When the array is not initialized to null, this code converts the initialized constants one by one in reverse order, then adds the "array length" and OpCode.PACK
32
+
/// </remarks>
33
+
/// <example>
34
+
/// Example of a array creation syntax:
35
+
/// <c>var array = new byte[4];</c>
36
+
/// The compilation result of the example code is: OpCode.PUSH4, OpCode.NEWBUFFER
37
+
/// <c>var array = new int[4] { 5, 6, 7, 8};</c>
38
+
/// The compilation result of the example code is: OpCode.PUSH8, OpCode.PUSH7, OpCode.PUSH6, OpCode.PUSH5, OpCode.PUSH4, OpCode.PACK
Copy file name to clipboardexpand all lines: src/Neo.Compiler.CSharp/MethodConvert/Expression/AssignmentExpression.CoalesceAssignment.cs
+26
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,32 @@ namespace Neo.Compiler;
21
21
22
22
partialclassMethodConvert
23
23
{
24
+
/// <summary>
25
+
/// Converts the code for null-coalescing assignment expression into OpCodes.
26
+
/// The null-coalescing assignment operator ??= assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null.
27
+
/// The ??= operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null.
28
+
/// Null-coalescing assignment expressions are a new feature introduced in C# 8.0(Released September, 2019).
29
+
/// </summary>
30
+
/// <param name="model">The semantic model providing context and information about coalesce assignment expression.</param>
31
+
/// <param name="expression">The syntax representation of the coalesce assignment expression statement being converted.</param>
32
+
/// <exception cref="CompilationException">Thrown when the syntax is not supported.</exception>
/// <c>nullableCat ??= nonNullableCat;</c> this line is evaluated as
47
+
/// <c>nullableCat = nullableCat ?? nonNullableCat;</c> is evaluated as <c>if (nullableCat == null) nullableCat = nonNullableCat;</c>
48
+
/// </example>
49
+
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator">?? and ??= operators - the null-coalescing operators</seealso>
Copy file name to clipboardexpand all lines: src/Neo.Compiler.CSharp/MethodConvert/Expression/AssignmentExpression.ComplexAssignment.cs
+28
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,34 @@ namespace Neo.Compiler;
21
21
22
22
partialclassMethodConvert
23
23
{
24
+
/// <summary>
25
+
/// Converts the code for complex assignment (or compound assignment) expression into OpCodes.
26
+
/// </summary>
27
+
/// <param name="model">The semantic model providing context and information about complex assignment expression.</param>
28
+
/// <param name="expression">The syntax representation of the complex assignment expression statement being converted.</param>
29
+
/// <exception cref="CompilationException">Thrown when the syntax is not supported.</exception>
30
+
/// <remarks>
31
+
/// For a binary operator op, a compound assignment expression of the form "x op= y" is equivalent to "x = x op y" except that x is only evaluated once.
32
+
/// </remarks>
33
+
/// <example>
34
+
/// The following example demonstrates the usage of compound assignment with arithmetic operators:
35
+
/// The corresponding code branch is "ConvertComplexAssignmentExpression"
Copy file name to clipboardexpand all lines: src/Neo.Compiler.CSharp/MethodConvert/Expression/BinaryExpression.cs
+26
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,32 @@ namespace Neo.Compiler;
19
19
20
20
partialclassMethodConvert
21
21
{
22
+
/// <summary>
23
+
/// The conditional logical OR operator ||, also known as the "short-circuiting" logical OR operator, computes the logical OR of its operands.
24
+
/// The result of x || y is true if either x or y evaluates to true.
25
+
/// Otherwise, the result is false. If x evaluates to true, y isn't evaluated.
26
+
///
27
+
/// The conditional logical AND operator &&, also known as the "short-circuiting" logical AND operator, computes the logical AND of its operands.
28
+
/// The result of x && y is true if both x and y evaluate to true.
29
+
/// Otherwise, the result is false. If x evaluates to false, y isn't evaluated.
30
+
///
31
+
/// The is operator checks if the run-time type of an expression result is compatible with a given type. The is operator also tests an expression result against a pattern.
32
+
///
33
+
/// The as operator explicitly converts the result of an expression to a given reference or nullable value type. If the conversion isn't possible, the as operator returns null. Unlike a cast expression, the as operator never throws an exception.
34
+
///
35
+
/// The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null;
36
+
/// otherwise, it evaluates the right-hand operand and returns its result.
37
+
/// The ?? operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null.
38
+
/// </summary>
39
+
/// <param name="model">The semantic model providing context and information about binary expression.</param>
40
+
/// <param name="expression">The syntax representation of the binary expression statement being converted.</param>
41
+
/// <exception cref="CompilationException">If an unsupported operator is encountered</exception>
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast">Type-testing operators and cast expressions - is, as</seealso>
44
+
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator">?? operators - the null-coalescing operators</seealso>
45
+
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators">Bitwise and shift operators</seealso>
Copy file name to clipboardexpand all lines: src/Neo.Compiler.CSharp/MethodConvert/Expression/ConditionalAccessExpression.cs
+30
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,36 @@ namespace Neo.Compiler;
19
19
20
20
partialclassMethodConvert
21
21
{
22
+
/// <summary>
23
+
/// This method converts a null-conditional access expression to OpCodes.
24
+
/// </summary>
25
+
/// /// <param name="model">The semantic model providing context and information about null-conditional access expression.</param>
26
+
/// <param name="expression">The syntax representation of the null-conditional access expression statement being converted.</param>
27
+
/// <remarks>
28
+
/// The method evaluates the expression and checks if it is null.
29
+
/// If the expression is not null, it converts the 'WhenNotNull' part of the expression.
30
+
/// If the resulting type of the expression is 'System.Void', it handles the case differently by dropping the result.
31
+
/// A null-conditional operator applies a member access (?.) or element access (?[]) operation to its operand only if that operand evaluates to non-null;
32
+
/// otherwise, it returns null.
33
+
/// It will jump to <see cref="ConvertMemberBindingExpression"/> and <see cref="ConvertElementBindingExpression"/> to handle the case where the variable or array is not null.
34
+
/// </remarks>
35
+
/// <example>
36
+
/// If Block is not null, get the block's timestamp; otherwise, it returns null.
37
+
/// <code>
38
+
/// var block = Ledger.GetBlock(10000);
39
+
/// var timestamp = block?.Timestamp;
40
+
/// Runtime.Log(timestamp.ToString());
41
+
/// </code>
42
+
/// If array is not null, get the array's element; otherwise, it returns null.
43
+
/// <code>
44
+
/// var a = Ledger.GetBlock(10000);
45
+
/// var b = Ledger.GetBlock(10001);
46
+
/// var array = new[] { a, b };
47
+
/// var firstItem = array?[0];
48
+
/// Runtime.Log(firstItem?.Timestamp.ToString());
49
+
/// </code>
50
+
/// </example>
51
+
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-">Null-conditional operators ?. and ?[]</seealso>
0 commit comments