Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CapturedReferenceValue.cs « DataFlow « ILLink.RoslynAnalyzer « src - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9fc77bc7f5c0115b5a8e72e877d15f6a0d29e45 (plain)
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
49
50
51
52
53
54
55
56
57
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using ILLink.Shared.DataFlow;
using Microsoft.CodeAnalysis;

namespace ILLink.RoslynAnalyzer.DataFlow
{
	public struct CapturedReferenceValue : IEquatable<CapturedReferenceValue>
	{
		public readonly IOperation? Reference;

		public CapturedReferenceValue (IOperation operation)
		{
			switch (operation.Kind) {
			case OperationKind.PropertyReference:
			case OperationKind.LocalReference:
			case OperationKind.FieldReference:
			case OperationKind.ParameterReference:
			case OperationKind.ArrayElementReference:
			case OperationKind.ImplicitIndexerReference:
				break;
			case OperationKind.None:
			case OperationKind.InstanceReference:
			case OperationKind.Invocation:
			case OperationKind.EventReference:
				// These will just be ignored when referenced later.
				break;
			default:
				throw new NotImplementedException (operation.Kind.ToString ());
			}
			Reference = operation;
		}

		public bool Equals (CapturedReferenceValue other) => Reference == other.Reference;
	}


	public struct CapturedReferenceLattice : ILattice<CapturedReferenceValue>
	{
		public CapturedReferenceValue Top => new CapturedReferenceValue ();

		public CapturedReferenceValue Meet (CapturedReferenceValue left, CapturedReferenceValue right)
		{
			if (left.Equals (right))
				return left;
			if (left.Reference == null)
				return right;
			if (right.Reference == null)
				return left;
			// Both non-null and different shouldn't happen.
			// We assume that a flow capture can capture only a single property.
			throw new InvalidOperationException ();
		}
	}
}