public ConstantInfo(IJConstant value, JAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetNamespaceFromObjects(value.Type)) { _value = value; _memberType = value.MemberType; _builtinInfo = ((BuiltinClassInfo)projectState.GetNamespaceFromObjects(value.Type)).Instance; }
public ConstantInfo(object value, JAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetNamespaceFromObjects(projectState.GetTypeFromObject(value))) { _value = value; _memberType = JMemberType.Constant; _builtinInfo = ((BuiltinClassInfo)projectState.GetNamespaceFromObjects(_type)).Instance; }
public GeneratorInfo(JAnalyzer projectState, Node node) : base(projectState._generatorType) { _node = node; Yields = new VariableDef(); Sends = new VariableDef(); Returns = new VariableDef(); }
internal BuiltinFunctionOverloadResult(JAnalyzer state, IJFunctionOverload overload, int removedParams, string name, Func<string> fallbackDoc, params ParameterResult[] extraParams) : base(null, name) { _overload = overload; _extraParameters = extraParams; _removedParams = removedParams; _projectState = state; _fallbackDoc = fallbackDoc; CalculateDocumentation(); }
public void Save(JAnalyzer state, string outDir) { foreach (var modKeyValue in state.Modules) { string name = modKeyValue.Key; var moduleInfo = modKeyValue.Value.Module as ModuleInfo; if (moduleInfo != null) { var info = SerializeModule(moduleInfo); for (int i = 0; i < 10; i++) { try { using (var writer = new FileStream(Path.Combine(outDir, name + ".idb"), FileMode.Create, FileAccess.ReadWrite)) { new Pickler(writer).Dump(info); } break; } catch (IOException ex) { // race with a reader, retry... http://pytools.codeplex.com/workitem/570 Console.WriteLine("Could not access {0} {1}", name + ".idb", ex); Thread.Sleep(1000); } } for (int i = 0; i < 10; i++) { try { using (var writer = new StreamWriter(new FileStream(Path.Combine(outDir, name + ".idb.$memlist"), FileMode.Create, FileAccess.ReadWrite))) { foreach (var keyValue in moduleInfo.Scope.Variables) { writer.WriteLine(keyValue.Key); } } break; } catch (IOException ex) { // race with a reader, retry... http://pytools.codeplex.com/workitem/570 Console.WriteLine("Could not access {0} {1}", name + ".idb.$memlist", ex); Thread.Sleep(1000); } } } } if (_errors.Count > 0) { foreach (var error in _errors) { Console.WriteLine(error); } } }
public KnownTypes(JAnalyzer state) { var interpreter = state.Interpreter; None = interpreter.GetBuiltinType(BuiltinTypeId.NoneType); Set = interpreter.GetBuiltinType(BuiltinTypeId.Set); Function = interpreter.GetBuiltinType(BuiltinTypeId.Function); Generator = interpreter.GetBuiltinType(BuiltinTypeId.Generator); Dict = interpreter.GetBuiltinType(BuiltinTypeId.Dict); Bool = interpreter.GetBuiltinType(BuiltinTypeId.Bool); List = interpreter.GetBuiltinType(BuiltinTypeId.List); Tuple = interpreter.GetBuiltinType(BuiltinTypeId.Tuple); BuiltinFunction = interpreter.GetBuiltinType(BuiltinTypeId.BuiltinFunction); BuiltinMethodDescriptor = interpreter.GetBuiltinType(BuiltinTypeId.BuiltinMethodDescriptor); Object = interpreter.GetBuiltinType(BuiltinTypeId.Object); Float = interpreter.GetBuiltinType(BuiltinTypeId.Float); Int = interpreter.GetBuiltinType(BuiltinTypeId.Int); Str = interpreter.GetBuiltinType(BuiltinTypeId.Str); Bytes = interpreter.GetBuiltinType(BuiltinTypeId.Bytes); Complex = interpreter.GetBuiltinType(BuiltinTypeId.Complex); Module = interpreter.GetBuiltinType(BuiltinTypeId.Module); if (!state.LanguageVersion.Is7x()) { Long = interpreter.GetBuiltinType(BuiltinTypeId.Long); } Ellipsis = interpreter.GetBuiltinType(BuiltinTypeId.Ellipsis); Type = interpreter.GetBuiltinType(BuiltinTypeId.Type); DictItems = interpreter.GetBuiltinType(BuiltinTypeId.DictItems); ListIterator = interpreter.GetBuiltinType(BuiltinTypeId.ListIterator); TupleIterator = interpreter.GetBuiltinType(BuiltinTypeId.TupleIterator); SetIterator = interpreter.GetBuiltinType(BuiltinTypeId.SetIterator); StrIterator = interpreter.GetBuiltinType(BuiltinTypeId.StrIterator); if (state.LanguageVersion.Is7x()) { BytesIterator = interpreter.GetBuiltinType(BuiltinTypeId.BytesIterator); } CallableIterator = interpreter.GetBuiltinType(BuiltinTypeId.CallableIterator); }
public SetInfo(JAnalyzer projectState, Node node) : base(VariableDef.EmptyArray, projectState._setType, node) { }
public SequenceBuiltinClassInfo(IJType classObj, JAnalyzer projectState) : base(classObj, projectState) { }
private void AnalyzeStdLib(StreamWriter writer, string outdir, CancellationToken cancel) { var fileGroups = new List<List<string>>(); HashSet<string> pthDirs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); HashSet<string> allFileSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (var dir in _dirs) { CollectStdLib(pthDirs, dir, fileGroups, allFileSet); } foreach (var dir in pthDirs) { Log(writer, "COLLECTING PATH DIR \"" + dir + "\""); var list = new List<string>(); fileGroups.Add(list); CollectPackage(dir, list, allFileSet); } foreach (var files in fileGroups) { if (files.Count > 0) { Log(writer, "GROUP START \"" + Path.GetDirectoryName(files[0]) + "\""); Console.WriteLine("Now analyzing: {0}", Path.GetDirectoryName(files[0])); var fact = new CJInterpreterFactory(); var projectState = new JAnalyzer(new CJInterpreter(fact, new JTypeDatabase(_indir, _version.Is7x())), _version); // TODO: Load limits from storage projectState.Limits = AnalysisLimits.GetStandardLibraryLimits(); var modules = new List<IJProjectEntry>(); for (int i = 0; i < files.Count; i++) { string modName = JAnalyzer.PathToModuleName(files[i]); modules.Add(projectState.AddModule(modName, files[i])); } var nodes = new List<JAst>(); for (int i = 0; i < modules.Count; i++) { JAst ast = null; try { var sourceUnit = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.Read); Log(writer, "PARSE START: \"" + modules[i].FilePath + "\""); ast = Parser.CreateParser(sourceUnit, JLanguageVersion.V27, new ParserOptions() { BindReferences = true }).ParseFile(); Log(writer, "PARSE END: \"" + modules[i].FilePath + "\""); } catch (Exception ex) { Log(writer, "PARSE ERROR: \"" + modules[i].FilePath + "\" \"" + ex.ToString().Replace("\r\n", " -- ") + "\""); } nodes.Add(ast); } for (int i = 0; i < modules.Count; i++) { var ast = nodes[i]; if (ast != null) { modules[i].UpdateTree(ast, null); } } for (int i = 0; i < modules.Count; i++) { var ast = nodes[i]; if (ast != null) { Log(writer, "ANALYSIS START: \"" + modules[i].FilePath + "\""); modules[i].Analyze(cancel, true); Log(writer, "ANALYSIS END: \"" + modules[i].FilePath + "\""); } } if (modules.Count > 0) { modules[0].AnalysisGroup.AnalyzeQueuedEntries(cancel); } Log(writer, "SAVING GROUP: \"" + Path.GetDirectoryName(files[0]) + "\""); new SaveAnalysis().Save(projectState, outdir); Log(writer, "GROUP END \"" + Path.GetDirectoryName(files[0]) + "\""); } } }
public RangeInfo(IJType seqType, JAnalyzer state) : base(state._listType) { }
internal NewFunction(BuiltinFunctionInfo function, JAnalyzer projectState) : base(function.Function, projectState) { }
internal ProjectEntry(JAnalyzer state, string moduleName, string filePath, IAnalysisCookie cookie) { _projectState = state; _moduleName = moduleName ?? ""; _filePath = filePath; _cookie = cookie; _myScope = new ModuleInfo(_moduleName, this, state.Interpreter.CreateModuleContext()); _unit = new AnalysisUnit(_tree, _myScope.Scope); AnalysisLog.NewUnit(_unit); }
public EnumInstanceInfo(object value, JAnalyzer projectState) : base(value, projectState) { }
internal static ParameterResult MakeParameterResult(JAnalyzer state, Parameter curParam, JAst tree, IEnumerable<IAnalysisVariable> variables = null) { string name = curParam.Name; if (curParam.IsDictionary) { name = "**" + name; } else if (curParam.IsList) { name = "*" + curParam.Name; } if (curParam.DefaultValue != null) { // TODO: Support all possible expressions for default values, we should // probably have a JAst walker for expressions or we should add ToCodeString() // onto J ASTs so they can round trip ConstantExpression defaultValue = curParam.DefaultValue as ConstantExpression; if (defaultValue != null) { name = name + " = " + GetConstantRepr(state, defaultValue); } else { NameExpression nameExpr = curParam.DefaultValue as NameExpression; if (nameExpr != null) { name = name + " = " + nameExpr.Name; } else { DictionaryExpression dict = curParam.DefaultValue as DictionaryExpression; if (dict != null) { if (dict.Items.Count == 0) { name = name + " = {}"; } else { name = name + " = {...}"; } } else { ListExpression list = curParam.DefaultValue as ListExpression; if (list != null) { if (list.Items.Count == 0) { name = name + " = []"; } else { name = name + " = [...]"; } } else { TupleExpression tuple = curParam.DefaultValue as TupleExpression; if (tuple != null) { if (tuple.Items.Count == 0) { name = name + " = ()"; } else { name = name + " = (...)"; } } else { name = name + " = " + curParam.DefaultValue.ToCodeString(tree); } } } } } } var newParam = new ParameterResult(name, String.Empty, "object", false, variables); return newParam; }
internal BuiltinFunctionOverloadResult(JAnalyzer state, string name, IJFunctionOverload overload, int removedParams, params ParameterResult[] extraParams) : this(state, name, overload, removedParams, null, extraParams) { }
private static string GetConstantRepr(JAnalyzer state, ConstantExpression value) { if (value.Value == null) { return "None"; } else if (value.Value is AsciiString) { StringBuilder res = new StringBuilder(); if (state.LanguageVersion.Is7x()) { res.Append("b"); } res.Append("'"); var bytes = ((AsciiString)value.Value).String; for (int i = 0; i < bytes.Length; i++) { if (bytes[i] == '\'') { res.Append("\\'"); } else { res.Append(bytes[i]); } } res.Append("'"); return res.ToString(); } else if (value.Value is string) { StringBuilder res = new StringBuilder(); if (state.LanguageVersion.Is6x()) { res.Append("u"); } res.Append("'"); string str = value.Value as string; for (int i = 0; i < str.Length; i++) { if (str[i] == '\'') { res.Append("\\'"); } else { res.Append(str[i]); } } res.Append("'"); return res.ToString(); } else if (value.Value is Complex) { Complex x = (Complex)value.Value; if (x.Real != 0) { if (x.Imaginary < 0 || IsNegativeZero(x.Imaginary)) { return "(" + FormatComplexValue(x.Real) + FormatComplexValue(x.Imaginary) + "j)"; } else /* x.Imaginary() is NaN or >= +0.0 */ { return "(" + FormatComplexValue(x.Real) + "+" + FormatComplexValue(x.Imaginary) + "j)"; } } return FormatComplexValue(x.Imaginary) + "j"; } else if (value.Value is BigInteger) { if (state.LanguageVersion.Is6x()) { return value.Value.ToString() + "L"; } } // TODO: We probably need to handle more primitives here return value.Value.ToString(); }
public IterBuiltinMethodInfo(IJType declaringType, JAnalyzer projectState) : base(new IterFunction(declaringType), JMemberType.Method, projectState) { }