Skip to content
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

comment for Expression #980

Merged
merged 40 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5709e36
update
chenzhitong Mar 4, 2024
0d8976b
Update BinaryExpression.cs
chenzhitong Mar 4, 2024
2134fb1
Update AnonymousObjectCreationExpression.cs
chenzhitong Mar 4, 2024
ceb138b
Update ElementExpression.cs
chenzhitong Mar 4, 2024
7f35bfc
Update CastExpression.cs
chenzhitong Mar 4, 2024
dec24ed
Update CastExpression.cs
chenzhitong Mar 4, 2024
9249d59
Update ConditionalAccessExpression.cs
chenzhitong Mar 4, 2024
3809a63
TernaryConditional & NullConditionalAccess
chenzhitong Mar 4, 2024
6b22cfe
revert rename
chenzhitong Mar 4, 2024
566af11
update ConvertCheckedExpression.cs
chenzhitong Mar 4, 2024
48671e5
Update IdentifierNameExpression.cs
chenzhitong Mar 4, 2024
443380b
Update ImplicitArrayCreationExpression.cs
chenzhitong Mar 5, 2024
e580b19
update InterpolatedStringExpression.cs
chenzhitong Mar 5, 2024
ff9e303
update
chenzhitong Mar 5, 2024
283ee84
Update SwitchExpression.cs
chenzhitong Mar 5, 2024
139cd1a
update
chenzhitong Mar 6, 2024
6c229be
Merge branch 'master' into comment2
shargon Mar 6, 2024
bdf62ef
update
chenzhitong Mar 7, 2024
5092117
Merge branch 'comment2' of https://github.com/chenzhitong/neo-devpack…
chenzhitong Mar 7, 2024
5e9077c
update
chenzhitong Mar 7, 2024
7f3fcd4
Merge branch 'master' into comment2
Jim8y Mar 7, 2024
ea2b666
add seealso
chenzhitong Mar 7, 2024
6f8fafe
Merge branch 'comment2' of https://github.com/chenzhitong/neo-devpack…
chenzhitong Mar 7, 2024
7c9ed32
update
chenzhitong Mar 7, 2024
5831fce
update
chenzhitong Mar 7, 2024
f2c27c2
ConvertMemberBindingExpression and ConvertElementBindingExpression
chenzhitong Mar 8, 2024
637c061
ConvertInitializerExpression
chenzhitong Mar 8, 2024
3ce867a
BaseExpression and ThisExpression
chenzhitong Mar 8, 2024
fb99b89
Create Contract_Logical.cs
chenzhitong Mar 8, 2024
c4027cd
Update Contract_Logical.cs
chenzhitong Mar 8, 2024
a57885b
format
chenzhitong Mar 8, 2024
aeb9abf
add ut
chenzhitong Mar 8, 2024
d922352
Update Contract_NULL.cs
chenzhitong Mar 8, 2024
1cc369d
throw
chenzhitong Mar 8, 2024
e08b74f
Merge branch 'master' into comment2
Jim8y Mar 8, 2024
1218f3d
Merge branch 'master' into comment2
Jim8y Mar 8, 2024
c6a9ab3
fix
chenzhitong Mar 8, 2024
ad70e85
Merge branch 'comment2' of https://github.com/chenzhitong/neo-devpack…
chenzhitong Mar 8, 2024
bbcd3e0
delegate
chenzhitong Mar 8, 2024
0b8358b
Update src/Neo.Compiler.CSharp/MethodConvert/Expression/AssignmentExp…
shargon Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ namespace Neo.Compiler;

