public AnalyzerResult( SemanticDocument document, IEnumerable<ITypeParameterSymbol> typeParametersInDeclaration, IEnumerable<ITypeParameterSymbol> typeParametersInConstraintList, IList<VariableInfo> variables, VariableInfo variableToUseAsReturnValue, ITypeSymbol returnType, bool awaitTaskReturn, bool instanceMemberIsUsed, bool endOfSelectionReachable, OperationStatus status) { var semanticModel = document.SemanticModel; this.UseInstanceMember = instanceMemberIsUsed; this.EndOfSelectionReachable = endOfSelectionReachable; this.AwaitTaskReturn = awaitTaskReturn; this.SemanticDocument = document; _typeParametersInDeclaration = typeParametersInDeclaration.Select(s => semanticModel.ResolveType(s)).ToList(); _typeParametersInConstraintList = typeParametersInConstraintList.Select(s => semanticModel.ResolveType(s)).ToList(); _variables = variables; this.ReturnType = semanticModel.ResolveType(returnType); _variableToUseAsReturnValue = variableToUseAsReturnValue; this.Status = status; }
public override IEnumerable<VariableInfo> GetProperties() { foreach (var item in _module.ExportedProperies) { var vi = new VariableInfo(); vi.Identifier = item.SymbolicName; vi.Index = item.Index; vi.Type = SymbolType.ContextProperty; yield return vi; } }
public VariableInfo Parse() { //var rslt = new FieldInfo(); //rslt.Name = this.Name; //rslt.Type_name = this.Type_name; //return rslt; var rslt = new VariableInfo(this); rslt.Name = this.Name; rslt.Type_name = this.Type_name; if (this.Default_value != null) { rslt.Value = Default_value.Parse(); } return rslt; }
public void InitFromXml(XmlElement element) { m_name = element.GetAttribute("Name"); String expression = element.GetAttribute("Expression"); if(string.IsNullOrWhiteSpace(expression)) { XmlElement sequenceNode = element["Sequence"]; XmlElement argumentsNode = element["Arguments"]; m_sequenceFactory = (c) => SequenceFactory.Instance.CreateChildrenAsSequence(sequenceNode, c); m_variableInfos = new List<VariableInfo>(); if (argumentsNode != null) { foreach (XmlNode childNode in argumentsNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Element && childNode.Name == "Argument") { XmlElement childElement = (XmlElement)childNode; VariableInfo info = new VariableInfo(); info.name = childElement.GetAttribute("Name"); if (string.IsNullOrWhiteSpace(childElement.InnerText)) { info.defaultCreator = (c) => new EmptyValueNode(); } else { info.defaultCreator = (c) => SequenceFactory.Instance.CreateChildrenAsSequence(childElement, c); } m_variableInfos.Add(info); } } } } else { m_sequenceFactory = (c) => ExpressionParser.ParseExpression(expression, c)(); m_variableInfos = new List<VariableInfo>(); } }
protected Tuple<VariableInfo, Exception> getVariableInfo(statdataEntities ctx, VariableDesc oVar) { Exception err = null; VariableInfo info = null; if (oVar == null) { return new Tuple<VariableInfo, Exception>(info, new ArgumentNullException()); } DbVariable pVar = findVariable(ctx, oVar); if (pVar == null) { return new Tuple<VariableInfo, Exception>(info, err); } info = new VariableInfo(); String stype = pVar.VarType.Trim().ToLower(); info.VariableId = pVar.Id; info.VariableName = pVar.Name; info.DataSetId = pVar.DataSetId; info.DataSetName = pVar.DataSet.Name; info.DataType = stype; info.IsCategVar = pVar.IsCateg; if ((stype == "bool") || (stype == "string")) { info.IsCategVar = true; } { var q1 = pVar.Values; int nMissing = 0; int nCount = 0; foreach (var p in q1) { String sval = p.Value; if (!String.IsNullOrEmpty(sval)) { sval = StatHelpers.ConvertValue(sval); } if (String.IsNullOrEmpty(sval)) { ++nMissing; } ++nCount; }// p info.MissingValuesCount = nMissing; info.TotalValuesCount = nCount; } if (info.IsCategVar) { Dictionary<String, int> dict = new Dictionary<string, int>(); var q2 = from x in pVar.Values select x.Value; foreach (var p in q2) { String sval = StatHelpers.ConvertValue(p); if (!String.IsNullOrEmpty(sval)) { if (!dict.ContainsKey(sval)) { dict[sval] = 1; } else { dict[sval] = dict[sval] + 1; } } }// p CategValueDescs vv = new CategValueDescs(); var keys = dict.Keys; foreach (var s in keys) { CategValueDesc c = new CategValueDesc(); c.StringValue = s; c.Count = dict[s]; c.VariableId = info.VariableId; vv.Add(c); } info.CategValues = vv; info.DistinctValues = keys.ToList(); } else { var q3 = pVar.Values; int nCount = 0; List<double> dList = new List<double>(); foreach (var p in q3) { String sval = StatHelpers.ConvertValue(p.Value); if (!String.IsNullOrEmpty(sval)) { double xcur = 0; if (double.TryParse(sval, out xcur)) { dList.Add(xcur); }// ok } }// p nCount = dList.Count(); if (nCount > 0) { DescriptiveStatistics st = new DescriptiveStatistics(dList); info.MinValue = st.Minimum; info.MaxValue = st.Maximum; info.MeanValue = myconvert(st.Mean); info.Deviation = myconvert(st.StandardDeviation); info.Skewness = myconvert(st.Skewness); info.Flatness = myconvert(st.Kurtosis); dList.Sort(); var oAr = dList.ToArray(); info.Quantile05 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.05)); info.Quantile10 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.10)); info.Quantile25 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.25)); info.Median = myconvert(SortedArrayStatistics.Quantile(oAr, 0.5)); info.Quantile75 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.75)); info.Quantile90 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.90)); info.Quantile95 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.10)); } } info.IsModified = false; // return new Tuple<VariableInfo, Exception>(info, err); }
/// <summary> /// Default ctor /// </summary> public DalvikStackFrameValue(Value value, VariableInfo variable, DalvikProcess process) : base(value, process) { Variable = variable; }
public Set(ref TextWriter writer, ref Dictionary <string, VariableInfo> storage, VariableInfo variable, int realLine) : base(ref writer, ref storage, realLine, "set") { _variable = variable; }
public ReflectedFieldInfo(VariableInfo info, bool isPublic) { _info = info; _isPublic = isPublic; }
/// <summary> /// Get all local registers for this frame. /// </summary> /// <returns></returns> public Task<List<DalvikStackFrameValue>> GetRegistersAsync(bool parametersOnly = false, Jdwp.Tag type = Jdwp.Tag.Int, params int[] indizes) { if (parametersOnly && parameters != null) return parameters.AsTask(); if (!parametersOnly && registers != null && indizes.Length == 0) return registers.AsTask(); return Task.Factory.StartNew(() => { var ret = new List<DalvikStackFrameValue>(); var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout); List<Register> regDefs; MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc); if(indizes.Length == 0) { if (methodDiss == null) return ret; var body = methodDiss.Method.Body; regDefs = (parametersOnly ? body.Registers.Where(r=>body.IsComing(r)) : body.Registers) .Where(p => indizes.Length == 0 || indizes.Contains(p.Index)) .OrderBy(p=>p.Index) .ToList(); } else { regDefs = indizes.Select(i => new Register(i)).ToList(); } var requests = regDefs.Select(reg => new SlotRequest(reg.Index, type)).ToList(); var regValues = Debugger.StackFrame.GetValuesAsync(thread.Id, Id, requests.ToArray()) .Await(DalvikProcess.VmTimeout); var process = thread.Manager.Process; for (int i = 0; i < regDefs.Count && i < regValues.Count; ++i) { var reg = regDefs[i]; if (methodDiss != null) { var body = methodDiss.Method.Body; bool isParam = body.IsComing(reg); string regName = MethodDisassembly.FormatRegister(reg, body); var valInfo = new VariableInfo(0, regName, null, null, body.Instructions.Count, reg.Index); DalvikStackFrameValue val = new DalvikStackFrameValue(regValues[i], valInfo, isParam, process); ret.Add(val); } else { string regName = "r" + reg.Index; var valInfo = new VariableInfo(0, regName, null, null, int.MaxValue, reg.Index); var val = new DalvikStackFrameValue(regValues[i], valInfo, false, process); ret.Add(val); } } if (indizes.Length > 0) return ret; if(parametersOnly) parameters = parameters ?? ret; else registers = registers ?? ret; return ret; }); }
/// <summary> /// Constructor. /// </summary> /// <param name="vi"> Contains all information about a variable / expression. </param> public AD7Property(VariableInfo vi) { _variableInfo = vi; }
// 导出每个表格所对应的脚本 bool ExportScript() { // 生成变量信息 if (!GenerateVariableInfo()) { return(false); } // 导出脚本 string exportPath = Application.dataPath + m_ScriptExportPath + "Tables/"; if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } string exportFileName = m_TabInfo.m_RealName; string exportFileNameWithExt = exportFileName;// + ".txt"; FileStream file = File.Create(exportPath + "Table_" + m_TabInfo.m_ExportClassName + ".cs"); StreamWriter writer = new StreamWriter(file, Encoding.UTF8); int nodeCnt = m_TableNodes.Count; NodeInfo nodeInfo = null; string fullReader = ""; for (int nodeIdx = 0; nodeIdx < nodeCnt; ++nodeIdx) { nodeInfo = m_TableNodes[nodeIdx]; if (nodeInfo.m_Name.Equals("descript")) { writer.Write(nodeInfo.m_Content); } else if (nodeInfo.m_Name.Equals("import")) { writer.Write(nodeInfo.m_Content); } else if (nodeInfo.m_Name.Equals("namespace")) { writer.Write(nodeInfo.m_Content); } else if (nodeInfo.m_Name.Equals("classhead")) { string content = nodeInfo.m_Content.Replace("${CodeName}", m_TabInfo.m_ExportClassName); content = content.Replace("${ValueNum}", (m_Names.Count - 2).ToString()); // -2:去掉Id列和注释列 content = content.Replace("${FileNameWithExt}", exportFileNameWithExt); content = content.Replace("${FileName}", exportFileName); string fullEnum = "INVLAID_INDEX = -1,\n"; int cnt = m_Names.Count; for (int idx = 0; idx < cnt; ++idx) { if (idx == m_SkipColumn) { continue; } fullEnum += "\t\t\tID_" + m_Names[idx].ToUpper() + ",\n"; } fullEnum += "\t\t\tMAX_RECORD"; content = content.Replace("${FULLENUM}", fullEnum); writer.Write(content); } else if (nodeInfo.m_Name.Equals("variables")) { string singleContent = m_TableNodeDict["single"].m_Content; string repeatContent = m_TableNodeDict["repeat"].m_Content; int cnt = m_Variables.Count; VariableInfo info = null; for (int idx = 0; idx < cnt; ++idx) { info = m_Variables[idx]; TypeInfo typeInfo = m_TypeInfoDict[info.m_DataType]; if (!info.m_IsKey && (typeInfo.m_DataType == DataType.INT || typeInfo.m_DataType == DataType.FLOAT)) { singleContent = m_TableNodeDict["singleEncrypt"].m_Content; repeatContent = m_TableNodeDict["repeatEncrypt"].m_Content; } else { singleContent = m_TableNodeDict["single"].m_Content; repeatContent = m_TableNodeDict["repeat"].m_Content; } if (info.m_Type == VariableType.Single) { string content = singleContent.Replace("${type}", typeInfo.m_TypeStr); content = content.Replace("${Variable}", info.m_Name); writer.Write(content); } else if (info.m_Type == VariableType.Repeat) { if (info.m_Count == 1) { string content = singleContent.Replace("${type}", typeInfo.m_TypeStr); content = content.Replace("${Variable}", info.m_BakName); writer.Write(content); } else { string content = repeatContent.Replace("${type}", typeInfo.m_TypeStr); content = content.Replace("${Variable}", info.m_Name); content = content.Replace("${COUNT}", info.m_Count.ToString()); content = content.Replace("${defaultvalue}", typeInfo.m_DefaultValStr); writer.Write(content); } } fullReader += GenerateVariableReaderCode("tabData", info); } } else if (nodeInfo.m_Name.Equals("inittable")) { string content = nodeInfo.m_Content.Replace("${CodeName}", m_TabInfo.m_ExportClassName); content = content.Replace("${FULLREADER}", fullReader); writer.Write(content); } else if (nodeInfo.m_Name.Equals("tail")) { writer.Write(nodeInfo.m_Content); } } writer.Flush(); writer.Close(); return(true); }
public override void Do() { _variable = GetFromStorage(_variable.Name); Storage.Remove(_variable.Name); }
/// <summary> /// Enumerates the children of a property. This provides support for dereferencing pointers, displaying members of an array, or /// fields of a class or struct. (http://msdn.microsoft.com/en-us/library/bb161791.aspx) /// </summary> /// <param name="dwFields"> A combination of flags from the DEBUGPROP_INFO_FLAGS enumeration that specifies which fields in /// the enumerated DEBUG_PROPERTY_INFO structures are to be filled in. </param> /// <param name="dwRadix"> Specifies the radix to be used in formatting any numerical information. </param> /// <param name="guidFilter"> GUID of the filter used with the dwAttribFilter and pszNameFilter parameters to select which /// DEBUG_PROPERTY_INFO children are to be enumerated. For example, guidFilterLocals filters for local variables. </param> /// <param name="dwAttribFilter"> A combination of flags from the DBG_ATTRIB_FLAGS enumeration that specifies what type of /// objects to enumerate, for example DBG_ATTRIB_METHOD for all methods that might be children of this property. Used in /// combination with the guidFilter and pszNameFilter parameters. </param> /// <param name="pszNameFilter"> The name of the filter used with the guidFilter and dwAttribFilter parameters to select which /// DEBUG_PROPERTY_INFO children are to be enumerated. For example, setting this parameter to "MyX" filters for all children /// with the name "MyX." </param> /// <param name="dwTimeout"> Specifies the maximum time, in milliseconds, to wait before returning from this method. Use /// INFINITE to wait indefinitely. </param> /// <param name="ppEnum"> Returns an IEnumDebugPropertyInfo2 object containing a list of the child properties. </param> /// <returns> If successful, returns S_OK; otherwise returns S_FALSE. </returns> public int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref System.Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum) { ppEnum = null; if (_variableInfo != null) { if (_variableInfo._children != null) { if (_variableInfo._children.Count == 0) { // This is an array, struct, union, or pointer. // Create a variable object so we can list this variable's children. /// Some VS variable names cannot be used by GDB. When that happens, it is added the prefix VsNdK_ to the GDB variable /// name and it is stored in the GDBNames array. At the same time, the VS name is stored in the VSNames array using the /// same index position. This bool variable just indicate if this prefix is used or not. bool hasVsNdK_ = false; string numChildren = AD7StackFrame.m_dispatcher.createVar(_variableInfo._name, ref hasVsNdK_); ArrayList GDBNames = new ArrayList(); ArrayList VSNames = new ArrayList(); if (hasVsNdK_) { _variableInfo._GDBName = "VsNdK_" + _variableInfo._name; GDBNames.Add("VsNdK_" + _variableInfo._name); VSNames.Add(_variableInfo._name); } try // Catch non-numerical data { if (Convert.ToInt32(numChildren) > 0) // If the variable has children evaluate { if (_variableInfo._type.Contains("struct")) { if (_variableInfo._type[_variableInfo._type.Length - 1] == '*') { _variableInfo.listChildren(AD7StackFrame.m_dispatcher, "*", GDBNames, VSNames, hasVsNdK_, null); } else if (_variableInfo._type.Contains("[")) { _variableInfo.listChildren(AD7StackFrame.m_dispatcher, "struct[]", GDBNames, VSNames, hasVsNdK_, null); } else { _variableInfo.listChildren(AD7StackFrame.m_dispatcher, "struct", GDBNames, VSNames, hasVsNdK_, null); } } else if (_variableInfo._type.Contains("[")) { _variableInfo.listChildren(AD7StackFrame.m_dispatcher, "[]", GDBNames, VSNames, hasVsNdK_, null); } else if (_variableInfo._type.Contains("*")) { _variableInfo.listChildren(AD7StackFrame.m_dispatcher, "*", GDBNames, VSNames, hasVsNdK_, null); } else { _variableInfo.listChildren(AD7StackFrame.m_dispatcher, "", GDBNames, VSNames, hasVsNdK_, null); } } } catch (FormatException e) { } AD7StackFrame.m_dispatcher.deleteVar(_variableInfo._name, hasVsNdK_); } DEBUG_PROPERTY_INFO[] properties = new DEBUG_PROPERTY_INFO[_variableInfo._children.Count]; int i = 0; foreach (VariableInfo child in _variableInfo._children) { VariableInfo.evaluateExpression(child._name, ref child._value, child._GDBName); properties[i] = new AD7Property(child).ConstructDebugPropertyInfo(dwFields); i++; } ppEnum = new AD7PropertyEnum(properties); return(VSConstants.S_OK); } } else if (_stackFrame != null) { uint elementsReturned = 0; _stackFrame.CreateLocalsPlusArgsProperties(dwFields, out elementsReturned, out ppEnum); return(VSConstants.S_OK); } return(VSConstants.S_FALSE); }
public Remove(ref TextWriter writer, ref Dictionary <string, VariableInfo> storage, string variableName, int realLine) : base(ref writer, ref storage, realLine, "rem") { _variable = new VariableInfo(variableName); }
public override void Do() { _variable = GetFromStorage(_variable.Name); _variable.Value -= _subValue; }
public Sub(ref TextWriter writer, ref Dictionary <string, VariableInfo> storage, string variableName, int subValue, int realLine) : base(ref writer, ref storage, realLine, "sub") { _variable = new VariableInfo(variableName); _subValue = subValue; }
public static Variable DefineVariable(this ITransaction transaction, string name, SqlType type) { var variableInfo = new VariableInfo(name, type, false); transaction.CreateObject(variableInfo); return transaction.GetVariable(name); }
bool GenerateVariableInfo() { Dictionary <string, int> variableIdxDict = new Dictionary <string, int>(); int cnt = m_Names.Count; string realName = ""; int index = -1; m_Variables.Clear(); for (int idx = 0; idx < cnt; ++idx) { if (idx == m_SkipColumn) { continue; } string varName = m_Names[idx]; if (IsEndWithNumber(varName, out index, out realName)) { if (variableIdxDict.ContainsKey(realName)) { int varIdx = variableIdxDict[realName]; VariableInfo info = m_Variables[varIdx]; DataType dataType = m_Types[idx]; if (info.m_DataType != dataType) { string infoStr = "表格:【" + m_TabInfo.m_RealName + "】第" + idx + "列数据类型和第" + varIdx + "列数据类型不一致. 请检查!!!\n注意,行列索引从0开始!!!"; Debug.LogError(infoStr); EditorUtility.DisplayDialog("提示", infoStr, "确定"); return(false); } info.m_EnumStr.Add("ID_" + varName.ToUpper()); info.m_ValueId.Add(idx); info.m_Count++; } else { VariableInfo info = new VariableInfo(); info.m_Type = VariableType.Repeat; info.m_DataType = m_Types[idx]; info.m_Name = realName; info.m_BakName = varName; info.m_Count = 1; info.m_EnumStr = new List <string>(); info.m_EnumStr.Add("ID_" + varName.ToUpper()); info.m_ValueId = new List <int>(); info.m_ValueId.Add(idx); m_Variables.Add(info); variableIdxDict.Add(realName, m_Variables.Count - 1); } } else { if (variableIdxDict.ContainsKey(realName)) { string infoStr = "表格:【" + m_TabInfo.m_RealName + "】第" + idx + "列数据名称和前面重复:【" + varName + "】-> 转换后名字【" + realName + "】. 请检查!!!\n注意,行列索引从0开始!!!"; Debug.LogError(infoStr); EditorUtility.DisplayDialog("提示", infoStr, "确定"); return(false); } else { VariableInfo info = new VariableInfo(); info.m_Type = VariableType.Single; info.m_DataType = m_Types[idx]; info.m_Name = realName; info.m_Count = 0; info.m_EnumStr = new List <string>(); info.m_EnumStr.Add("ID_" + varName.ToUpper()); info.m_ValueId = new List <int>(); info.m_ValueId.Add(idx); if (idx == 0) { info.m_IsKey = true; } m_Variables.Add(info); variableIdxDict.Add(realName, m_Variables.Count - 1); } } } m_Variables.Sort((VariableInfo a, VariableInfo b) => { return(a.m_Name.CompareTo(b.m_Name)); }); return(true); }
public static VariableInfo CreateReturnValue(VariableInfo variable) { Contract.ThrowIfNull(variable); Contract.ThrowIfFalse(variable.CanBeUsedAsReturnValue); Contract.ThrowIfFalse(variable.ParameterModifier == ParameterBehavior.Out || variable.ParameterModifier == ParameterBehavior.Ref); return new VariableInfo(variable._variableSymbol, variable._variableStyle, useAsReturnValue: true); }
public ILProperty(VariableInfo info) { this.info = info; }
private static int Compare(VariableInfo left, VariableInfo right, INamedTypeSymbol cancellationTokenType) => VariableSymbol.Compare(left._variableSymbol, right._variableSymbol, cancellationTokenType);
/// <summary> /// If possible, separates local variables into several independent variables. /// It should undo any compilers merging. /// </summary> private void ConvertLocalVariables(List<ByteCode> body) { foreach (var varDef in methodDef.Body.Variables) { // Find all definitions and uses of this variable var refs = body.Where(b => (b.Operand is LocalVariableReference) && (((LocalVariableReference)b.Operand) == varDef)).ToList(); var defs = refs.Where(b => b.IsVariableDefinition).ToList(); var uses = refs.Where(b => !b.IsVariableDefinition).ToList(); List<VariableInfo> newVars; // If any of the uses is from unknown definition, use single variable if (!optimize || uses.Any(b => b.VariablesBefore[varDef.Index].UnknownDefinition)) { newVars = new List<VariableInfo>(1) { new VariableInfo { Variable = new AstJavaVariable(null, varDef, "var_" + varDef.Index), Defs = defs, Uses = uses } }; } else { // Create a new variable for each definition newVars = defs.Select(def => new VariableInfo { Variable = new AstJavaVariable(null, varDef, "var_" + varDef.Index + "_" + def.Offset.ToString("X2")), Defs = new List<ByteCode> { def }, Uses = new List<ByteCode>() }).ToList(); // Add loads to the data structure; merge variables if necessary foreach (var use in uses) { var useDefs = use.VariablesBefore[varDef.Index].Definitions; if (useDefs.Length == 1) { var newVar = newVars.Single(v => v.Defs.Contains(useDefs[0])); newVar.Uses.Add(use); } else { var mergeVars = newVars.Where(v => v.Defs.Intersect(useDefs).Any()).ToList(); var mergedVar = new VariableInfo { Variable = mergeVars[0].Variable, Defs = mergeVars.SelectMany(v => v.Defs).ToList(), Uses = mergeVars.SelectMany(v => v.Uses).ToList() }; mergedVar.Uses.Add(use); newVars = newVars.Except(mergeVars).ToList(); newVars.Add(mergedVar); } } } // Set bytecode operands foreach (var newVar in newVars) { foreach (var def in newVar.Defs) { def.Operand = newVar.Variable; if ((def.Type != null) && (newVar.Variable.Type == null)) { newVar.Variable.Type = def.Type; } } foreach (var use in newVar.Uses) { use.Operand = newVar.Variable; } } } }
/// <summary> /// Default ctor /// </summary> public DalvikStackFrameValue(Value value, VariableInfo variable, bool isParameter, DalvikProcess process) : base(value, process) { IsParameter = isParameter; Variable = variable; }
public void AddMember( VariableInfo info ) { myMembers.Add( info.Name, new VariableInfo( (ushort) ( ( Root ? 0 : Parent.Count ) + Count ), info ) ); ++Count; }
public static List <VariableInfo> DrawVariables(Rect position, IEnumerable <VariableInfo> variables, Dictionary <string, VariableInfo> ovrrideInputs, List <VariableInfo> inputs) { if (inputs != null) { for (int i = 0; i < inputs.Count; i++) { var input = inputs[i]; var variable = variables.Where(o => o.Name == input.Name).FirstOrDefault(); if (variable == null || variable.Type != input.Type) { inputs.RemoveAt(i); i--; GUI.changed = true; } } } Rect rowRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); GUIStyle labelStyle = new GUIStyle("label"); // labelStyle.fontStyle = FontStyle.Bold; int inputCount = variables.Where(o => o.IsIn).Count(); // if (inputCount > 0) { rowRect.x = position.x; rowRect.width = position.width; rowRect.xMin += GUI.depth * GUIDepthScope.Pixels; //rowRect = EditorGUI.PrefixLabel(rowRect, new GUIContent("Input"), labelStyle); GUI.Label(GUIExtensions.Width(ref rowRect, EditorGUIUtility.labelWidth), new GUIContent("Input"), labelStyle); rowRect.y += rowRect.height; using (new GUIDepthScope()) { variables.Where(o => o.IsIn).OrderBy(o => o.Name).Where((variable, index) => { VariableInfo inVar = null; if (inputs != null) { inVar = inputs.Where(o => o.Name == variable.Name).FirstOrDefault(); } if (inVar != null && inVar.Type != variable.Type) { inputs.Remove(inVar); inVar = null; GUI.changed = true; } rowRect.x = position.x; rowRect.width = position.width; rowRect.xMin += GUI.depth * GUIDepthScope.Pixels; if (inVar == null) { GUI.color = Color.gray; } else { GUI.color = Color.white; } GUI.Label(GUIExtensions.Width(ref rowRect, variableLabelWidth), new GUIContent(variable.Name)); GUI.color = Color.white; var tmpRect = GUIExtensions.Width(ref rowRect, rowRect.width - variableCheckWidth); if (inVar != null) { object newValue2; newValue2 = SerializableValuePropertyDrawer.ValueField(tmpRect, inVar.DefaultValue, inVar.Type); if (!object.Equals(newValue2, inVar.DefaultValue)) { inVar.DefaultValue = newValue2; GUI.changed = true; } } else { GUI.enabled = false; object value = variable.DefaultValue; if (ovrrideInputs.ContainsKey(variable.Name)) { value = ovrrideInputs[variable.Name].DefaultValue; } SerializableValuePropertyDrawer.ValueField(tmpRect, value, variable.Type); GUI.enabled = true; } rowRect.xMin += 5f; if (EditorGUI.Toggle(rowRect, inVar != null)) { if (inVar == null) { inVar = new VariableInfo(variable.Name, variable.Type, variable.DefaultValue); if (inputs == null) { inputs = new List <VariableInfo>(); } inputs.Add(inVar); GUI.changed = true; } } else { if (inVar != null) { inputs.Remove(inVar); GUI.changed = true; } } rowRect.y = rowRect.yMax; return(false); }).Count(); } } int outputCount = variables.Where(o => o.IsOut).Count(); // if (outputCount > 0) { rowRect.x = position.x; rowRect.width = position.width; rowRect.xMin += GUI.depth * GUIDepthScope.Pixels; //rowRect = EditorGUI.PrefixLabel(rowRect, new GUIContent("Output"), labelStyle); GUI.Label(GUIExtensions.Width(ref rowRect, EditorGUIUtility.labelWidth), new GUIContent("Output"), labelStyle); rowRect.y += rowRect.height; using (new GUIDepthScope()) { variables.Where(o => o.IsOut).OrderBy(o => o.Name).Where((variable, index) => { rowRect.x = position.x; rowRect.width = position.width; rowRect.xMin += GUI.depth * GUIDepthScope.Pixels; GUI.Label(GUIExtensions.Width(ref rowRect, variableLabelWidth), new GUIContent(variable.Name)); GUI.Label(rowRect, new GUIContent(FlowNode.GetDisplayValueTypeName(variable.Type), variable.Type.FullName)); rowRect.y += rowRect.height; return(false); }).Count(); } } return(inputs); }
public override void Do() { _variable = GetFromStorage(_variable.Name); // вау аутизм Writer.WriteLine(_variable.Value); Console.WriteLine(_variable.Value); }
public VariableInfo( ushort offset, VariableInfo info ) { Offset = offset; Name = info.Name; Type = info.Type; Length = info.Length; Reference = info.Reference; Size = info.Size; }
private void AddVariableToMap(IDictionary <ISymbol, VariableInfo> variableInfoMap, ISymbol localOrParameter, VariableInfo variableInfo) { variableInfoMap.Add(localOrParameter, variableInfo); }
public IEnumerable<VariableInfo> GetProperties() { VariableInfo[] array = new VariableInfo[_properties.Count]; foreach (var propKeyValue in _propHolder.GetProperties()) { var descr = new VariableInfo(); descr.Identifier = propKeyValue.Key; descr.Type = SymbolType.ContextProperty; array[propKeyValue.Value] = descr; } return array; }
private static VariableInfo GetVariableInfo(string Variable, string JavaCode) { VariableInfo Result = new VariableInfo(); Result.Identifier = Variable; Result.IsData = IsDataVariable(Variable, JavaCode); Result.IsSteward = IsStewardVariable(Variable, JavaCode); Result.IsModified = IsModifiedVariable(Variable, JavaCode); if (!(Result.IsData || Result.IsModified || Result.IsSteward)) Result.IsParasitic = true; else Result.IsParasitic = false; return Result; }
/// <summary> /// If possible, separates local variables into several independent variables. /// It should undo any compilers merging. /// </summary> void ConvertLocalVariables(List <ByteCode> body) { if (optimize) { int varCount = methodDef.Body.Variables.Count; for (int variableIndex = 0; variableIndex < varCount; variableIndex++) { // Find all stores and loads for this variable List <ByteCode> stores = body.Where(b => b.Code == ILCode.Stloc && b.Operand is VariableDefinition && b.OperandAsVariable.Index == variableIndex).ToList(); List <ByteCode> loads = body.Where(b => (b.Code == ILCode.Ldloc || b.Code == ILCode.Ldloca) && b.Operand is VariableDefinition && b.OperandAsVariable.Index == variableIndex).ToList(); TypeReference varType = methodDef.Body.Variables[variableIndex].VariableType; List <VariableInfo> newVars; bool isPinned = methodDef.Body.Variables[variableIndex].IsPinned; // If the variable is pinned, use single variable. // If any of the loads is from "all", use single variable // If any of the loads is ldloca, fallback to single variable as well if (isPinned || loads.Any(b => b.VariablesBefore[variableIndex].StoredByAll || b.Code == ILCode.Ldloca)) { newVars = new List <VariableInfo>(1) { new VariableInfo() { Variable = new ILVariable() { Name = "var_" + variableIndex, Type = isPinned ? ((PinnedType)varType).ElementType : varType, OriginalVariable = methodDef.Body.Variables[variableIndex] }, Stores = stores, Loads = loads } }; } else { // Create a new variable for each store newVars = stores.Select(st => new VariableInfo() { Variable = new ILVariable() { Name = "var_" + variableIndex + "_" + st.Offset.ToString("X2"), Type = varType, OriginalVariable = methodDef.Body.Variables[variableIndex] }, Stores = new List <ByteCode>() { st }, Loads = new List <ByteCode>() }).ToList(); // VB.NET uses the 'init' to allow use of uninitialized variables. // We do not really care about them too much - if the original variable // was uninitialized at that point it means that no store was called and // thus all our new variables must be uninitialized as well. // So it does not matter which one we load. // TODO: We should add explicit initialization so that C# code compiles. // Remember to handle cases where one path inits the variable, but other does not. // Add loads to the data structure; merge variables if necessary foreach (ByteCode load in loads) { ByteCode[] storedBy = load.VariablesBefore[variableIndex].StoredBy; if (storedBy.Length == 0) { // Load which always loads the default ('uninitialized') value // Create a dummy variable just for this load newVars.Add(new VariableInfo() { Variable = new ILVariable() { Name = "var_" + variableIndex + "_" + load.Offset.ToString("X2") + "_default", Type = varType, OriginalVariable = methodDef.Body.Variables[variableIndex] }, Stores = new List <ByteCode>(), Loads = new List <ByteCode>() { load } }); } else if (storedBy.Length == 1) { VariableInfo newVar = newVars.Where(v => v.Stores.Contains(storedBy[0])).Single(); newVar.Loads.Add(load); } else { List <VariableInfo> mergeVars = newVars.Where(v => v.Stores.Union(storedBy).Any()).ToList(); VariableInfo mergedVar = new VariableInfo() { Variable = mergeVars[0].Variable, Stores = mergeVars.SelectMany(v => v.Stores).ToList(), Loads = mergeVars.SelectMany(v => v.Loads).ToList() }; mergedVar.Loads.Add(load); newVars = newVars.Except(mergeVars).ToList(); newVars.Add(mergedVar); } } } // Set bytecode operands foreach (VariableInfo newVar in newVars) { foreach (ByteCode store in newVar.Stores) { store.Operand = newVar.Variable; } foreach (ByteCode load in newVar.Loads) { load.Operand = newVar.Variable; } } } } else { var variables = methodDef.Body.Variables.Select(v => new ILVariable() { Name = string.IsNullOrEmpty(v.Name) ? "var_" + v.Index : v.Name, Type = v.VariableType, OriginalVariable = v }).ToList(); foreach (ByteCode byteCode in body) { if (byteCode.Code == ILCode.Ldloc || byteCode.Code == ILCode.Stloc || byteCode.Code == ILCode.Ldloca) { int index = ((VariableDefinition)byteCode.Operand).Index; byteCode.Operand = variables[index]; } } } }
private void EvaluateVariableOrFunction() { int startIndex = Offset; while (Offset < sourceLength && (char.IsLetterOrDigit(Source[Offset]) || Source[Offset] == '_')) { Offset++; } string name = Source.Substring(startIndex, Offset - startIndex); switch (name) { case "now": PushValue(DateTime.Now); break; case "null": PushValue(null); break; case "true": PushValue(true); break; case "false": PushValue(false); break; default: SkipWhitespace(); if (Offset < sourceLength && Source[Offset] == '(') { EvaluateFunction(name); } else { VariableInfo info = new VariableInfo(name); FindVariable(this, info); PushValue(info.Result); } break; } }
public override void CheckSemantics(Scope scope, List <SemanticError> errors) { //-------------------------------------------------- // Por Default, El Nodo No Tiene Errores. //-------------------------------------------------- this.IsOk = true; //-------------------------------------------------- // Si Existe Una Función O Una Variable Con El Mismo // Nombre En El Scope Local, Reportar Error. //-------------------------------------------------- if (scope.FindLocalFunctionInfo(this.ID.Name) != null || scope.FindLocalVariableInfo(this.ID.Name) != null) { errors.Add(SemanticError.PreviousVariableOrFunctionDeclaration(this.ID.Name, this)); this.IsOk = false; } //-------------------------------------------------- // Hacer 'CheckSemantics' Al Valor De La Variable. //-------------------------------------------------- this.Expression.CheckSemantics(scope, errors); //-------------------------------------------------- // Si El Valor De La Expresión Tiene Algún Error, // Parar De Reportar Errores. //-------------------------------------------------- if (this.Expression.ExpressionType == PredefinedTypes.ErrorType) { this.IsOk = false; } if (!this.IsOk) { return; } if (this.ChildCount == 3) { //-------------------------------------------------- // Si La Variable Tiene El Tipo Explícitamente Entonces // Es De La Siguiente Forma: // // var id : type-id := expr //-------------------------------------------------- var typeID = this.Children[2] as IdNode; //-------------------------------------------------- // Si El Tipo No Existe, Entonces Reportar El Error. //-------------------------------------------------- var TI = scope.FindTypeInfo(typeID.Name); if (TI == null) { errors.Add(SemanticError.TypeDoesNotExist(typeID.Name, this)); this.IsOk = false; return; } if (this.Expression.ExpressionType == PredefinedTypes.NilType) { //-------------------------------------------------- // Si El Valor De La Expresión Es <nil>, Entonces El // Tipo De La Variable, Escrito Explícitamente; Puede // Ser Cualquiera, Excepto 'int'. // // var id : type-id := nil //-------------------------------------------------- if (TI.TypeNode == PredefinedTypes.IntType) { errors.Add(SemanticError.InvalidIntNilAssignation(this)); this.IsOk = false; return; } } else if (TI.TypeNode != this.Expression.ExpressionType) { //-------------------------------------------------- // Si Los Tipos Son Diferentes, Reportar Error. //-------------------------------------------------- this.IsOk = false; errors.Add(SemanticError.InvalidTypeConvertion(TI.TypeNode, this.Expression.ExpressionType, this)); return; } //-------------------------------------------------- // Crear 'VariableInfo'. //-------------------------------------------------- this.VariableInfo = new VariableInfo(this.ID.Name, TI.TypeNode); } else { //-------------------------------------------------- // En Este Caso Se Omite El Tipo De La Variable, Por // Tanto Se Debe Inferir De La Parte Derecha. Se Debe // Comprobar Que La Parte Derecha No Sea <nil> o <void>. // // var id := expr //-------------------------------------------------- if (this.Expression.ExpressionType == PredefinedTypes.NilType || this.Expression.ExpressionType == PredefinedTypes.VoidType) { errors.Add(SemanticError.InvalidTypeInference(this.Expression.ExpressionType, this)); this.IsOk = false; return; } //-------------------------------------------------- // Crear 'VariableInfo'. //-------------------------------------------------- this.VariableInfo = new VariableInfo(this.ID.Name, this.Expression.ExpressionType); } //-------------------------------------------------- // Actualizar 'Scope' Con La Variable Actual. //-------------------------------------------------- scope.Add(this.VariableInfo); }
/// <summary> /// If possible, separates local variables into several independent variables. /// It should undo any compilers merging. /// </summary> void ConvertLocalVariables(List<ByteCode> body) { foreach (var varDef in methodDef.Body.Variables) { // Find all definitions and uses of this variable var defs = body.Where(b => b.Operand == varDef && b.IsVariableDefinition).ToList(); var uses = body.Where(b => b.Operand == varDef && !b.IsVariableDefinition).ToList(); List<VariableInfo> newVars; // If the variable is pinned, use single variable. // If any of the uses is from unknown definition, use single variable // If any of the uses is ldloca with a nondeterministic usage pattern, use single variable if (!optimize || varDef.IsPinned || uses.Any(b => b.VariablesBefore[varDef.Index].UnknownDefinition || (b.Code == AstCode.Ldloca && !IsDeterministicLdloca(b)))) { newVars = new List<VariableInfo>(1) { new VariableInfo() { Variable = new AstILVariable( string.IsNullOrEmpty(varDef.Name) ? "var_" + varDef.Index : varDef.Name, XBuilder.AsTypeReference(module, varDef.IsPinned ? ((PinnedType)varDef.VariableType).ElementType : varDef.VariableType), varDef), Defs = defs, Uses = uses }}; } else { // Create a new variable for each definition newVars = defs.Select(def => new VariableInfo() { Variable = new AstILVariable( (string.IsNullOrEmpty(varDef.Name) ? "var_" + varDef.Index : varDef.Name) + "_" + def.Offset.ToString("X2"), XBuilder.AsTypeReference(module, varDef.VariableType), varDef), Defs = new List<ByteCode> { def }, Uses = new List<ByteCode>() }).ToList(); // VB.NET uses the 'init' to allow use of uninitialized variables. // We do not really care about them too much - if the original variable // was uninitialized at that point it means that no store was called and // thus all our new variables must be uninitialized as well. // So it does not matter which one we load. // TODO: We should add explicit initialization so that C# code compiles. // Remember to handle cases where one path inits the variable, but other does not. // Add loads to the data structure; merge variables if necessary foreach (ByteCode use in uses) { ByteCode[] useDefs = use.VariablesBefore[varDef.Index].Definitions; if (useDefs.Length == 1) { VariableInfo newVar = newVars.Single(v => v.Defs.Contains(useDefs[0])); newVar.Uses.Add(use); } else { List<VariableInfo> mergeVars = newVars.Where(v => v.Defs.Intersect(useDefs).Any()).ToList(); VariableInfo mergedVar = new VariableInfo() { Variable = mergeVars[0].Variable, Defs = mergeVars.SelectMany(v => v.Defs).ToList(), Uses = mergeVars.SelectMany(v => v.Uses).ToList() }; mergedVar.Uses.Add(use); newVars = newVars.Except(mergeVars).ToList(); newVars.Add(mergedVar); } } } // Set bytecode operands foreach (VariableInfo newVar in newVars) { foreach (ByteCode def in newVar.Defs) { def.Operand = newVar.Variable; } foreach (ByteCode use in newVar.Uses) { use.Operand = newVar.Variable; } } } }
/// <summary> /// If possible, separates local variables into several independent variables. /// It should undo any compilers merging. /// </summary> void ConvertLocalVariables(List <ByteCode> body) { foreach (Local varDef in methodDef.Body.Variables) { // Find all definitions and uses of this variable var defs = body.Where(b => b.Operand == varDef && b.IsVariableDefinition).ToList(); var uses = body.Where(b => b.Operand == varDef && !b.IsVariableDefinition).ToList(); List <VariableInfo> newVars; // If the variable is pinned, use single variable. // If any of the uses is from unknown definition, use single variable // If any of the uses is ldloca with a nondeterministic usage pattern, use single variable if (!optimize || varDef.Type is PinnedSig || uses.Any(b => b.VariablesBefore[varDef.Index].UnknownDefinition || (b.Code == ILCode.Ldloca && !IsDeterministicLdloca(b)))) { newVars = new List <VariableInfo>(1) { new VariableInfo() { Variable = new ILVariable() { Name = string.IsNullOrEmpty(varDef.Name) ? "var_" + varDef.Index : varDef.Name, Type = varDef.Type is PinnedSig ? ((PinnedSig)varDef.Type).Next : varDef.Type, OriginalVariable = varDef }, Defs = defs, Uses = uses } }; } else { // Create a new variable for each definition newVars = defs.Select(def => new VariableInfo() { Variable = new ILVariable() { Name = (string.IsNullOrEmpty(varDef.Name) ? "var_" + varDef.Index : varDef.Name) + "_" + def.Offset.ToString("X2"), Type = varDef.Type, OriginalVariable = varDef }, Defs = new List <ByteCode>() { def }, Uses = new List <ByteCode>() }).ToList(); // VB.NET uses the 'init' to allow use of uninitialized variables. // We do not really care about them too much - if the original variable // was uninitialized at that point it means that no store was called and // thus all our new variables must be uninitialized as well. // So it does not matter which one we load. // TODO: We should add explicit initialization so that C# code compiles. // Remember to handle cases where one path inits the variable, but other does not. // Add loads to the data structure; merge variables if necessary foreach (ByteCode use in uses) { ByteCode[] useDefs = use.VariablesBefore[varDef.Index].Definitions; if (useDefs.Length == 1) { VariableInfo newVar = newVars.Single(v => v.Defs.Contains(useDefs[0])); newVar.Uses.Add(use); } else { List <VariableInfo> mergeVars = newVars.Where(v => v.Defs.Intersect(useDefs).Any()).ToList(); VariableInfo mergedVar = new VariableInfo() { Variable = mergeVars[0].Variable, Defs = mergeVars.SelectMany(v => v.Defs).ToList(), Uses = mergeVars.SelectMany(v => v.Uses).ToList() }; mergedVar.Uses.Add(use); newVars = newVars.Except(mergeVars).ToList(); newVars.Add(mergedVar); } } } // Set bytecode operands foreach (VariableInfo newVar in newVars) { foreach (ByteCode def in newVar.Defs) { def.Operand = newVar.Variable; } foreach (ByteCode use in newVar.Uses) { use.Operand = newVar.Variable; } } } }
public static int Compare(VariableInfo left, VariableInfo right) { return VariableSymbol.Compare(left._variableSymbol, right._variableSymbol); }
protected abstract TStatement CreateDeclarationStatement(VariableInfo variable, TExpression initialValue, CancellationToken cancellationToken);
public static int Compare(VariableInfo left, VariableInfo right) { return(VariableSymbol.Compare(left._variableSymbol, right._variableSymbol)); }
/// <summary> /// If possible, separates local variables into several independent variables. /// It should undo any compilers merging. /// </summary> void ConvertLocalVariables(List <ByteCode> body) { if (optimize) { int varCount = methodDef.Body.Variables.Count; for (int variableIndex = 0; variableIndex < varCount; variableIndex++) { // Find all stores and loads for this variable List <ByteCode> stores = body.Where(b => b.Code == ILCode.Stloc && b.Operand is VariableDefinition && b.OperandAsVariable.Index == variableIndex).ToList(); List <ByteCode> loads = body.Where(b => (b.Code == ILCode.Ldloc || b.Code == ILCode.Ldloca) && b.Operand is VariableDefinition && b.OperandAsVariable.Index == variableIndex).ToList(); TypeReference varType = methodDef.Body.Variables[variableIndex].VariableType; List <VariableInfo> newVars; bool isPinned = methodDef.Body.Variables[variableIndex].IsPinned; // If the variable is pinned, use single variable. // If any of the loads is from "all", use single variable // If any of the loads is ldloca, fallback to single variable as well if (isPinned || loads.Any(b => b.VariablesBefore[variableIndex].StoredByAll || b.Code == ILCode.Ldloca)) { newVars = new List <VariableInfo>(1) { new VariableInfo() { Variable = new ILVariable() { Name = "var_" + variableIndex, Type = isPinned ? ((PinnedType)varType).ElementType : varType, OriginalVariable = methodDef.Body.Variables[variableIndex] }, Stores = stores, Loads = loads } }; } else { // Create a new variable for each store newVars = stores.Select(st => new VariableInfo() { Variable = new ILVariable() { Name = "var_" + variableIndex + "_" + st.Offset.ToString("X2"), Type = varType, OriginalVariable = methodDef.Body.Variables[variableIndex] }, Stores = new List <ByteCode>() { st }, Loads = new List <ByteCode>() }).ToList(); // Add loads to the data structure; merge variables if necessary foreach (ByteCode load in loads) { ByteCode[] storedBy = load.VariablesBefore[variableIndex].StoredBy; if (storedBy.Length == 0) { throw new Exception("Load of uninitialized variable"); } else if (storedBy.Length == 1) { VariableInfo newVar = newVars.Where(v => v.Stores.Contains(storedBy[0])).Single(); newVar.Loads.Add(load); } else { List <VariableInfo> mergeVars = newVars.Where(v => v.Stores.Union(storedBy).Any()).ToList(); VariableInfo mergedVar = new VariableInfo() { Variable = mergeVars[0].Variable, Stores = mergeVars.SelectMany(v => v.Stores).ToList(), Loads = mergeVars.SelectMany(v => v.Loads).ToList() }; mergedVar.Loads.Add(load); newVars = newVars.Except(mergeVars).ToList(); newVars.Add(mergedVar); } } } // Set bytecode operands foreach (VariableInfo newVar in newVars) { foreach (ByteCode store in newVar.Stores) { store.Operand = newVar.Variable; } foreach (ByteCode load in newVar.Loads) { load.Operand = newVar.Variable; } } } } else { var variables = methodDef.Body.Variables.Select(v => new ILVariable() { Name = string.IsNullOrEmpty(v.Name) ? "var_" + v.Index : v.Name, Type = v.VariableType, OriginalVariable = v }).ToList(); foreach (ByteCode byteCode in body) { if (byteCode.Code == ILCode.Ldloc || byteCode.Code == ILCode.Stloc || byteCode.Code == ILCode.Ldloca) { int index = ((VariableDefinition)byteCode.Operand).Index; byteCode.Operand = variables[index]; } } } }