コード例 #1
0
        private static async Task<bool> ExceptionDeclarationCouldBeRemoved(CodeFixContext context, SyntaxNode root, ThrowStatementSyntax originalThrowStatement)
        {
            // If "ex" from "throw ex" was the only reference to "ex", then additional modification should be made
            // "catch(Exception ex)" should be replaced by "catch(Exception)"

            var throwExIdentifier = originalThrowStatement.Expression.As(x => x as IdentifierNameSyntax);

            Contract.Assert(throwExIdentifier != null);

            var model = await context.Document.GetSemanticModelAsync();
            var solution = context.Document.Project.Solution;
            var symbol = model.GetSymbolInfo(throwExIdentifier);

            Contract.Assert(symbol.Symbol != null);

            // Not sure this is a good idea!
            // TODO: talk to nikov about it! If there is an optimization for locals than everything should be fine!
            // Otherwise - not!
            // Searching within one document should be fast. Still need to check!

            var references = await SymbolFinder.FindReferencesAsync(symbol.Symbol, solution, ImmutableHashSet.Create(context.Document));
            var locations = references.SelectMany(x => x.Locations).ToArray();
            var numberOfUsages =
                references
                .SelectMany(x => x.Locations)
                .Select(x => root.FindToken(x.Location.SourceSpan.Start))
                .Count(token => token.Parent.Parent is ThrowStatementSyntax); // TODO: code duplication with GetThrowStatementFrom!

            // "ex" in the "Exception ex" could be removed only if there is no any other usages. Otherwise the fix will fail.
            // Consider following case:
            // There is two usages of the "ex" in two "throw ex" statemetns.
            // Two different fixes would be run for both warnings.
            // The first fix will change the code to "catch(Exception) {throw ex; throw;}" witch is not a valid C# program
            return numberOfUsages == 1 && locations.Length == 1;
        }
 private Task<Solution> RemoveRethrowAsync(Document document, SyntaxNode root, ThrowStatementSyntax throwStatement)
 {
     var newStatement = SyntaxFactory.ThrowStatement();
     var newRoot = root.ReplaceNode(throwStatement, newStatement);
     var newDocument = document.WithSyntaxRoot(newRoot);
     return Task.FromResult(newDocument.Project.Solution);
 }
コード例 #3
0
        public IfThrowPrecondition(StatementSyntax ifThrowStaement, ThrowStatementSyntax throwStatement)
        {
            Contract.Requires(ifThrowStaement != null);
            Contract.Requires(throwStatement != null);

            IfThrowStaement = ifThrowStaement;
            ThrowStatement = throwStatement;
        }
        public ITypeSymbol GetThrownExceptionTypeSymbol(SemanticModel semanticModel, ThrowStatementSyntax throwStatementSyntax)
        {
            SemanticModel = semanticModel;
            ThrowStatementSyntax = throwStatementSyntax;

            SyntaxNode syntaxNodeToGetTypeOf = ThrowStatementSyntax.Expression;

            if (syntaxNodeToGetTypeOf == null)
                syntaxNodeToGetTypeOf = GetCatchClaue();

            if (syntaxNodeToGetTypeOf == null)
                return null; //Not sure this is possible....

            return semanticModel.GetTypeInfo(syntaxNodeToGetTypeOf).Type;
        }
コード例 #5
0
        public static void Go(OutputWriter writer, ThrowStatementSyntax statement)
        {
            writer.WriteIndent();

            writer.Write("throw ");

            if (statement.Expression == null)
            {
                //On just "throw" with no exception name, navigate up the stack to find the nearest catch block and insert the exception's name
                CatchClauseSyntax catchBlock;
                SyntaxNode node = statement;
                do
                    catchBlock = (node = node.Parent) as CatchClauseSyntax;
                while (catchBlock == null);

                if (catchBlock == null)
                {
                    throw new Exception("throw statement with no exception name, and could not locate a catch block " +
                                        Utility.Descriptor(statement));
                }

                if (catchBlock.Declaration == null || catchBlock.Declaration.Identifier.Value == null)
                    //Some people write code in the form catch(Exception) ...grrr
                    writer.Write("__ex");
                else
                {
                    var exName = WriteIdentifierName.TransformIdentifier(catchBlock.Declaration.Identifier.Text);

                    if (string.IsNullOrWhiteSpace(exName))
                        writer.Write("__ex");
                    else
                        writer.Write(exName);
                }
            }
            else
                Core.Write(writer, statement.Expression);
            writer.Write(";\r\n");
        }
