private void FinishLoadKnownTypes(PythonTypeDatabase db) { _itemCache.Clear(); if (db == null) { db = PythonTypeDatabase.CreateDefaultTypeDatabase(LanguageVersion.ToVersion()); Types = KnownTypes.Create(this, db); } else { Types = KnownTypes.CreateDefault(this, db); } ClassInfos = (IKnownClasses)Types; _noneInst = (ConstantInfo)GetCached( _nullKey, () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant) ); DoNotUnionInMro = AnalysisSet.Create(new AnalysisValue[] { ClassInfos[BuiltinTypeId.Object], ClassInfos[BuiltinTypeId.Type] }); AddBuiltInSpecializations(); }
private void AddEnumInfo(string componentKey, XmlNode enumNode, ConstantInfo constInfo) { XmlNode componentsNode = enumNode.SelectSingleNode("Components"); XmlNode componentNode = _parent.GetChildNodeByInnerText(componentsNode, componentKey); if (null == componentNode) { componentNode = _parent.COMTree.CreateElement("Component"); componentNode.InnerText = componentKey; componentsNode.AppendChild(componentNode); } XmlNode membersNode = enumNode.SelectSingleNode("Members"); foreach (TLI.MemberInfo itemMember in constInfo.Members) { XmlNode enumMemberNode = _parent.GetChildNodeByAttribute(membersNode, "Name", itemMember.Name); if (null == enumMemberNode) { enumMemberNode = _parent.COMTree.CreateElement("EnumMember"); _parent.AddAtrributeToNode(enumMemberNode, "Name", itemMember.Name); _parent.AddAtrributeToNode(enumMemberNode, "Value", itemMember.Value.ToString()); membersNode.AppendChild(enumMemberNode); _parent.AddNewChildNode(enumMemberNode, "Components"); } AddComponentToEnumMember(componentKey, enumMemberNode); } }
private async Task LoadKnownTypesAsync(CancellationToken token) { _itemCache.Clear(); var fallback = new FallbackBuiltinModule(_langVersion); var moduleRef = await Modules.TryImportAsync(_builtinName, token).ConfigureAwait(false); if (moduleRef != null) { _builtinModule = (BuiltinModule)moduleRef.Module; } else { _builtinModule = new BuiltinModule(fallback, this); Modules[_builtinName] = new ModuleReference(_builtinModule, _builtinName); } _builtinModule.InterpreterModule.Imported(_defaultContext); Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap); Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap); _knownTypes = KnownTypes.Create(this, fallback); _noneInst = (ConstantInfo)GetCached( _nullKey, () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant) ); AddBuiltInSpecializations(); }
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { // xmlhelper.Read("bookstore/book[@ISBN=\"7-111-19149-6\"]") Attributes 的属性 // xmlhelper.Read("bookstore/book[title=\"计算机硬件技术基础\"]") 内部节点 XmlNodeList xmlNodeLst = xmlhelper.Read("datatype/item[@gid=\"" + tmpconstantInfo.Gid + "\"]"); Int32 idx = -1; switch (e.Column.ToString()) { case "名称": idx = 0; break; case "常量值": idx = 1; break; case "说明": idx = 2; break; } if (idx == -1) { return; } xmlNodeLst.Item(idx).InnerText = e.Value.ToString(); xmlhelper.Save(false); tmpconstantInfo = null; }
/// <summary> /// 绑定数据 /// </summary> private void BindData() { XmlNodeList xmlNodeLst = xmlhelper.Read("datatype"); List <ConstantInfo> constantInfoList = new List <ConstantInfo>(); foreach (XmlNode xn1 in xmlNodeLst) { ConstantInfo constantInfo = new ConstantInfo(); // 将节点转换为元素,便于得到节点的属性值 XmlElement xe = (XmlElement)xn1; // 得到Type和ISBN两个属性的属性值 constantInfo.Gid = xe.GetAttribute("gid").ToString(); // 得到ConstantInfo节点的所有子节点 XmlNodeList xnl0 = xe.ChildNodes; constantInfo.Name = xnl0.Item(0).InnerText; constantInfo.ConstantValue = xnl0.Item(1).InnerText; constantInfo.Remark = xnl0.Item(2).InnerText; constantInfo.lstInfo = new Dictionary <string, DevExpress.XtraEditors.DXErrorProvider.ErrorInfo>(); constantInfoList.Add(constantInfo); } // 添加一行空行 constantInfoList.Add(new ConstantInfo()); gridControl1.DataSource = constantInfoList; gridView1.Columns["gid"].Visible = false; gridView1.Columns["lstInfo"].Visible = false; }
public void setData(LuaTable table1, LuaTable table2) { var head = new string[table1.Length]; SDataUtils.dealTable(table1, (Object o1, Object o2) => { head[(int)(double)o1 - 1] = (string)o2; }); SDataUtils.dealTable(table2, (Object o1, Object o2) => { ConstantInfo dif = new ConstantInfo(); SDataUtils.dealTable((LuaTable)o2, (Object o11, Object o22) => { switch (head[(int)(double)o11 - 1]) { case "ID": dif.ID = (int)(double)o22; break; case "Name": dif.Name = (string)o22; break; case "Value": dif.Value = (float)(double)o22; break; } }); if (Data.ContainsKey(dif.ID)) { MonoEX.Debug.Logout(MonoEX.LOG_TYPE.LT_ERROR, "重复的ID:" + dif.ID.ToString()); } Data.Add(dif.ID, dif); }); }
private Dictionary <string, object> GenerateConstant(ConstantInfo constantInfo) { return(new Dictionary <string, object>() { { "type", GenerateTypeName(constantInfo.PythonType) } }); }
public static ConstantInfo ToConstantInfo(this D3DXCONSTANT_DESC desc) { var info = new ConstantInfo { Name = desc.Name.ReadAsAnsiString(), RegisterSet = desc.RegisterSet.ToRegisterSet(), RegisterIndex = (int)desc.RegisterIndex, RegisterCount = (int)desc.RegisterCount, Class = desc.Class.ToParameterClass(), Type = desc.Type.ToParameterType(), Rows = (int)desc.Rows, Columns = (int)desc.Columns, Elements = (int)desc.Elements, StructMembers = (int)desc.StructMembers, Bytes = (int)desc.Bytes, }; if (desc.DefaultValue != IntPtr.Zero) { info.DefaultValue = new byte[desc.Bytes]; Marshal.Copy( desc.DefaultValue, info.DefaultValue, 0, (int)desc.Bytes); } return(info); }
private KeyValuePair <string, TSEnumDescription> ToTSEnumDescription(ConstantInfo c) { var ret = new TSEnumDescription(); c.Members.Cast().Select(x => KVP(x.Name, AsString((object)x.Value))).AddRangeTo(ret.Members); ret.JsDoc.Add("", c.HelpString); return(KVP($"{c.Parent.Name}.{c.Name}", ret)); }
private void gridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (string.IsNullOrEmpty((gridView1.GetFocusedRow() as ConstantInfo).Gid) && (gridView1.FocusedRowHandle + 1 == gridView1.RowCount)) { btnAdd_Click(null, null); } tmpconstantInfo = gridView1.GetRow(e.RowHandle) as ConstantInfo; }
public void TestAddConstant() { ConstantRegistry registry = new ConstantRegistry(false); registry.RegisterConstant("test", 42.0); ConstantInfo functionInfo = registry.GetConstantInfo("test"); Assert.IsNotNull(functionInfo); Assert.AreEqual("test", functionInfo.ConstantName); Assert.AreEqual(42.0, functionInfo.Value); }
/// <summary> /// 新增 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { var constantInfo = new ConstantInfo(); constantInfo.GUID = System.Guid.NewGuid().ToString(); constantInfo.lstInfo = new Dictionary <string, DevExpress.XtraEditors.DXErrorProvider.ErrorInfo>(); xmlhelper.InsertElement("datatype", "item", "guid", constantInfo.GUID, string.Format(xmlModel, string.Empty, string.Empty, string.Empty)); xmlhelper.Save(false); (gridView1.DataSource as List <ConstantInfo>).Insert(gridView1.RowCount - 1, constantInfo); gridView1.RefreshData(); }
/// <summary> /// 插入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInsert_Click(object sender, EventArgs e) { XmlNodeList xmlNodeLst = xmlhelper.Read("datatype/item[@gid=\"" + (gridView1.GetFocusedRow() as ConstantInfo).Gid + "\"]"); var constantInfo = new ConstantInfo(); constantInfo.Gid = System.Guid.NewGuid().ToString(); constantInfo.lstInfo = new Dictionary <string, DevExpress.XtraEditors.DXErrorProvider.ErrorInfo>(); xmlhelper.InsertElement("item", "gid", constantInfo.Gid, string.Format(xmlModel, string.Empty, string.Empty, string.Empty), xmlNodeLst.Item(0).ParentNode); xmlhelper.Save(false); (gridView1.DataSource as List <ConstantInfo>).Insert(gridView1.FocusedRowHandle, constantInfo); gridView1.RefreshData(); }
public PythonAnalyzer(IPythonInterpreter pythonInterpreter, PythonLanguageVersion langVersion) { _langVersion = langVersion; _interpreter = pythonInterpreter; _modules = new Dictionary <string, ModuleReference>(); _modulesByFilename = new Dictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase); _itemCache = new Dictionary <object, object>(); InitializeBuiltinModules(); pythonInterpreter.ModuleNamesChanged += new EventHandler(ModuleNamesChanged); _types = new KnownTypes(this); _builtinModule = (BuiltinModule)Modules["__builtin__"].Module; _propertyObj = GetBuiltin("property"); _classmethodObj = GetBuiltin("classmethod"); _staticmethodObj = GetBuiltin("staticmethod"); _typeObj = GetBuiltin("type"); _intType = GetBuiltin("int"); _stringType = (BuiltinClassInfo)GetBuiltin("str"); _objectSet = new HashSet <Namespace>(new[] { GetBuiltin("object") }); _setType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Set)); _rangeFunc = GetBuiltin("range"); _frozensetType = GetBuiltin("frozenset"); _functionType = GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Function)); _generatorType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Generator)); _dictType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Dict)); _boolType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Bool)); _noneInst = (ConstantInfo)GetNamespaceFromObjects(null); _listType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.List)); _tupleType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Tuple)); _queue = new Deque <AnalysisUnit>(); SpecializeFunction("__builtin__", "range", (n, unit, args) => unit.DeclaringModule.GetOrMakeNodeVariable(n, (nn) => new RangeInfo(_types.List, unit.ProjectState).SelfSet)); SpecializeFunction("__builtin__", "min", ReturnUnionOfInputs); SpecializeFunction("__builtin__", "max", ReturnUnionOfInputs); pythonInterpreter.Initialize(this); _defaultContext = pythonInterpreter.CreateModuleContext(); // cached for quick checks to see if we're a call to clr.AddReference try { SpecializeFunction("wpf", "LoadComponent", LoadComponent); } catch (KeyNotFoundException) { // IronPython.Wpf.dll isn't available... } }
internal ConstantInfo Parse() { var rslt = new ConstantInfo(this); rslt.Is_Char = this.Is_char; rslt.Is_Decimal = this.Is_decimal; rslt.Is_Float = this.Is_float; rslt.Is_Hex = this.Is_hex; rslt.Is_Octal = this.Is_octal; rslt.Is_String = this.Is_string; rslt.Is_Bool = this.Is_bool; rslt.Value = Value; return rslt; }
/// <summary> /// 下移 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMoveDown_Click(object sender, EventArgs e) { if (gridView1.FocusedRowHandle == (gridView1.RowCount - 2)) { return; } ConstantInfo cuconstantInfo = gridView1.GetFocusedRow() as ConstantInfo; ConstantInfo nextconstantInfo = gridView1.GetRow(gridView1.FocusedRowHandle + 1) as ConstantInfo; // 深拷贝 ConstantInfo tmpconstantInfo = new ConstantInfo(); tmpconstantInfo.Gid = cuconstantInfo.Gid; tmpconstantInfo.Name = cuconstantInfo.Name; tmpconstantInfo.ConstantValue = cuconstantInfo.ConstantValue; tmpconstantInfo.Remark = cuconstantInfo.Remark; tmpconstantInfo.lstInfo = cuconstantInfo.lstInfo; // 更新内容 cuconstantInfo.Gid = nextconstantInfo.Gid; cuconstantInfo.Name = nextconstantInfo.Name; cuconstantInfo.ConstantValue = nextconstantInfo.ConstantValue; cuconstantInfo.Remark = nextconstantInfo.Remark; cuconstantInfo.lstInfo = nextconstantInfo.lstInfo; nextconstantInfo.Gid = tmpconstantInfo.Gid; nextconstantInfo.Name = tmpconstantInfo.Name; nextconstantInfo.ConstantValue = tmpconstantInfo.ConstantValue; nextconstantInfo.Remark = tmpconstantInfo.Remark; nextconstantInfo.lstInfo = tmpconstantInfo.lstInfo; // 更细XML内容 string cuXMLStr = xmlhelper.ReadInnerXML("datatype/item[@gid=\"" + cuconstantInfo.Gid + "\"]"); string preXMLStr = xmlhelper.ReadInnerXML("datatype/item[@gid=\"" + nextconstantInfo.Gid + "\"]"); xmlhelper.Replace("datatype/item[@gid=\"" + cuconstantInfo.Gid + "\"]", preXMLStr); xmlhelper.Replace("datatype/item[@gid=\"" + nextconstantInfo.Gid + "\"]", cuXMLStr); // 更新gid var cuattribute = xmlhelper.Read("datatype/item[@gid=\"" + cuconstantInfo.Gid + "\"]").Item(0).ParentNode.Attributes["gid"]; var nextattribute = xmlhelper.Read("datatype/item[@gid=\"" + nextconstantInfo.Gid + "\"]").Item(0).ParentNode.Attributes["gid"]; cuattribute.Value = nextconstantInfo.Gid; nextattribute.Value = cuconstantInfo.Gid; xmlhelper.Save(false); gridView1.RefreshData(); gridView1.FocusedRowHandle = gridView1.FocusedRowHandle + 1; }
private static void PublishWorker <T>(int start, int nTypes, ConstantInfo info, T value, T[] fallbackArray) { int arrIndex = start + info.Offset - nTypes * StorageData.StaticFields; ((ReducibleExpression)info.Expression).Start = start; if (arrIndex < 0) { ((ReducibleExpression)info.Expression).FieldInfo.SetValue(null, value); } else { fallbackArray[arrIndex] = value; } }
internal ConstantInfo Parse() { var rslt = new ConstantInfo(this); rslt.Is_Char = this.Is_char; rslt.Is_Decimal = this.Is_decimal; rslt.Is_Float = this.Is_float; rslt.Is_Hex = this.Is_hex; rslt.Is_Octal = this.Is_octal; rslt.Is_String = this.Is_string; rslt.Is_Bool = this.Is_bool; rslt.Value = Value; return(rslt); }
/// <summary> /// 上移 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMoveUp_Click(object sender, EventArgs e) { if (gridView1.FocusedRowHandle == 0) { return; } ConstantInfo cuconstantInfo = gridView1.GetFocusedRow() as ConstantInfo; ConstantInfo preconstantInfo = gridView1.GetRow(gridView1.FocusedRowHandle - 1) as ConstantInfo; // 深拷贝 ConstantInfo tmpconstantInfo = new ConstantInfo(); tmpconstantInfo.GUID = cuconstantInfo.GUID; tmpconstantInfo.Name = cuconstantInfo.Name; tmpconstantInfo.Value = cuconstantInfo.Value; tmpconstantInfo.Remark = cuconstantInfo.Remark; tmpconstantInfo.lstInfo = cuconstantInfo.lstInfo; // 更新内容 cuconstantInfo.GUID = preconstantInfo.GUID; cuconstantInfo.Name = preconstantInfo.Name; cuconstantInfo.Value = preconstantInfo.Value; cuconstantInfo.Remark = preconstantInfo.Remark; cuconstantInfo.lstInfo = preconstantInfo.lstInfo; preconstantInfo.GUID = tmpconstantInfo.GUID; preconstantInfo.Name = tmpconstantInfo.Name; preconstantInfo.Value = tmpconstantInfo.Value; preconstantInfo.Remark = tmpconstantInfo.Remark; preconstantInfo.lstInfo = tmpconstantInfo.lstInfo; // 更细XML内容 string cuXMLStr = xmlhelper.ReadInnerXML("datatype/item[@guid=\"" + cuconstantInfo.GUID + "\"]"); string preXMLStr = xmlhelper.ReadInnerXML("datatype/item[@guid=\"" + preconstantInfo.GUID + "\"]"); xmlhelper.Replace("datatype/item[@guid=\"" + cuconstantInfo.GUID + "\"]", preXMLStr); xmlhelper.Replace("datatype/item[@guid=\"" + preconstantInfo.GUID + "\"]", cuXMLStr); // 更新GUID var cuattribute = xmlhelper.Read("datatype/item[@guid=\"" + cuconstantInfo.GUID + "\"]").Item(0).ParentNode.Attributes["guid"]; var preattribute = xmlhelper.Read("datatype/item[@guid=\"" + preconstantInfo.GUID + "\"]").Item(0).ParentNode.Attributes["guid"]; cuattribute.Value = preconstantInfo.GUID; preattribute.Value = cuconstantInfo.GUID; xmlhelper.Save(false); gridView1.RefreshData(); gridView1.FocusedRowHandle = gridView1.FocusedRowHandle - 1; }
public override MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, PythonVariable variable, PythonGlobal /*!*/ global) { Assert.NotNull(global); lock (StorageData.Globals) { ConstantInfo info = NextGlobal(0); StorageData.GlobalStorageType(StorageData.GlobalCount + 1); PublishWorker(StorageData.GlobalCount, StorageData.GlobalTypes, info, global, StorageData.Globals); StorageData.GlobalCount += 1; return(new PythonGlobalVariableExpression(info.Expression, variable, global)); } }
// // public bool TryGetConstantInfo(string constantName, out ConstantInfo constantInfo) // { // var constInfo = new ConstantInfo(constantName); // // var that = this; // do // { // if (that._constants.TryGetValue(constInfo, out constantInfo)) // { // return true; // } // // } while ((that = that.Parent) != null); // // return false; // } public bool TryGetConstantInfo(VariableAccessStatement variableAccessStatement, out ConstantInfo constantInfo) { var constInfo = new ConstantInfo(variableAccessStatement.VariableName); var that = this; do { if (that._constants.TryGetValue(constInfo, out constantInfo)) { return(true); } } while ((that = that.Parent) != null); return(false); }
public override void PublishContext(CodeContext /*!*/ context, ConstantInfo /*!*/ codeContextInfo) { int arrIndex = codeContextInfo.Offset - StorageData.ContextTypes * StorageData.StaticFields; if (arrIndex < 0) { codeContextInfo.Field.SetValue(null, context); } else { lock (StorageData.Contexts) { StorageData.Contexts[arrIndex] = context; } } ((CodeContextExpression)codeContextInfo.Expression).Context = context; }
/// <summary> /// 导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, EventArgs e) { string importFile = FileDialogHelper.OpenExcel(false); if (!string.IsNullOrEmpty(importFile)) { // 判断文件是否被占用 if (FileUtil.FileIsUsing(importFile)) { MessageDxUtil.ShowWarning(string.Format("文件[{0}]被占用,请先关闭文件后再重试!", importFile)); return; } DataTable dt = MyXlsHelper.Import(importFile, "用户常量", 2, 1); // 如果没有结果集就不在继续 if (dt == null) { return; } Int32 addRows = 0; for (Int32 i = 0; i < dt.Rows.Count; i++) { // 判断是否存在不存在则添加 if (!lstName.Contains(dt.Rows[i][0].ToString())) { var constantInfo = new ConstantInfo(); constantInfo.Gid = System.Guid.NewGuid().ToString(); constantInfo.Name = dt.Rows[i][0].ToString(); constantInfo.ConstantValue = dt.Rows[i][1].ToString(); constantInfo.Remark = dt.Rows[i][2].ToString(); xmlhelper.InsertElement("datatype", "item", "gid", constantInfo.Gid, string.Format(xmlModel, dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString())); (gridView1.DataSource as List <ConstantInfo>).Insert((gridView1.DataSource as List <ConstantInfo>).Count - 1, constantInfo); addRows++; lstName.Add(dt.Rows[i][0].ToString()); } } xmlhelper.Save(false); gridView1.RefreshData(); } }
/// <summary> /// 新增 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { // 假如在查询去掉查询在新增 if (!string.IsNullOrEmpty(gridView1.ActiveFilterString)) { gridView1.ActiveFilterString = ""; } var constantInfo = new ConstantInfo(); constantInfo.Gid = System.Guid.NewGuid().ToString(); constantInfo.lstInfo = new Dictionary <string, DevExpress.XtraEditors.DXErrorProvider.ErrorInfo>(); xmlhelper.InsertElement("datatype", "item", "gid", constantInfo.Gid, string.Format(xmlModel, string.Empty, string.Empty, string.Empty)); xmlhelper.Save(false); (gridView1.DataSource as List <ConstantInfo>).Insert((gridView1.DataSource as List <ConstantInfo>).Count - 1, constantInfo); gridView1.RefreshData(); }
private void LoadKnownTypes() { _itemCache.Clear(); ModuleReference moduleRef; if (Modules.TryImport(_builtinName, out moduleRef)) { _builtinModule = (BuiltinModule)moduleRef.Module; } else { var fallbackDb = PythonTypeDatabase.CreateDefaultTypeDatabase(LanguageVersion.ToVersion()); _builtinModule = _modules.GetBuiltinModule(fallbackDb.GetModule(SharedDatabaseState.BuiltinName2x)); Modules[_builtinName] = new ModuleReference(_builtinModule); } Types = new KnownTypes(this); ClassInfos = (IKnownClasses)Types; _noneInst = (ConstantInfo)GetCached(_nullKey, () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], (object)null)); DoNotUnionInMro = AnalysisSet.Create(new AnalysisValue[] { ClassInfos[BuiltinTypeId.Object], ClassInfos[BuiltinTypeId.Type] }); AddBuiltInSpecializations(); ModuleReference sysModule; if (_modules.TryImport("sys", out sysModule)) { var bm = sysModule.AnalysisModule as BuiltinModule; if (bm != null) { sysModule.Module = new SysModuleInfo(bm); } } }
private async Task LoadKnownTypesAsync(CancellationToken token) { _itemCache.Clear(); var fallback = new FallbackBuiltinModule(LanguageVersion); if (Modules.TryImport(_builtinName, out var moduleRef)) { _builtinModule = (BuiltinModule)moduleRef.Module; } else { _builtinModule = new BuiltinModule(fallback, this); Modules.SetModule(_builtinName, BuiltinModule); } _builtinModule.InterpreterModule.Imported(_defaultContext); var builtinModuleNamesMember = ((IBuiltinPythonModule)_builtinModule.InterpreterModule).GetAnyMember("__builtin_module_names__"); if (builtinModuleNamesMember is Interpreter.Ast.AstPythonStringLiteral builtinModuleNamesLiteral && builtinModuleNamesLiteral.Value != null) { var builtinModuleNames = builtinModuleNamesLiteral.Value.Split(',').Select(n => n.Trim()); _pathResolver.SetBuiltins(builtinModuleNames); } Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap); Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap); _knownTypes = KnownTypes.Create(this, fallback); _noneInst = (ConstantInfo)GetCached( _nullKey, () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant) ); AddBuiltInSpecializations(); }
private async Task LoadKnownTypesAsync() { _itemCache.Clear(); var fallback = new FallbackBuiltinModule(_langVersion); var moduleRef = await Modules.TryImportAsync(_builtinName).ConfigureAwait(false); if (moduleRef != null) { _builtinModule = (BuiltinModule)moduleRef.Module; } else { _builtinModule = new BuiltinModule(fallback, this); Modules[_builtinName] = new ModuleReference(_builtinModule, _builtinName); } Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap); Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap); Types = KnownTypes.Create(this, fallback); ClassInfos = (IKnownClasses)Types; _noneInst = (ConstantInfo)GetCached( _nullKey, () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant) ); DoNotUnionInMro = AnalysisSet.Create(new AnalysisValue[] { ClassInfos[BuiltinTypeId.Object], ClassInfos[BuiltinTypeId.Type] }); AddBuiltInSpecializations(); }
public override MSAst.Expression/*!*/ GetConstant(object value) { // if we can emit the value and we won't be continiously boxing/unboxing // then don't bother caching the value in a static field. if (CompilerHelpers.CanEmitConstant(value, CompilerHelpers.GetType(value)) && !CompilerHelpers.GetType(value).IsValueType) { return Ast.Constant(value); } ConstantInfo ci; if (!_constants.TryGetValue(value, out ci)) { string name = "Constant " + (_constantsCreated++) + CompilerHelpers.GetType(value).Name; FieldBuilder field = _typeGen.AddStaticField(typeof(object), FieldAttributes.Public, name); _constants[value] = ci = new ConstantInfo(field, CreateFieldBuilderExpression(field)); } return ci.Expression; }
private ConstantInfo/*!*/ GetGlobalInfo(string name) { ConstantInfo res; if (!_globals.TryGetValue(name, out res)) { FieldBuilder field = _typeGen.AddStaticField(typeof(PythonGlobal), FieldAttributes.Public, GetGlobalFieldName(name)); _globals[name] = res = new ConstantInfo(field, CreateFieldBuilderExpression(field)); } return res; }
public virtual void PublishContext(CodeContext codeContext, ConstantInfo _contextInfo) { }
public override MSAst.Expression/*!*/ GetConstant(object value) { // if we can emit the value and we won't be continiously boxing/unboxing // then don't bother caching the value in a static field. // TODO: Sometimes we don't want to pre-box the values, such as if it's an int // going to a call site which can be strongly typed. We need to coordinate // more with whoever consumes the values. if (CompilerHelpers.CanEmitConstant(value, CompilerHelpers.GetType(value)) && !CompilerHelpers.GetType(value).IsValueType) { return Ast.Constant(value); } ConstantInfo ci; if (!_constants.TryGetValue(value, out ci)) { string name = "Constant " + (_constantsCreated++) + CompilerHelpers.GetType(value).Name; FieldBuilder field = _typeGen.AddStaticField(typeof(object), FieldAttributes.Public, name); _constants[value] = ci = new ConstantInfo(field, CreateFieldBuilderExpression(field)); } return ci.Expression; }
private static void PublishConstant(object constant, ConstantInfo info) { StorageData.ConstantStorageType(info.Offset); PublishWorker(0, StorageData.ConstantTypes, info, constant, StorageData.Constants); }
internal static Tuple<ConstantInfo, IndexInfo> ScanNext(IndexInfo LastIndex) { var Signature = LastIndex.GetNextTrimmedLine(); if (!Signature.Text.Contains(":")) return null; var a = Signature.Text.IndexInfoOf(":"); var IsAirOnly = false; var Name = a.BeforeSubject.Trim(); if (Name.StartsWith(KeywordAirOnly)) { Name = Name.Substring(KeywordAirOnly.Length + 1).Trim(); IsAirOnly = true; } var b = a.IndexInfoOf("="); var Type = ""; var Value = ""; if (b.Index == -1) Type = a.AfterSubject.Trim(); else { Type = a.SubString(b).Trim(); Value = b.AfterSubject.Trim(); } var Summary = Signature.GetNextTrimmedLine(); var DefinedBy = Summary.GetNextTrimmedLine(); var n = new ConstantInfo { Signature = Signature.Text, Summary = Summary.Text, DefinedBy = DefinedBy.Text, IsAirOnly = IsAirOnly, Type = Type, Name = Name, Value = Value }; return new Tuple<ConstantInfo, IndexInfo> { TValue = n, FValue = DefinedBy }; }
private object GetMemberValueInternal(AnalysisValue type, ModuleInfo declModule, bool isRef) { SpecializedNamespace specialCallable = type as SpecializedNamespace; if (specialCallable != null) { if (specialCallable.Original == null) { return(null); } return(GetMemberValueInternal(specialCallable.Original, declModule, isRef)); } switch (type.MemberType) { case PythonMemberType.Function: FunctionInfo fi = type as FunctionInfo; if (fi != null) { if (fi.DeclaringModule.GetModuleInfo() != declModule) { return(GenerateFuncRef(fi)); } else { return(GenerateFunction(fi)); } } BuiltinFunctionInfo bfi = type as BuiltinFunctionInfo; if (bfi != null) { return(GenerateFuncRef(bfi)); } return("function"); case PythonMemberType.Method: BoundMethodInfo mi = type as BoundMethodInfo; if (mi != null) { return(GenerateMethod(mi)); } return("method"); case PythonMemberType.Property: FunctionInfo prop = type as FunctionInfo; if (prop != null) { return(GenerateProperty(prop)); } break; case PythonMemberType.Class: ClassInfo ci = type as ClassInfo; if (ci != null) { if (isRef || ci.DeclaringModule.GetModuleInfo() != declModule) { // TODO: Save qualified name so that classes defined in classes/function can be resolved return(GetTypeRef(ci.DeclaringModule.ModuleName, ci.Name)); } else { return(GenerateClass(ci, declModule)); } } BuiltinClassInfo bci = type as BuiltinClassInfo; if (bci != null) { return(GetTypeRef(bci.PythonType.DeclaringModule.Name, bci.PythonType.Name)); } return("type"); case PythonMemberType.Constant: ConstantInfo constantInfo = type as ConstantInfo; if (constantInfo != null) { return(GenerateConstant(constantInfo)); } break; case PythonMemberType.Module: if (type is ModuleInfo) { return(GetModuleName(((ModuleInfo)type).Name)); } else if (type is BuiltinModule) { return(GetModuleName(((BuiltinModule)type).Name)); } break; case PythonMemberType.Instance: return(new Dictionary <string, object> { { "type", GenerateTypeName(type, true) } }); default: return(new Dictionary <string, object>() { { "type", GenerateTypeName(type.PythonType) } }); } return(null); }
internal IAnalysisSet GetConstant(object value) { object key = value ?? _nullKey; return(GetCached(key, () => ConstantInfo.Create(this, value) ?? _noneInst) ?? _noneInst); }