4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) .NET Foundation and Contributors
4 |
5 | All rights reserved.
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
--------------------------------------------------------------------------------
/image/image.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:3f05217ac6b5ac776a41905a6eca2dceb325da7f33a7ad95cd3e2b11a8ae92f5
3 | size 27152
4 |
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Directory.build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(AssemblyName) ($(TargetFramework))
4 |
5 |
6 |
7 | $(DefineConstants);NET_45;XAML
8 |
9 |
10 | $(DefineConstants);NETFX_CORE;XAML;WINDOWS_UWP
11 |
12 |
13 | $(DefineConstants);MONO;UIKIT;COCOA
14 |
15 |
16 | $(DefineConstants);MONO;COCOA
17 |
18 |
19 | $(DefineConstants);MONO;UIKIT;COCOA
20 |
21 |
22 | $(DefineConstants);MONO;UIKIT;COCOA
23 |
24 |
25 | $(DefineConstants);MONO;ANDROID
26 |
27 |
28 | $(DefineConstants);TIZEN
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/DecompilerNuGetPackageIcon.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:9a405719968acc92a330412b4c1c8ebc8d2c30996c4027c6ba9035db2424bee6
3 | size 2454
4 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | netstandard2.0;net6.0;net7.0
6 |
7 | IL decompiler engine
8 | ic#code
9 | ILSpy
10 | Copyright 2011-2020 AlphaSierraPapa for the SharpDevelop Team
11 | en-US
12 |
13 | latest
14 | true
15 | 1701;1702;1591;1573
16 | false
17 | false
18 | false
19 | true
20 | false
21 | $(NoWarn);SYSLIB0011
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | TextTemplatingFileGenerator
32 | ILOpCodes.cs
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | True
43 | True
44 | ILOpCodes.tt
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/IL/PrimitiveType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Reflection.Metadata;
20 |
21 | namespace ICSharpCode.Decompiler.IL
22 | {
23 | public enum PrimitiveType : byte
24 | {
25 | None,
26 | I1 = PrimitiveTypeCode.SByte,
27 | I2 = PrimitiveTypeCode.Int16,
28 | I4 = PrimitiveTypeCode.Int32,
29 | I8 = PrimitiveTypeCode.Int64,
30 | R4 = PrimitiveTypeCode.Single,
31 | R8 = PrimitiveTypeCode.Double,
32 | U1 = PrimitiveTypeCode.Byte,
33 | U2 = PrimitiveTypeCode.UInt16,
34 | U4 = PrimitiveTypeCode.UInt32,
35 | U8 = PrimitiveTypeCode.UInt64,
36 | I = PrimitiveTypeCode.IntPtr,
37 | U = PrimitiveTypeCode.UIntPtr,
38 | /// Managed reference
39 | Ref = 16,
40 | /// Floating point type of unspecified size:
41 | /// usually 80 bits on x86 (when the runtime uses x87 instructions);
42 | /// but only 64-bit on x64.
43 | /// This only occurs for "conv.r.un" instructions. The C# compiler usually follows those
44 | /// with a "conv.r4" or "conv.r8" instruction to indicate the desired float type, so
45 | /// we only use this as conversion target type and don't bother tracking it as its own stack type:
46 | /// basically everything treats R identical to R8, except for the (conv.r.un + conv.r[48] => conv.r[48].un)
47 | /// combining logic which should not combine (conv.r.un + conv.r8 + conv.r4) into a single conv.r4.un.
48 | ///
49 | R = 254,
50 | Unknown = 255
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/ITextOutput.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 |
20 | using System.Reflection.Metadata;
21 |
22 | using ICSharpCode.Decompiler.Disassembler;
23 | using ICSharpCode.Decompiler.Metadata;
24 | using ICSharpCode.Decompiler.TypeSystem;
25 |
26 | namespace ICSharpCode.Decompiler
27 | {
28 | public interface ITextOutput
29 | {
30 | string IndentationString { get; set; }
31 | void Indent();
32 | void Unindent();
33 | void Write(char ch);
34 | void Write(string text);
35 | void WriteLine();
36 | void WriteReference(OpCodeInfo opCode, bool omitSuffix = false);
37 | void WriteReference(PEFile module, Handle handle, string text, string protocol = "decompile", bool isDefinition = false);
38 | void WriteReference(IType type, string text, bool isDefinition = false);
39 | void WriteReference(IMember member, string text, bool isDefinition = false);
40 | void WriteLocalReference(string text, object reference, bool isDefinition = false);
41 |
42 | void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false);
43 | void MarkFoldEnd();
44 | }
45 |
46 | public static class TextOutputExtensions
47 | {
48 | public static void Write(this ITextOutput output, string format, params object[] args)
49 | {
50 | output.Write(string.Format(format, args));
51 | }
52 |
53 | public static void WriteLine(this ITextOutput output, string text)
54 | {
55 | output.Write(text);
56 | output.WriteLine();
57 | }
58 |
59 | public static void WriteLine(this ITextOutput output, string format, params object[] args)
60 | {
61 | output.WriteLine(string.Format(format, args));
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Siegfried Pammer
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Runtime.Serialization;
21 |
22 | namespace ICSharpCode.Decompiler.Metadata
23 | {
24 | [Serializable]
25 | public class EnumUnderlyingTypeResolveException : Exception
26 | {
27 | public EnumUnderlyingTypeResolveException() { }
28 | public EnumUnderlyingTypeResolveException(string message) : base(message) { }
29 | public EnumUnderlyingTypeResolveException(string message, Exception inner) : base(message, inner) { }
30 | protected EnumUnderlyingTypeResolveException(
31 | SerializationInfo info,
32 | StreamingContext context) : base(info, context) { }
33 | }
34 |
35 | [Serializable]
36 | public class PEFileNotSupportedException : Exception
37 | {
38 | public PEFileNotSupportedException() { }
39 | public PEFileNotSupportedException(string message) : base(message) { }
40 | public PEFileNotSupportedException(string message, Exception inner) : base(message, inner) { }
41 | protected PEFileNotSupportedException(
42 | SerializationInfo info,
43 | StreamingContext context) : base(info, context) { }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Metadata/LightJson/JsonValueType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3 |
4 | namespace LightJson
5 | {
6 | ///
7 | /// Enumerates the types of Json values.
8 | ///
9 | internal enum JsonValueType : byte
10 | {
11 | ///
12 | /// A null value.
13 | ///
14 | Null = 0,
15 |
16 | ///
17 | /// A boolean value.
18 | ///
19 | Boolean,
20 |
21 | ///
22 | /// A number value.
23 | ///
24 | Number,
25 |
26 | ///
27 | /// A string value.
28 | ///
29 | String,
30 |
31 | ///
32 | /// An object value.
33 | ///
34 | Object,
35 |
36 | ///
37 | /// An array value.
38 | ///
39 | Array,
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Metadata/LightJson/Serialization/TextPosition.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3 |
4 | namespace LightJson.Serialization
5 | {
6 | ///
7 | /// Represents a position within a plain text resource.
8 | ///
9 | internal struct TextPosition
10 | {
11 | ///
12 | /// The column position, 0-based.
13 | ///
14 | public long Column;
15 |
16 | ///
17 | /// The line position, 0-based.
18 | ///
19 | public long Line;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Metadata/MetadataTokenHelpers.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Siegfried Pammer
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Reflection.Metadata;
21 | using System.Reflection.Metadata.Ecma335;
22 |
23 | namespace ICSharpCode.Decompiler.Metadata
24 | {
25 | public static class MetadataTokenHelpers
26 | {
27 | public static EntityHandle? TryAsEntityHandle(int metadataToken)
28 | {
29 | // SRM would interpret negative token values as virtual tokens,
30 | // but that causes problems later on.
31 | if (metadataToken < 0)
32 | return null;
33 | try
34 | {
35 | return MetadataTokens.EntityHandle(metadataToken);
36 | }
37 | catch (ArgumentException)
38 | {
39 | return null;
40 | }
41 | }
42 |
43 | public static EntityHandle EntityHandleOrNil(int metadataToken)
44 | {
45 | // SRM would interpret negative token values as virtual tokens,
46 | // but that causes problems later on.
47 | if (metadataToken < 0)
48 | return MetadataTokens.EntityHandle(0);
49 | try
50 | {
51 | return MetadataTokens.EntityHandle(metadataToken);
52 | }
53 | catch (ArgumentException)
54 | {
55 | return MetadataTokens.EntityHandle(0);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Metadata/UnresolvedAssemblyNameReference.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Siegfried Pammer
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 | using System.Linq;
21 |
22 | namespace ICSharpCode.Decompiler.Metadata
23 | {
24 | public sealed class UnresolvedAssemblyNameReference
25 | {
26 | public string FullName { get; }
27 |
28 | public bool HasErrors => Messages.Any(m => m.Item1 == MessageKind.Error);
29 |
30 | public List<(MessageKind, string)> Messages { get; } = new List<(MessageKind, string)>();
31 |
32 | public UnresolvedAssemblyNameReference(string fullName)
33 | {
34 | this.FullName = fullName;
35 | }
36 | }
37 |
38 | public enum MessageKind { Error, Warning, Info }
39 | }
40 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/SRMHacks.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Immutable;
2 | using System.Reflection.Metadata;
3 |
4 | namespace ICSharpCode.Decompiler
5 | {
6 | public static partial class SRMExtensions
7 | {
8 | public static ImmutableArray GetMethodImplementations(
9 | this MethodDefinitionHandle handle, MetadataReader reader)
10 | {
11 | var resultBuilder = ImmutableArray.CreateBuilder();
12 | var typeDefinition = reader.GetTypeDefinition(reader.GetMethodDefinition(handle)
13 | .GetDeclaringType());
14 |
15 | foreach (var methodImplementationHandle in typeDefinition.GetMethodImplementations())
16 | {
17 | var methodImplementation = reader.GetMethodImplementation(methodImplementationHandle);
18 | if (methodImplementation.MethodBody == handle)
19 | {
20 | resultBuilder.Add(methodImplementationHandle);
21 | }
22 | }
23 |
24 | return resultBuilder.ToImmutable();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/AmbiguousResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.TypeSystem;
20 |
21 | namespace ICSharpCode.Decompiler.Semantics
22 | {
23 | ///
24 | /// Represents an ambiguous type resolve result.
25 | ///
26 | public class AmbiguousTypeResolveResult : TypeResolveResult
27 | {
28 | public AmbiguousTypeResolveResult(IType type) : base(type)
29 | {
30 | }
31 |
32 | public override bool IsError {
33 | get { return true; }
34 | }
35 | }
36 |
37 | ///
38 | /// Represents an ambiguous field/property/event access.
39 | ///
40 | public class AmbiguousMemberResolveResult : MemberResolveResult
41 | {
42 | public AmbiguousMemberResolveResult(ResolveResult targetResult, IMember member) : base(targetResult, member)
43 | {
44 | }
45 |
46 | public override bool IsError {
47 | get { return true; }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ArrayAccessResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 |
23 | using ICSharpCode.Decompiler.TypeSystem;
24 |
25 | namespace ICSharpCode.Decompiler.Semantics
26 | {
27 | ///
28 | /// Resolve result representing an array access.
29 | ///
30 | public class ArrayAccessResolveResult : ResolveResult
31 | {
32 | public readonly ResolveResult Array;
33 | public readonly IList Indexes;
34 |
35 | public ArrayAccessResolveResult(IType elementType, ResolveResult array, IList indexes) : base(elementType)
36 | {
37 | if (array == null)
38 | throw new ArgumentNullException(nameof(array));
39 | if (indexes == null)
40 | throw new ArgumentNullException(nameof(indexes));
41 | this.Array = array;
42 | this.Indexes = indexes;
43 | }
44 |
45 | public override IEnumerable GetChildResults()
46 | {
47 | return new[] { Array }.Concat(Indexes);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ArrayCreateResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 |
23 | using ICSharpCode.Decompiler.TypeSystem;
24 |
25 | namespace ICSharpCode.Decompiler.Semantics
26 | {
27 | ///
28 | /// Resolve result representing an array creation.
29 | ///
30 | public class ArrayCreateResolveResult : ResolveResult
31 | {
32 | ///
33 | /// Gets the size arguments.
34 | ///
35 | public readonly IReadOnlyList SizeArguments;
36 |
37 | ///
38 | /// Gets the initializer elements.
39 | /// This field may be null if no initializer was specified.
40 | ///
41 | public readonly IReadOnlyList InitializerElements;
42 |
43 | public ArrayCreateResolveResult(IType arrayType, IReadOnlyList sizeArguments, IReadOnlyList initializerElements)
44 | : base(arrayType)
45 | {
46 | if (sizeArguments == null)
47 | throw new ArgumentNullException(nameof(sizeArguments));
48 | this.SizeArguments = sizeArguments;
49 | this.InitializerElements = initializerElements;
50 | }
51 |
52 | public override IEnumerable GetChildResults()
53 | {
54 | if (InitializerElements != null)
55 | return SizeArguments.Concat(InitializerElements);
56 | else
57 | return SizeArguments;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ByReferenceResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 | using System.Globalization;
21 | using System.Linq;
22 |
23 | using ICSharpCode.Decompiler.TypeSystem;
24 |
25 | namespace ICSharpCode.Decompiler.Semantics
26 | {
27 | ///
28 | /// Represents the resolve result of an 'ref x', 'in x' or 'out x' expression.
29 | ///
30 | public class ByReferenceResolveResult : ResolveResult
31 | {
32 | public ReferenceKind ReferenceKind { get; }
33 | public bool IsOut => ReferenceKind == ReferenceKind.Out;
34 | public bool IsRef => ReferenceKind == ReferenceKind.Ref;
35 | public bool IsIn => ReferenceKind == ReferenceKind.In;
36 |
37 | public readonly ResolveResult ElementResult;
38 |
39 | public ByReferenceResolveResult(ResolveResult elementResult, ReferenceKind kind)
40 | : this(elementResult.Type, kind)
41 | {
42 | this.ElementResult = elementResult;
43 | }
44 |
45 | public ByReferenceResolveResult(IType elementType, ReferenceKind kind)
46 | : base(new ByReferenceType(elementType))
47 | {
48 | this.ReferenceKind = kind;
49 | }
50 |
51 | public IType ElementType {
52 | get { return ((ByReferenceType)this.Type).ElementType; }
53 | }
54 |
55 | public override IEnumerable GetChildResults()
56 | {
57 | if (ElementResult != null)
58 | return new[] { ElementResult };
59 | else
60 | return Enumerable.Empty();
61 | }
62 |
63 | public override string ToString()
64 | {
65 | return string.Format(CultureInfo.InvariantCulture, "[{0} {1} {2}]", GetType().Name, ReferenceKind.ToString().ToLowerInvariant(), ElementType);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ConstantResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Globalization;
20 |
21 | using ICSharpCode.Decompiler.TypeSystem;
22 |
23 | namespace ICSharpCode.Decompiler.Semantics
24 | {
25 | ///
26 | /// ResolveResult representing a compile-time constant.
27 | /// Note: this class is mainly used for literals; there may be other ResolveResult classes
28 | /// which are compile-time constants as well.
29 | /// For example, a reference to a const field results in a .
30 | ///
31 | /// Check to determine is a resolve result is a constant.
32 | ///
33 | public class ConstantResolveResult : ResolveResult
34 | {
35 | object constantValue;
36 |
37 | public ConstantResolveResult(IType type, object constantValue) : base(type)
38 | {
39 | this.constantValue = constantValue;
40 | }
41 |
42 | public override bool IsCompileTimeConstant {
43 | get { return true; }
44 | }
45 |
46 | public override object ConstantValue {
47 | get { return constantValue; }
48 | }
49 |
50 | public override string ToString()
51 | {
52 | return string.Format(CultureInfo.InvariantCulture, "[{0} {1} = {2}]", GetType().Name, this.Type, constantValue);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ErrorResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.CSharp.Syntax;
20 | using ICSharpCode.Decompiler.TypeSystem;
21 |
22 | namespace ICSharpCode.Decompiler.Semantics
23 | {
24 | ///
25 | /// Represents a resolve error.
26 | ///
27 | /// Note: some errors are represented by other classes; for example a may
28 | /// be erroneous if the conversion is invalid.
29 | ///
30 | /// .
31 | public class ErrorResolveResult : ResolveResult
32 | {
33 | ///
34 | /// Gets an ErrorResolveResult instance with Type = SpecialType.UnknownType.
35 | ///
36 | public static readonly ErrorResolveResult UnknownError = new ErrorResolveResult(SpecialType.UnknownType);
37 |
38 | public ErrorResolveResult(IType type) : base(type)
39 | {
40 | }
41 |
42 | public ErrorResolveResult(IType type, string message, TextLocation location) : base(type)
43 | {
44 | this.Message = message;
45 | this.Location = location;
46 | }
47 |
48 | public override bool IsError {
49 | get { return true; }
50 | }
51 |
52 | public string Message { get; private set; }
53 |
54 | public TextLocation Location { get; private set; }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/InitializedObjectResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.TypeSystem;
20 |
21 | namespace ICSharpCode.Decompiler.Semantics
22 | {
23 | ///
24 | /// Refers to the object that is currently being initialized.
25 | /// Used within .
26 | ///
27 | public class InitializedObjectResolveResult : ResolveResult
28 | {
29 | public InitializedObjectResolveResult(IType type) : base(type)
30 | {
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/InterpolatedStringResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Siegfried Pammer
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 |
21 | using ICSharpCode.Decompiler.TypeSystem;
22 |
23 | namespace ICSharpCode.Decompiler.Semantics
24 | {
25 | public class InterpolatedStringResolveResult : ResolveResult
26 | {
27 | public readonly string FormatString;
28 | public readonly ResolveResult[] Arguments;
29 |
30 | public InterpolatedStringResolveResult(IType stringType, string formatString, params ResolveResult[] arguments)
31 | : base(stringType)
32 | {
33 | FormatString = formatString;
34 | Arguments = arguments;
35 | }
36 |
37 | public override IEnumerable GetChildResults()
38 | {
39 | return Arguments;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/LocalResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Globalization;
21 |
22 | using ICSharpCode.Decompiler.TypeSystem;
23 |
24 | namespace ICSharpCode.Decompiler.Semantics
25 | {
26 | ///
27 | /// Represents a local variable or parameter.
28 | ///
29 | public class LocalResolveResult : ResolveResult
30 | {
31 | readonly IVariable variable;
32 |
33 | public LocalResolveResult(IVariable variable)
34 | : base(UnpackTypeIfByRefParameter(variable))
35 | {
36 | this.variable = variable;
37 | }
38 |
39 | static IType UnpackTypeIfByRefParameter(IVariable variable)
40 | {
41 | if (variable == null)
42 | throw new ArgumentNullException(nameof(variable));
43 | var type = variable.Type;
44 | if (type.Kind == TypeKind.ByReference)
45 | {
46 | var p = variable as IParameter;
47 | if (p != null && p.ReferenceKind != ReferenceKind.None)
48 | return ((ByReferenceType)type).ElementType;
49 | }
50 | return type;
51 | }
52 |
53 | public IVariable Variable {
54 | get { return variable; }
55 | }
56 |
57 | public bool IsParameter {
58 | get { return variable is IParameter; }
59 | }
60 |
61 | public override bool IsCompileTimeConstant {
62 | get { return variable.IsConst; }
63 | }
64 |
65 | public override object ConstantValue {
66 | get { return IsParameter ? null : variable.GetConstantValue(); }
67 | }
68 |
69 | public override string ToString()
70 | {
71 | return string.Format(CultureInfo.InvariantCulture, "[LocalResolveResult {0}]", variable);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/NamespaceResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Globalization;
20 |
21 | using ICSharpCode.Decompiler.TypeSystem;
22 |
23 | namespace ICSharpCode.Decompiler.Semantics
24 | {
25 | ///
26 | /// Represents that an expression resolved to a namespace.
27 | ///
28 | public class NamespaceResolveResult : ResolveResult
29 | {
30 | readonly INamespace ns;
31 |
32 | public NamespaceResolveResult(INamespace ns) : base(SpecialType.NoType)
33 | {
34 | this.ns = ns;
35 | }
36 |
37 | public INamespace Namespace {
38 | get { return ns; }
39 | }
40 |
41 | public string NamespaceName {
42 | get { return ns.FullName; }
43 | }
44 |
45 | public override string ToString()
46 | {
47 | return string.Format(CultureInfo.InvariantCulture, "[{0} {1}]", GetType().Name, ns);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/OutVarResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.TypeSystem;
20 |
21 | namespace ICSharpCode.Decompiler.Semantics
22 | {
23 | ///
24 | /// Represents the implicitly-typed "out var".
25 | /// Special-cased in overload resolution to be compatible with any out-parameter.
26 | ///
27 | class OutVarResolveResult : ResolveResult
28 | {
29 | public static readonly OutVarResolveResult Instance = new OutVarResolveResult();
30 |
31 | public OutVarResolveResult() : base(SpecialType.NoType) { }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 |
23 | using ICSharpCode.Decompiler.TypeSystem;
24 |
25 | namespace ICSharpCode.Decompiler.Semantics
26 | {
27 | ///
28 | /// Represents the result of resolving an expression.
29 | ///
30 | public class ResolveResult
31 | {
32 | readonly IType type;
33 |
34 | public ResolveResult(IType type)
35 | {
36 | if (type == null)
37 | throw new ArgumentNullException(nameof(type));
38 | this.type = type;
39 | }
40 |
41 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods",
42 | Justification = "Unrelated to object.GetType()")]
43 | public IType Type {
44 | get { return type; }
45 | }
46 |
47 | public virtual bool IsCompileTimeConstant {
48 | get { return false; }
49 | }
50 |
51 | public virtual object ConstantValue {
52 | get { return null; }
53 | }
54 |
55 | public virtual bool IsError {
56 | get { return false; }
57 | }
58 |
59 | public override string ToString()
60 | {
61 | return "[" + GetType().Name + " " + type + "]";
62 | }
63 |
64 | public virtual IEnumerable GetChildResults()
65 | {
66 | return Enumerable.Empty();
67 | }
68 |
69 | public virtual ResolveResult ShallowClone()
70 | {
71 | return (ResolveResult)MemberwiseClone();
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/SizeOfResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.Decompiler.TypeSystem;
22 |
23 | namespace ICSharpCode.Decompiler.Semantics
24 | {
25 | ///
26 | /// Represents the 'sizeof'.
27 | ///
28 | public class SizeOfResolveResult : ResolveResult
29 | {
30 | readonly IType referencedType;
31 | readonly int? constantValue;
32 |
33 | public SizeOfResolveResult(IType int32, IType referencedType, int? constantValue)
34 | : base(int32)
35 | {
36 | if (referencedType == null)
37 | throw new ArgumentNullException(nameof(referencedType));
38 | this.referencedType = referencedType;
39 | this.constantValue = constantValue;
40 | }
41 |
42 | ///
43 | /// The type referenced by the 'sizeof'.
44 | ///
45 | public IType ReferencedType {
46 | get { return referencedType; }
47 | }
48 |
49 | public override bool IsCompileTimeConstant {
50 | get {
51 | return constantValue != null;
52 | }
53 | }
54 |
55 | public override object ConstantValue {
56 | get {
57 | return constantValue;
58 | }
59 | }
60 |
61 | public override bool IsError {
62 | get {
63 | return referencedType.IsReferenceType != false;
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ThisResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.TypeSystem;
20 |
21 | namespace ICSharpCode.Decompiler.Semantics
22 | {
23 | ///
24 | /// Represents the 'this' reference.
25 | /// Also used for the 'base' reference.
26 | ///
27 | public class ThisResolveResult : ResolveResult
28 | {
29 | bool causesNonVirtualInvocation;
30 |
31 | public ThisResolveResult(IType type, bool causesNonVirtualInvocation = false) : base(type)
32 | {
33 | this.causesNonVirtualInvocation = causesNonVirtualInvocation;
34 | }
35 |
36 | ///
37 | /// Gets whether this resolve result causes member invocations to be non-virtual.
38 | ///
39 | public bool CausesNonVirtualInvocation {
40 | get { return causesNonVirtualInvocation; }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/ThrowResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.TypeSystem;
20 |
21 | namespace ICSharpCode.Decompiler.Semantics
22 | {
23 | class ThrowResolveResult : ResolveResult
24 | {
25 | public ThrowResolveResult() : base(SpecialType.NoType)
26 | {
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/TupleResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 | using System.Collections.Immutable;
21 | using System.Linq;
22 |
23 | using ICSharpCode.Decompiler.TypeSystem;
24 |
25 | namespace ICSharpCode.Decompiler.Semantics
26 | {
27 | ///
28 | /// Resolve result for a C# 7 tuple literal.
29 | ///
30 | public class TupleResolveResult : ResolveResult
31 | {
32 | public ImmutableArray Elements { get; }
33 |
34 | public TupleResolveResult(ICompilation compilation,
35 | ImmutableArray elements,
36 | ImmutableArray elementNames = default(ImmutableArray),
37 | IModule valueTupleAssembly = null)
38 | : base(GetTupleType(compilation, elements, elementNames, valueTupleAssembly))
39 | {
40 | this.Elements = elements;
41 | }
42 |
43 | public override IEnumerable GetChildResults()
44 | {
45 | return Elements;
46 | }
47 |
48 | static IType GetTupleType(ICompilation compilation, ImmutableArray elements, ImmutableArray elementNames, IModule valueTupleAssembly)
49 | {
50 | if (elements.Any(e => e.Type.Kind == TypeKind.None || e.Type.Kind == TypeKind.Null))
51 | return SpecialType.NoType;
52 | else
53 | return new TupleType(compilation, elements.Select(e => e.Type).ToImmutableArray(), elementNames, valueTupleAssembly);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/TypeIsResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.Decompiler.TypeSystem;
22 |
23 | namespace ICSharpCode.Decompiler.Semantics
24 | {
25 | ///
26 | /// Resolve result for a C# 'is' expression.
27 | /// "Input is TargetType".
28 | ///
29 | public class TypeIsResolveResult : ResolveResult
30 | {
31 | public readonly ResolveResult Input;
32 | ///
33 | /// Type that is being compared with.
34 | ///
35 | public readonly IType TargetType;
36 |
37 | public TypeIsResolveResult(ResolveResult input, IType targetType, IType booleanType)
38 | : base(booleanType)
39 | {
40 | if (input == null)
41 | throw new ArgumentNullException(nameof(input));
42 | if (targetType == null)
43 | throw new ArgumentNullException(nameof(targetType));
44 | this.Input = input;
45 | this.TargetType = targetType;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/TypeOfResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.Decompiler.TypeSystem;
22 |
23 | namespace ICSharpCode.Decompiler.Semantics
24 | {
25 | ///
26 | /// Represents the 'typeof'.
27 | ///
28 | public class TypeOfResolveResult : ResolveResult
29 | {
30 | readonly IType referencedType;
31 |
32 | public TypeOfResolveResult(IType systemType, IType referencedType)
33 | : base(systemType)
34 | {
35 | if (referencedType == null)
36 | throw new ArgumentNullException(nameof(referencedType));
37 | this.referencedType = referencedType;
38 | }
39 |
40 | ///
41 | /// The type referenced by the 'typeof'.
42 | ///
43 | public IType ReferencedType {
44 | get { return referencedType; }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Semantics/TypeResolveResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.TypeSystem;
20 |
21 | namespace ICSharpCode.Decompiler.Semantics
22 | {
23 | ///
24 | /// The resolved expression refers to a type name.
25 | ///
26 | public class TypeResolveResult : ResolveResult
27 | {
28 | public TypeResolveResult(IType type)
29 | : base(type)
30 | {
31 | }
32 |
33 | public override bool IsError {
34 | get { return this.Type.Kind == TypeKind.Unknown; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/ComHelper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | ///
22 | /// Helper methods for COM.
23 | ///
24 | public static class ComHelper
25 | {
26 | ///
27 | /// Gets whether the specified type is imported from COM.
28 | ///
29 | public static bool IsComImport(ITypeDefinition typeDefinition)
30 | {
31 | return typeDefinition != null
32 | && typeDefinition.Kind == TypeKind.Interface
33 | && typeDefinition.HasAttribute(KnownAttribute.ComImport, inherit: false);
34 | }
35 |
36 | ///
37 | /// Gets the CoClass of the specified COM interface.
38 | ///
39 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Co",
40 | Justification = "Consistent with CoClassAttribute")]
41 | public static IType GetCoClass(ITypeDefinition typeDefinition)
42 | {
43 | if (typeDefinition == null)
44 | return SpecialType.UnknownType;
45 | var coClassAttribute = typeDefinition.GetAttribute(KnownAttribute.CoClass, inherit: false);
46 | if (coClassAttribute != null && coClassAttribute.FixedArguments.Length == 1)
47 | {
48 | if (coClassAttribute.FixedArguments[0].Value is IType ty)
49 | return ty;
50 | }
51 | return SpecialType.UnknownType;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Immutable;
20 | using System.Reflection.Metadata;
21 |
22 | namespace ICSharpCode.Decompiler.TypeSystem
23 | {
24 | ///
25 | /// Represents an attribute.
26 | ///
27 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
28 | public interface IAttribute
29 | {
30 | ///
31 | /// Gets the type of the attribute.
32 | ///
33 | IType AttributeType { get; }
34 |
35 | ///
36 | /// Gets the constructor being used.
37 | /// This property may return null if no matching constructor was found.
38 | ///
39 | IMethod Constructor { get; }
40 |
41 | ///
42 | /// Gets whether there were errors decoding the attribute.
43 | ///
44 | bool HasDecodeErrors { get; }
45 |
46 | ///
47 | /// Gets the positional arguments.
48 | ///
49 | ImmutableArray> FixedArguments { get; }
50 |
51 | ///
52 | /// Gets the named arguments passed to the attribute.
53 | ///
54 | ImmutableArray> NamedArguments { get; }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 |
21 | namespace ICSharpCode.Decompiler.TypeSystem
22 | {
23 | public interface ICodeContext : ITypeResolveContext
24 | {
25 | ///
26 | /// Gets all currently visible local variables and lambda parameters.
27 | /// Does not include method parameters.
28 | ///
29 | IEnumerable LocalVariables { get; }
30 |
31 | ///
32 | /// Gets whether the context is within a lambda expression or anonymous method.
33 | ///
34 | bool IsWithinLambdaExpression { get; }
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | ///
22 | /// Main interface for the decompiler type system.
23 | ///
24 | /// The MetadataModule class allows decoding/resolving metadata tokens into type system entities.
25 | ///
26 | public interface IDecompilerTypeSystem : ICompilation
27 | {
28 | new MetadataModule MainModule { get; }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | public interface IEvent : IMember
22 | {
23 | bool CanAdd { get; }
24 | bool CanRemove { get; }
25 | bool CanInvoke { get; }
26 |
27 | IMethod AddAccessor { get; }
28 | IMethod RemoveAccessor { get; }
29 | IMethod InvokeAccessor { get; }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IField.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | ///
22 | /// Represents a field or constant.
23 | ///
24 | public interface IField : IMember, IVariable
25 | {
26 | ///
27 | /// Gets the name of the field.
28 | ///
29 | new string Name { get; } // solve ambiguity between IMember.Name and IVariable.Name
30 |
31 | ///
32 | /// Gets whether this field is readonly.
33 | ///
34 | bool IsReadOnly { get; }
35 |
36 | ///
37 | /// Gets whether this field is volatile.
38 | ///
39 | bool IsVolatile { get; }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IFreezable.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | public interface IFreezable
22 | {
23 | ///
24 | /// Gets if this instance is frozen. Frozen instances are immutable and thus thread-safe.
25 | ///
26 | bool IsFrozen { get; }
27 |
28 | ///
29 | /// Freezes this instance.
30 | ///
31 | void Freeze();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/INamedElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | public interface INamedElement
22 | {
23 | ///
24 | /// Gets the fully qualified name of the class the return type is pointing to.
25 | ///
26 | ///
27 | /// "System.Int32[]" for int[]
28 | /// "System.Collections.Generic.List" for List<string>
29 | /// "System.Environment.SpecialFolder" for Environment.SpecialFolder
30 | ///
31 | string FullName { get; }
32 |
33 | ///
34 | /// Gets the short name of the class the return type is pointing to.
35 | ///
36 | ///
37 | /// "Int32[]" for int[]
38 | /// "List" for List<string>
39 | /// "SpecialFolder" for Environment.SpecialFolder
40 | ///
41 | string Name { get; }
42 |
43 | ///
44 | /// Gets the full reflection name of the element.
45 | ///
46 | ///
47 | /// For types, the reflection name can be parsed back into a ITypeReference by using
48 | /// .
49 | ///
50 | ///
51 | /// "System.Int32[]" for int[]
52 | /// "System.Int32[][,]" for C# int[,][]
53 | /// "System.Collections.Generic.List`1[[System.String]]" for List<string>
54 | /// "System.Environment+SpecialFolder" for Environment.SpecialFolder
55 | ///
56 | string ReflectionName { get; }
57 |
58 | ///
59 | /// Gets the full name of the namespace containing this entity.
60 | ///
61 | string Namespace { get; }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 |
21 | namespace ICSharpCode.Decompiler.TypeSystem
22 | {
23 | ///
24 | /// Represents a method or property.
25 | ///
26 | public interface IParameterizedMember : IMember
27 | {
28 | IReadOnlyList Parameters { get; }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IProperty.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | ///
22 | /// Represents a property or indexer.
23 | ///
24 | public interface IProperty : IParameterizedMember
25 | {
26 | bool CanGet { get; }
27 | bool CanSet { get; }
28 |
29 | IMethod Getter { get; }
30 | IMethod Setter { get; }
31 |
32 | bool IsIndexer { get; }
33 |
34 | ///
35 | /// Gets whether the return type is 'ref readonly'.
36 | ///
37 | bool ReturnTypeIsRefReadOnly { get; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | ///
22 | /// Interface for TypeSystem objects that support interning.
23 | /// See for more information.
24 | ///
25 | public interface ISupportsInterning
26 | {
27 | ///
28 | /// Gets a hash code for interning.
29 | ///
30 | int GetHashCodeForInterning();
31 |
32 | ///
33 | /// Equality test for interning.
34 | ///
35 | bool EqualsForInterning(ISupportsInterning other);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/IVariable.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem
20 | {
21 | ///
22 | /// Represents a variable (name/type pair).
23 | ///
24 | public interface IVariable : ISymbol
25 | {
26 | ///
27 | /// Gets the name of the variable.
28 | ///
29 | new string Name { get; }
30 |
31 | ///
32 | /// Gets the type of the variable.
33 | ///
34 | IType Type { get; }
35 |
36 | ///
37 | /// Gets whether this variable is a constant (C#-like const).
38 | ///
39 | bool IsConst { get; }
40 |
41 | ///
42 | /// If this field is a constant, retrieves the value.
43 | /// For parameters, this is the default value.
44 | ///
45 | object GetConstantValue(bool throwOnInvalidMetadata = false);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultVariable.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation
22 | {
23 | ///
24 | /// Default implementation of .
25 | ///
26 | public sealed class DefaultVariable : IVariable
27 | {
28 | readonly string name;
29 | readonly IType type;
30 | readonly object constantValue;
31 | readonly bool isConst;
32 |
33 | public DefaultVariable(IType type, string name)
34 | {
35 | if (type == null)
36 | throw new ArgumentNullException(nameof(type));
37 | if (name == null)
38 | throw new ArgumentNullException(nameof(name));
39 | this.type = type;
40 | this.name = name;
41 | }
42 |
43 | public DefaultVariable(IType type, string name,
44 | bool isConst = false, object constantValue = null)
45 | : this(type, name)
46 | {
47 | this.isConst = isConst;
48 | this.constantValue = constantValue;
49 | }
50 |
51 | public string Name {
52 | get { return name; }
53 | }
54 |
55 | public IType Type {
56 | get { return type; }
57 | }
58 |
59 | public bool IsConst {
60 | get { return isConst; }
61 | }
62 |
63 | public object GetConstantValue(bool throwOnInvalidMetadata)
64 | {
65 | return constantValue;
66 | }
67 |
68 | public SymbolKind SymbolKind {
69 | get { return SymbolKind.Variable; }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.Decompiler.Util;
20 |
21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation
22 | {
23 | ///
24 | /// Cache for KnownTypeReferences.
25 | ///
26 | sealed class KnownTypeCache
27 | {
28 | readonly ICompilation compilation;
29 | readonly IType[] knownTypes = new IType[KnownTypeReference.KnownTypeCodeCount];
30 |
31 | public KnownTypeCache(ICompilation compilation)
32 | {
33 | this.compilation = compilation;
34 | }
35 |
36 | public IType FindType(KnownTypeCode typeCode)
37 | {
38 | var type = LazyInit.VolatileRead(ref knownTypes[(int)typeCode]);
39 | if (type != null)
40 | {
41 | return type;
42 | }
43 | return LazyInit.GetOrSet(ref knownTypes[(int)typeCode], SearchType(typeCode));
44 | }
45 |
46 | IType SearchType(KnownTypeCode typeCode)
47 | {
48 | var typeRef = KnownTypeReference.Get(typeCode);
49 | if (typeRef == null)
50 | return SpecialType.UnknownType;
51 | var typeName = new TopLevelTypeName(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount);
52 | foreach (var asm in compilation.Modules)
53 | {
54 | var typeDef = asm.GetTypeDefinition(typeName);
55 | if (typeDef != null)
56 | return typeDef;
57 | }
58 | return new UnknownType(typeName);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Siegfried Pammer
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using SRM = System.Reflection.Metadata;
20 |
21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation
22 | {
23 | public sealed class PinnedType : TypeWithElementType
24 | {
25 | public PinnedType(IType elementType)
26 | : base(elementType)
27 | {
28 | }
29 |
30 | public override string NameSuffix => " pinned";
31 |
32 | public override bool? IsReferenceType => elementType.IsReferenceType;
33 | public override bool IsByRefLike => elementType.IsByRefLike;
34 |
35 | public override TypeKind Kind => TypeKind.Other;
36 |
37 | public override IType VisitChildren(TypeVisitor visitor)
38 | {
39 | var newType = elementType.AcceptVisitor(visitor);
40 | if (newType == elementType)
41 | return this;
42 | return new PinnedType(newType);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/Implementation/ThreeState.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation
20 | {
21 | ///
22 | /// Constants used instead of bool?
23 | /// in multithreaded code, as bool? might produce torn reads.
24 | ///
25 | static class ThreeState
26 | {
27 | public const byte Unknown = 0;
28 | public const byte False = 1;
29 | public const byte True = 2;
30 |
31 | public static byte From(bool value) => value ? True : False;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/Implementation/TypeWithElementType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.Decompiler.TypeSystem.Implementation
22 | {
23 | public abstract class TypeWithElementType : AbstractType
24 | {
25 | protected IType elementType;
26 |
27 | protected TypeWithElementType(IType elementType)
28 | {
29 | if (elementType == null)
30 | throw new ArgumentNullException(nameof(elementType));
31 | this.elementType = elementType;
32 | }
33 |
34 | public override string Name {
35 | get { return elementType.Name + NameSuffix; }
36 | }
37 |
38 | public override string Namespace {
39 | get { return elementType.Namespace; }
40 | }
41 |
42 | public override string FullName {
43 | get { return elementType.FullName + NameSuffix; }
44 | }
45 |
46 | public override string ReflectionName {
47 | get { return elementType.ReflectionName + NameSuffix; }
48 | }
49 |
50 | public override string ToString()
51 | {
52 | return elementType.ToString() + NameSuffix;
53 | }
54 |
55 | public abstract string NameSuffix { get; }
56 |
57 | public IType ElementType {
58 | get { return elementType; }
59 | }
60 |
61 | // Force concrete implementations to override VisitChildren - the base implementation
62 | // in AbstractType assumes there are no children, but we know there is (at least) 1.
63 | public abstract override IType VisitChildren(TypeVisitor visitor);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/Nullability.cs:
--------------------------------------------------------------------------------
1 | namespace ICSharpCode.Decompiler.TypeSystem
2 | {
3 | public enum Nullability : byte
4 | {
5 | Oblivious = 0,
6 | NotNullable = 1,
7 | Nullable = 2
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/TypeSystem/ReflectionNameParseException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Runtime.Serialization;
21 |
22 | namespace ICSharpCode.Decompiler.TypeSystem
23 | {
24 | ///
25 | /// Represents an error while parsing a reflection name.
26 | ///
27 | [Serializable]
28 | public class ReflectionNameParseException : Exception
29 | {
30 | int position;
31 |
32 | public int Position {
33 | get { return position; }
34 | }
35 |
36 | public ReflectionNameParseException(int position)
37 | {
38 | this.position = position;
39 | }
40 |
41 | public ReflectionNameParseException(int position, string message) : base(message)
42 | {
43 | this.position = position;
44 | }
45 |
46 | public ReflectionNameParseException(int position, string message, Exception innerException) : base(message, innerException)
47 | {
48 | this.position = position;
49 | }
50 |
51 | // This constructor is needed for serialization.
52 | protected ReflectionNameParseException(SerializationInfo info, StreamingContext context) : base(info, context)
53 | {
54 | position = info.GetInt32("position");
55 | }
56 |
57 | public override void GetObjectData(SerializationInfo info, StreamingContext context)
58 | {
59 | base.GetObjectData(info, context);
60 | info.AddValue("position", position);
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/src/ICSharpCode.Decompiler/Util/CacheManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Concurrent;
21 |
22 | namespace ICSharpCode.Decompiler.Util
23 | {
24 | ///
25 | /// Allows caching values for a specific compilation.
26 | /// A CacheManager consists of a for shared instances (shared among all threads working with that resolve context).
27 | ///
28 | /// This class is thread-safe
29 | public sealed class CacheManager
30 | {
31 | readonly ConcurrentDictionary