コード例 #6
0
ファイル: ThrowStatement.cs プロジェクト: andry-tino/Rosetta
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrowStatement"/> class.
 /// </summary>
 /// <param name="syntaxNode"></param>
 /// <param name="semanticModel"></param>
 public ThrowStatement(ThrowStatementSyntax syntaxNode, SemanticModel semanticModel)
     : base(syntaxNode, semanticModel)
 {
 }
コード例 #7
0
ファイル: Function.cs プロジェクト: VendanAndrews/ls2csc
 public void Flatten(ThrowStatementSyntax node, List<FlatStatement> instructions)
 {
     if (node.Expression == null)
     {
         FlatStatement.THROW(FlatOperand.ExceptionRef());
         return;
     }
     FlatOperand fop_exception = this.ResolveExpression(node.Expression, null, instructions);
     instructions.Add(FlatStatement.THROW(fop_exception));
 }
コード例 #8
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     base.VisitThrowStatement(node);
     this.walker.StoreVisitData(node, this.walker.ConditionalTerminates, this.walker.UnconditionalTerminates);
 }
コード例 #9
0
 private async Task <Document> RemoveThrowAsync(Document document, ThrowStatementSyntax @throw, CancellationToken ct)
 {
     return(document.WithSyntaxRoot((await document.GetSyntaxRootAsync(ct)).RemoveNode(@throw, SyntaxRemoveOptions.KeepNoTrivia)));
 }
コード例 #10
0
ファイル: ThrowStatement.cs プロジェクト: scottyb86/Rosetta
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrowStatement"/> class.
 /// </summary>
 /// <param name="syntaxNode"></param>
 /// <param name="semanticModel"></param>
 public ThrowStatement(ThrowStatementSyntax syntaxNode, SemanticModel semanticModel)
     : base(syntaxNode, semanticModel)
 {
 }
コード例 #11
0
 public static void Analyze(SyntaxNodeAnalysisContext context, ThrowStatementSyntax throwStatement)
 {
     Analyze(context, throwStatement.Expression);
 }
コード例 #12
0
        static void ProcessThrowClause(SemanticModel semanticModel, ThrowStatementSyntax throwClause)
        {
            var thrownTypeExtractor = new ThrownTypeExtractor();
            ITypeSymbol typeSymbol = thrownTypeExtractor.GetThrownExceptionTypeSymbol(semanticModel, throwClause);
            if (typeSymbol == null)
                return;
            if (!typeSymbol.ContainingNamespace.ToDisplayParts().Any(x => x.Kind == SymbolDisplayPartKind.NamespaceName
                                                                          && x.Symbol.Name.ToLowerInvariant() == "tombola"))
                return;

            var containingMethods = throwClause.AncestorsAndSelf().OfType<MethodDeclarationSyntax>();
            if (containingMethods == null || containingMethods.Count() == 0)
                return;
            var containingMethod = containingMethods.Last();
            if (containingMethod == null)
                return;
            if (!DoesContainingMethodDeclareExceptionType(containingMethod, typeSymbol.Name))
                AddToMissingDefinitions(containingMethod, typeSymbol);
        }
コード例 #13
0
 protected override bool IsThrowStatementWithNoArgument(ThrowStatementSyntax throwNode)
 {
     Debug.Assert(throwNode != null);
     return(throwNode.Expression == null);
 }
