Esempio n. 1
0
        public void ObjectMatchesCriteriaWithInequalitiesAndErrorValues()
        {
            var nullError        = ExcelErrorValue.Create(eErrorType.Null);
            var div0Error        = ExcelErrorValue.Create(eErrorType.Div0);
            var valueError       = ExcelErrorValue.Create(eErrorType.Value);
            var refError         = ExcelErrorValue.Create(eErrorType.Ref);
            var nameError        = ExcelErrorValue.Create(eErrorType.Name);
            var numError         = ExcelErrorValue.Create(eErrorType.Num);
            var naError          = ExcelErrorValue.Create(eErrorType.NA);
            var nullLessThanDiv  = IfHelper.ObjectMatchesCriterion(nullError, "<#DIV/0!");
            var divLessThanValue = IfHelper.ObjectMatchesCriterion(div0Error, "<#VALUE!");;
            var valueLessThanRef = IfHelper.ObjectMatchesCriterion(valueError, "<#REF!");;
            var refLessThanName  = IfHelper.ObjectMatchesCriterion(refError, "<#NAME?");;
            var nameLessThanNum  = IfHelper.ObjectMatchesCriterion(nameError, "<#NUM!");;
            var numLessThanNA    = IfHelper.ObjectMatchesCriterion(numError, "<#N/A");
            var naGreaterThanNum = IfHelper.ObjectMatchesCriterion(naError, ">#NUM!");;

            Assert.AreEqual(nullLessThanDiv, true);
            Assert.AreEqual(divLessThanValue, true);
            Assert.AreEqual(valueLessThanRef, true);
            Assert.AreEqual(refLessThanName, true);
            Assert.AreEqual(nameLessThanNum, true);
            Assert.AreEqual(numLessThanNA, true);
            Assert.AreEqual(naGreaterThanNum, true);
        }
Esempio n. 2
0
 public void ExtractCriterionFromCellRangeWithSameRowCellReferenceReturnsCorrectValue()
 {
     using (var package = new ExcelPackage())
     {
         var worksheet = package.Workbook.Worksheets.Add("Sheet2");
         var provider  = new EpplusExcelDataProvider(package);
         this.ParsingContext.Scopes.NewScope(RangeAddress.Empty);
         worksheet.Cells["B1"].Value = 5;
         worksheet.Cells["B2"].Value = 10;
         worksheet.Cells["B3"].Value = 15;
         IRangeInfo testRange  = provider.GetRange(worksheet.Name, 1, 2, 3, 2);
         IRangeInfo firstRange = provider.GetRange(worksheet.Name, 2, 2, 2, 2);
         var        address    = firstRange.Address;
         var        arguments  = FunctionsHelper.CreateArgs(firstRange, testRange);
         var        result     = IfHelper.ExtractCriterionFromCellRange(arguments.ElementAt(1), worksheet, address._fromRow, address._fromCol);
         Assert.AreEqual(10, result);
     }
 }
