X Tutup
Skip to content

Commit 16ec3dd

Browse files
committed
sVB 3.1.2
1 parent 198f35a commit 16ec3dd

File tree

488 files changed

+112457
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

488 files changed

+112457
-530
lines changed

SBCompiler/SBCompiler/Expressions/ArrayExpression.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@ Namespace Microsoft.SmallVisualBasic.Expressions
117117
Return Nothing
118118
End Function
119119

120+
Public Overrides Function ToVB() As String
121+
Return $"{LeftHand.ToVB()}({Indexer.ToVB()})"
122+
End Function
120123
End Class
121124
End Namespace

SBCompiler/SBCompiler/Expressions/BinaryExpression.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,8 @@ Namespace Microsoft.SmallVisualBasic.Expressions
171171
End Select
172172
End Function
173173

174+
Public Overrides Function ToVB() As String
175+
Return $"({LeftHandSide.ToVB()} {[Operator].Text} {RightHandSide.ToVB()})"
176+
End Function
174177
End Class
175178
End Namespace

SBCompiler/SBCompiler/Expressions/Expression.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ Namespace Microsoft.SmallVisualBasic.Expressions
2121
Public MustOverride Function InferType(symbolTable As SymbolTable) As VariableType
2222

2323
Public MustOverride Function Evaluate(runner As Engine.ProgramRunner) As Library.Primitive
24+
25+
Public MustOverride Function ToVB() As String
26+
2427
End Class
2528
End Namespace

SBCompiler/SBCompiler/Expressions/IdentifierExpression.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,9 @@ Namespace Microsoft.SmallVisualBasic.Expressions
5858

5959
Return Nothing
6060
End Function
61+
62+
Public Overrides Function ToVB() As String
63+
Return Identifier.Text
64+
End Function
6165
End Class
6266
End Namespace

SBCompiler/SBCompiler/Expressions/InitializerExpression.vb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,22 @@ Namespace Microsoft.SmallVisualBasic.Expressions
122122
Next
123123
Return arr
124124
End Function
125+
126+
Public Overrides Function ToVB() As String
127+
Dim x = New Primitive({1, 2, 3, 4}, False)
128+
Dim sb As New StringBuilder("New Primitive({")
129+
130+
If Arguments.Count > 0 Then
131+
For Each arg In Arguments
132+
sb.Append(arg.ToVB())
133+
sb.Append(", ")
134+
Next
135+
136+
sb.Remove(sb.Length - 2, 2)
137+
End If
138+
139+
sb.Append("}, False)")
140+
Return sb.ToString()
141+
End Function
125142
End Class
126143
End Namespace

SBCompiler/SBCompiler/Expressions/LiteralExpression.vb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ Namespace Microsoft.SmallVisualBasic.Expressions
129129

130130
Select Case Literal.Type
131131
Case TokenType.StringLiteral
132-
Return New Library.Primitive(GetString(Literal.Text, """"))
132+
Return New Library.Primitive(GetString(text, """"))
133133

134134
Case TokenType.DateLiteral
135-
Dim result = Parser.ParseDateLiteral(Literal.Text)
135+
Dim result = Parser.ParseDateLiteral(text)
136136
Return If(result.IsDate,
137137
Library.Primitive.DateToPrimitive(result.Ticks),
138138
Library.Primitive.TimeSpanToPrimitive(result.Ticks)
@@ -150,6 +150,20 @@ Namespace Microsoft.SmallVisualBasic.Expressions
150150

151151
End Function
152152

153+
Public Overrides Function ToVB() As String
154+
Dim text = _Literal.Text
155+
156+
If Literal.Type = TokenType.DateLiteral Then
157+
Dim result = Parser.ParseDateLiteral(text)
158+
If result.IsDate Then
159+
Return $"Date.Parse(""{text.Trim("#"c)}"", CultureInfo.InvariantCulture)"
160+
Else
161+
Return $"TimeSpan.Parse(""{text.Trim("#"c, "+"c)}"", CultureInfo.InvariantCulture)"
162+
End If
163+
Else
164+
Return text
165+
End If
166+
End Function
153167
End Class
154168

155169
End Namespace

SBCompiler/SBCompiler/Expressions/MethodCallExpression.vb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,26 @@ Namespace Microsoft.SmallVisualBasic.Expressions
191191
End If
192192
End Function
193193

194+
Public Overrides Function ToVB() As String
195+
Dim sb As New StringBuilder()
196+
197+
If Not _TypeName.IsIllegal Then
198+
sb.Append($"{_TypeName.Text}.")
199+
End If
200+
201+
sb.Append(_MethodName.Text & "(")
202+
203+
If _Arguments.Count > 0 Then
204+
For Each arg In _Arguments
205+
sb.Append(arg.ToVB())
206+
sb.Append(", ")
207+
Next
208+
209+
sb.Remove(sb.Length - 2, 2)
210+
End If
211+
212+
sb.Append(")")
213+
Return sb.ToString()
214+
End Function
194215
End Class
195216
End Namespace

SBCompiler/SBCompiler/Expressions/NegativeExpression.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ Namespace Microsoft.SmallVisualBasic.Expressions
4242
Public Overrides Function Evaluate(runner As Engine.ProgramRunner) As Primitive
4343
Return -_Expression.Evaluate(runner)
4444
End Function
45+
46+
Public Overrides Function ToVB() As String
47+
Return $"-{Expression.ToVB()}"
48+
End Function
4549
End Class
4650
End Namespace

SBCompiler/SBCompiler/Expressions/NothingExpression.vb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Namespace Microsoft.SmallVisualBasic.Expressions
5454
Public Overrides Function Evaluate(runner As Engine.ProgramRunner) As Primitive
5555
Return Nothing
5656
End Function
57+
58+
Public Overrides Function ToVB() As String
59+
' Must use RemoveHandler in VB
60+
' ToDo: Replace handler with the subroutine name!
61+
Dim s = CType(Me.Parent, Statements.AssignmentStatement)
62+
Return $"RemoveHandler {s.LeftValue}, handler"
63+
End Function
5764
End Class
5865

5966
End Namespace

SBCompiler/SBCompiler/Expressions/PropertyExpression.vb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,11 @@ Namespace Microsoft.SmallVisualBasic.Expressions
125125
End If
126126
End Function
127127

128+
Public Overrides Function ToVB() As String
129+
If IsDynamic Then
130+
Return $"{TypeName.Text}({PropertyName.Text})"
131+
End If
132+
Return $"{TypeName.Text}.{PropertyName.Text}"
133+
End Function
128134
End Class
129135
End Namespace

0 commit comments

Comments
 (0)
X Tutup