Skip to content

Commit a6fd7a3

Browse files
committed
C#: Extract record declarations
1 parent f0d5a91 commit a6fd7a3

9 files changed

Lines changed: 684 additions & 88 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp/Populators/TypeContainerVisitor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public override void VisitDelegateDeclaration(DelegateDeclarationSyntax node)
4343
Entities.NamedType.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(trapFile, parent);
4444
}
4545

46+
public override void VisitRecordDeclaration(RecordDeclarationSyntax node)
47+
{
48+
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(trapFile, parent);
49+
}
50+
4651
public override void VisitClassDeclaration(ClassDeclarationSyntax classDecl)
4752
{
4853
Entities.Type.Create(cx, cx.GetModel(classDecl).GetDeclaredSymbol(classDecl)).ExtractRecursive(trapFile, parent);

csharp/ql/src/semmle/code/csharp/PrintAst.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ private ValueOrRefType getAnInterestingBaseType(ValueOrRefType type) {
102102
not type instanceof ArrayType and
103103
not type instanceof NullableType and
104104
result = type.getABaseType() and
105-
isInterestingBaseType(result)
105+
isInterestingBaseType(type, result)
106106
}
107107

108-
private predicate isInterestingBaseType(ValueOrRefType base) {
108+
private predicate isInterestingBaseType(ValueOrRefType type, ValueOrRefType base) {
109109
not base instanceof ObjectType and
110110
not base.getQualifiedName() = "System.ValueType" and
111111
not base.getQualifiedName() = "System.Delegate" and
112112
not base.getQualifiedName() = "System.MulticastDelegate" and
113-
not base.getQualifiedName() = "System.Enum"
113+
not base.getQualifiedName() = "System.Enum" and
114+
exists(TypeMention tm | tm.getTarget() = type and tm.getType() = base)
114115
}
115116

116117
/**

csharp/ql/test/library-tests/csharp9/InitOnlyProperty.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
using System;
22

3-
namespace System.Runtime.CompilerServices
4-
{
5-
public sealed class IsExternalInit
6-
{
7-
}
8-
}
9-
103
public class Base
114
{
125
public int Prop0 { get { return 1; } init { Prop1 = value; } }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System;
2+
using System.Text;
3+
4+
namespace System.Runtime.CompilerServices
5+
{
6+
public class IsExternalInit { }
7+
}

0 commit comments

Comments
 (0)