public ConstantInfo(object value, ProjectState projectState) : base((BuiltinClassInfo)projectState.GetNamespaceFromObjects(DynamicHelpers.GetPythonType(value))) { _value = value; _type = DynamicHelpers.GetPythonType(value); _builtinInfo = ((BuiltinClassInfo)projectState.GetNamespaceFromObjects(_type)).Instance; }
public override ISet <Namespace> GetStaticDescriptor(Interpreter.AnalysisUnit unit) { if (_value.Info.IsStatic) { BuiltinClassInfo klass = (BuiltinClassInfo)ProjectState.GetNamespaceFromObjects(_value.FieldType); return(klass.Instance.SelfSet); } return(base.GetStaticDescriptor(unit)); }
private void WalkFromImportWorker(FromImportStatement node, Namespace userMod, object[] mods, string impName, string newName) { var saveName = (newName == null) ? impName : newName; GlobalScope.Imports[node].Types.Add(new[] { impName, newName }); // TODO: Better node would be the name node but we don't have a name node (they're just strings in the AST w/ no position info) var variable = Scopes[Scopes.Length - 1].CreateVariable(node, _unit, saveName); ISet <Namespace> newTypes = EmptySet <Namespace> .Instance; bool madeSet = false; // look for builtin / user-defined modules first ModuleInfo module = userMod as ModuleInfo; if (module != null) { var modVal = module.Scope.CreateVariable(node, _unit, impName); modVal.AddDependency(_unit); newTypes = newTypes.Union(modVal.Types, ref madeSet); } BuiltinModule builtinModule = userMod as BuiltinModule; if (builtinModule != null) { var modVal = builtinModule.GetMember(node, _unit, impName); newTypes = newTypes.Union(modVal, ref madeSet); } // then look for .NET reflected namespace if (mods != null) { var mems = new List <object>(mods.Length); foreach (var mod in mods) { object val; if (ProjectState.TryGetMember(mod, impName, out val) && val != null) { mems.Add(val); } } if (mems.Count > 0) { GlobalScope.ShowClr = true; var ns = ProjectState.GetNamespaceFromObjects(mems); newTypes = newTypes.Union(ns.SelfSet, ref madeSet); } } variable.AddTypes(node, _unit, newTypes); }
public override ISet <Namespace> GetStaticDescriptor(Interpreter.AnalysisUnit unit) { ReflectedProperty rp = _value as ReflectedProperty; if (rp != null && (rp.Info.GetGetMethod() ?? rp.Info.GetSetMethod()).IsStatic) { BuiltinClassInfo klass = (BuiltinClassInfo)ProjectState.GetNamespaceFromObjects(rp.PropertyType); return(klass.Instance.SelfSet); } return(base.GetStaticDescriptor(unit)); }
internal ISet <Namespace> GetClr(string index, bool showClr, ISet <Namespace> defaultValue) { ISet <Namespace> result; if (_variables.TryGetValue(index, out result)) { return(result ?? defaultValue); } var attrs = new List <object>(); foreach (var module in _objects) { try { var attr = GetOne(module, index, showClr); if (attr != this) { attrs.Add(attr); } } catch { // TODO: Remove when Python bug is fixed } } if (attrs.Count > 0) { var ns = _projectState.GetNamespaceFromObjects(attrs); result = _variables[index] = ns.SelfSet; return(result); } else { _variables[index] = null; } return(defaultValue); }
internal static ISet <Namespace> GetReturnTypes(BuiltinFunction func, ProjectState projectState) { var result = new HashSet <Namespace>(); var found = new HashSet <Type>(); foreach (var target in func.Overloads.Targets) { var targetInfo = (target as System.Reflection.MethodInfo); if (targetInfo != null && !found.Contains(targetInfo.ReturnType)) { var pyType = ClrModule.GetPythonType(targetInfo.ReturnType); result.Add(((BuiltinClassInfo)projectState.GetNamespaceFromObjects(pyType)).Instance); found.Add(targetInfo.ReturnType); } } return(result); }
public override ISet <Namespace> GetMember(Node node, AnalysisUnit unit, string name) { ISet <Namespace> specialziedRes; if (_specializedValues != null && _specializedValues.TryGetValue(name, out specialziedRes)) { return(specialziedRes); } var res = _type.GetMember(unit.DeclaringModule.InterpreterContext, name); if (res != null) { return(ProjectState.GetNamespaceFromObjects(res).SelfSet); } return(EmptySet <Namespace> .Instance); }
internal void PropagateBaseParams(FunctionInfo newScope, Namespace method) { foreach (var overload in method.Overloads) { var p = overload.Parameters; if (p.Length == newScope.ParameterTypes.Length) { for (int i = 1; i < p.Length; i++) { var baseParam = p[i]; var newParam = newScope.ParameterTypes[i]; // TODO: baseParam.Type isn't right, it's a string, not a type object var baseType = ProjectState.GetNamespaceFromObjects(baseParam.Type); if (baseType != null) { newParam.Types.Add(baseType); } } } } }
public ISet <Namespace> this[string name] { get { ISet <Namespace> res; if (_specializedValues != null && _specializedValues.TryGetValue(name, out res)) { return(res); } var member = _type.GetMember(ProjectState._defaultContext, name); if (member != null) { return(ProjectState.GetNamespaceFromObjects(member)); } throw new KeyNotFoundException(String.Format("Key {0} not found", name)); } set { if (_specializedValues == null) { _specializedValues = new Dictionary <string, ISet <Namespace> >(); } _specializedValues[name] = value; } }
public override ISet <Namespace> GetDescriptor(Namespace instance, Interpreter.AnalysisUnit unit) { return(((BuiltinClassInfo)ProjectState.GetNamespaceFromObjects(_value.Type)).Instance.SelfSet); }
public override bool Walk(ImportStatement node) { var iinfo = new ImportInfo("", node.Span); GlobalScope.Imports[node] = iinfo; int len = Math.Min(node.Names.Count, node.AsNames.Count); for (int i = 0; i < len; i++) { var impNode = node.Names[i]; var newName = node.AsNames[i]; var strImpName = impNode.MakeString(); iinfo.Types.Add(new[] { strImpName, newName }); if (strImpName == "clr") { GlobalScope.ShowClr = true; } else if (strImpName == "wpf") { AddWpfReferences(); } var saveName = (String.IsNullOrEmpty(newName)) ? strImpName : newName; ModuleReference modRef; var def = Scopes[Scopes.Length - 1].CreateVariable(impNode, _unit, saveName); if (ProjectState.Modules.TryGetValue(strImpName, out modRef)) { if (modRef.Module != null) { ModuleInfo mi = modRef.Module as ModuleInfo; if (mi != null) { mi.ModuleDefinition.AddDependency(_unit); } def.AddTypes(impNode, _unit, modRef.Module.SelfSet); continue; } else { modRef.References.Add(_unit); } } else { ProjectState.Modules[strImpName] = modRef = new ModuleReference(); if (modRef.References == null) { modRef.References = new HashSet <AnalysisUnit>(); } modRef.References.Add(_unit); } var builtinRefs = ProjectState.GetReflectedNamespaces(impNode.Names, impNode.Names.Count > 1 && !String.IsNullOrEmpty(newName)); if (builtinRefs != null && builtinRefs.Length > 0) { GlobalScope.ShowClr = true; var ns = ProjectState.GetNamespaceFromObjects(builtinRefs); // TODO: Should we pony up a fake module for the module we failed to resolve? if (ns != null) { def.AddTypes(impNode, _unit, ns.SelfSet); } } else { } } return(true); }