mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #15036 from michaelnebel/csharp/intptrdefaultssimple
C#: Parameter defaults for `nint` and `nuint` in compiled code.
This commit is contained in:
@@ -214,7 +214,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
if (type.SpecialType is SpecialType.None)
|
||||
{
|
||||
return ImplicitCast.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
|
||||
return ImplicitCast.CreateGeneratedConversion(cx, parent, childIndex, type, defaultValue, location);
|
||||
}
|
||||
|
||||
if (type.SpecialType is SpecialType.System_DateTime)
|
||||
@@ -222,6 +222,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
return DateTimeObjectCreation.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
|
||||
}
|
||||
|
||||
if (type.SpecialType is SpecialType.System_IntPtr || type.SpecialType is SpecialType.System_UIntPtr)
|
||||
{
|
||||
return ImplicitCast.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
|
||||
}
|
||||
|
||||
// const literal:
|
||||
return Literal.CreateGenerated(cx, parent, childIndex, type, defaultValue, location);
|
||||
}
|
||||
|
||||
@@ -51,8 +51,10 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
)
|
||||
.FirstOrDefault();
|
||||
|
||||
// Creates a new generated expression with an implicit cast added, if needed.
|
||||
public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object value,
|
||||
/// <summary>
|
||||
/// Creates a new generated expression with an implicit conversion added.
|
||||
/// </summary>
|
||||
public static Expression CreateGeneratedConversion(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object value,
|
||||
Extraction.Entities.Location location)
|
||||
{
|
||||
ExpressionInfo create(ExprKind kind, string? v) =>
|
||||
@@ -79,7 +81,27 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a new expression, adding casts as required.
|
||||
/// <summary>
|
||||
/// Creates a new generated cast expression.
|
||||
/// </summary>
|
||||
public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object value,
|
||||
Extraction.Entities.Location location)
|
||||
{
|
||||
var info = new ExpressionInfo(cx,
|
||||
AnnotatedTypeSymbol.CreateNotAnnotated(type),
|
||||
location,
|
||||
ExprKind.CAST,
|
||||
parent,
|
||||
childIndex,
|
||||
true,
|
||||
ValueAsString(value));
|
||||
|
||||
return new Expression(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new expression, adding casts as required.
|
||||
/// </summary>
|
||||
public static Expression Create(ExpressionNodeInfo info)
|
||||
{
|
||||
var resolvedType = info.ResolvedType;
|
||||
|
||||
Reference in New Issue
Block a user