Esempio n. 3
0
 public void ExtractCriterionFromCellRangeWithNonMatchingColReturnsZero()
 {
     using (var package = new ExcelPackage())
     {
         var worksheet = package.Workbook.Worksheets.Add("Sheet1");
         var provider  = new EpplusExcelDataProvider(package);
         this.ParsingContext.Scopes.NewScope(RangeAddress.Empty);
         worksheet.Cells["E7"].Value = 5;
         worksheet.Cells["F7"].Value = 10;
         worksheet.Cells["G7"].Value = 15;
         IRangeInfo testRange  = provider.GetRange(worksheet.Name, 7, 5, 7, 7);
         IRangeInfo firstRange = provider.GetRange(worksheet.Name, 8, 8, 8, 8);
         var        address    = firstRange.Address;
         var        arguments  = FunctionsHelper.CreateArgs(firstRange, testRange);
         var        result     = IfHelper.ExtractCriterionFromCellRange(arguments.ElementAt(1), worksheet, address._fromRow, address._fromCol);
         Assert.AreEqual(0, result);
     }
 }
        /// <exception cref="System.IO.IOException"/>
        public static RootStatement CodeToJava(StructMethod mt, MethodDescriptor md, VarProcessor
                                               varProc)
        {
            StructClass cl            = mt.GetClassStruct();
            bool        isInitializer = ICodeConstants.Clinit_Name.Equals(mt.GetName());

            // for now static initializer only
            mt.ExpandData();
            InstructionSequence seq   = mt.GetInstructionSequence();
            ControlFlowGraph    graph = new ControlFlowGraph(seq);

            DeadCodeHelper.RemoveDeadBlocks(graph);
            graph.InlineJsr(mt);
            // TODO: move to the start, before jsr inlining
            DeadCodeHelper.ConnectDummyExitBlock(graph);
            DeadCodeHelper.RemoveGotos(graph);
            ExceptionDeobfuscator.RemoveCircularRanges(graph);
            ExceptionDeobfuscator.RestorePopRanges(graph);
            if (DecompilerContext.GetOption(IFernflowerPreferences.Remove_Empty_Ranges))
            {
                ExceptionDeobfuscator.RemoveEmptyRanges(graph);
            }
            if (DecompilerContext.GetOption(IFernflowerPreferences.Ensure_Synchronized_Monitor
                                            ))
            {
                // special case: search for 'synchronized' ranges w/o monitorexit instruction (as generated by Kotlin and Scala)
                DeadCodeHelper.ExtendSynchronizedRangeToMonitorexit(graph);
            }
            if (DecompilerContext.GetOption(IFernflowerPreferences.No_Exceptions_Return))
            {
                // special case: single return instruction outside of a protected range
                DeadCodeHelper.IncorporateValueReturns(graph);
            }
            //		ExceptionDeobfuscator.restorePopRanges(graph);
            ExceptionDeobfuscator.InsertEmptyExceptionHandlerBlocks(graph);
            DeadCodeHelper.MergeBasicBlocks(graph);
            DecompilerContext.GetCounterContainer().SetCounter(CounterContainer.Var_Counter,
                                                               mt.GetLocalVariables());
            if (ExceptionDeobfuscator.HasObfuscatedExceptions(graph))
            {
                DecompilerContext.GetLogger().WriteMessage("Heavily obfuscated exception ranges found!"
                                                           , IFernflowerLogger.Severity.Warn);
                if (!ExceptionDeobfuscator.HandleMultipleEntryExceptionRanges(graph))
                {
                    DecompilerContext.GetLogger().WriteMessage("Found multiple entry exception ranges which could not be splitted"
                                                               , IFernflowerLogger.Severity.Warn);
                }
                ExceptionDeobfuscator.InsertDummyExceptionHandlerBlocks(graph, cl.GetBytecodeVersion
                                                                            ());
            }
            RootStatement    root  = DomHelper.ParseGraph(graph);
            FinallyProcessor fProc = new FinallyProcessor(md, varProc);

            while (fProc.IterateGraph(mt, root, graph))
            {
                root = DomHelper.ParseGraph(graph);
            }
            // remove synchronized exception handler
            // not until now because of comparison between synchronized statements in the finally cycle
            DomHelper.RemoveSynchronizedHandler(root);
            //		LabelHelper.lowContinueLabels(root, new HashSet<StatEdge>());
            SequenceHelper.CondenseSequences(root);
            ClearStructHelper.ClearStatements(root);
            ExprProcessor proc = new ExprProcessor(md, varProc);

            proc.ProcessStatement(root, cl);
            SequenceHelper.CondenseSequences(root);
            StackVarsProcessor stackProc = new StackVarsProcessor();

            do
            {
                stackProc.SimplifyStackVars(root, mt, cl);
                varProc.SetVarVersions(root);
            }while (new PPandMMHelper().FindPPandMM(root));
            while (true)
            {
                LabelHelper.CleanUpEdges(root);
                do
                {
                    MergeHelper.EnhanceLoops(root);
                }while (LoopExtractHelper.ExtractLoops(root) || IfHelper.MergeAllIfs(root));
                if (DecompilerContext.GetOption(IFernflowerPreferences.Idea_Not_Null_Annotation))
                {
                    if (IdeaNotNullHelper.RemoveHardcodedChecks(root, mt))
                    {
                        SequenceHelper.CondenseSequences(root);
                        stackProc.SimplifyStackVars(root, mt, cl);
                        varProc.SetVarVersions(root);
                    }
                }
                LabelHelper.IdentifyLabels(root);
                if (InlineSingleBlockHelper.InlineSingleBlocks(root))
                {
                    continue;
                }
                // initializer may have at most one return point, so no transformation of method exits permitted
                if (isInitializer || !ExitHelper.CondenseExits(root))
                {
                    break;
                }
            }
            // FIXME: !!
            //if(!EliminateLoopsHelper.eliminateLoops(root)) {
            //  break;
            //}
            ExitHelper.RemoveRedundantReturns(root);
            SecondaryFunctionsHelper.IdentifySecondaryFunctions(root, varProc);
            varProc.SetVarDefinitions(root);
            // must be the last invocation, because it makes the statement structure inconsistent
            // FIXME: new edge type needed
            LabelHelper.ReplaceContinueWithBreak(root);
            mt.ReleaseResources();
            return(root);
        }