Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Decompiling constants of the target type #1084

Closed
sharwell opened this issue Mar 7, 2018 · 1 comment
Closed

Decompiling constants of the target type #1084

sharwell opened this issue Mar 7, 2018 · 1 comment
Assignees
Labels
C# Decompiler The decompiler engine itself

Comments

@sharwell
Copy link
Contributor

sharwell commented Mar 7, 2018

Originally reported by @davkean in dotnet/roslyn#25006:

The following:

        internal int ActualMaxDegreeOfParallelism
        {
            get { return (_maxDegreeOfParallelism == Unbounded) ? int.MaxValue : _maxDegreeOfParallelism; }
        }

gets decompiled to:

		internal int ActualMaxDegreeOfParallelism
		{
			get
			{
				if (this.m_maxDegreeOfParallelism != -1)
				{
					return this.m_maxDegreeOfParallelism;
				}
				return 2147483647;
			}
		}

Similar to other decompilers, we should be smarter around replacing magic "literals" with their appropriate constants.

I suggest implementing the feature mentioned by @CyrusNajmabadi in dotnet/roslyn#25006 (comment):

... looks in the Type for that value for any constants matching the value. If it finds any, it will use them. As such, it will replace constants with things like int.MaxValue, double.Infinity, ...

🔗 This is related to #517, but is much more narrowly-scoped and (I believe) much easier to implement as an interim solution covering majority cases.

@siegfriedpammer
Copy link
Member

siegfriedpammer commented Mar 8, 2018

@sharwell @davkean Would you expect the decompiler to replace literals with constants everywhere? Even in constant / enum declarations?

Which one do you prefer? enum E : sbyte { A = 0x7F } or enum E : sbyte { A = sbyte.MaxValue }

(Of course the definition of public const double NaN in System.Double and others would not reference itself.)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
C# Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

2 participants