コード例 #14
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     Write("throw");
     Visit(node.Expression);
 }
コード例 #15
0
        public override void VisitThrowStatement(ThrowStatementSyntax node)
        {
            var statement = VisitSyntaxNode(node.Expression);

            _currentNode = new Throw(statement);
        }
コード例 #16
0
 // throw语句
 public virtual void VisitThrowStatementSyntax(ThrowStatementSyntax value)
 {
     DefaultVisit(value);
 }
コード例 #17
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     // end not connected with data
     curNode = builder.CreateEndNode(node);
 }
コード例 #18
0
 //
 // Summary:
 //     Called when the visitor visits a ThrowStatementSyntax node.
 public virtual void VisitThrowStatement(ThrowStatementSyntax node);
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     AddExpressionTerms(node.Expression, _expressions);
 }
コード例 #20
0
			public override void VisitThrowStatement(ThrowStatementSyntax node)
			{
				base.VisitThrowStatement(node);
				_counter++;
			}
コード例 #21
0
        /// <inheritdoc/>
        public override SyntaxNode?VisitThrowStatement(ThrowStatementSyntax node)
        {
            Context.ReportDiagnostic(ThrowExpressionOrStatement, node);

            return(base.VisitThrowStatement(node));
        }
コード例 #22
0
 private void BuildThrowStatement(ThrowStatementSyntax throwStatement)
 {
     BuildJumpToExitStatement(throwStatement, throwStatement.Expression);
 }
コード例 #23
0
 /// <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 VisitThrowStatement(ThrowStatementSyntax node)
 {
     this.VisitStatement(node);
 }
コード例 #24
0
            private IEnumerable<ITypeSymbol> InferTypeInThrowStatement(ThrowStatementSyntax throwStatement, SyntaxToken? previousToken = null)
            {
                // If we have a position, it has to be after the 'throw' keyword.
                if (previousToken.HasValue && previousToken.Value != throwStatement.ThrowKeyword)
                {
                    return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
                }

                return SpecializedCollections.SingletonEnumerable(this.Compilation.ExceptionType());
            }
コード例 #25
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
 }
コード例 #26
0
ファイル: ThrowStatement.cs プロジェクト: scottyb86/Rosetta
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrowStatement"/> class.
 /// </summary>
 /// <param name="syntaxNode"></param>
 public ThrowStatement(ThrowStatementSyntax syntaxNode)
     : this(syntaxNode, null)
 {
 }
コード例 #27
0
ファイル: Binder_Statements.cs プロジェクト: abock/roslyn
        private BoundStatement BindThrow(ThrowStatementSyntax node, DiagnosticBag diagnostics)
        {
            if (node.Expression == null)
            {
                return BindThrowParts(node, diagnostics);
            }

            var binder = GetBinder(node);
            Debug.Assert(binder != null);
            return binder.WrapWithVariablesIfAny(node, binder.BindThrowParts(node, diagnostics));
        }
