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(); } } }