Exemple #1
0
 public override void Visit(DeclarationStatementSyntax pNode)
 {
     base.Visit(pNode);
     if (pNode.Identifier.GetType() == typeof(ArrayAccessExpressionSyntax))
     {
         Compiler.ReportError(CompilerErrorType.InvalidArraySpecifier, pNode);
     }
 }
Exemple #2
0
        public override void Visit(DeclarationStatementSyntax pNode)
        {
            if (!pNode.Identifier.Type.IsAssignableFrom(pNode.Value.Type))
            {
                Compiler.ReportError(CompilerErrorType.TypeMismatch, pNode, pNode.Value.Type.ToString(), pNode.Identifier.Type.ToString());
            }

            if (pNode.Identifier.Type.IsGenericDefinition && !pNode.Identifier.Type.IsGeneric)
            {
                Compiler.ReportError(CompilerErrorType.GenericArgs, pNode.Identifier);
            }

            base.Visit(pNode);
        }
        public override void Visit(DeclarationStatementSyntax pNode)
        {
            base.Visit(pNode);
            //Tuple types will have been rewritten by GroupAssignmentSyntaxRewriter
            if (pNode.Value.Type.IsTupleType)
            {
                pNode.Identifier.SetType(pNode.Value.Type);
            }

            if (pNode.Value.GetType() == typeof(ArrayLiteralSyntax))
            {
                ((ArrayLiteralSyntax)pNode.Value).SetType(pNode.Identifier.Type);
            }
        }
Exemple #4
0
        public override SyntaxNode Visit(DeclarationStatementSyntax pNode)
        {
            var v = pNode.Value.Accept <ExpressionSyntax>(this);

            IdentifierSyntax n = null;

            using (new ContextValue(this, "InDeclaration", true))
            {
                using (new ContextValue(this, "LoadObject", pNode.Value.GetType() == typeof(ObjectInitializerExpressionSyntax)))
                {
                    n = pNode.Identifier.Accept <IdentifierSyntax>(this);
                }
            }

            return(SyntaxFactory.DeclarationStatement(n, v));
        }
Exemple #5
0
        private void AnalyzeExpression(SyntaxNodeAnalysisContext context, ConcurrentDictionary <int, Diagnostic> reports)
        {
            var parentKind = context.Node.Parent.Kind();

            // will be handled at higher level
            if (parentKind == SyntaxKind.SimpleMemberAccessExpression || parentKind == SyntaxKind.QualifiedName)
            {
                return;
            }

            var target = GetTargetOfNode(context.Node, context.SemanticModel);

            if (target == null)
            {
                return;
            }

            var platform = Analyzer.GetPlatformForSymbol(target);

            // Some quick escapes
            if (platform.Kind == PlatformKind.Unchecked)
            {
                return;
            }

            if (platform.Kind == PlatformKind.Uwp && platform.Version == Analyzer.N2SDKVersion)
            {
                return;
            }

            // Is this expression inside a method/constructor/property that claims to be specific?
            DeclarationStatementSyntax containingMember = context.Node.FirstAncestorOrSelf <MethodBlockBaseSyntax>();

            if (containingMember is AccessorBlockSyntax)
            {
                containingMember = containingMember.FirstAncestorOrSelf <PropertyBlockSyntax>();
            }

            // Is this invocation properly guarded? See readme.md for explanations.
            if (IsProperlyGuarded(context.Node, context.SemanticModel))
            {
                return;
            }

            if (containingMember != null)
            {
                foreach (var ret in containingMember.DescendantNodes().OfType <ReturnStatementSyntax>())
                {
                    if (IsProperlyGuarded(ret, context.SemanticModel))
                    {
                        return;
                    }
                }
            }

            // We'll report only a single diagnostic per line, the first.
            var loc = context.Node.GetLocation();

            if (!loc.IsInSource)
            {
                return;
            }

            var line = loc.GetLineSpan().StartLinePosition.Line;

            Diagnostic diagnostic = null;

            if (reports.TryGetValue(line, out diagnostic) && diagnostic.Location.SourceSpan.Start <= loc.SourceSpan.Start)
            {
                return;
            }

            diagnostic = Diagnostic.Create(platform.Kind == PlatformKind.Uwp ? Analyzer.VersionRule : Analyzer.PlatformRule, loc);

            reports[line] = diagnostic;

            context.ReportDiagnostic(diagnostic);
        }