コード例 #28
0
        public void Generate()
        {
            // standard using directives
            CompilationUnitSyntax cu = SyntaxFactory.CompilationUnit()
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Collections.Generic")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Linq")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Text")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Threading.Tasks")));

            NamespaceDeclarationSyntax localNamespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName(directoryName));

            ClassDeclarationSyntax localClass = SyntaxFactory.ClassDeclaration(Name);

            foreach (var member in Declarations)
            {
                switch (member.DeclarationType)
                {
                case "method":
                    var currentMethod = member as Method;

                    //currentMethod.Type is a string parsed from the uml diagram
                    MethodDeclarationSyntax method = SyntaxFactory.MethodDeclaration(SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(currentMethod.Type)), currentMethod.Name);

                    List <SyntaxToken> mods = new List <SyntaxToken>();

                    foreach (var modifier in currentMethod.Modifiers)
                    {
                        mods.Add(SyntaxFactory.ParseToken(modifier));
                    }

                    method = method.AddModifiers(mods.ToArray());

                    SeparatedSyntaxList <ParameterSyntax> ssl = SyntaxFactory.SeparatedList <ParameterSyntax>();
                    foreach (var param in currentMethod.Arguments)
                    {
                        ParameterSyntax ps = SyntaxFactory.Parameter(
                            new SyntaxList <AttributeListSyntax>(),
                            new SyntaxTokenList(),
                            SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(param.Type)),
                            SyntaxFactory.Identifier(param.Name), null);

                        ssl = ssl.Add(ps);
                    }

                    method = method.AddParameterListParameters(ssl.ToArray());

                    // we add an exception to the body of an otherwise empty method
                    ThrowStatementSyntax notReady = SyntaxFactory.ThrowStatement(SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName("NotImplementedException"), SyntaxFactory.ArgumentList(), null));

                    method = method.AddBodyStatements(notReady);

                    localClass = localClass.AddMembers(method);
                    break;

                case "field":
                    var currentField = member as Field;

                    SyntaxTokenList stl = new SyntaxTokenList();

                    foreach (var modifier in currentField.Modifiers)
                    {
                        stl = stl.Add(SyntaxFactory.ParseToken(modifier));
                    }

                    SeparatedSyntaxList <VariableDeclaratorSyntax> svd = SyntaxFactory.SeparatedList <VariableDeclaratorSyntax>();

                    svd = svd.Add(SyntaxFactory.VariableDeclarator(currentField.Name));

                    // currentField.Type is a string parsed from the uml diagram
                    VariableDeclarationSyntax variable = SyntaxFactory.VariableDeclaration(SyntaxFactory.ParseTypeName(currentField.Type), svd);

                    FieldDeclarationSyntax field = SyntaxFactory.FieldDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        stl,
                        variable
                        );

                    localClass = localClass.AddMembers(field);
                    break;
                }
            }

            localNamespace = localNamespace.AddMembers(localClass);
            cu             = cu.AddMembers(localNamespace);

            AdhocWorkspace cw      = new AdhocWorkspace();
            OptionSet      options = cw.Options;

            cw.Options.WithChangedOption(CSharpFormattingOptions.IndentBraces, true);
            SyntaxNode formattedNode = Formatter.Format(cu, cw, options);

            formattedNode.WriteTo(writer);
        }
コード例 #29
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     if (node.Expression != null)
     {
         Visit(node.Expression, _enclosing);
     }
 }
コード例 #30
0
 /// <inheritdoc/>
 public override bool VisitThrowStatement(ThrowStatementSyntax node)
 {
     return(this.VisitStatement(node));
 }
コード例 #31
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     AddExpressionTerms(node.Expression, _expressions);
 }
コード例 #32
0
ファイル: VisitorBlock.cs プロジェクト: zwdesigns/Phase
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     Emit <ThrowBlock, ThrowStatementSyntax>(node);
 }
コード例 #33
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     VisitNodeToBind(node.Expression);
 }
コード例 #34
0
 internal ThrowStatementInfo(ThrowStatementSyntax node, ExpressionSyntax expression, ITypeSymbol exceptionSymbol)
     : base(node, expression, exceptionSymbol)
 {
 }
コード例 #35
0
ファイル: ThrowStatement.cs プロジェクト: andry-tino/Rosetta
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrowStatement"/> class.
 /// </summary>
 /// <param name="syntaxNode"></param>
 public ThrowStatement(ThrowStatementSyntax syntaxNode)
     : this(syntaxNode, null)
 {
 }
コード例 #36
0
            public override void VisitThrowStatement(ThrowStatementSyntax node)
            {
                base.VisitThrowStatement(node);

                this.context.ReportDiagnosticWhenActive(Diagnostic.Create(rule, node.GetLocation()));
            }
コード例 #37
0
ファイル: CodeWalker.cs プロジェクト: guipadua/NTratch
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     this.invokedThrows.Add(node);
 }
