/// <summary> /// Block the running Thread until the file has been parsed /// </summary> public void WaitParsing() { if (!HasCode) { return; } //_parsedEvent.WaitOne(); System.Diagnostics.Trace.WriteLine("-->> XFile.WaitParsing()"); lock (_lock) { if (!Parsed) { // using (SourceWalker sw = new SourceWalker(this)) { try { var xTree = sw.Parse(); sw.BuildModel(xTree, false); // } catch (Exception e) { Support.Debug("XFile.WaitParsing" + e.Message); } } } } System.Diagnostics.Trace.WriteLine("<<-- XFile.WaitParsing()"); }
public static Assembly LoadAssemblyFromFile(string fileName) { if (!File.Exists(fileName)) { return(null); } try { FileStream input = new FileStream(fileName, FileMode.Open, FileAccess.Read); byte[] rawAssembly = new BinaryReader(input).ReadBytes((int)input.Length); if (rawAssembly.Length != input.Length) { //MessageBox.Show("Intellisense error 9"); } input.Close(); // if the PDB file exists then this might put a lock on the pdb file. // so we rename the pdb temporarily to prevent the lock var cPdb = Path.ChangeExtension(fileName, ".pdb"); var cTmp = Path.ChangeExtension(fileName, ".p$$"); bool renamed = false; if (File.Exists(cPdb)) { renamed = true; if (File.Exists(cTmp)) { File.Delete(cTmp); } File.Move(cPdb, cTmp); } var assembly = Assembly.Load(rawAssembly); if (renamed && File.Exists(cTmp)) { File.Move(cTmp, cPdb); } input.Dispose(); return(assembly); } catch (Exception e) { Support.Debug("Generic exception:"); Support.Debug(e.Message); } return(null); }
public override void EnterLocalvar([NotNull] XSharpParser.LocalvarContext context) { try { if (context.DataType != null) { XVariable local; String localType = context.DataType.GetText(); String localName; // Push to stack so we can manage all contexts in one loop _localDecls.Push(context); while (_localDecls.Count > 0) { XSharpParser.LocalvarContext tmpContext = _localDecls.Pop(); localName = tmpContext.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(tmpContext), new TextInterval(tmpContext), localType); local.File = this._file; local.IsArray = tmpContext.Dim != null; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } } else { // We may have something like // LOCAL x,y as STRING // for x, we don't have a DataType, so save it _localDecls.Push(context); } } catch (Exception ex) { Support.Debug("EnterLocalvar : Error Walking {0}, at {1}/{2} : " + ex.Message, this.File.Name, context.Start.Line, context.Start.Column); } }
internal void StopThread() { try { if (_WalkerThread == null) { return; } if (_WalkerThread.IsAlive) { _WalkerThread.Abort(); } } catch (Exception e) { Support.Debug("Cannot stop Background walker Thread : "); Support.Debug(e.Message); } _WalkerThread = null; return; }
public void BuildModel(XSharpParser.SourceContext xTree, bool buildLocals) { // abort when the project is unloaded or when no project // because in these cases there is no need to build a model if (_prjNode == null || !_file.Project.Loaded) { return; } // if (xTree != null) { try { XSharpModelDiscover mdiscover; if (buildLocals) { mdiscover = new XSharpModelDiscoverWithLocals(_file, xTree, _errors); } else { mdiscover = new XSharpModelDiscover(_file, xTree, _errors); } var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); // // Walk the tree. The XSharpModelDiscover class will build the model. walker.Walk(mdiscover, xTree); // Callback for LibraryManager // Disabled for Now RvdH //if ( _file.Project != null) // _file.Project.FileWalkComplete?.Invoke(_file); // } catch (Exception e) { Support.Debug("SourceWalker.BuildModel failed: " + e.Message); } } }
public void Walk() { if (suspendLevel != 0) { return; } try { StopThread(); ThreadStart ts = new ThreadStart(this.Walker); _WalkerThread = new Thread(ts); _WalkerThread.IsBackground = true; _WalkerThread.Priority = ThreadPriority.Highest; _WalkerThread.Name = "ModelWalker"; _WalkerThread.Start(); } catch (Exception e) { Support.Debug("Cannot start Background walker Thread : "); Support.Debug(e.Message); } return; }
public override void EnterImpliedvar([NotNull] XSharpParser.ImpliedvarContext context) { try { if (context.Expression is XSharpParser.PrimaryExpressionContext) { XSharpParser.PrimaryExpressionContext primaryEx = (XSharpParser.PrimaryExpressionContext)context.Expression; XSharpParser.PrimaryContext primary = primaryEx.Expr; if (primary is XSharpParser.LiteralExpressionContext) { // LOCAL IMPLIED xxx:= "azertyuiop" XSharpParser.LiteralExpressionContext lit = (XSharpParser.LiteralExpressionContext)primary; XVariable local; String localType = buildLiteralValue(lit.Literal); String localName; localName = context.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(context), localType); local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } else if (primary is XSharpParser.NameExpressionContext) { // LOCAL IMPLIED xx:= otherLocalVar XVariable local; XSharpParser.NameExpressionContext expr = (XSharpParser.NameExpressionContext)primary; string name = expr.Name.Id.GetText(); // String localName; localName = context.Id.GetText(); String localType = buildValueName(name); if (localType == XVariable.VarType) { XVariable xVar = findLocal(name); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), xVar.Interval, XVariable.VarType); } else { // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(context), localType); } local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } else if (primary is XSharpParser.CtorCallContext) { // LOCAL IMPLIED xxxx:= List<STRING>{ } XVariable local; XSharpParser.CtorCallContext expr = (XSharpParser.CtorCallContext)primary; XCodeTypeReference typeRef = buildDataType(expr.Type); // String localType = typeRef.TypeName; String localName; localName = context.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(context), localType); local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } } else if (context.Expression is XSharpParser.MethodCallContext) { // LOCAL IMPLIED xxxxx:= Obj:MethodCall() XSharpParser.MethodCallContext callCtxEx = (XSharpParser.MethodCallContext)context.Expression; XSharpParser.ExpressionContext exprCtx = callCtxEx.Expr; String mtdCall = exprCtx.GetText(); XVariable local; String localName; localName = context.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(exprCtx), XVariable.VarType); local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } } catch (Exception ex) { Support.Debug("EnterImpliedvar : Error Walking {0}, at {1}/{2} : " + ex.Message, this.File.Name, context.Start.Line, context.Start.Column); } }
internal void UpdateAssembly() { if (this._failed > 3) { return; } Type[] types = null; var aTypes = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase); var aExtensions = new List <MethodInfo>(); // int num; string nspace = ""; string fullName = ""; string simpleName = ""; // this._nameSpaces.Clear(); this._nameSpaceTexts.Clear(); this._zeroNamespace.Clear(); this._globalClassName = ""; this._HasExtensions = false; // this.LoadAssembly(); try { if (_assembly != null) { object[] customAttributes = _assembly.GetCustomAttributes(false); for (num = 1; num <= customAttributes.Length; num++) { object custattr = customAttributes[num - 1]; Type type = custattr.GetType(); switch (custattr.ToString()) { case "Vulcan.Internal.VulcanClassLibraryAttribute": this._globalClassName = type.GetProperty("globalClassName").GetValue(custattr, null).ToString(); // string defaultNS = type.GetProperty("defaultNamespace").GetValue(custattr, null).ToString(); if (!string.IsNullOrEmpty(defaultNS)) { this._implicitNamespaces.Add(defaultNS); } break; case "System.Runtime.CompilerServices.ExtensionAttribute": this._HasExtensions = true; break; case "Vulcan.VulcanImplicitNamespaceAttribute": string nameS = type.GetProperty("Namespace").GetValue(custattr, null).ToString(); if (!string.IsNullOrEmpty(nameS)) { this._implicitNamespaces.Add(nameS); } break; } } } } catch { } // Load Types From Assembly, if possible // register event handler to find missing assemblies AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; try { if (_assembly != null) { types = _assembly.GetTypes(); } this._failed = 0; } catch (ReflectionTypeLoadException e) { Support.Debug("Cannot load types from {0}", _assembly.GetName().Name); Support.Debug("Exception details:"); string lastMsg = null; foreach (var le in e.LoaderExceptions) { if (le.Message != lastMsg) { Support.Debug(le.Message); lastMsg = le.Message; } } Support.Debug("Types loaded:"); foreach (var t in e.Types) { if (t != null) { Support.Debug(t.FullName); } } _assembly = null; this._failed += 1; } catch (Exception e) { Support.Debug("Generic exception:"); Support.Debug(e.Message); } // Has Types ? currentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; if (types?.Length > 0 && (aTypes?.Count == 0 | !_LoadedTypes)) { try { for (num = 1; num <= types.Length; num++) { // First, Get Fullname ( for eg, System.Collections.Generic.List`1 ) fullName = types[num - 1].FullName; // Remove "special" Types if (fullName.StartsWith("$") || fullName.StartsWith("<")) { continue; } // if (this._HasExtensions && HasExtensionAttribute(types[num - 1])) { MethodInfo[] methods = types[num - 1].GetMethods(BindingFlags.Public | BindingFlags.Static); foreach (MethodInfo info in methods) { if (HasExtensionAttribute(info)) { aExtensions.Add(info); } } } // Nested Type ? if (fullName.Contains("+")) { fullName = fullName.Replace('+', '.'); } // Generic ? if (fullName.Contains("`")) { // Extract the "normal" name fullName = fullName.Substring(0, fullName.IndexOf("`") + 2); } // Add to the FullyQualified name if (!aTypes.ContainsKey(fullName)) { aTypes.Add(fullName, types[num - 1]); } // Now, with Standard name simpleName = types[num - 1].Name; simpleName = simpleName.Replace('+', '.'); // Not Empty namespace, not a generic, not nested, not starting with underscore if (((string.IsNullOrEmpty(types[num - 1].Namespace) && (simpleName.IndexOf('`') == -1)) && ((simpleName.IndexOf('+') == -1) && (simpleName.IndexOf('<') == -1))) && !simpleName.StartsWith("_")) { // Add the Name only, with the Kind this._zeroNamespace.AddType(simpleName, this.GetTypeTypesFromType(types[num - 1])); } // Public Type, not Nested and no Underscore if ((types[num - 1].IsPublic && (simpleName.IndexOf('+') == -1)) && (simpleName.IndexOf('_') == -1)) { // Get the Namespace nspace = types[num - 1].Namespace; // and the normal name simpleName = types[num - 1].Name; simpleName = simpleName.Replace('+', '.'); // Generic ? int index = simpleName.IndexOf('`'); if (index != -1) { simpleName = simpleName.Substring(0, index); } if ((nspace != null) && (nspace.Length > 0)) { NameSpaceContainer container; ; if (!this._nameSpaces.ContainsKey(nspace)) { container = new NameSpaceContainer(nspace); container.AddType(simpleName, this.GetTypeTypesFromType(types[num - 1])); this._nameSpaces.Add(nspace, container); this._nameSpaceTexts.Add(nspace); } else { container = (NameSpaceContainer)this._nameSpaces[nspace]; container.AddType(simpleName, this.GetTypeTypesFromType(types[num - 1])); } while (nspace.Contains(".")) { nspace = nspace.Substring(0, nspace.LastIndexOf('.')); if (!this._nameSpaceTexts.Contains(nspace)) { this._nameSpaceTexts.Add(nspace); } } } } } // Mark as Loaded this._LoadedTypes = true; this._aTypes = aTypes.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase); this._aExtensions = aExtensions.ToImmutableList(); this._failed = 0; _assembly = null; } catch (Exception e) { Support.Debug("Generic exception:"); Support.Debug(e.Message); // empty values _clearInfo(); } } }