internal static BoundNode Rewrite(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet<LocalSymbol> declaredLocals, BoundNode node) { var builder = ArrayBuilder<BoundStatement>.GetInstance(); bool hasChanged; // Rewrite top-level declarations only. switch (node.Kind) { case BoundKind.LocalDeclaration: RewriteLocalDeclaration(compilation, container, declaredLocals, builder, (BoundLocalDeclaration)node); hasChanged = true; break; case BoundKind.MultipleLocalDeclarations: foreach (var declaration in ((BoundMultipleLocalDeclarations)node).LocalDeclarations) { RewriteLocalDeclaration(compilation, container, declaredLocals, builder, declaration); } hasChanged = true; break; default: hasChanged = false; break; } if (hasChanged) { node = new BoundBlock(node.Syntax, ImmutableArray<LocalSymbol>.Empty, builder.ToImmutable()) { WasCompilerGenerated = true }; } builder.Free(); return node; }
public override BoundNode Visit(BoundNode node) { if (_mayHaveSideEffects) { return null; } return base.Visit(node); }
public override BoundNode Visit(BoundNode node) { var expression = node as BoundExpression; if (expression != null) { _typeParameterChecker.Visit(expression.ExpressionSymbol); } return base.Visit(node); }
protected override void Visit(BoundNode node) { if (node != null && node.Syntax != null) { NoteLocation(node.Syntax.Span); } base.Visit(node); }
internal static BoundNode Rewrite( ParameterSymbol targetMethodThisParameter, Conversions conversions, ImmutableDictionary<string, DisplayClassVariable> displayClassVariables, BoundNode node, DiagnosticBag diagnostics) { var rewriter = new CapturedVariableRewriter(targetMethodThisParameter, conversions, displayClassVariables, diagnostics); return rewriter.Visit(node); }
public override BoundNode Visit(BoundNode node) { var expression = node as BoundExpression; if (expression != null) { var constantValue = expression.ConstantValue; if (constantValue != null && constantValue.IsDecimal) { return RewriteConstant(expression); } } return base.Visit(node); }
/// <summary> /// Classifies the operations performed on the <paramref name="variable" /> within the <paramref name="node" />. /// </summary> /// <param name="node">The node of a bound tree the <paramref name="variable" /> should be classified for.</param> /// <param name="variable">The variable that should be classified.</param> public static VariableOperations Classify(BoundNode node, VariableMetadata variable) { Requires.NotNull(node, () => node); Requires.NotNull(variable, () => variable); _instance._writeContext = 0; _instance._operations = VariableOperations.None; _instance._variable = variable; _instance.Visit(node); Assert.That(_instance._writeContext == 0, "Unbalanced write context operations."); return _instance._operations; }
internal static IEnumerable<StatementSyntax> Analyze(Compilation compilation, MethodSymbol sourceMethod, BoundNode node, BoundNode firstInRegion, BoundNode lastInRegion) { var walker = new ReturnStatementsWalker(compilation, sourceMethod, node, firstInRegion, lastInRegion); try { bool badRegion = false; walker.Analyze(ref badRegion); return badRegion ? Enumerable.Empty<StatementSyntax>() : walker.returnStatements.ToArray(); } finally { walker.Free(); } }
public override BoundNode Visit(BoundNode node) { if (found == null) { if (node != null && !node.WasCompilerGenerated && node.Syntax == syntax) { found = node; } else { base.Visit(node); } } return null; }
public override BoundNode Visit(BoundNode node) { if (!_found) { return base.Visit(node); } return null; }
public override BoundNode Visit(BoundNode node) { BoundNode result; BoundExpression expr = node as BoundExpression; if (expr != null) { Debug.Assert(expr.Kind != BoundKind.Label); result = VisitExpression(expr, ExprContext.Value); } else { result = VisitStatement(node); } return result; }
private void Output(BoundNode node, string prefix) { switch (node.Type) { case NodeType.Literal: OutputLiteral((BoundLiteral)node, prefix); break; case NodeType.UnaryExpression: OutputUnaryExpression((BoundUnaryExpression)node, prefix); break; case NodeType.BinaryExpression: OutputBinaryExpression((BoundBinaryExpression)node, prefix); break; case NodeType.AssignmentExpression: OutputAssignmentExpression((BoundAssignmentExpression)node, prefix); break; case NodeType.Variable: OutputVariable((BoundVariableExpression)node, prefix); break; case NodeType.Block: OutputBlock((BoundBlock)node, prefix); break; case NodeType.VariableDeclaration: OutputVariableDeclaration((BoundVariableDeclarationStatement)node, prefix); break; case NodeType.Expression: OutputExpressionStatement((BoundExpressionStatement)node, prefix); break; case NodeType.Label: OutputLabel((BoundLabel)node, prefix); break; case NodeType.ConditionalBranch: OutputConditionalBranch((BoundConditionalBranchStatement)node, prefix); break; case NodeType.Branch: OutputBranch((BoundBranchStatement)node, prefix); break; case NodeType.TypeDefinition: OutputTypeDefinition((BoundTypeDefinition)node, prefix); break; case NodeType.FunctionCall: OutputFunctionCall((BoundFunctionCall)node, prefix); break; case NodeType.InternalTypeConversion: OutputInternalTypeConversion((BoundInternalTypeConversion)node, prefix); break; case NodeType.Accessor: OutputAccessor((BoundAccessor)node, prefix); break; case NodeType.Tuple: OutputTuple((BoundTuple)node, prefix); break; case NodeType.Return: OutputReturn((BoundReturnStatement)node, prefix); break; case NodeType.FunctionPointer: OutputFunctionPointer((BoundFunctionPointer)node, prefix); break; } }
public void AddBoundNode(SyntaxNode syntaxNode, BoundNode boundNode) { _boundNodeFromSyntaxNode.Add(syntaxNode, boundNode); }
// Adds every syntax/bound pair in a tree rooted at the given bound node to the map, and the // performs a lookup of the given syntax node in the map. private BoundNode AddBoundTreeAndGetBoundNodeFromMap(SyntaxNode syntax, BoundNode bound) { using (nodeMapLock.DisposableWrite()) { NodeMapBuilder.AddToMap(bound, this.guardedNodeMap); BoundNode result; this.guardedNodeMap.TryGetValue(syntax, out result); return result; } }
public override BoundNode Visit(BoundNode node) { var expression = node as BoundExpression; if (expression != null && _resultExpressions.Contains(expression)) { // Create a temporary to hold the result. var temporary = new BoundTemporary( --_lastTemporaryIndex, _typeManager.CreateType(null, BoundTypeKind.Temporary) ); var nodes = new ReadOnlyArray<BoundStatement>.Builder(); // Initialize the temporary with the expression. nodes.Add(new BoundSetVariable( temporary, expression, SourceLocation.Missing )); // Copy the temporary to the result. nodes.Add(new BoundSetVariable( _resultTemporary, new BoundGetVariable(temporary), SourceLocation.Missing )); // Return an expression block. return new BoundExpressionBlock( temporary, new BoundBlock( ReadOnlyArray<BoundTemporary>.CreateFrom(temporary), nodes.ToReadOnly(), SourceLocation.Missing ) ); } return base.Visit(node); }
/// <summary> /// Construct context /// </summary> public RegionAnalysisContext(LanguageCompilation compilation, Symbol member, BoundNode boundNode, BoundNode firstInRegion, BoundNode lastInRegion) { this.Compilation = compilation; this.Member = member; this.BoundNode = boundNode; this.FirstInRegion = firstInRegion; this.LastInRegion = lastInRegion; this.Failed = boundNode == null || firstInRegion == null || lastInRegion == null || firstInRegion.Syntax.SpanStart > lastInRegion.Syntax.Span.End; if (!this.Failed && ReferenceEquals(firstInRegion, lastInRegion)) { throw new NotImplementedException("TODO:MetaDslx"); /*switch (firstInRegion.Kind) * { * case BoundKind.NamespaceExpression: * case BoundKind.TypeExpression: * * // Some bound nodes are still considered to be invalid for flow analysis * this.Failed = true; * break; * }*/ } }
private void GetBoundNodes(LanguageSyntaxNode node, out LanguageSyntaxNode bindableNode, out BoundNode lowestBoundNode, out BoundNode highestBoundNode, out BoundNode boundParent) { _boundTree.GetBoundNodes(node, out bindableNode, out lowestBoundNode, out highestBoundNode, out boundParent); }
internal static BoundNode Rewrite(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet <LocalSymbol> declaredLocals, BoundNode node) { var rewriter = new PlaceholderLocalRewriter(compilation, container, declaredLocals); return(rewriter.Visit(node)); }
protected override void DefaultVisit(BoundNode node) => throw new NotSupportedException(node.Kind.ToString());
public static void WriteTo(BoundNode node, IndentedTextWriter writer) => node.Accept(new BoundNodePrinter(writer));
public static void WriteTo(this BoundNode node, IndentedTextWriter writer) => BoundNodePrinter.WriteTo(node, writer);
internal static BoundNode Rewrite(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet <LocalSymbol> declaredLocals, BoundNode node) { var builder = ArrayBuilder <BoundStatement> .GetInstance(); bool hasChanged; // Rewrite top-level declarations only. switch (node.Kind) { case BoundKind.LocalDeclaration: RewriteLocalDeclaration(compilation, container, declaredLocals, builder, (BoundLocalDeclaration)node); hasChanged = true; break; case BoundKind.MultipleLocalDeclarations: foreach (var declaration in ((BoundMultipleLocalDeclarations)node).LocalDeclarations) { RewriteLocalDeclaration(compilation, container, declaredLocals, builder, declaration); } hasChanged = true; break; default: hasChanged = false; break; } if (hasChanged) { node = new BoundBlock(node.Syntax, ImmutableArray <LocalSymbol> .Empty, builder.ToImmutable()) { WasCompilerGenerated = true }; } builder.Free(); return(node); }
protected object Unimplemented(BoundNode node, String feature) { Diagnostics.Add(ErrorCode.ERR_NotYetImplementedInRoslyn, new SourceLocation(tree, node.Syntax), feature); return(null); }
public override BoundNode DefaultVisit(BoundNode node) { Debug.Fail($"Override the visitor for {node.Kind}"); return(base.DefaultVisit(node)); }
private bool TryReplaceWithProxy(Symbol parameterOrLocal, SyntaxNode syntax, out BoundNode replacement) { CapturedSymbolReplacement proxy; if (proxies.TryGetValue(parameterOrLocal, out proxy)) { replacement = proxy.Replacement(syntax, frameType => FramePointer(syntax, frameType)); return true; } replacement = null; return false; }
internal static BoundNode Rewrite(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet<LocalSymbol> declaredLocals, BoundNode node, DiagnosticBag diagnostics) { var rewriter = new PlaceholderLocalRewriter(compilation, container, declaredLocals, diagnostics); return rewriter.Visit(node); }
public static IEnumerable<BoundNode> GetNodes(BoundNode root) { var s = new BoundTreeSequencer(); s.Visit(root); foreach (var node in s._list) yield return node; }
// Simply add a syntax/bound pair to the map. private void AddBoundNodeToMap(SyntaxNode syntax, BoundNode bound) { using (nodeMapLock.DisposableWrite()) { // Suppose we have bound a subexpression, say "x", and have cached the result in the // map. Later on, we bind the parent expression, "x + y" and end up re-binding x. In // this situation we do not want to clobber the existing "x" in the map because x // might be a complex expression that contains lambda symbols (or, equivalently, // lambda parameter symbols). We want to make sure we always get the same symbols // out of the cache every time we ask. if (!this.guardedNodeMap.ContainsKey(syntax)) { this.guardedNodeMap.Add(syntax, bound); } } }
private static ShowPlanNode Build(BoundNode node) { switch (node.Kind) { case BoundNodeKind.Query: return(BuildQueryRelation((BoundQuery)node)); case BoundNodeKind.ConstantRelation: return(BuildConstant((BoundConstantRelation)node)); case BoundNodeKind.TableRelation: return(BuildTable((BoundTableRelation)node)); case BoundNodeKind.DerivedTableRelation: return(BuildDerivedTable((BoundDerivedTableRelation)node)); case BoundNodeKind.FilterRelation: return(BuildFilter((BoundFilterRelation)node)); case BoundNodeKind.ComputeRelation: return(BuildCompute((BoundComputeRelation)node)); case BoundNodeKind.JoinRelation: return(BuildJoin((BoundJoinRelation)node)); case BoundNodeKind.HashMatchRelation: return(BuildHashMatch((BoundHashMatchRelation)node)); case BoundNodeKind.TopRelation: return(BuildTop((BoundTopRelation)node)); case BoundNodeKind.SortRelation: return(BuildSort((BoundSortRelation)node)); case BoundNodeKind.UnionRelation: return(BuildUnionRelation((BoundUnionRelation)node)); case BoundNodeKind.ConcatenationRelation: return(BuildConcatenationRelation((BoundConcatenationRelation)node)); case BoundNodeKind.IntersectOrExceptRelation: return(BuildIntersectOrExceptRelation((BoundIntersectOrExceptRelation)node)); case BoundNodeKind.GroupByAndAggregationRelation: return(BuildGroupByAndAggregation((BoundGroupByAndAggregationRelation)node)); case BoundNodeKind.StreamAggregatesRelation: return(BuildStreamAggregatesRelation((BoundStreamAggregatesRelation)node)); case BoundNodeKind.ProjectRelation: return(BuildProject((BoundProjectRelation)node)); case BoundNodeKind.AssertRelation: return(BuildAssert((BoundAssertRelation)node)); case BoundNodeKind.TableSpoolPusher: return(BuildTableSpoolPusher((BoundTableSpoolPusher)node)); case BoundNodeKind.TableSpoolPopper: return(BuildTableSpoolPopper((BoundTableSpoolPopper)node)); case BoundNodeKind.UnaryExpression: return(BuildUnaryExpression((BoundUnaryExpression)node)); case BoundNodeKind.BinaryExpression: return(BuildBinaryExpression((BoundBinaryExpression)node)); case BoundNodeKind.LiteralExpression: return(BuildLiteralExpression((BoundLiteralExpression)node)); case BoundNodeKind.ValueSlotExpression: return(BuildValueSlotExpression((BoundValueSlotExpression)node)); case BoundNodeKind.VariableExpression: return(BuildVariableExpression((BoundVariableExpression)node)); case BoundNodeKind.FunctionInvocationExpression: return(BuildFunctionInvocationExpression((BoundFunctionInvocationExpression)node)); case BoundNodeKind.PropertyAccessExpression: return(BuildPropertyAccessExpression((BoundPropertyAccessExpression)node)); case BoundNodeKind.MethodInvocationExpression: return(BuildMethodInvocationExpression((BoundMethodInvocationExpression)node)); case BoundNodeKind.ConversionExpression: return(BuildConversionExpression((BoundConversionExpression)node)); case BoundNodeKind.IsNullExpression: return(BuildIsNullExpression((BoundIsNullExpression)node)); case BoundNodeKind.CaseExpression: return(BuildCaseExpression((BoundCaseExpression)node)); case BoundNodeKind.SingleRowSubselect: return(BuildSingleRowSubselect((BoundSingleRowSubselect)node)); case BoundNodeKind.ExistsSubselect: return(BuildExistsSubselect((BoundExistsSubselect)node)); default: throw ExceptionBuilder.UnexpectedValue(node.Kind); } }
public static void Check(BoundNode node, ImmutableArray<TypeParameterSymbol> acceptableTypeParameters) { new BlockChecker(new TypeParameterChecker(acceptableTypeParameters)).Visit(node); }
public override BoundNode Visit(BoundNode node) { BoundNode result; // rewriting constants may undo constant folding and make thing worse. // so we will not go into constant nodes. // CodeGen will not do that either. var asExpression = node as BoundExpression; if (asExpression != null && asExpression.ConstantValue != null) { result = node; } else { result = base.Visit(node); } _nodeCounter += 1; return result; }
/// <summary> /// Since each language construct must be handled according to the rules of the language specification, /// the default visitor reports that the construct for the node is not implemented in the compiler. /// </summary> /// <param name="node"></param> /// <param name="arg"></param> /// <returns></returns> public override object DefaultVisit(BoundNode node, object arg) { return(Unimplemented(node, "node kind '" + node.Kind + "' for flow analysis")); }
public static void Check(BoundNode node, ImmutableArray <TypeParameterSymbol> acceptableTypeParameters) { new BlockChecker(new TypeParameterChecker(acceptableTypeParameters)).Visit(node); }
internal static bool MayHaveSideEffects(BoundNode node) { var visitor = new MayHaveSideEffectsVisitor(); visitor.Visit(node); return visitor._mayHaveSideEffects; }
internal static Base Deserialize(BoundNode boundBody, IMethodSymbol methodSymbol = null, SpecialCases specialCase = SpecialCases.None) { // method var boundStatementList = boundBody as BoundStatementList; if (boundStatementList != null) { if (methodSymbol != null || boundStatementList.Syntax.Green is MethodDeclarationSyntax) { var methodBody = new MethodBody(methodSymbol); methodBody.Parse(boundStatementList); return(methodBody); } if (boundStatementList.Syntax.Green is VariableDeclarationSyntax) { var variableDeclaration = new VariableDeclaration(); variableDeclaration.Parse(boundStatementList); return(variableDeclaration); } if (boundStatementList.Syntax.Green is IfStatementSyntax) { var ifStatement = new IfStatement(); if (ifStatement.Parse(boundStatementList)) { return(ifStatement); } } if (boundStatementList.Syntax.Green is ForStatementSyntax) { var forStatement = new ForStatement(); if (forStatement.Parse(boundStatementList)) { return(forStatement); } } if (boundStatementList.Syntax.Green is WhileStatementSyntax) { var whileStatement = new WhileStatement(); if (whileStatement.Parse(boundStatementList)) { return(whileStatement); } } if (boundStatementList.Syntax.Green is DoStatementSyntax) { var doStatement = new DoStatement(); if (doStatement.Parse(boundStatementList)) { return(doStatement); } } var forEachStatementSyntax = boundStatementList.Syntax.Green as ForEachStatementSyntax; if (forEachStatementSyntax != null) { if (specialCase != SpecialCases.ForEachBody) { var forEachSimpleArrayStatement = new ForEachSimpleArrayStatement(); if (forEachSimpleArrayStatement.Parse(boundStatementList)) { return(forEachSimpleArrayStatement); } var forEachIteratorStatement = new ForEachIteratorStatement(); if (forEachIteratorStatement.Parse(boundStatementList)) { return(forEachIteratorStatement); } } } // try to detect 'if' var ifStatementNoHint = new IfStatement(); if (ifStatementNoHint.Parse(boundStatementList)) { return(ifStatementNoHint); } var whileStatementNoHint = new WhileStatement(); if (whileStatementNoHint.Parse(boundStatementList)) { return(whileStatementNoHint); } var block = new Block(); block.Parse(boundStatementList, specialCase); return(block); } var boundConversion = boundBody as BoundConversion; if (boundConversion != null) { var conversion = new Conversion(); conversion.Parse(boundConversion); return(conversion); } var boundTypeExpression = boundBody as BoundTypeExpression; if (boundTypeExpression != null) { var typeExpression = new TypeExpression(); typeExpression.Parse(boundTypeExpression); return(typeExpression); } var boundThisReference = boundBody as BoundThisReference; if (boundThisReference != null) { var thisReference = new ThisReference(); thisReference.Parse(boundThisReference); return(thisReference); } var boundBaseReference = boundBody as BoundBaseReference; if (boundBaseReference != null) { var baseReference = new BaseReference(); baseReference.Parse(boundBaseReference); return(baseReference); } var boundFieldAccess = boundBody as BoundFieldAccess; if (boundFieldAccess != null) { var fieldAccess = new FieldAccess(); fieldAccess.Parse(boundFieldAccess); return(fieldAccess); } var boundParameter = boundBody as BoundParameter; if (boundParameter != null) { var parameter = new Parameter(); parameter.Parse(boundParameter); return(parameter); } var boundLocal = boundBody as BoundLocal; if (boundLocal != null) { var local = new Local(); local.Parse(boundLocal); return(local); } var boundLiteral = boundBody as BoundLiteral; if (boundLiteral != null) { var literal = new Literal(); literal.Parse(boundLiteral); return(literal); } var boundExpressionStatement = boundBody as BoundExpressionStatement; if (boundExpressionStatement != null) { var expressionStatement = new ExpressionStatement(); expressionStatement.Parse(boundExpressionStatement); return(expressionStatement); } var boundSequence = boundBody as BoundSequence; if (boundSequence != null) { if (boundSequence.Syntax.Green is PrefixUnaryExpressionSyntax) { var prefixUnaryExpression = new PrefixUnaryExpression(); if (prefixUnaryExpression.Parse(boundSequence)) { return(prefixUnaryExpression); } } if (boundSequence.Syntax.Green is PostfixUnaryExpressionSyntax) { var postfixUnaryExpression = new PostfixUnaryExpression(); if (postfixUnaryExpression.Parse(boundSequence)) { return(postfixUnaryExpression); } } var sideEffectsAsLambdaCallExpression = new SideEffectsAsLambdaCallExpression(); sideEffectsAsLambdaCallExpression.Parse(boundSequence); return(sideEffectsAsLambdaCallExpression); } var boundCall = boundBody as BoundCall; if (boundCall != null) { var call = new Call(); call.Parse(boundCall); return(call); } var boundBinaryOperator = boundBody as BoundBinaryOperator; if (boundBinaryOperator != null) { var binaryOperator = new BinaryOperator(); binaryOperator.Parse(boundBinaryOperator); return(binaryOperator); } var boundAssignmentOperator = boundBody as BoundAssignmentOperator; if (boundAssignmentOperator != null) { var assignmentOperator = new AssignmentOperator(); assignmentOperator.Parse(boundAssignmentOperator); return(assignmentOperator); } var boundObjectCreationExpression = boundBody as BoundObjectCreationExpression; if (boundObjectCreationExpression != null) { var objectCreationExpression = new ObjectCreationExpression(); objectCreationExpression.Parse(boundObjectCreationExpression); return(objectCreationExpression); } var boundUnaryOperator = boundBody as BoundUnaryOperator; if (boundUnaryOperator != null) { var unaryOperator = new UnaryOperator(); unaryOperator.Parse(boundUnaryOperator); return(unaryOperator); } var boundConditionalOperator = boundBody as BoundConditionalOperator; if (boundConditionalOperator != null) { var conditionalOperator = new ConditionalOperator(); conditionalOperator.Parse(boundConditionalOperator); return(conditionalOperator); } var boundNullCoalescingOperator = boundBody as BoundNullCoalescingOperator; if (boundNullCoalescingOperator != null) { var nullCoalescingOperator = new NullCoalescingOperator(); nullCoalescingOperator.Parse(boundNullCoalescingOperator); return(nullCoalescingOperator); } var boundArrayCreation = boundBody as BoundArrayCreation; if (boundArrayCreation != null) { var arrayCreation = new ArrayCreation(); arrayCreation.Parse(boundArrayCreation); return(arrayCreation); } var boundArrayInitialization = boundBody as BoundArrayInitialization; if (boundArrayInitialization != null) { var arrayInitialization = new ArrayInitialization(); arrayInitialization.Parse(boundArrayInitialization); return(arrayInitialization); } var boundArrayAccess = boundBody as BoundArrayAccess; if (boundArrayAccess != null) { var arrayAccess = new ArrayAccess(); arrayAccess.Parse(boundArrayAccess); return(arrayAccess); } var boundArrayLength = boundBody as BoundArrayLength; if (boundArrayLength != null) { var arrayLength = new ArrayLength(); arrayLength.Parse(boundArrayLength); return(arrayLength); } var boundStackAllocArrayCreation = boundBody as BoundStackAllocArrayCreation; if (boundStackAllocArrayCreation != null) { var stackAllocArrayCreation = new StackAllocArrayCreation(); stackAllocArrayCreation.Parse(boundStackAllocArrayCreation); return(stackAllocArrayCreation); } var boundDefaultOperator = boundBody as BoundDefaultOperator; if (boundDefaultOperator != null) { var defaultOperator = new DefaultOperator(); defaultOperator.Parse(boundDefaultOperator); return(defaultOperator); } var boundReturnStatement = boundBody as BoundReturnStatement; if (boundReturnStatement != null) { var returnStatement = new ReturnStatement(); returnStatement.Parse(boundReturnStatement); return(returnStatement); } var boundDelegateCreationExpression = boundBody as BoundDelegateCreationExpression; if (boundDelegateCreationExpression != null) { var delegateCreationExpression = new DelegateCreationExpression(); delegateCreationExpression.Parse(boundDelegateCreationExpression); return(delegateCreationExpression); } var boundThrowStatement = boundBody as BoundThrowStatement; if (boundThrowStatement != null) { var throwStatement = new ThrowStatement(); throwStatement.Parse(boundThrowStatement); return(throwStatement); } var boundTryStatement = boundBody as BoundTryStatement; if (boundTryStatement != null) { var tryStatement = new TryStatement(); tryStatement.Parse(boundTryStatement); return(tryStatement); } var boundCatchBlock = boundBody as BoundCatchBlock; if (boundCatchBlock != null) { var catchBlock = new CatchBlock(); catchBlock.Parse(boundCatchBlock); return(catchBlock); } var boundGotoStatement = boundBody as BoundGotoStatement; if (boundGotoStatement != null) { if (boundGotoStatement.Syntax.Green is ContinueStatementSyntax) { var continueStatement = new ContinueStatement(); continueStatement.Parse(boundGotoStatement); return(continueStatement); } if (boundGotoStatement.Syntax.Green is BreakStatementSyntax) { var breakStatement = new BreakStatement(); breakStatement.Parse(boundGotoStatement); return(breakStatement); } ////var continueStatementNoHint = new ContinueStatement(); ////if (continueStatementNoHint.Parse(boundGotoStatement)) ////{ //// return continueStatementNoHint; ////} ////var breakStatementNoHint = new BreakStatement(); ////if (breakStatementNoHint.Parse(boundGotoStatement)) ////{ //// return breakStatementNoHint; ////} var gotoStatement = new GotoStatement(); gotoStatement.Parse(boundGotoStatement); return(gotoStatement); } var boundLabelStatement = boundBody as BoundLabelStatement; if (boundLabelStatement != null) { var labelStatement = new LabelStatement(); labelStatement.Parse(boundLabelStatement); return(labelStatement); } var boundMethodGroup = boundBody as BoundMethodGroup; if (boundMethodGroup != null) { var methodGroup = new MethodGroup(); methodGroup.Parse(boundMethodGroup); return(methodGroup); } var boundConditionalGoto = boundBody as BoundConditionalGoto; if (boundConditionalGoto != null) { var conditionalGoto = new ConditionalGoto(); conditionalGoto.Parse(boundConditionalGoto); return(conditionalGoto); } var boundAsOperator = boundBody as BoundAsOperator; if (boundAsOperator != null) { var asOperator = new AsOperator(); asOperator.Parse(boundAsOperator); return(asOperator); } var boundIsOperator = boundBody as BoundIsOperator; if (boundIsOperator != null) { var isOperator = new IsOperator(); isOperator.Parse(boundIsOperator); return(isOperator); } var boundTypeOfOperator = boundBody as BoundTypeOfOperator; if (boundTypeOfOperator != null) { var typeOfOperator = new TypeOfOperator(); typeOfOperator.Parse(boundTypeOfOperator); return(typeOfOperator); } var boundSwitchStatement = boundBody as BoundSwitchStatement; if (boundSwitchStatement != null) { var switchStatement = new SwitchStatement(); switchStatement.Parse(boundSwitchStatement); return(switchStatement); } var boundAddressOfOperator = boundBody as BoundAddressOfOperator; if (boundAddressOfOperator != null) { var addressOfOperator = new AddressOfOperator(); addressOfOperator.Parse(boundAddressOfOperator); return(addressOfOperator); } var boundPointerIndirectionOperator = boundBody as BoundPointerIndirectionOperator; if (boundPointerIndirectionOperator != null) { if (boundPointerIndirectionOperator.Syntax.Green is ElementAccessExpressionSyntax) { var elementAccessExpression = new ElementAccessExpression(); if (elementAccessExpression.Parse(boundPointerIndirectionOperator)) { return(elementAccessExpression); } } var pointerIndirectionOperator = new PointerIndirectionOperator(); pointerIndirectionOperator.Parse(boundPointerIndirectionOperator); return(pointerIndirectionOperator); } var boundMakeRefOperator = boundBody as BoundMakeRefOperator; if (boundMakeRefOperator != null) { var makeRefOperator = new MakeRefOperator(); makeRefOperator.Parse(boundMakeRefOperator); return(makeRefOperator); } var boundRefValueOperator = boundBody as BoundRefValueOperator; if (boundRefValueOperator != null) { var refValueOperator = new RefValueOperator(); refValueOperator.Parse(boundRefValueOperator); return(refValueOperator); } var boundRefTypeOperator = boundBody as BoundRefTypeOperator; if (boundRefTypeOperator != null) { var refTypeOperator = new RefTypeOperator(); refTypeOperator.Parse(boundRefTypeOperator); return(refTypeOperator); } var boundSizeOfOperator = boundBody as BoundSizeOfOperator; if (boundSizeOfOperator != null) { var sizeOfOperator = new SizeOfOperator(); sizeOfOperator.Parse(boundSizeOfOperator); return(sizeOfOperator); } var boundNoOpStatement = boundBody as BoundNoOpStatement; if (boundNoOpStatement != null) { var noOpStatement = new NoOpStatement(); noOpStatement.Parse(boundNoOpStatement); return(noOpStatement); } var boundIteratorScope = boundBody as BoundIteratorScope; if (boundIteratorScope != null) { var iteratorScope = new IteratorScope(); iteratorScope.Parse(boundIteratorScope); return(iteratorScope); } var boundArgList = boundBody as BoundArgList; if (boundArgList != null) { var argList = new ArgList(); argList.Parse(boundArgList); return(argList); } var boundArgListOperator = boundBody as BoundArgListOperator; if (boundArgListOperator != null) { var argListOperator = new ArgListOperator(); argListOperator.Parse(boundArgListOperator); return(argListOperator); } var statemnent = Unwrap(boundBody); if (statemnent != null) { throw new InvalidOperationException("Unwrap statement in foreach cycle in block class"); } if (statemnent == null) { throw new NotImplementedException(); } return(Deserialize(statemnent)); }
public BoundNode VisitStatement(BoundNode node) { Debug.Assert(node == null || EvalStackIsEmpty()); var origStack = StackDepth(); var prevContext = _context; var result = base.Visit(node); _context = prevContext; SetStackDepth(origStack); _counter += 1; return result; }
private bool TryReplaceWithProxy(Symbol parameterOrLocal, CSharpSyntaxNode syntax, out BoundNode replacement) { CapturedSymbolReplacement proxy; if (proxies.TryGetValue(parameterOrLocal, out proxy)) { replacement = proxy.Replacement(syntax, frameType => FramePointer(syntax, frameType)); return(true); } replacement = null; return(false); }
public override BoundNode Visit(BoundNode node) { if (node != null) //e.g. static method invocations have null receivers { _list.Add(node); } return base.Visit(node); }
public BoundNode VisitStatement(BoundNode node) { var prevContext = _context; int prevStack = _evalStack; var result = base.Visit(node); ClearLastExpression(); _counter += 1; _evalStack = prevStack; _context = prevContext; return result; }
internal ReturnStatementsWalker(Compilation compilation, MethodSymbol sourceMethod, BoundNode node, BoundNode firstInRegion, BoundNode lastInRegion) : base(compilation, sourceMethod, node, firstInRegion, lastInRegion) { }
// here we have a case of indirect assignment: *t1 = expr; // normally we would need to push t1 and that will cause spilling of t2 // // TODO: an interesting case arises in unused x[i]++ and ++x[i] : // we have trees that look like: // // t1 = &(x[0]) // t2 = *t1 // *t1 = t2 + 1 // // t1 = &(x[0]) // t2 = *t1 + 1 // *t1 = t2 // // in these cases, we could keep t2 on stack (dev10 does). // we are dealing with exactly 2 locals and access them in strict order // t1, t2, t1, t2 and we are not using t2 after that. // We may consider detecting exactly these cases and pretend that we do not need // to push either t1 or t2 in this case. // private bool LhsUsesStackWhenAssignedTo(BoundNode node, ExprContext context) { Debug.Assert(context == ExprContext.AssignmentTarget); switch (node.Kind) { case BoundKind.Parameter: case BoundKind.Local: return false; case BoundKind.FieldAccess: return !((BoundFieldAccess)node).FieldSymbol.IsStatic; case BoundKind.Sequence: return LhsUsesStackWhenAssignedTo(((BoundSequence)node).Value, context); } return true; }
public static BoundNode Analyze( BoundNode node, Dictionary<LocalSymbol, LocalDefUseInfo> locals, ArrayBuilder<ValueTuple<BoundExpression, ExprContext>> evalStack, bool debugFriendly) { var analyzer = new StackOptimizerPass1(locals, evalStack, debugFriendly); var rewritten = analyzer.Visit(node); return rewritten; }
private void LoadDataSourceFields() { this.EnterLoadingMode(); IDataSourceFieldSchema[] fieldSchemas = this.GetFieldSchemas(); if ((fieldSchemas != null) && (fieldSchemas.Length > 0)) { DataFieldNode node = new DataFieldNode(this); this._availableFieldsTree.Nodes.Insert(0, node); foreach (IDataSourceFieldSchema schema in fieldSchemas) { BoundNode node2 = new BoundNode(this, schema); this._selectedDataSourceNode.Nodes.Add(node2); } this._selectedDataSourceNode.Expand(); foreach (IDataSourceFieldSchema schema2 in fieldSchemas) { if ((schema2.DataType == typeof(bool)) || (schema2.DataType == typeof(bool?))) { CheckBoxNode node3 = new CheckBoxNode(this, schema2); this._selectedCheckBoxDataSourceNode.Nodes.Add(node3); } } this._selectedCheckBoxDataSourceNode.Expand(); this._availableFieldsTree.SelectedNode = node; node.EnsureVisible(); } else { BoundNode node4 = new BoundNode(this, null); this._availableFieldsTree.Nodes.Insert(0, node4); node4.EnsureVisible(); CheckBoxNode node5 = new CheckBoxNode(this, null); this._availableFieldsTree.Nodes.Insert(1, node5); node5.EnsureVisible(); this._availableFieldsTree.SelectedNode = node4; } this.ExitLoadingMode(); }
public BoundNode VisitStatement(BoundNode node) { Debug.Assert(node == null || EvalStackIsEmpty()); var origStack = StackDepth(); var prevContext = _context; var result = base.Visit(node); // prevent cross-statement local optimizations // when emitting debug-friendly code. if (_debugFriendly) { EnsureOnlyEvalStack(); } _context = prevContext; SetStackDepth(origStack); _counter += 1; return result; }
public static BoundNode FindChildForSyntax(BoundNode parent, SyntaxNode childSyntax) { var finder = new BoundChildFinder(childSyntax); finder.Visit(parent); return finder.found; }
public override BoundNode Visit(BoundNode node) { var expr = node as BoundExpression; if (expr != null) { var text = node.Syntax.ToString(); if (!string.IsNullOrEmpty(text)) { text = Microsoft.CodeAnalysis.CSharp.SymbolDisplay.FormatLiteral(text, quote: false); Symbol accessedLocalOrParameterOpt; bool isNonMoveableVariable = _binder.IsNonMoveableVariable(expr, out accessedLocalOrParameterOpt); if (isNonMoveableVariable) { _builder.Add(string.Format("Yes, {0} '{1}' is a non-moveable variable{2}", expr.Kind, text, accessedLocalOrParameterOpt == null ? "" : string.Format(" with underlying symbol '{0}'", accessedLocalOrParameterOpt.Name))); } else { _builder.Add(string.Format("No, {0} '{1}' is not a non-moveable variable", expr.Kind, text)); } } } return base.Visit(node); }
internal ImmutableArray <IArgumentOperation> DeriveArguments(BoundNode containingExpression) { switch (containingExpression.Kind) { case BoundKind.IndexerAccess: { var boundIndexer = (BoundIndexerAccess)containingExpression; return(DeriveArguments(boundIndexer, boundIndexer.BinderOpt, boundIndexer.Indexer, boundIndexer.UseSetterForDefaultArgumentGeneration ? boundIndexer.Indexer.GetOwnOrInheritedSetMethod() : boundIndexer.Indexer.GetOwnOrInheritedGetMethod(), boundIndexer.Arguments, boundIndexer.ArgumentNamesOpt, boundIndexer.ArgsToParamsOpt, boundIndexer.ArgumentRefKindsOpt, boundIndexer.Indexer.Parameters, boundIndexer.Expanded, boundIndexer.Syntax)); } case BoundKind.ObjectCreationExpression: { var objectCreation = (BoundObjectCreationExpression)containingExpression; return(DeriveArguments(objectCreation, objectCreation.BinderOpt, objectCreation.Constructor, objectCreation.Constructor, objectCreation.Arguments, objectCreation.ArgumentNamesOpt, objectCreation.ArgsToParamsOpt, objectCreation.ArgumentRefKindsOpt, objectCreation.Constructor.Parameters, objectCreation.Expanded, objectCreation.Syntax)); } case BoundKind.Call: { var boundCall = (BoundCall)containingExpression; return(DeriveArguments(boundCall, boundCall.BinderOpt, boundCall.Method, boundCall.Method, boundCall.Arguments, boundCall.ArgumentNamesOpt, boundCall.ArgsToParamsOpt, boundCall.ArgumentRefKindsOpt, boundCall.Method.Parameters, boundCall.Expanded, boundCall.Syntax, boundCall.InvokedAsExtensionMethod)); } case BoundKind.CollectionElementInitializer: { var boundCollectionElementInitializer = (BoundCollectionElementInitializer)containingExpression; return(DeriveArguments(boundCollectionElementInitializer, boundCollectionElementInitializer.BinderOpt, boundCollectionElementInitializer.AddMethod, boundCollectionElementInitializer.AddMethod, boundCollectionElementInitializer.Arguments, argumentNamesOpt: default, boundCollectionElementInitializer.ArgsToParamsOpt, argumentRefKindsOpt: default, boundCollectionElementInitializer.AddMethod.Parameters, boundCollectionElementInitializer.Expanded, boundCollectionElementInitializer.Syntax, boundCollectionElementInitializer.InvokedAsExtensionMethod)); }