コード例 #38
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitThrowStatement(ThrowStatementSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitThrowStatement(node);
 }
コード例 #39
0
        public void VisitThrowStatement(ThrowStatementSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            WriteLeadingTrivia(node);

            _writer.WriteIndent();
            _writer.WriteKeyword(PrinterKeyword.Throw);

            if (node.Expression != null)
            {
                _writer.WriteSpace();
                node.Expression.Accept(this);
            }

            _writer.EndStatement();

            WriteTrailingTrivia(node);
        }
コード例 #40
0
    /// <inheritdoc/>
    public override SyntaxNode?VisitThrowStatement(ThrowStatementSyntax node)
    {
        Diagnostics.Add(ThrowExpressionOrStatement, node);

        return(base.VisitThrowStatement(node));
    }
コード例 #41
0
 public ThrowStatementTranslation(ThrowStatementSyntax syntax, SyntaxTranslation parent)
     : base(syntax, parent)
 {
     Expression = syntax.Expression.Get<ExpressionTranslation>(this);
 }
コード例 #42
0
 /// <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 VisitThrowStatement(ThrowStatementSyntax node)
 {
     this.VisitStatement(node);
 }
コード例 #43
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     currentState.Add(StateMachineThisFixer.Fix(node));
 }
コード例 #44
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitThrowStatement(ThrowStatementSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitThrowStatement(node);
 }
コード例 #45
0
ファイル: Syntax.cs プロジェクト: modulexcite/CSharpSyntax
        public static ThrowStatementSyntax ThrowStatement(ExpressionSyntax expression = null)
        {
            var result = new ThrowStatementSyntax();

            result.Expression = expression;

            return result;
        }
コード例 #46
0
 public ThrowStatementTranslation(ThrowStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
     Expression = syntax.Expression.Get <ExpressionTranslation>(this);
 }
コード例 #47
0
ファイル: Program.cs プロジェクト: itowlson/torment-roslyn
            public override void VisitThrowStatement(ThrowStatementSyntax node)
            {
                base.VisitThrowStatement(node);

                var thrown = node.Expression;

                if (thrown != null)  // it can be null for a rethrow (throw;) expression
                {
                    bool rethrowing = IsRethrowOfCaughtException(thrown);

                    var typeInfo = _semanticModel.GetTypeInfo(thrown);

                    // we should never really be throwing weakly typed expressions, so if we
                    // see such a thing, drill in to check if we can learn more
                    if (typeInfo.Type.Name == "Exception")
                    {
                        // check if the expression is a call to one of our methods (throw Util.BlahBlahBlah):
                        // if so, it will get picked up in the ObjectCreationExpression clause, so we don't
                        // need to report the weak type
                        if (!rethrowing && IsObtainedFromFactory(thrown))
                        {
                            return;
                        }

                        // we can't prove a stronger type, so dump some information to help us investigate
                        // further in case we can improve the tool
                        var span = thrown.GetLocation().GetLineSpan();
                        System.Diagnostics.Debug.WriteLine($">>> {span.Path}: {span.StartLinePosition.Line}");
                        System.Diagnostics.Debug.WriteLine($">>> {thrown.ToString()}");
                    }

                    _thrownExceptionTypeNames.Add(typeInfo.Type.Name + (rethrowing ? " - rethrown" : ""));
                }
            }
コード例 #48
0
 public virtual void VisitThrowStatement(ThrowStatementSyntax node) => DefaultVisit(node);
