Omitted operations in the roseline

When operations were introduced at Roslyn, one of the goals was to provide reduced operations (I think it was in the design review video), which, as I understand it, should provide explicit operations for implicit compiler actions at higher levels. I see that the directory is located in Roslyn, but the classes are internal there. Can I now omit operations or not have a public API?

In the example below, the operation already removes some implicit parts - adding a return statement for the body of the expression and displaying a symbol for the overloaded statement. But pre and post increments differ only in appearance.

using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Semantics; using System.Linq; namespace so39468373 { internal static class Program { private static void Main() { var tree = CSharpSyntaxTree.ParseText(@" public class c { public static c operator ++(co) { return o; } static c pre(co) => ++o; static c post(co) => o++; public static void Main() {} }"); var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); var compilation = CSharpCompilation.Create(null, new[] { tree }, new[] { mscorlib }); var model = compilation.GetSemanticModel(tree); foreach (var node in tree.GetRoot().DescendantNodes().OfType<ArrowExpressionClauseSyntax>()) { var operation = model.GetOperation(node); var block = (IBlockStatement)operation; var statement = (IReturnStatement)block.Statements.First(); var increment = (IIncrementExpression)statement.ReturnedValue; // How to get lowered operations for increment here? } } } } 

Code on github - https://github.com/isanych/so-39468373

+53
c # roslyn
Sep 13 '16 at 10:59
source share
2 answers

Different angle on this answer - what about this aspect of the compiler?

InternalVisibleTo Attribute

link: https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx

Is it possible to make an interesting conversation topic related to the “other angle” in order to use the debugging approach?

ADDITIONAL INFORMATION (from the article):

Version Information

Universal Windows Platform Available with 8 .NET Framework
Available with 2.0 Portable Class Library
Supported in: .NET Silverlight Portable Platforms
Available with 2.0 Windows Phone Silverlight
Available with 7.0 Windows Phone
Available from 8.1

+1
Sep 21 '17 at 3:03 on
source share
— -

This example will help you solve it.

 using System.Collections.Immutable; using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp { /// <summary> /// The dynamic operation factories below return this struct so that the caller /// have the option of separating the call-site initialization from its invocation. /// /// Most callers just call <see cref="ToExpression"/> to get the combo but some (object and array initializers) /// hoist all call-site initialization code and emit multiple invocations of the same site. /// </summary> internal struct LoweredDynamicOperation { private readonly SyntheticBoundNodeFactory _factory; private readonly TypeSymbol _resultType; private readonly ImmutableArray<LocalSymbol> _temps; public readonly BoundExpression SiteInitialization; public readonly BoundExpression SiteInvocation; public LoweredDynamicOperation(SyntheticBoundNodeFactory factory, BoundExpression siteInitialization, BoundExpression siteInvocation, TypeSymbol resultType, ImmutableArray<LocalSymbol> temps) { _factory = factory; _resultType = resultType; _temps = temps; this.SiteInitialization = siteInitialization; this.SiteInvocation = siteInvocation; } public static LoweredDynamicOperation Bad( BoundExpression loweredReceiver, ImmutableArray<BoundExpression> loweredArguments, BoundExpression loweredRight, TypeSymbol resultType) { var children = ArrayBuilder<BoundNode>.GetInstance(); children.AddOptional(loweredReceiver); children.AddRange(loweredArguments); children.AddOptional(loweredRight); return LoweredDynamicOperation.Bad(resultType, children.ToImmutableAndFree()); } public static LoweredDynamicOperation Bad(TypeSymbol resultType, ImmutableArray<BoundNode> children) { Debug.Assert(children.Length > 0); var bad = new BoundBadExpression(children[0].Syntax, LookupResultKind.Empty, ImmutableArray<Symbol>.Empty, children, resultType); return new LoweredDynamicOperation(null, null, bad, resultType, default(ImmutableArray<LocalSymbol>)); } public BoundExpression ToExpression() { if (_factory == null) { Debug.Assert(SiteInitialization == null && SiteInvocation is BoundBadExpression && _temps.IsDefaultOrEmpty); return SiteInvocation; } // TODO (tomat): we might be able to use SiteInvocation.Type instead of resultType once we stop using GetLoweredType if (_temps.IsDefaultOrEmpty) { return _factory.Sequence(new[] { SiteInitialization }, SiteInvocation, _resultType); } else { return new BoundSequence(_factory.Syntax, _temps, ImmutableArray.Create(SiteInitialization), SiteInvocation, _resultType) { WasCompilerGenerated = true }; } } } } 
0
Mar 21 '17 at 23:56 on
source share



All Articles