/// <summary> /// Generate new name for each assignment using the counters. /// </summary> /// <param name="VarName"></param> /// <param name="DefinedBlock"></param> /// <returns></returns> internal static string GenerateNewName(string VarName, Block DefinedBlock) { int i = Counters[VarName]; Counters[VarName] += 1; string newName = String.Format(CultureInfo.CurrentCulture, "{0}{1}", VarName, i); var varAnalysis = new VariableAnalysisDetails { Name = newName, DefinedBlock = DefinedBlock, RealName = VarName }; SSADictionary[VarName].Push(varAnalysis); InternalVariablesDictionary[newName] = varAnalysis; return newName; }
internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memAst, VariableAnalysisDetails analysis, TypeDefinitionAst psClass) #endif { if (memAst != null && memAst.Expression is VariableExpressionAst && memAst.Member is StringConstantExpressionAst && !String.Equals((memAst.Expression as VariableExpressionAst).VariablePath.UserPath, "this", StringComparison.OrdinalIgnoreCase)) { string fieldName = (memAst.Member as StringConstantExpressionAst).Value; #if !PSV3 if (psClass == null && analysis.Constant == SpecialVars.ThisVariable) { psClass = AssignmentTarget.FindClassAncestor(memAst); } if (psClass != null) { Type typeFromClass = AssignmentTarget.GetTypeFromClass(psClass, memAst); { if (typeFromClass != null) { return typeFromClass; } } } #endif // If the type is not a ps class or there are some types of the same name. if (analysis != null && analysis.Type != null && analysis.Type != typeof(object) && analysis.Type != typeof(Unreached) && analysis.Type != typeof(Undetermined)) { if (memAst is InvokeMemberExpressionAst) { return AssignmentTarget.GetTypeFromInvokeMemberAst(analysis.Type, memAst as InvokeMemberExpressionAst, fieldName, false); } else { return AssignmentTarget.GetPropertyOrFieldTypeFromMemberExpressionAst(analysis.Type, fieldName); } } } return null; }
// Return true if the variable is newly allocated and should be allocated in the locals tuple. internal void NoteVariable(string variableName, Type type) { if (!_variables.ContainsKey(variableName)) { var details = new VariableAnalysisDetails { Name = variableName, Type = type }; _variables.Add(variableName, details); } }
/// <summary> /// Get the type from member expression ast in the form of $variable.field/method /// type is the type of variable. Class is the class that matches the type /// </summary> /// <param name="analysis"></param> /// <param name="memAst"></param> /// <param name="psClass"></param> /// <returns></returns> #if PSV3 internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memAst, VariableAnalysisDetails analysis)