コード例 #49
0
        private BoundThrowStatement BindThrow(ThrowStatementSyntax node, DiagnosticBag diagnostics)
        {
            BoundExpression boundExpr = null;
            bool hasErrors = false;

            ExpressionSyntax exprSyntax = node.Expression;
            if (exprSyntax != null)
            {
                boundExpr = BindValue(exprSyntax, diagnostics, BindValueKind.RValue);

                // SPEC VIOLATION: The spec requires the thrown exception to have a type, and that the type
                // be System.Exception or derived from System.Exception. (Or, if a type parameter, to have
                // an effective base class that meets that criterion.) However, we allow the literal null 
                // to be thrown, even though it does not meet that criterion and will at runtime always
                // produce a null reference exception.

                if (!boundExpr.IsLiteralNull())
                {
                    var type = boundExpr.Type;

                    // If the expression is a lambda, anonymous method, or method group then it will
                    // have no compile-time type; give the same error as if the type was wrong.

                    if ((object)type == null || !type.IsErrorType() && !Compilation.IsExceptionType(type.EffectiveTypeNoUseSiteDiagnostics))
                    {
                        diagnostics.Add(ErrorCode.ERR_BadExceptionType, exprSyntax.Location);
                        hasErrors = true;
                    }
                }
            }
            else if (!this.Flags.Includes(BinderFlags.InCatchBlock))
            {
                diagnostics.Add(ErrorCode.ERR_BadEmptyThrow, node.ThrowKeyword.GetLocation());
                hasErrors = true;
            }
            else if (this.Flags.Includes(BinderFlags.InFinallyBlock))
            {
                // There's a special error code for a rethrow in a finally clause in a catch clause.
                // Best guess interpretation: if an exception occurs within the nested try block
                // (i.e. the one in the catch clause, to which the finally clause is attached),
                // then it's not clear whether the runtime will try to rethrow the "inner" exception
                // or the "outer" exception.  For this reason, the case is disallowed.

                // At this point, we know that we're within both a catch block and a finally block,
                // but we don't know which is nested within the other.  We can't walk up the syntax
                // tree because we might be binding speculatively.  Instead, we'll walk up the binder
                // chain and see which flag gets dropped first.

                Binder curr = this;
                while (curr.Flags.Includes(BinderFlags.InFinallyBlock | BinderFlags.InCatchBlock))
                {
                    curr = curr.Next;
                }

                if (curr.Flags.Includes(BinderFlags.InCatchBlock))
                {
                    // The finally block is below the catch block in the binder chain, so it 
                    // musted be nested within the catch block syntactically.

                    diagnostics.Add(ErrorCode.ERR_BadEmptyThrowInFinally, node.ThrowKeyword.GetLocation());
                    hasErrors = true;
                }
                else
                {
                    // Can't have added both flags in the same binder.
                    Debug.Assert(curr.Flags.Includes(BinderFlags.InFinallyBlock));
                }
            }

            return new BoundThrowStatement(node, boundExpr, hasErrors);
        }
コード例 #50
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     VisitNodeToBind(node.Expression);
 }
コード例 #51
0
 public virtual void VisitThrowStatement(ThrowStatementSyntax node)
 {
     DefaultVisit(node);
 }
コード例 #52
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     base.VisitThrowStatement(node);
     _counter++;
 }
コード例 #53
0
ファイル: LocalBinderFactory.cs プロジェクト: CAPCHIK/roslyn
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     if (node.Expression != null)
     {
         var patternBinder = new PatternVariableBinder(node, _enclosing);
         AddToMap(node, patternBinder);
         Visit(node.Expression, patternBinder);
     }
 }
コード例 #54
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     LogicalLineCount++;
     base.VisitThrowStatement(node);
 }
コード例 #55
0
ファイル: Binder_Statements.cs プロジェクト: abock/roslyn
        private BoundThrowStatement BindThrowParts(ThrowStatementSyntax node, DiagnosticBag diagnostics)
        {
            BoundExpression boundExpr = null;
            bool hasErrors = false;

            ExpressionSyntax exprSyntax = node.Expression;
            if (exprSyntax != null)
            {
                boundExpr = BindThrownExpression(exprSyntax, diagnostics, ref hasErrors);
            }
            else if (!this.Flags.Includes(BinderFlags.InCatchBlock))
            {
                diagnostics.Add(ErrorCode.ERR_BadEmptyThrow, node.ThrowKeyword.GetLocation());
                hasErrors = true;
            }
            else if (this.Flags.Includes(BinderFlags.InNestedFinallyBlock))
            {
                // There's a special error code for a rethrow in a finally clause in a catch clause.
                // Best guess interpretation: if an exception occurs within the nested try block
                // (i.e. the one in the catch clause, to which the finally clause is attached),
                // then it's not clear whether the runtime will try to rethrow the "inner" exception
                // or the "outer" exception. For this reason, the case is disallowed.

                diagnostics.Add(ErrorCode.ERR_BadEmptyThrowInFinally, node.ThrowKeyword.GetLocation());
                hasErrors = true;
            }

            return new BoundThrowStatement(node, boundExpr, hasErrors);
        }