partial class MethodConvert
{
/// <summary>
/// Methods for converting the creation of an object of an anonymous type into a series of instructions.
/// </summary>
/// <param name="model">The semantic model providing context and information about the anonymous object creation.</param>
/// <param name="expression">The syntax representation of the anonymous object creation statement being converted.</param>
/// <remarks>
/// 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. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too long, break into two lines please

/// </remarks>
/// <example>
/// The following example shows an anonymous type that is initialized with two properties named Amount and Message.
/// <code>
/// var v = new { Amount = 108, Message = "Hello" };
/// Runtime.Log(v.Amount + v.Message);
/// </code>
/// </example>
private void ConvertAnonymousObjectCreationExpression(SemanticModel model, AnonymousObjectCreationExpressionSyntax expression)
{
AddInstruction(OpCode.NEWARRAY0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ namespace Neo.Compiler;

partial class MethodConvert
{
/// <summary>
/// Converts the code for constructing arrays and initializing arrays into a sequence of instructions.
/// This method includes analyzing the array length, array type, array dimension and initial data.
/// </summary>
/// <param name="model">The semantic model providing context and information about the array creation.</param>
/// <param name="expression">The syntax representation of the array creation statement being converted.</param>
/// <exception cref="CompilationException">Only one-dimensional arrays are supported, otherwise an exception is thrown.</exception>
/// <remarks>
/// When the array is initialized to null, this code converts it to "array length" + OpCode.NEWBUFFER (only for byte[]) or OpCode.NEWARRAY_T.
/// 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
/// </remarks>
/// <example>
/// Example of a array creation syntax:
/// <code>
/// var array = new byte[4];
/// </code>
/// The compilation result of the example code is: OpCode.PUSH4, OpCode.NEWBUFFER
/// <code>
/// var array = new int[4] { 5, 6, 7, 8};
/// </code>
/// The compilation result of the example code is: OpCode.PUSH8, OpCode.PUSH7, OpCode.PUSH6, OpCode.PUSH5, OpCode.PUSH4, OpCode.PACK
/// </example>
private void ConvertArrayCreationExpression(SemanticModel model, ArrayCreationExpressionSyntax expression)
{
ArrayRankSpecifierSyntax specifier = expression.Type.RankSpecifiers[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ namespace Neo.Compiler;

partial class MethodConvert
{
/// <summary>
/// The assignment operator = assigns the value of its right-hand operand to a variable,
/// a property, or an indexer element given by its left-hand operand.
/// The result of an assignment expression is the value assigned to the left-hand operand.
/// The type of the right-hand operand must be the same as the type of the left-hand operand or implicitly convertible to it.
/// 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.
/// The ??= operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null.
/// </summary>
/// <param name="model">The semantic model providing context and information about assignment expression.</param>
/// <param name="expression">The syntax representation of the assignment expression statement being converted.</param>
/// <example>
/// The assignment operator = is right-associative, that is, an expression of the form
/// <code>
/// a = b = c
/// </code>
/// is evaluated as
/// <code>
/// a = (b = c)
/// </code>
/// </example>
private void ConvertAssignmentExpression(SemanticModel model, AssignmentExpressionSyntax expression)
{
switch (expression.OperatorToken.ValueText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ namespace Neo.Compiler;

partial class MethodConvert
{
/// <summary>
/// The conditional logical OR operator ||, also known as the "short-circuiting" logical OR operator, computes the logical OR of its operands.
/// The result of x || y is true if either x or y evaluates to true.
/// Otherwise, the result is false. If x evaluates to true, y isn't evaluated.
///
/// The conditional logical AND operator &&, also known as the "short-circuiting" logical AND operator, computes the logical AND of its operands.
/// The result of x && y is true if both x and y evaluate to true.
/// Otherwise, the result is false. If x evaluates to false, y isn't evaluated.
///
/// 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.
///
/// 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.
///
/// The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null;
/// otherwise, it evaluates the right-hand operand and returns its result.
/// The ?? operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null.
/// </summary>
/// <param name="model">The semantic model providing context and information about binary expression.</param>
/// <param name="expression">The syntax representation of the binary expression statement being converted.</param>
/// <exception cref="CompilationException">If an unsupported operator is encountered</exception>
private void ConvertBinaryExpression(SemanticModel model, BinaryExpressionSyntax expression)
{
switch (expression.OperatorToken.ValueText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ namespace Neo.Compiler;

partial class MethodConvert
{
/// <summary>
/// Converts the code for tuple type into a sequence of instructions.
/// </summary>
/// <param name="model">The semantic model providing context and information about the tuple type.</param>
/// <param name="expression">The syntax representation of the tuple type statement being converted.</param>
/// <example>
/// The tuples feature provides concise syntax to group multiple data elements in a lightweight data structure.
/// The following example shows how you can declare a tuple variable, initialize it, and access its data members:
/// <code>
/// (string, int) t1 = ("chris", 3);
/// Runtime.Log($"Tuple with elements {t1.Item1} and {t1.Item2}.");
/// (string Name, int Count) t2 = ("chris", 3);
/// Runtime.Log($"Sum of {t2.Name} elements is {t2.Count}.");
/// </code>
/// </example>
private void ConvertTupleExpression(SemanticModel model, TupleExpressionSyntax expression)
{
AddInstruction(OpCode.NEWSTRUCT0);
Expand Down
Loading