예제 #1
0
        private void AnalyzeFunction(
				FunctionUnit functionUnit,
				WarningEmitter warningEmitter)
        {
            if (functionUnit.FunctionSymbol.IsCompilerGenerated())
            {
                return;
            }

            var instructions = functionUnit.Instructions.ToList();

            foreach (var instruction in instructions)
            {
                if (instruction.SourceOperand == null)
                {
                    // 変数定義
                    continue;
                }

                if (instruction.DestinationOperand == null ||
                    instruction.DestinationOperand?.UseInstruction != null ||
                    !functionUnit.SymbolTable.AllSymbols.Contains(instruction.DestinationOperand.Symbol))
                {
                    continue;
                }

                var returnedOperands = functionUnit.IsNoReturn()
                    ? null
                    : instructions
                        .Where(inst => inst.IsReturn)
                        .Select(inst => inst.SourceOperand.DefinitionInstruction.DestinationOperand)
                        .ToList();

                var isUsedOnAnyCopiedOperand = EnumerableUtility.Seek(
                    instruction,
                    inst => inst.SourceOperand?.DefinitionInstruction,
                    inst => inst.IsCopy)
                    .Select(inst => inst.DestinationOperand)
                    .Any(op => op.UseInstruction != null && returnedOperands.Contains(op));

                if (!isUsedOnAnyCopiedOperand)
                {
                    this.Violate(warningEmitter, instruction, instruction.DestinationOperand.Symbol);
                }
            }
        }
        private void AnalyzeFunction(
			FunctionUnit functionUnit,
			WarningEmitter warningEmitter)
        {
            var comps = functionUnit.Instructions.OfType<CompareInstruction>().ToList();

            foreach (var comp in comps)
            {
                if (comp.GetFileName().IsNull)
                {
                    // ラムダ式などから生成されたメソッドで対応コードが無い部分の場合
                    continue;
                }

                var functionSymbol =
                    comp.SourceOperand2.IsNullPtr()
                        ? comp.SourceOperand1.DefinitionInstruction.SourceOperand?.AsFunctionOperand?.FunctionSymbol
                    : comp.SourceOperand1.IsNullPtr()
                        ? comp.SourceOperand2.DefinitionInstruction.SourceOperand?.AsFunctionOperand?.FunctionSymbol
                        : null;

                if (functionSymbol == null)
                {
                    continue;
                }

                var symbol = functionSymbol.UninstantiatedFunctionSymbol ?? functionSymbol;
                var fullNameWithoutGenericParameter = string.Format(
                    "{0}.{1}",
                    symbol.EnclosingAggregateType.DefinitionType.TypeSymbol.NameString,
                    symbol.NameString);

                if (Settings.UnNullReturnMethod.Contains(fullNameWithoutGenericParameter))
                {
                    this.Violate(warningEmitter, comp, symbol);
                }
            }
        }
예제 #3
0
        private void AnalyzeFunction(
			FunctionUnit functionUnit,
			WarningEmitter warningEmitter)
        {
            //this.Violate(warningEmitter, functionUnit.FirstInstruction);
        }
예제 #4
0
 protected void Violate(WarningEmitter warningEmitter, Instruction instruction, params object[] args)
 {
     var violationMessage = this.ReportLocalizedWarning(instruction, args);
     Debug.WriteLine(violationMessage.ToString(), args);
     warningEmitter.Add(violationMessage);
 }