private static void AddVariablesToGlobalVarList(
     Dictionary <string, VariableDeclarationBaseSyntax> globalVariables,
     SyntaxList <VariableDeclarationBaseSyntax> variables)
 {
     foreach (VariableDeclarationBaseSyntax variable in variables)
     {
         VariableInitializationUsageAnalyzer.AddVariableToGlobalVarList(globalVariables, variable);
     }
 }
            private void ReportInitializedNotUsedNotInitializedUsedLocalVars(
                CodeBlockAnalysisContext context)
            {
                PooledHashSet <IdentifierNameSyntax> instance1 = PooledHashSet <IdentifierNameSyntax> .GetInstance();

                PooledHashSet <IdentifierNameSyntax> instance2 = PooledHashSet <IdentifierNameSyntax> .GetInstance();

                try
                {
                    this.CollectInitializedNotUsedNotInitializedUsedLocalVars((HashSet <IdentifierNameSyntax>)instance1, (HashSet <IdentifierNameSyntax>)instance2);
                    VariableInitializationUsageAnalyzer.ReportInitializedNotUsedVariables(new Action <Diagnostic>(context.ReportDiagnostic), instance1);
                    VariableInitializationUsageAnalyzer.ReportNotInitializedVariables(new Action <Diagnostic>(context.ReportDiagnostic), instance2);
                }
                finally
                {
                    instance1.Free();
                    instance2.Free();
                }
            }
        private static void InitializeGlobalVariablesAnalyzer(
            SyntaxNodeAnalysisContext syntaxNodeAnalysisContext)
        {
            PooledNameObjectDictionary <VariableDeclarationBaseSyntax> instance1 = PooledNameObjectDictionary <VariableDeclarationBaseSyntax> .GetInstance();

            PooledNameObjectDictionary <IdentifierNameSyntax> instance2 = PooledNameObjectDictionary <IdentifierNameSyntax> .GetInstance();

            PooledNameObjectDictionary <IdentifierNameSyntax> instance3 = PooledNameObjectDictionary <IdentifierNameSyntax> .GetInstance();

            PooledNameObjectDictionary <IdentifierNameSyntax> instance4 = PooledNameObjectDictionary <IdentifierNameSyntax> .GetInstance();

            PooledNameObjectDictionary <IdentifierNameSyntax> instance5 = PooledNameObjectDictionary <IdentifierNameSyntax> .GetInstance();

            try
            {
                VariableInitializationUsageAnalyzer.CollectDeclaredGlobalVariables(syntaxNodeAnalysisContext, (Dictionary <string, VariableDeclarationBaseSyntax>)instance1);
                foreach (SyntaxNode descendantNode in syntaxNodeAnalysisContext.Node.DescendantNodes())
                {
                    if (descendantNode.IsKind(SyntaxKind.IdentifierName))
                    {
                        // ISSUE: variable of a compiler-generated type
                        IdentifierNameSyntax identifier = (IdentifierNameSyntax)descendantNode;
                        if (instance1.ContainsKey(identifier.Identifier.ValueText) && !identifier.Parent.IsKind(SyntaxKind.VariableDeclaration))
                        {
                            VariableInitializationUsageAnalyzer.AnalyzeGlobalVarUsage(identifier, (Dictionary <string, IdentifierNameSyntax>)instance2, (Dictionary <string, IdentifierNameSyntax>)instance3, (Dictionary <string, IdentifierNameSyntax>)instance4, (Dictionary <string, IdentifierNameSyntax>)instance5, syntaxNodeAnalysisContext, (Dictionary <string, VariableDeclarationBaseSyntax>)instance1);
                        }
                    }
                }
                VariableInitializationUsageAnalyzer.ReportInitializedNotUsedNotInitializedUsedVars(syntaxNodeAnalysisContext, (Dictionary <string, IdentifierNameSyntax>)instance3, (Dictionary <string, IdentifierNameSyntax>)instance2, (Dictionary <string, VariableDeclarationBaseSyntax>)instance1);
            }
            finally
            {
                instance1.Free();
                instance2.Free();
                instance3.Free();
                instance4.Free();
                instance5.Free();
            }
        }
        private static void ReportInitializedNotUsedNotInitializedUsedVars(
            SyntaxNodeAnalysisContext context,
            Dictionary <string, IdentifierNameSyntax> firstGlobalVarInitializerSyntax,
            Dictionary <string, IdentifierNameSyntax> firstGlobalVarUsageSyntax,
            Dictionary <string, VariableDeclarationBaseSyntax> globalVariables)
        {
            PooledHashSet <IdentifierNameSyntax> instance1 = PooledHashSet <IdentifierNameSyntax> .GetInstance();

            PooledHashSet <IdentifierNameSyntax> instance2 = PooledHashSet <IdentifierNameSyntax> .GetInstance();

            try
            {
                VariableInitializationUsageAnalyzer.CollectInitializedNotUsedNotInitializedUsedGlobalVars((HashSet <IdentifierNameSyntax>)instance2, (HashSet <IdentifierNameSyntax>)instance1, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax, globalVariables);
                VariableInitializationUsageAnalyzer.ReportInitializedNotUsedVariables(new Action <Diagnostic>(context.ReportDiagnostic), instance1);
                VariableInitializationUsageAnalyzer.ReportNotInitializedVariables(new Action <Diagnostic>(context.ReportDiagnostic), instance2);
            }
            finally
            {
                instance1.Free();
                instance2.Free();
            }
        }
            public void CollectLocalVariablesUsage(SyntaxNodeAnalysisContext context)
            {
                IdentifierNameSyntax identifierNameSyntax = context.GetIdentifierNameSyntax();

                if (identifierNameSyntax == null || this.localVariables.Count == 0 || !this.localVariables.ContainsKey(identifierNameSyntax.Identifier.ValueText))
                {
                    return;
                }
                VariableDeclarationBaseSyntax declarationBaseSyntax;

                this.localVariables.TryGetValue(identifierNameSyntax.Identifier.ValueText, out declarationBaseSyntax);
                NavTypeKind navTypeKind = NavTypeExtensions.GetNavTypeKind(declarationBaseSyntax?.Type.DataType.TypeName.ValueText);
                SyntaxKind  kind        = identifierNameSyntax.Parent.Kind;

                if ((uint)kind <= 233U)
                {
                    switch (kind)
                    {
                    case SyntaxKind.AssignmentStatement:
                        VariableInitializationUsageAnalyzer.AnalyzeAssignmentStatementIdentifier(identifierNameSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstLocalVarUsageSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstRecordChangeSyntax, navTypeKind);
                        return;

                    case SyntaxKind.CompoundAssignmentStatement:
                        VariableInitializationUsageAnalyzer.AnalyzeCompoundAssignmentStatementIdentifier(identifierNameSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstLocalVarUsageSyntax);
                        return;

                    case SyntaxKind.ForStatement:
                        VariableInitializationUsageAnalyzer.AnalyzeForStatementIdentifier(identifierNameSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstLocalVarUsageSyntax);
                        return;
                    }
                }
                else
                {
                    switch (kind)
                    {
                    case SyntaxKind.ForEachStatement:
                        VariableInitializationUsageAnalyzer.AnalyzeForEachStatementIdentifier(identifierNameSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstLocalVarUsageSyntax);
                        return;

                    case SyntaxKind.ArrayIndexExpression:
                        if (navTypeKind != NavTypeKind.Code && navTypeKind != NavTypeKind.Text)
                        {
                            return;
                        }
                        VariableInitializationUsageAnalyzer.AnalyzeArrayIndexExpressionIdentifier(identifierNameSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax);
                        return;

                    case SyntaxKind.MemberAccessExpression:
                        if (navTypeKind != NavTypeKind.List && navTypeKind != NavTypeKind.Record)
                        {
                            return;
                        }
                        VariableInitializationUsageAnalyzer.AnalyzeMemberAccessIdentifier(identifierNameSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstLocalVarUsageSyntax, (Dictionary <string, IdentifierNameSyntax>) this.lastRecordModifyInvocationSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstRecordChangeSyntax, navTypeKind);
                        return;

                    case SyntaxKind.OptionAccessExpression:
                        return;

                    case SyntaxKind.ArgumentList:
                        VariableInitializationUsageAnalyzer.AnalyzeArgumentListIdentifier(identifierNameSyntax, context, (Dictionary <string, IdentifierNameSyntax>) this.firstInitializerSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstLocalVarUsageSyntax, (Dictionary <string, IdentifierNameSyntax>) this.firstRecordChangeSyntax, navTypeKind);
                        return;
                    }
                }
                this.firstLocalVarUsageSyntax.AddIdentifierIfNotExist(identifierNameSyntax);
            }
        private static void CollectDeclaredGlobalVariables(
            SyntaxNodeAnalysisContext syntaxNodeAnalysisContext,
            Dictionary <string, VariableDeclarationBaseSyntax> globalVariables)
        {
            // ISSUE: variable of a compiler-generated type
            ApplicationObjectSyntax   node    = (ApplicationObjectSyntax)syntaxNodeAnalysisContext.Node;
            SyntaxList <MemberSyntax> members = node.Members;
            int index1 = members.IndexOf((Func <MemberSyntax, bool>)(ms => ms.Kind == SyntaxKind.GlobalVarSection));

            if (index1 != -1)
            {
                members = node.Members;
                foreach (VariableDeclarationBaseSyntax variable in ((VarSectionBaseSyntax)members[index1]).Variables)
                {
                    VariableInitializationUsageAnalyzer.AddVariableToGlobalVarList(globalVariables, variable);
                }
            }
            if (!syntaxNodeAnalysisContext.Node.IsKind(SyntaxKind.ReportObject, SyntaxKind.XmlPortObject))
            {
                return;
            }
            switch (syntaxNodeAnalysisContext.Node.Kind)
            {
            case SyntaxKind.ReportObject:
                // ISSUE: variable of a compiler-generated type
                RequestPageSyntax requestPage = ((ReportSyntax)syntaxNodeAnalysisContext.Node).RequestPage;
                int num1;
                if (requestPage == null)
                {
                    num1 = -1;
                }
                else
                {
                    members = requestPage.Members;
                    num1    = members.IndexOf((Func <MemberSyntax, bool>)(ms => ms.Kind == SyntaxKind.GlobalVarSection));
                }
                int index2 = num1;
                if (index2 == -1)
                {
                    break;
                }
                Dictionary <string, VariableDeclarationBaseSyntax> globalVariables1 = globalVariables;
                members = ((ReportSyntax)syntaxNodeAnalysisContext.Node).RequestPage.Members;
                SyntaxList <VariableDeclarationBaseSyntax> variables1 = ((VarSectionBaseSyntax)members[index2]).Variables;
                VariableInitializationUsageAnalyzer.AddVariablesToGlobalVarList(globalVariables1, variables1);
                break;

            case SyntaxKind.XmlPortObject:
                // ISSUE: variable of a compiler-generated type
                RequestPageSyntax xmlPortRequestPage = ((XmlPortSyntax)syntaxNodeAnalysisContext.Node).XmlPortRequestPage;
                int num2;
                if (xmlPortRequestPage == null)
                {
                    num2 = -1;
                }
                else
                {
                    members = xmlPortRequestPage.Members;
                    num2    = members.IndexOf((Func <MemberSyntax, bool>)(ms => ms.Kind == SyntaxKind.GlobalVarSection));
                }
                int index3 = num2;
                if (index3 == -1)
                {
                    break;
                }
                Dictionary <string, VariableDeclarationBaseSyntax> globalVariables2 = globalVariables;
                members = ((XmlPortSyntax)syntaxNodeAnalysisContext.Node).XmlPortRequestPage.Members;
                SyntaxList <VariableDeclarationBaseSyntax> variables2 = ((VarSectionBaseSyntax)members[index3]).Variables;
                VariableInitializationUsageAnalyzer.AddVariablesToGlobalVarList(globalVariables2, variables2);
                break;
            }
        }
 public override void Initialize(AnalysisContext context)
 {
     context.RegisterSyntaxNodeAction(new Action <SyntaxNodeAnalysisContext>(VariableInitializationUsageAnalyzer.InitializeGlobalVariablesAnalyzer), VariableInitializationUsageAnalyzer.objectSyntaxKinds);
     VariableInitializationUsageAnalyzer.InitializeLocalVariablesAnalyzer(context);
 }
        private static void AnalyzeGlobalVarUsage(
            IdentifierNameSyntax identifier,
            Dictionary <string, IdentifierNameSyntax> firstGlobalVarUsageSyntax,
            Dictionary <string, IdentifierNameSyntax> firstGlobalVarInitializerSyntax,
            Dictionary <string, IdentifierNameSyntax> lastRecordModifyInvocationSyntax,
            Dictionary <string, IdentifierNameSyntax> firstRecordChangeSyntax,
            SyntaxNodeAnalysisContext syntaxNodeAnalysisContext,
            Dictionary <string, VariableDeclarationBaseSyntax> globalVariables)
        {
            if (IdentifierUtilities.IdentifierIsLocalVariable(identifier))
            {
                return;
            }
            SyntaxKind kind = identifier.Parent.Kind;

            switch (kind)
            {
            case SyntaxKind.PageField:
            case SyntaxKind.ReportColumn:
                firstGlobalVarInitializerSyntax.AddIdentifierIfNotExist(identifier);
                firstGlobalVarUsageSyntax.AddIdentifierIfNotExist(identifier);
                break;

            default:
                if (globalVariables.Count == 0 || !globalVariables.ContainsKey(identifier.Identifier.ValueText))
                {
                    break;
                }
                // ISSUE: variable of a compiler-generated type
                VariableDeclarationBaseSyntax declarationBaseSyntax;
                globalVariables.TryGetValue(identifier.Identifier.ValueText, out declarationBaseSyntax);
                NavTypeKind navTypeKind = NavTypeExtensions.GetNavTypeKind(declarationBaseSyntax?.Type.DataType.TypeName.ValueText);
                if ((uint)kind <= 233U)
                {
                    switch (kind)
                    {
                    case SyntaxKind.AssignmentStatement:
                        VariableInitializationUsageAnalyzer.AnalyzeAssignmentStatementIdentifier(identifier, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax, firstRecordChangeSyntax, navTypeKind);
                        return;

                    case SyntaxKind.CompoundAssignmentStatement:
                        if (navTypeKind == NavTypeKind.Record)
                        {
                            return;
                        }
                        VariableInitializationUsageAnalyzer.AnalyzeCompoundAssignmentStatementIdentifier(identifier, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax);
                        return;

                    case SyntaxKind.ForStatement:
                        if (navTypeKind == NavTypeKind.Record)
                        {
                            return;
                        }
                        VariableInitializationUsageAnalyzer.AnalyzeForStatementIdentifier(identifier, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax);
                        return;
                    }
                }
                else if ((uint)kind <= 262U)
                {
                    switch (kind)
                    {
                    case SyntaxKind.ForEachStatement:
                        if (navTypeKind == NavTypeKind.Record)
                        {
                            return;
                        }
                        VariableInitializationUsageAnalyzer.AnalyzeForEachStatementIdentifier(identifier, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax);
                        return;

                    case SyntaxKind.ArrayIndexExpression:
                        if (navTypeKind != NavTypeKind.Code && navTypeKind != NavTypeKind.Text)
                        {
                            return;
                        }
                        VariableInitializationUsageAnalyzer.AnalyzeArrayIndexExpressionIdentifier(identifier, firstGlobalVarInitializerSyntax);
                        return;
                    }
                }
                else if (kind != SyntaxKind.MemberAccessExpression)
                {
                    if (kind == SyntaxKind.ArgumentList)
                    {
                        VariableInitializationUsageAnalyzer.AnalyzeArgumentListIdentifier(identifier, syntaxNodeAnalysisContext, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax, firstRecordChangeSyntax, navTypeKind);
                        break;
                    }
                }
                else
                {
                    VariableInitializationUsageAnalyzer.AnalyzeMemberAccessIdentifier(identifier, firstGlobalVarInitializerSyntax, firstGlobalVarUsageSyntax, lastRecordModifyInvocationSyntax, firstRecordChangeSyntax, navTypeKind);
                    break;
                }
                if (navTypeKind == NavTypeKind.Record)
                {
                    break;
                }
                firstGlobalVarUsageSyntax.AddIdentifierIfNotExist(identifier);
                break;
            }
        }