Пример #1
0
        internal IEnumerable <AnalysisVariable> ToVariables(IReferenceable referenceable)
        {
            LocatedVariableDef locatedDef = referenceable as LocatedVariableDef;

            if (locatedDef != null &&
                locatedDef.Entry.Tree != null &&    // null tree if there are errors in the file
                locatedDef.DeclaringVersion == locatedDef.Entry.AnalysisVersion)
            {
                var start = locatedDef.Node.GetStart(locatedDef.Entry.Tree);
                yield return(new AnalysisVariable(VariableType.Definition, new LocationInfo(locatedDef.Entry.FilePath, start.Line, start.Column)));
            }

            VariableDef def = referenceable as VariableDef;

            if (def != null)
            {
                foreach (var location in def.TypesNoCopy.SelectMany(type => type.Locations))
                {
                    yield return(new AnalysisVariable(VariableType.Value, location));
                }
            }

            foreach (var reference in referenceable.Definitions)
            {
                yield return(new AnalysisVariable(
                                 VariableType.Definition,
                                 reference.GetLocationInfo()
                                 ));
            }

            foreach (var reference in referenceable.References)
            {
                yield return(new AnalysisVariable(
                                 VariableType.Reference,
                                 reference.GetLocationInfo()
                                 ));
            }
        }
Пример #2
0
 private object GetMemberValue(VariableDef variableDef, bool isRef)
 {
     if (variableDef.Types.Count == 1)
     {
         var type = variableDef.Types.First();
         var res  = GetMemberValue(type, isRef);
         if (res == null)
         {
             _errors.Add(String.Format("Cannot save single member: {0}", variableDef.Types.First()));
         }
         return(res);
     }
     else if (variableDef.Types.Count == 0)
     {
         return(new Dictionary <string, object>()
         {
             { "type", new object[] { "__builtin__", "object" } }
         });
     }
     else
     {
         List <object> res = new List <object>();
         foreach (var type in variableDef.Types)
         {
             res.Add(
                 new Dictionary <string, object>()
             {
                 { "kind", GetMemberKind(type, isRef) },
                 { "value", GetMemberValue(type, isRef) }
             }
                 );
         }
         return(new Dictionary <string, object>()
         {
             { "members", res.ToArray() }
         });
     }
 }
Пример #3
0
        private object GenerateParameter(Parameter param, VariableDef typeInfo)
        {
            Dictionary <string, object> res = new Dictionary <string, object>();

            // TODO: Serialize default values and type name
            if (param.Name.StartsWith("**"))
            {
                res["name"]       = param.Name.Substring(2);
                res["arg_format"] = "**";
                res["type"]       = GenerateTypeName(typeInfo.Types);
            }
            else if (param.Name.StartsWith("*"))
            {
                res["name"]       = param.Name.Substring(1);
                res["arg_format"] = "*";
                res["type"]       = GenerateTypeName(typeInfo.Types);
            }
            else
            {
                res["name"] = param.Name;
                res["type"] = GenerateTypeName(typeInfo.Types);
            }
            return(res);
        }
Пример #4
0
 private object GetMemberValue(VariableDef variableDef, ModuleInfo declModule, bool isRef)
 {
     return(GetMemberValue(variableDef.TypesNoCopy, declModule, isRef));
 }
 public LocatedVariableDef(IPythonProjectEntry entry, EncodedLocation location, VariableDef copy)
 {
     Entry            = entry;
     Location         = location;
     _dependencies    = copy._dependencies;
     DeclaringVersion = entry.AnalysisVersion;
 }