public override void VisitGotoStatement(GotoStatementSyntax node) { if (node.Kind() == SyntaxKind.GotoCaseStatement) { Visit(node.Expression); } }
public override void VisitGotoStatement(GotoStatementSyntax node) { var label = ((IdentifierNameSyntax)node.Expression).Identifier.ToString(); var labelState = FindLabeledState(label); GotoState(labelState); }
public override void VisitGotoStatement(GotoStatementSyntax node) { LLVMBasicBlockRef gotoBB; switch (node.CaseOrDefaultKeyword.Kind()) { case SyntaxKind.DefaultKeyword: gotoBB = this.currentSwitchStatement[defaultHash]; break; case SyntaxKind.CaseKeyword: var constantValueObject = this.semanticModel.GetConstantValue(node.Expression).Value; gotoBB = this.currentSwitchStatement[constantValueObject]; break; case SyntaxKind.None: var identifier = ((IdentifierNameSyntax)node.Expression).Identifier.Text; var basicBlocks = this.labels.Peek(); if (!basicBlocks.TryGetValue(identifier, out gotoBB)) { gotoBB = LLVM.AppendBasicBlock(this.function, identifier); basicBlocks.Add(identifier, gotoBB); } break; default: throw new Exception("Unreachable"); } LLVM.BuildBr(this.builder, gotoBB); LLVM.PositionBuilderAtEnd(this.builder, LLVM.AppendBasicBlock(this.function, "UnreachableGoto")); }
private void BuildGotoCaseStatement(GotoStatementSyntax statement) { if (SwitchGotoJumpBlocks.Count == 0) { throw new InvalidOperationException("goto case; outside a switch"); } var jumpBlock = CreateJumpBlock(statement, CreateTemporaryBlock(), currentBlock); currentBlock = jumpBlock; var constValue = semanticModel.GetConstantValue(statement.Expression); if (!constValue.HasValue) { throw new InvalidOperationException("Expression has no constant value"); } var currentJumpBlocks = SwitchGotoJumpBlocks.Peek(); if (!currentJumpBlocks.ContainsKey(constValue.Value)) { currentJumpBlocks.Add(constValue.Value, new List <JumpBlock>()); } currentJumpBlocks[constValue.Value].Add(jumpBlock); }
private int GetCaseLabelIndex(GotoStatementSyntax node) { var switchStatement = (SwitchStatementSyntax)FindParent(node, SyntaxKind.SwitchStatement); int index = 0; foreach (var section in switchStatement.Sections) { bool isFound = section.Labels.Any(i => { if (i.IsKind(SyntaxKind.CaseSwitchLabel)) { var label = (CaseSwitchLabelSyntax)i; if (label.Value.ToString() == node.Expression.ToString()) { return(true); } } return(false); }); if (isFound) { return(index); } } throw new InvalidOperationException(); }
public override void VisitGotoStatement(GotoStatementSyntax node) { base.VisitGotoStatement(node); StatementsAnalyzer statementsAnalyzer = this; statementsAnalyzer.counter = checked (statementsAnalyzer.counter + 1); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (!_featureStatisticsBuilder.HasGoto) { _featureStatisticsBuilder.HasGoto = true; } base.VisitGotoStatement(node); }
public override void VisitGotoStatement(GotoStatementSyntax node) { base.VisitGotoStatement(node); if (!yieldOnly) { isSpecial = true; } }
public override SyntaxNode VisitGotoStatement(GotoStatementSyntax node) { var label = node.Expression.ToString(); if (label.StartsWith("_")) return node; return StateGenerator.ChangeState(labelStates[label]); }
public override void VisitGotoStatement(GotoStatementSyntax node) { var o = (IBranchStatement)Model.GetOperation(node); var label = o.Target; Console.WriteLine(label); base.VisitGotoStatement(node); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (entryPoint.IsMethodLevel() && node.IsParent <AnonymousFunctionExpressionSyntax>()) { return; } noscounter++; base.VisitGotoStatement(node); }
public override void VisitGotoStatement(GotoStatementSyntax node) { var remainderBlock = new BasicBlock(_currentBlock.Terminator); var targetLabelSymbol = (ILabelSymbol)_model.GetSymbolInfo(node.Expression).Symbol; var targetBlock = _labels.GetOrCreate(targetLabelSymbol, () => new BasicBlock(null)); _currentBlock.Terminator = new JumpTerminator(targetBlock); _currentBlock = remainderBlock; // The rest of the current block continues in the remainder }
public override SyntaxNode VisitGotoStatement(GotoStatementSyntax node) { var label = node.Expression.ToString(); if (label.StartsWith("_")) { return(node); } return(StateGenerator.ChangeState(labelStates[label])); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (node.IsKind(SyntaxKind.GotoDefaultStatement) || node.IsKind(SyntaxKind.GotoCaseStatement)) { gotoCaseOrDefault.Add(curNode); } else { builder.gotoStatements.Add(node); } curNode = builder.CreateEndNode(node); }
public override SyntaxNode VisitGotoStatement(GotoStatementSyntax node) { if (node.CaseOrDefaultKeyword.Kind() != SyntaxKind.None) { return(base.VisitGotoStatement(node)); } var resumeLocation = node.GetLocation().GetMappedLineSpan(); node = (GotoStatementSyntax)base.VisitGotoStatement(node); return(InjectedBlock(node, resumeLocation)); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (!PreVisit(node)) { return; } node.Expression?.Accept(this); base.VisitGotoStatement(node); PostVisit(node); }
public override void VisitGotoStatement(GotoStatementSyntax node) { var scope = FindScope(node) ?? throw new System.Exception("Scope not found for node."); if (string.IsNullOrWhiteSpace(node.LabelName.Text)) { return; } var label = scope.GetOrCreateLabel(node.LabelName.Text); label.AddJump(node); _labels[node] = label; }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (entryNode is AnonymousFunctionExpressionSyntax && embeddedNode is AnonymousFunctionExpressionSyntax) { return; } if (_weComeFromMethod && _weInAnonymousMethod) { return; } InsertLLOCMap(node.GetLocation()); base.VisitGotoStatement(node); }
public static void Go(OutputWriter writer, GotoStatementSyntax method) { writer.WriteIndent(); writer.Write("goto "); writer.Write((method.CaseOrDefaultKeyword != default(SyntaxToken)) ? method.CaseOrDefaultKeyword.ValueText : ""); writer.Write(" "); if (method.Expression != null) { Core.Write(writer, method.Expression); } writer.Write(";\r\n"); }
public override void VisitGotoStatement(GotoStatementSyntax node) { var name = node.CaseOrDefaultKeyword.ValueText != null ? string.Join(" ", new[] { node.CaseOrDefaultKeyword.Text, node.Expression?.ToString() }.Where(x => x != null)) + ":" : node.Expression.ToString(); var label = Model.LookupLabels(node.SpanStart, name).OfType <ILabelSymbol>().SingleOrDefault(); var label2 = ((IBranchStatement)Model.GetOperation(node)).Target; // (label == label2).Dump(); base.VisitGotoStatement(node); }
public static Doc Print(GotoStatementSyntax node) { Doc expression = node.Expression != null ? Doc.Concat(" ", Node.Print(node.Expression)) : string.Empty; return(Doc.Concat( ExtraNewLines.Print(node), Token.Print(node.GotoKeyword), node.CaseOrDefaultKeyword.RawKind != 0 ? " " : Doc.Null, Token.Print(node.CaseOrDefaultKeyword), expression, Token.Print(node.SemicolonToken) )); }
public static void Go(OutputWriter writer, GotoStatementSyntax method) { writer.WriteIndent(); writer.Write("goto "); writer.Write((method.CaseOrDefaultKeyword != default(SyntaxToken)) ? method.CaseOrDefaultKeyword.Text : ""); writer.Write(" "); if (method.Expression != null) if (method.Expression.ToString ().Trim() == "null") writer.Write("-1"); else Core.Write(writer, method.Expression); writer.Write(";\r\n"); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (node.CaseOrDefaultKeyword == default(SyntaxToken) && node.Expression.IsKind(SyntaxKind.IdentifierName)) { var name = ((IdentifierNameSyntax)node.Expression); FlowLocation location; if (this.labelLocations.TryGetValue(name.Identifier.ValueText, out location)) { this.BranchToLocation(location, this.lexicalState); } } // TODO: handle goto case and goto default }
private void RunGoto(GotoStatementSyntax node) { var label = $"{node.Expression.GetText()}"; var dst = Ctx.Method.Jumps .Where(x => x.Label == label) .FirstOrDefault(); if (dst == null) { throw new SemanticViolationException($"goto destination not found: {label}"); } // TODO: frame unwinding // goto is very unstalbe in current implementation RunBlock((BlockSyntax)dst.Statement, Vars, dst.Pc); }
private Doc PrintGotoStatementSyntax(GotoStatementSyntax node) { var expression = node.Expression != null ? Concat(" ", this.Print(node.Expression)) : string.Empty; return(Concat( this.PrintExtraNewLines(node), this.PrintSyntaxToken(node.GotoKeyword), node.CaseOrDefaultKeyword.RawKind != 0 ? SpaceIfNoPreviousComment : Doc.Null, this.PrintSyntaxToken(node.CaseOrDefaultKeyword), expression, this.PrintSyntaxToken(node.SemicolonToken) )); }
public override IStatement VisitGotoStatement(GotoStatementSyntax node) { var e = node.Expression as IdentifierNameSyntax; ILabeledStatement l; if (!this.labelTable.TryGetValue(e.Identifier.Value, out l)) { l = new LabeledStatement() { Label = this.host.NameTable.GetNameFor(e.GetText().ToString()), Locations = Helper.SourceLocation(this.tree, node), }; this.labelTable.Add(e.Identifier.Value, l); } return(new GotoStatement() { TargetStatement = l, }); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (node.CaseOrDefaultKeyword.IsKind(SyntaxKind.CaseKeyword)) { if (this.switchDict.Contains(this.model.GetConstantValue(node.Expression).Value)) { var dtt = this.model.GetTypeInfo(node.Expression); } foreach (var statement in ((SwitchSectionSyntax)node.Parent).Statements) { //statement. } } //v//ar typeInfo = this.model.GetTypeInfo(node.Expression); var tt = this.model.GetTypeInfo(node); base.VisitGotoStatement(node); }
private Block BuildGotoCaseStatement(GotoStatementSyntax statement, Block currentBlock) { if (SwitchGotoJumpBlocks.Count == 0) { throw new InvalidOperationException("goto case; outside a switch"); } var jumpBlock = CreateJumpBlock(statement, CreateTemporaryBlock(), currentBlock); var currentJumpBlocks = SwitchGotoJumpBlocks.Peek(); var indexer = GetCaseIndexer(statement.Expression); if (!currentJumpBlocks.ContainsKey(indexer)) { currentJumpBlocks.Add(indexer, new List <JumpBlock>()); } currentJumpBlocks[indexer].Add(jumpBlock); return(jumpBlock); }
private Block BuildGotoStatement(GotoStatementSyntax statement, Block currentBlock) { var jumpBlock = CreateJumpBlock(statement, CreateTemporaryBlock(), currentBlock); var identifier = statement.Expression as IdentifierNameSyntax; if (identifier == null) { throw new InvalidOperationException("goto with no identifier"); } if (!GotoJumpBlocks.ContainsKey(identifier.Identifier.ValueText)) { GotoJumpBlocks.Add(identifier.Identifier.ValueText, new List <JumpBlock>()); } GotoJumpBlocks[identifier.Identifier.ValueText].Add(jumpBlock); return(jumpBlock); }
private Block BuildGotoDefaultStatement(GotoStatementSyntax statement, Block currentBlock) { if (SwitchGotoJumpBlocks.Count == 0) { throw new InvalidOperationException("goto default; outside a switch"); } var jumpBlock = CreateJumpBlock(statement, CreateTemporaryBlock(), currentBlock); var currentJumpBlocks = SwitchGotoJumpBlocks.Peek(); if (!currentJumpBlocks.ContainsKey(GotoDefaultEntry)) { currentJumpBlocks.Add(GotoDefaultEntry, new List <JumpBlock>()); } currentJumpBlocks[GotoDefaultEntry].Add(jumpBlock); return(jumpBlock); }
public static void Go(OutputWriter writer, GotoStatementSyntax method) { writer.WriteIndent(); writer.Write("goto "); writer.Write((method.CaseOrDefaultKeyword != default(SyntaxToken)) ? method.CaseOrDefaultKeyword.Text : ""); writer.Write(" "); if (method.Expression != null) { if (method.Expression.ToString().Trim() == "null") { writer.Write("-1"); } else { Core.Write(writer, method.Expression); } } writer.Write(";\r\n"); }
private BoundStatement BindGoto(GotoStatementSyntax node, DiagnosticBag diagnostics) { switch (node.Kind()) { case SyntaxKind.GotoStatement: var expression = BindLabel(node.Expression, diagnostics); var boundLabel = expression as BoundLabel; if (boundLabel == null) { // diagnostics already reported return new BoundBadStatement(node, ImmutableArray.Create<BoundNode>(expression), true); } var symbol = boundLabel.Label; return new BoundGotoStatement(node, symbol, null, boundLabel); case SyntaxKind.GotoCaseStatement: case SyntaxKind.GotoDefaultStatement: // SPEC: If the goto case statement is not enclosed by a switch statement, a compile-time error occurs. // SPEC: If the goto default statement is not enclosed by a switch statement, a compile-time error occurs. SwitchBinder binder = GetSwitchBinder(this); if (binder == null) { Error(diagnostics, ErrorCode.ERR_InvalidGotoCase, node); return new BoundBadStatement(node, ImmutableArray<BoundNode>.Empty, true); } return binder.BindGotoCaseOrDefault(node, diagnostics); default: throw ExceptionUtilities.UnexpectedValue(node.Kind()); } }
internal BoundStatement BindGotoCaseOrDefault(GotoStatementSyntax node, Binder gotoBinder, DiagnosticBag diagnostics) { Debug.Assert(node.Kind() == SyntaxKind.GotoCaseStatement || node.Kind() == SyntaxKind.GotoDefaultStatement); BoundExpression gotoCaseExpressionOpt = null; // Prevent cascading diagnostics if (!node.HasErrors) { ConstantValue gotoCaseExpressionConstant = null; bool hasErrors = false; SourceLabelSymbol matchedLabelSymbol; // SPEC: If the goto case statement is not enclosed by a switch statement, if the constant-expression // SPEC: is not implicitly convertible (§6.1) to the governing type of the nearest enclosing switch statement, // SPEC: or if the nearest enclosing switch statement does not contain a case label with the given constant value, // SPEC: a compile-time error occurs. // SPEC: If the goto default statement is not enclosed by a switch statement, or if the nearest enclosing // SPEC: switch statement does not contain a default label, a compile-time error occurs. if (node.Expression != null) { Debug.Assert(node.Kind() == SyntaxKind.GotoCaseStatement); // Bind the goto case expression gotoCaseExpressionOpt = gotoBinder.BindValue(node.Expression, diagnostics, BindValueKind.RValue); gotoCaseExpressionOpt = ConvertCaseExpression(node, gotoCaseExpressionOpt, gotoBinder, ref gotoCaseExpressionConstant, diagnostics, isGotoCaseExpr: true); // Check for bind errors hasErrors = hasErrors || gotoCaseExpressionOpt.HasAnyErrors; if (!hasErrors && gotoCaseExpressionConstant == null) { diagnostics.Add(ErrorCode.ERR_ConstantExpected, node.Location); hasErrors = true; } // LabelSymbols for all the switch case labels are created by BuildLabels(). // Fetch the matching switch case label symbols matchedLabelSymbol = FindMatchingSwitchCaseLabel(gotoCaseExpressionConstant, node); } else { Debug.Assert(node.Kind() == SyntaxKind.GotoDefaultStatement); matchedLabelSymbol = GetDefaultLabel(); } if ((object)matchedLabelSymbol == null) { if (!hasErrors) { // No matching case label/default label found var labelName = SyntaxFacts.GetText(node.CaseOrDefaultKeyword.Kind()); if (node.Kind() == SyntaxKind.GotoCaseStatement) { labelName += " " + gotoCaseExpressionConstant.Value?.ToString(); } labelName += ":"; diagnostics.Add(ErrorCode.ERR_LabelNotFound, node.Location, labelName); hasErrors = true; } } else { return new BoundGotoStatement(node, matchedLabelSymbol, gotoCaseExpressionOpt, null, hasErrors); } } return new BoundBadStatement( syntax: node, childBoundNodes: gotoCaseExpressionOpt != null ? ImmutableArray.Create<BoundNode>(gotoCaseExpressionOpt) : ImmutableArray<BoundNode>.Empty, hasErrors: true); }
public override void VisitGotoStatement(GotoStatementSyntax node) { if (node.IsKind(SyntaxKind.GotoDefaultStatement) || node.IsKind(SyntaxKind.GotoCaseStatement)) { gotoCaseOrDefault.Add(curNode); } else { builder.gotoStatements.Add(node); } curNode = builder.CreateEndNode(node); }
public GotoStatementTranslation(GotoStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { }
public void VisitGotoStatement(GotoStatementSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); WriteLeadingTrivia(node); _writer.WriteIndent(); _writer.WriteKeyword(PrinterKeyword.Goto); switch (node.Kind) { case CaseOrDefault.Case: _writer.WriteSpace(); _writer.WriteKeyword(PrinterKeyword.Case); break; case CaseOrDefault.Default: _writer.WriteSpace(); _writer.WriteKeyword(PrinterKeyword.Default); break; } if (node.Expression != null) { _writer.WriteSpace(); node.Expression.Accept(this); } _writer.EndStatement(); WriteTrailingTrivia(node); }
private GoTo TraverseGoToStatements(GotoStatementSyntax gtss) { GoTo retGoTo = new GoTo(); if (gtss.HasLeadingTrivia) { SetOuterComments(retGoTo, gtss.GetLeadingTrivia().ToFullString()); } if (gtss.HasTrailingTrivia) { SetInnerComments(retGoTo, gtss.GetTrailingTrivia().ToFullString()); } var labelStatements = from aLabelStatement in gtss.ChildNodes().OfType<LabeledStatementSyntax>() select aLabelStatement; foreach (LabeledStatementSyntax lss in labelStatements) { retGoTo.GoToLabel = TraverseLabelStatements(lss); } return retGoTo; }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <remarks> /// Statements will cause an AST walker to be created, thus we don't need to go further deeper in the /// tree by visiting the node. /// </remarks> public override void VisitGotoStatement(GotoStatementSyntax node) { this.VisitStatement(node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitGotoStatement(GotoStatementSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitGotoStatement(node); }
public void Flatten(GotoStatementSyntax node, List<FlatStatement> instructions) { /* * public SyntaxToken CaseOrDefaultKeyword { get; } // // Summary: // Gets a constant expression for a goto case statement. public ExpressionSyntax Expression { get; } // // Summary: // Gets a SyntaxToken that represents the goto keyword. public SyntaxToken GotoKeyword { get; } // // Summary: // Gets a SyntaxToken that represents the semi-colon at the end of the statement. public SyntaxToken SemicolonToken { get; } */ switch(node.CaseOrDefaultKeyword.CSharpKind()) { case SyntaxKind.DefaultKeyword: if (CurrentSwitchContext != null) { instructions.Add(FlatStatement.JMP(FlatOperand.LabelRef(CurrentSwitchContext.DefaultCaseLabel))); return; } break; case SyntaxKind.CaseKeyword: if (CurrentSwitchContext != null) { //prefix + "case[" + fop.ImmediateValue.ValueText+"]"; instructions.Add(FlatStatement.JMP(FlatOperand.LabelRef(CurrentSwitchContext.Prefix+"case["+node.Expression.ToString()+"]"))); return; } break; default: break; } throw new NotImplementedException("goto " + node.CaseOrDefaultKeyword.CSharpKind()); }
public override void VisitGotoStatement(GotoStatementSyntax node) { currentState.Add(StateMachineThisFixer.Fix(node)); currentState.Add(GotoTop()); SetClosed(currentState); }
public void Flatten(GotoStatementSyntax node, List<FlatStatement> instructions) { /* * public SyntaxToken CaseOrDefaultKeyword { get; } // // Summary: // Gets a constant expression for a goto case statement. public ExpressionSyntax Expression { get; } // // Summary: // Gets a SyntaxToken that represents the goto keyword. public SyntaxToken GotoKeyword { get; } // // Summary: // Gets a SyntaxToken that represents the semi-colon at the end of the statement. public SyntaxToken SemicolonToken { get; } */ switch(node.CaseOrDefaultKeyword.Kind) { case SyntaxKind.DefaultKeyword: break; case SyntaxKind.CaseKeyword: break; default: break; } throw new NotImplementedException("goto"); }
public override void VisitGotoStatement(GotoStatementSyntax node) { Fail = true; }
public override void VisitGotoStatement(GotoStatementSyntax node) { base.VisitGotoStatement(node); if (!yieldOnly) isSpecial = true; }
public override void VisitGotoStatement(GotoStatementSyntax node) { base.VisitGotoStatement(node); _counter++; }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitGotoStatement(GotoStatementSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitGotoStatement(node); }
public override SyntaxNode VisitGotoStatement(GotoStatementSyntax node) { this.AppendCompileIssue(node, IssueType.Error, IssueId.GotoNotSupport); return node; }
public override void VisitGotoStatement(GotoStatementSyntax node) { }
public override void VisitGotoStatement(GotoStatementSyntax node) { this.Logic.Add(this.nodeFactory.CreateGoTo(node)); }