/// <summary> /// Adds casts where the type inference resolved too general type. Only downcasts should be introduced. /// </summary> private void AddCasts() { StackUsageData stackData = context.MethodContext.StackData; foreach (KeyValuePair <VariableDefinition, StackVariableDefineUseInfo> pair in stackData.VariableToDefineUseInfo) { foreach (int usageOffset in pair.Value.UsedAt) { Expression usingExpression; if (offsetToExpression.TryGetValue(usageOffset, out usingExpression)) { AddCastIfNeeded(usingExpression, pair.Key); } } foreach (int defineOffset in pair.Value.DefinedAt) { Expression value = offsetToExpression[defineOffset]; InstructionBlock definingBlock = GetInstructionBlock(defineOffset); IList <Expression> expressionsList = context.MethodContext.Expressions.BlockExpressions[definingBlock.First.Offset]; FixAssignmentInList(expressionsList, value); } } }
/// <summary> /// The entry point of the class. /// </summary> /// <returns>Returns a collection of all nodes in the built graph.</returns> internal ICollection <ClassHierarchyNode> BuildHierarchy(HashSet <VariableReference> resolvedVariables) { StackUsageData stackData = methodContext.StackData; foreach (KeyValuePair <VariableDefinition, StackVariableDefineUseInfo> pair in stackData.VariableToDefineUseInfo) { VariableDefinition variableDef = pair.Key; if (resolvedVariables.Contains(variableDef)) { continue; } ///As this method is shared with IntegerTypesHierarchyByilder here is where the check if the phi variable should be used comes in place. ///For the purposes of TypeInferer all variables that don't have type yet should be considered. ///for the purposes of IntegerTypeInferer only variabless assigned Int32 as their type should be considered. if (!ShouldConsiderVariable(variableDef)) { continue; } ///Add a node for each variable and process all its appearances in the code. ClassHierarchyNode variableNode = GetVariableNode(variableDef); resultingGraph.Add(variableNode); foreach (int defineOffset in pair.Value.DefinedAt) { OnPhiVariableAssigned(defineOffset, variableNode); } foreach (int usageOffset in pair.Value.UsedAt) { OnPhiVariableUsed(usageOffset, variableNode); } } RemoveImpossibleEdges(); HashSet <ClassHierarchyNode> hardNodes = new HashSet <ClassHierarchyNode>(); foreach (ClassHierarchyNode node in resultingGraph) { if (node.IsHardNode) { hardNodes.Add(node); } } BuildUpHardNodesHierarchy(hardNodes); return(resultingGraph); }
internal MethodSpecificContext(DecompilationAnalysisResults analysisResults, YieldData yieldData, AsyncData asyncData, bool isMethodBodyChanged, Dictionary <string, Statement> gotoLabels, List <GotoStatement> gotoStatements, StackUsageData stackData, bool isBaseConstructorInvokingConstructor, bool enableEventAnalysis, MethodBody body, Collection <VariableDefinition> variables, ControlFlowGraph controlFlowGraph, ExpressionDecompilerData expressions, BlockLogicalConstruct logicalConstructsTree, LogicalFlowBuilderContext logicalConstructsContext, MethodInvocationExpression ctorInvokeExpression, Dictionary <Statement, ILogicalConstruct> statementToLogicalConstruct, Dictionary <ILogicalConstruct, List <Statement> > logicalConstructToStatements, Dictionary <VariableDefinition, string> variableDefinitionToNameMap, HashSet <string> variableNamesCollection, Dictionary <ParameterDefinition, string> parameterDefinitionToNameMap, HashSet <VariableDefinition> variablesToRename, Dictionary <FieldDefinition, Expression> fieldToExpression, int lambdaVariablesCount, Dictionary <VariableDefinition, AssignmentType> variableAssignmentData, List <ParameterDefinition> outParametersToAssign, bool isDestructor, BlockStatement destructorStatements, HashSet <VariableDefinition> undeclaredLinqVariables, Dictionary <VariableReference, Dictionary <FieldDefinition, Expression> > closureVariableToFieldValue, HashSet <VariableDefinition> variablesToNotDeclare, CompilerOptimizedSwitchByStringData switchByStringData) { this.AnalysisResults = analysisResults; this.YieldData = yieldData; this.AsyncData = asyncData; this.IsMethodBodyChanged = isMethodBodyChanged; this.GotoLabels = gotoLabels; this.GotoStatements = gotoStatements; this.StackData = stackData; this.IsBaseConstructorInvokingConstructor = isBaseConstructorInvokingConstructor; this.EnableEventAnalysis = enableEventAnalysis; this.Body = body; this.Variables = variables; this.ControlFlowGraph = controlFlowGraph; this.Expressions = expressions; this.LogicalConstructsTree = logicalConstructsTree; this.LogicalConstructsContext = logicalConstructsContext; this.CtorInvokeExpression = ctorInvokeExpression; this.StatementToLogicalConstruct = statementToLogicalConstruct; this.LogicalConstructToStatements = logicalConstructToStatements; this.VariableDefinitionToNameMap = variableDefinitionToNameMap; this.VariableNamesCollection = variableNamesCollection; this.ParameterDefinitionToNameMap = parameterDefinitionToNameMap; this.VariablesToRename = variablesToRename; this.FieldToExpression = fieldToExpression; this.LambdaVariablesCount = lambdaVariablesCount; this.VariableAssignmentData = variableAssignmentData; this.OutParametersToAssign = outParametersToAssign; this.IsDestructor = isDestructor; this.DestructorStatements = destructorStatements; this.UndeclaredLinqVariables = undeclaredLinqVariables; this.ClosureVariableToFieldValue = closureVariableToFieldValue; this.VariablesToNotDeclare = variablesToNotDeclare; this.SwitchByStringData = switchByStringData; }
internal MethodSpecificContext(DecompilationAnalysisResults analysisResults, Telerik.JustDecompiler.Decompiler.YieldData yieldData, Telerik.JustDecompiler.Decompiler.AsyncData asyncData, bool isMethodBodyChanged, Dictionary <string, Statement> gotoLabels, List <GotoStatement> gotoStatements, StackUsageData stackData, bool isBaseConstructorInvokingConstructor, bool enableEventAnalysis, MethodBody body, Collection <VariableDefinition> variables, Telerik.JustDecompiler.Cil.ControlFlowGraph controlFlowGraph, ExpressionDecompilerData expressions, BlockLogicalConstruct logicalConstructsTree, LogicalFlowBuilderContext logicalConstructsContext, MethodInvocationExpression ctorInvokeExpression, Dictionary <Statement, ILogicalConstruct> statementToLogicalConstruct, Dictionary <ILogicalConstruct, List <Statement> > logicalConstructToStatements, Dictionary <VariableDefinition, string> variableDefinitionToNameMap, HashSet <string> variableNamesCollection, Dictionary <ParameterDefinition, string> parameterDefinitionToNameMap, HashSet <VariableDefinition> variablesToRename, Dictionary <FieldDefinition, Expression> fieldToExpression, int lambdaVariablesCount, Dictionary <VariableDefinition, AssignmentType> variableAssignmentData, List <ParameterDefinition> outParametersToAssign, bool isDestructor, BlockStatement destructorStatements, HashSet <VariableDefinition> undeclaredLinqVariables, Dictionary <VariableReference, Dictionary <FieldDefinition, Expression> > closureVariableToFieldValue, HashSet <VariableDefinition> variablesToNotDeclare, CompilerOptimizedSwitchByStringData switchByStringData) { base(); this.set_AnalysisResults(analysisResults); this.set_YieldData(yieldData); this.set_AsyncData(asyncData); this.set_IsMethodBodyChanged(isMethodBodyChanged); this.set_GotoLabels(gotoLabels); this.set_GotoStatements(gotoStatements); this.set_StackData(stackData); this.set_IsBaseConstructorInvokingConstructor(isBaseConstructorInvokingConstructor); this.set_EnableEventAnalysis(enableEventAnalysis); this.set_Body(body); this.set_Variables(variables); this.set_ControlFlowGraph(controlFlowGraph); this.set_Expressions(expressions); this.set_LogicalConstructsTree(logicalConstructsTree); this.set_LogicalConstructsContext(logicalConstructsContext); this.set_CtorInvokeExpression(ctorInvokeExpression); this.set_StatementToLogicalConstruct(statementToLogicalConstruct); this.set_LogicalConstructToStatements(logicalConstructToStatements); this.set_VariableDefinitionToNameMap(variableDefinitionToNameMap); this.set_VariableNamesCollection(variableNamesCollection); this.set_ParameterDefinitionToNameMap(parameterDefinitionToNameMap); this.set_VariablesToRename(variablesToRename); this.set_FieldToExpression(fieldToExpression); this.set_LambdaVariablesCount(lambdaVariablesCount); this.set_VariableAssignmentData(variableAssignmentData); this.set_OutParametersToAssign(outParametersToAssign); this.set_IsDestructor(isDestructor); this.set_DestructorStatements(destructorStatements); this.set_UndeclaredLinqVariables(undeclaredLinqVariables); this.set_ClosureVariableToFieldValue(closureVariableToFieldValue); this.set_VariablesToNotDeclare(variablesToNotDeclare); this.set_SwitchByStringData(switchByStringData); return; }