コード例 #56
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     currentState.Add(YieldThisFixer.Fix(node));
 }
コード例 #57
0
 public override SyntaxNode VisitThrowStatement(ThrowStatementSyntax node)
 {
     if (node.Expression == null)
     {
         this.AppendCompileIssue(node, IssueType.Error, IssueId.ThrowNothing);
     }
     else
     {
         _output.Write(node.ThrowKeyword, "throw ");
         Visit(node.Expression);
     }
     return node;
 }
コード例 #58
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     base.VisitThrowStatement(node);
     ReportDiagnostic(AddDiagnostic, DiagnosticDescriptor, node);
 }
コード例 #59
0
        private BoundThrowStatement BindThrow(ThrowStatementSyntax node, DiagnosticBag diagnostics)
        {
            BoundExpression boundExpr = null;
            bool hasErrors = false;

            ExpressionSyntax exprSyntax = node.Expression;
            if (exprSyntax != null)
            {
                boundExpr = BindValue(exprSyntax, diagnostics, BindValueKind.RValue);

                // SPEC VIOLATION: The spec requires the thrown exception to have a type, and that the type
                // be System.Exception or derived from System.Exception. (Or, if a type parameter, to have
                // an effective base class that meets that criterion.) However, we allow the literal null 
                // to be thrown, even though it does not meet that criterion and will at runtime always
                // produce a null reference exception.

                if (!boundExpr.IsLiteralNull())
                {
                    var type = boundExpr.Type;

                    // If the expression is a lambda, anonymous method, or method group then it will
                    // have no compile-time type; give the same error as if the type was wrong.
                    HashSet<DiagnosticInfo> useSiteDiagnostics = null;

                    if ((object)type == null || !type.IsErrorType() && !Compilation.IsExceptionType(type.EffectiveType(ref useSiteDiagnostics), ref useSiteDiagnostics))
                    {
                        diagnostics.Add(ErrorCode.ERR_BadExceptionType, exprSyntax.Location);
                        hasErrors = true;
                        diagnostics.Add(exprSyntax, useSiteDiagnostics);
                    }
                }
            }
            else if (!this.Flags.Includes(BinderFlags.InCatchBlock))
            {
                diagnostics.Add(ErrorCode.ERR_BadEmptyThrow, node.ThrowKeyword.GetLocation());
                hasErrors = true;
            }
            else if (this.Flags.Includes(BinderFlags.InNestedFinallyBlock))
            {
                // There's a special error code for a rethrow in a finally clause in a catch clause.
                // Best guess interpretation: if an exception occurs within the nested try block
                // (i.e. the one in the catch clause, to which the finally clause is attached),
                // then it's not clear whether the runtime will try to rethrow the "inner" exception
                // or the "outer" exception. For this reason, the case is disallowed.

                diagnostics.Add(ErrorCode.ERR_BadEmptyThrowInFinally, node.ThrowKeyword.GetLocation());
                hasErrors = true;
            }

            return new BoundThrowStatement(node, boundExpr, hasErrors);
        }
コード例 #60
0
ファイル: LangVisitor.cs プロジェクト: yekainew/cs2php
 protected override object VisitThrowStatement(ThrowStatementSyntax node)
 {
     return(base.VisitThrowStatement(node));
 }