-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLocalFunction.cs
More file actions
48 lines (41 loc) · 1.62 KB
/
LocalFunction.cs
File metadata and controls
48 lines (41 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.CodeAnalysis;
namespace Semmle.Extraction.CSharp.Entities
{
class LocalFunction : Method
{
LocalFunction(Context cx, IMethodSymbol init) : base(cx, init)
{
}
public override IId Id
{
get
{
return new Key(tb =>
{
tb.Append(Location);
if (symbol.IsGenericMethod && !IsSourceDeclaration)
{
tb.Append("<");
tb.BuildList(",", symbol.TypeArguments, (ta, tb0) => AddSignatureTypeToId(Context, tb0, symbol, ta));
tb.Append(">");
}
tb.Append(";localfunction");
});
}
}
public static new LocalFunction Create(Context cx, IMethodSymbol field) => LocalFunctionFactory.Instance.CreateEntity(cx, field);
class LocalFunctionFactory : ICachedEntityFactory<IMethodSymbol, LocalFunction>
{
public static readonly LocalFunctionFactory Instance = new LocalFunctionFactory();
public LocalFunction Create(Context cx, IMethodSymbol init) => new LocalFunction(cx, init);
}
public override void Populate()
{
PopulateMethod();
var originalDefinition = IsSourceDeclaration ? this : Create(Context, symbol.OriginalDefinition);
var returnType = Type.Create(Context, symbol.ReturnType);
Context.Emit(Tuples.local_functions(this, symbol.Name, returnType, originalDefinition));
ExtractRefReturn();
}
}
}