Skip to content

Commit

Permalink
some major work for #434
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Nov 17, 2024
1 parent 7fe7da8 commit 2e82c26
Show file tree
Hide file tree
Showing 4 changed files with 1,823 additions and 1,722 deletions.
22 changes: 15 additions & 7 deletions src/FastExpressionCompiler.LightExpression/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ THE SOFTWARE.
namespace FastExpressionCompiler.LightExpression;

using static ExpressionCompiler;
using static ToCSharpPrinter;
using static CodePrinter;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

Expand Down Expand Up @@ -72,9 +74,9 @@ public virtual bool TryEmit(CompilerFlags flags, ref ClosureInfo closure, IParam
ILGenerator il, ParentFlags parent, int byRefIndex = -1) => false;

public virtual bool IsCustomToCSharpString => false;
public virtual StringBuilder CustomToCSharpString(StringBuilder sb, ToCSharpPrinter.EnclosedIn enclosedIn,
public virtual StringBuilder CustomToCSharpString(StringBuilder sb, EnclosedIn enclosedIn, ref SmallList4<object> uniquelyNamed,
int lineIndent = 0, bool stripNamespace = false, Func<Type, string, string> printType = null, int indentSpaces = 4,
CodePrinter.ObjectToCode notRecognizedToCode = null) => sb;
ObjectToCode notRecognizedToCode = null) => sb;

#if SUPPORTS_VISITOR
protected internal abstract Expression Accept(ExpressionVisitor visitor);
Expand Down Expand Up @@ -3200,15 +3202,17 @@ public override bool TryEmit(CompilerFlags flags, ref ClosureInfo closure, IPara
}

public override bool IsCustomToCSharpString => true;
public override StringBuilder CustomToCSharpString(StringBuilder sb, ToCSharpPrinter.EnclosedIn enclosedIn,
public override StringBuilder CustomToCSharpString(StringBuilder sb,
EnclosedIn enclosedIn, ref SmallList4<object> uniquelyNamed,
int lineIndent = 0, bool stripNamespace = false, Func<Type, string, string> printType = null, int indentSpaces = 4,
CodePrinter.ObjectToCode notRecognizedToCode = null)
ObjectToCode notRecognizedToCode = null)
{
var encloseInParens = enclosedIn != ToCSharpPrinter.EnclosedIn.LambdaBody && enclosedIn != ToCSharpPrinter.EnclosedIn.Return;
var encloseInParens = enclosedIn != EnclosedIn.LambdaBody && enclosedIn != EnclosedIn.Return;
sb = encloseInParens ? sb.Append("((") : sb.Append('(');

sb.Append(Type.ToCode(stripNamespace, printType)).Append(')');
sb = Operand.ToCSharpString(sb, lineIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode);
sb = Operand.ToCSharpString(sb, EnclosedIn.ParensByDefault, ref uniquelyNamed,
lineIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode);

sb.Append(".Invoke"); // Hey, this is the CUSTOM part of the output.

Expand Down Expand Up @@ -5043,7 +5047,11 @@ internal System.Linq.Expressions.LabelTarget ToSystemLabelTarget(ref SmallList<L
return sysItem;
}

public override string ToString() => this.ToCSharpString(new StringBuilder()).ToString();
public override string ToString()
{
SmallList4<object> uniquelyNamed = default;
return new StringBuilder().AppendLabelName(this, ref uniquelyNamed).ToString();
}
}

public sealed class TypedLabelTarget : LabelTarget
Expand Down
Loading

0 comments on commit 2e82c26

Please sign in to comment.