internal static string GetUrlString(this LocationInfo location, GeneroLanguageVersion languageVersion) { // first try to fill in the language version var type = typeof(GeneroLanguageVersion); var memInfo = type.GetMember(languageVersion.ToString()); var attributes = memInfo[0].GetCustomAttributes(typeof(GeneroLanguageVersionAttribute), false); var docNumber = ""; if (attributes.Length > 0) { docNumber = ((GeneroLanguageVersionAttribute)attributes[0]).DocumentationNumber; if (docNumber == null) { docNumber = ""; } } var urlStr = location.DefinitionURL; try { urlStr = string.Format(urlStr, docNumber); } catch (FormatException) { urlStr = location.DefinitionURL; } return(urlStr); }
/// <summary> /// Returns a sequence of all keywords that are invalid outside of /// function definitions in a particular version of Genero. /// </summary> public static IEnumerable <string> InvalidOutsideFunction( GeneroLanguageVersion version = GeneroLanguageVersion.None ) { yield return(null); // TODO: }
public BackwardTokenSearchItem(OrderedTokenSet tokenSet, bool match = true, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None) : base(minLangVersion) { TokenSet = tokenSet; SingleToken = TokenKind.EndOfFile; Match = match; }
/// <summary> /// Returns true if the specified identifier is a statement keyword in a /// particular version of Genero. /// </summary> public static bool IsStatementKeyword( string keyword, GeneroLanguageVersion version = GeneroLanguageVersion.None ) { return(Statement(version).Contains(keyword, StringComparer.Ordinal)); }
public ProgramRegister(string name, string typeName, IEnumerable <ProgramRegister> childRegisters = null, bool isArray = false, int arrayDimension = 0, string arrayType = null, GeneroLanguageVersion minimumBdlVersion = GeneroLanguageVersion.None, GeneroLanguageVersion maximumBdlVersion = GeneroLanguageVersion.Latest) { _parentRegister = null; _name = name; _typeName = typeName; _minBdlVersion = minimumBdlVersion; _maxBdlVersion = maximumBdlVersion; _isArray = isArray; _arrayDimension = arrayDimension; if (arrayType != null) { _arrayType = new VariableTypeResult { Typename = arrayType }; } _childRegisters = new Dictionary <string, ProgramRegister>(StringComparer.OrdinalIgnoreCase); if (childRegisters != null) { foreach (var reg in childRegisters) { reg._parentRegister = this; _childRegisters.Add(reg._name, reg); } } }
public BackwardTokenSearchItem(TokenKind singleToken, bool match = true, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None) : base(minLangVersion) { SingleToken = singleToken; TokenSet = null; Match = match; }
public BuiltinFunction(string name, string nameSpace, IEnumerable <ParameterResult> parameters, IEnumerable <string> returns, string description, GeneroLanguageVersion minimumBdlVersion = GeneroLanguageVersion.None) { _name = name; _namespace = nameSpace; _description = description; _parameters = new List <ParameterResult>(parameters); _returns = new List <string>(returns); _minBdlVersion = minimumBdlVersion; }
public SystemMacro(string name, Func <string> macroExpansion, GeneroLanguageVersion minimumBdlVersion = GeneroLanguageVersion.None, GeneroLanguageVersion maximumBdlVersion = GeneroLanguageVersion.Latest) { _name = name; _macroExpansion = macroExpansion; _minBdlVersion = minimumBdlVersion; _maxBdlVersion = maximumBdlVersion; }
public ContextPossibility(SingleToken[] singleTokens, ContextSetProviderContainer[] setProviders, BackwardTokenSearchItem[] backwardSearchItems, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None) : base(minLangVersion) { SingleTokens = singleTokens; SetProviders = setProviders; BackwardSearchItems = backwardSearchItems; }
public static GeneroLanguageVersion ToLanguageVersion(string versionString) { if (_languageVersions == null) { var type = typeof(GeneroLanguageVersion); _languageVersions = type.GetMembers().Select(x => x.GetCustomAttribute(typeof(GeneroLanguageVersionAttribute), false)) .Where(y => y != null) .ToDictionary(y => (y as GeneroLanguageVersionAttribute).VersionString, y => (y as GeneroLanguageVersionAttribute).LanguageVersion); } GeneroLanguageVersion glv = GeneroLanguageVersion.None; _languageVersions.TryGetValue(versionString, out glv); return(glv); }
public static IEnumerable <LocationInfo> GetLocations(ITextView textView, GeneroLanguageVersion languageVersion, GetLocationOptions options = GetLocationOptions.Definitions | GetLocationOptions.References | GetLocationOptions.Values) { List <LocationInfo> locations = new List <LocationInfo>(); Genero4glClassifier classifier; IFunctionInformationProvider funcProvider = null; IDatabaseInformationProvider dbProvider = null; IProgramFileProvider progfileProvider = null; if (textView.TextBuffer.Properties.TryGetProperty(typeof(Genero4glClassifier), out classifier)) { funcProvider = classifier.Provider._PublicFunctionProvider; dbProvider = classifier.Provider._DatabaseInfoProvider; progfileProvider = classifier.Provider._ProgramFileProvider; } var analysis = textView.GetExpressionAnalysis(funcProvider, dbProvider, progfileProvider); if (analysis != null) { Dictionary <LocationInfo, SimpleLocationInfo> references, definitions, values; GetDefsRefsAndValues(analysis, languageVersion, out definitions, out references, out values); if (options.HasFlag(GetLocationOptions.Values)) { foreach (var location in values.Keys) { locations.Add(location); } } if (options.HasFlag(GetLocationOptions.Definitions)) { foreach (var location in definitions.Keys) { locations.Add(location); } } if (options.HasFlag(GetLocationOptions.References)) { foreach (var location in references.Keys) { locations.Add(location); } } } return(locations); }
protected GeneroAst(AstNode body, int[] lineLocations, GeneroLanguageVersion langVersion = GeneroLanguageVersion.None, IProjectEntry projEntry = null, string filename = null) { if (body == null) { throw new ArgumentNullException("body"); } _langVersion = langVersion; _body = body; _lineLocations = lineLocations; _projEntry = projEntry; }
private static void GetDefsRefsAndValues(ExpressionAnalysis provider, GeneroLanguageVersion languageVersion, out Dictionary <LocationInfo, SimpleLocationInfo> definitions, out Dictionary <LocationInfo, SimpleLocationInfo> references, out Dictionary <LocationInfo, SimpleLocationInfo> values) { references = new Dictionary <LocationInfo, SimpleLocationInfo>(); definitions = new Dictionary <LocationInfo, SimpleLocationInfo>(); values = new Dictionary <LocationInfo, SimpleLocationInfo>(); var priorityVariables = new Dictionary <string, IAnalysisVariable>(StringComparer.OrdinalIgnoreCase); foreach (var v in provider.Variables.Where(x => x.Location != null)) { switch (v.Type) { case VariableType.Definition: values.Remove(v.Location); if (!string.IsNullOrWhiteSpace(v.Name) && v.Priority != 0) { IAnalysisVariable existing; if (priorityVariables.TryGetValue(v.Name, out existing)) { if (existing.Priority <= v.Priority) { break; } else { priorityVariables.Remove(v.Name); } } priorityVariables.Add(v.Name, v); } definitions[v.Location] = new SimpleLocationInfo(null, provider.Expression, v.Location, StandardGlyphGroup.GlyphGroupField, languageVersion); break; case VariableType.Reference: references[v.Location] = new SimpleLocationInfo(null, provider.Expression, v.Location, StandardGlyphGroup.GlyphGroupField, languageVersion); break; case VariableType.Value: if (!definitions.ContainsKey(v.Location)) { values[v.Location] = new SimpleLocationInfo(null, provider.Expression, v.Location, StandardGlyphGroup.GlyphGroupField, languageVersion); } break; } } }
public SimpleLocationInfo(System.IServiceProvider serviceProvider, string searchText, LocationInfo locInfo, StandardGlyphGroup glyphType, GeneroLanguageVersion languageVersion) { _serviceProvider = serviceProvider; _locationInfo = locInfo; _glyphType = glyphType; _languageVersion = languageVersion; _pathText = GetSearchDisplayText(); if (_locationInfo.ProjectEntry != null) { _lineText = _locationInfo.ProjectEntry.GetLine(_locationInfo.Line); } else { _lineText = ""; } }
public SystemImportModule(string name, string description, IEnumerable <BuiltinFunction> functions, GeneroLanguageVersion minimumBdlVersion = GeneroLanguageVersion.None, GeneroLanguageVersion maximumBdlVersion = GeneroLanguageVersion.Latest) { _name = name; _desc = description; _minBdlVersion = minimumBdlVersion; _maxBdlVersion = maximumBdlVersion; _memberFunctions = new Dictionary <string, IFunctionResult>(StringComparer.OrdinalIgnoreCase); foreach (var func in functions) { _memberFunctions.Add(func.Name, func); } }
private string GetLanguageVersion(XElement element, string attributeName) { var versionString = element.Attribute(attributeName)?.Value; GeneroLanguageVersion version = GeneroLanguageVersion.None; if (!string.IsNullOrWhiteSpace(versionString)) { _languageVersions.TryGetValue(versionString, out version); } if (attributeName == "maxVersion" && (version == GeneroLanguageVersion.None || version == GeneroLanguageVersion.Latest)) { version = GeneroLanguageVersion.Latest; } return(string.Format("GeneroLanguageVersion.{0}", version.ToString())); }
protected override GeneroAst CreateAst() { _languageVersion = GeneroLanguageVersionExtensions.GetLanguageVersion(_filename); ModuleNode moduleNode = null; if (ModuleNode.TryParseNode(this, out moduleNode)) { var ast = new Genero4glAst(moduleNode, _tokenizer.GetLineLocations(), LanguageVersion, _projectEntry, _filename); UpdateNodeAndTree(moduleNode, ast); return(ast); } return(null); }
public static Version ToVersion(this GeneroLanguageVersion version) { switch (version) { case GeneroLanguageVersion.V232: return(new Version(2, 32)); case GeneroLanguageVersion.V240: return(new Version(2, 40)); case GeneroLanguageVersion.V241: return(new Version(2, 41)); case GeneroLanguageVersion.V250: return(new Version(2, 50)); case GeneroLanguageVersion.V300: return(new Version(3, 0)); default: return(null); } }
public Genero4glAst(AstNode4gl body, int[] lineLocations, GeneroLanguageVersion langVersion = GeneroLanguageVersion.None, IProjectEntry projEntry = null, string filename = null) : base(body, lineLocations, langVersion, projEntry, filename) { InitializeBuiltins(); InitializeImportedPackages(); // for this instance InitializePackages(); if (body is ModuleNode) { foreach (var import in (body as ModuleNode).CExtensionImports) { if (_importedPackages.ContainsKey(import)) { _importedPackages[import] = true; } } } }
public OrderedTokenSet(IEnumerable <TokenContainer> tokenSet, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None) : base(minLangVersion) { Set = new List <TokenContainer>(tokenSet); }
public GeneroPerAst(AstNodePer body, int[] lineLocations, GeneroLanguageVersion langVersion = GeneroLanguageVersion.None, IProjectEntry projEntry = null, string filename = null) : base(body, lineLocations, langVersion, projEntry, filename) { }
public ContextEntry(IEnumerable <ContextPossibility> contextPossibles, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None) : base(minLangVersion) { ContextPossibilities = contextPossibles; }
/// <summary> /// Retuns a sequence of all keywords usable as a statement in a /// particular version of Genero. /// </summary> public static IEnumerable <string> Statement(GeneroLanguageVersion version = GeneroLanguageVersion.None) { return(Genero4glAst.ValidStatementKeywords.Select(x => Tokens.TokenKinds[x])); }
/// <summary> /// Returns a sequence of all keywords usable in an expression in a /// particular version of Genero. /// </summary> public static IEnumerable <string> Expression(GeneroLanguageVersion version = GeneroLanguageVersion.None) { yield return(null); // TODO: }
internal static LocationCategory GetFindRefLocations(ExpressionAnalysis analysis, GeneroLanguageVersion languageVersion) { Dictionary <LocationInfo, SimpleLocationInfo> references, definitions, values; GetDefsRefsAndValues(analysis, languageVersion, out definitions, out references, out values); var locations = new LocationCategory("Find All References", new SymbolList("Definitions", StandardGlyphGroup.GlyphLibrary, definitions.Values), new SymbolList("Values", StandardGlyphGroup.GlyphForwardType, values.Values), new SymbolList("References", StandardGlyphGroup.GlyphReference, references.Values) ); return(locations); }
public SingleToken(TokenKind token, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None) : base(minLangVersion) { Token = token; }
internal bool LoadFromXML() { if (File.Exists(Filename)) { _contextMap.Clear(); XmlDocument contextXml = new XmlDocument(); XmlReaderSettings rdrSettings = new XmlReaderSettings { IgnoreComments = true }; using (var reader = XmlReader.Create(Filename, rdrSettings)) { contextXml.Load(Filename); } foreach (XmlNode contextEntry in contextXml.LastChild.ChildNodes) { if (contextEntry.Name == "ContextEntry") { // Get the entry key object key = null; if (contextEntry.Attributes != null && contextEntry.Attributes["Type"].Value == "keyword") { var token = Tokens.GetToken(contextEntry.Attributes["Entry"].Value); if (token != null) { key = token.Kind; } else { key = Enum.Parse(typeof(TokenKind), contextEntry.Attributes["Entry"].Value); } } else if (contextEntry.Attributes != null && contextEntry.Attributes["Type"].Value == "category") { key = Enum.Parse(typeof(TokenCategory), contextEntry.Attributes["Entry"].Value); } else { return(false); } GeneroLanguageVersion contextEntryGLV = GeneroLanguageVersion.None; if (contextEntry.Attributes["minLanguageVersion"] != null) { contextEntryGLV = GeneroLanguageVersionExtensions.ToLanguageVersion(contextEntry.Attributes["minLanguageVersion"].Value); } List <ContextPossibility> possibilities = new List <ContextPossibility>(); foreach (XmlNode contextPossibility in contextEntry.ChildNodes) { var singleTokens = new List <SingleToken>(); var setProviders = new List <ContextSetProviderContainer>(); var backwardItems = new List <BackwardTokenSearchItem>(); GeneroLanguageVersion contextPossibilityGLV = GeneroLanguageVersion.None; if (contextPossibility.Attributes["minLanguageVersion"] != null) { contextPossibilityGLV = GeneroLanguageVersionExtensions.ToLanguageVersion(contextPossibility.Attributes["minLanguageVersion"].Value); } foreach (XmlNode possibility in contextPossibility.ChildNodes) { switch (possibility.Name) { case "SingleTokens": { foreach (XmlNode tokenNode in possibility.ChildNodes) { TokenKind tokenKind; var token = Tokens.GetToken(tokenNode.InnerText); if (token != null) { tokenKind = token.Kind; } else { tokenKind = (TokenKind)Enum.Parse(typeof(TokenKind), tokenNode.InnerText); } GeneroLanguageVersion singleTokenGLV = GeneroLanguageVersion.None; if (tokenNode.Attributes["minLanguageVersion"] != null) { singleTokenGLV = GeneroLanguageVersionExtensions.ToLanguageVersion(tokenNode.Attributes["minLanguageVersion"].Value); } singleTokens.Add(new SingleToken(tokenKind, singleTokenGLV)); } } break; case "ContextSetProviders": { foreach (XmlNode setProviderNode in possibility.ChildNodes) { MethodInfo provider = typeof(Genero4glAst).GetMethod(setProviderNode.InnerText, BindingFlags.NonPublic | BindingFlags.Static); if (provider != null) { MemberType mt = MemberType.All; var mta = provider.GetCustomAttributes(true).FirstOrDefault(x => x is MemberTypeAttribute); if (mta != null) { mt = (mta as MemberTypeAttribute).MemberType; } var del = Delegate.CreateDelegate(typeof(ContextSetProvider), provider); if (del != null) { GeneroLanguageVersion providerGLV = GeneroLanguageVersion.None; if (setProviderNode.Attributes["minLanguageVersion"] != null) { providerGLV = GeneroLanguageVersionExtensions.ToLanguageVersion(setProviderNode.Attributes["minLanguageVersion"].Value); } setProviders.Add(new ContextSetProviderContainer { Provider = del as ContextSetProvider, ReturningTypes = mt, MinimumLanguageVersion = providerGLV }); } } } } break; case "BackwardSearchItems": { foreach (XmlNode backwardItemNode in possibility.ChildNodes) { var childNodes = backwardItemNode.ChildNodes.Cast <XmlNode>().Where(x => !(x is XmlComment)).ToList(); if (backwardItemNode.Name == "BackwardTokenSearchItem" && childNodes.Count == 1) { GeneroLanguageVersion bsiGLV = GeneroLanguageVersion.None; if (backwardItemNode.Attributes["minLanguageVersion"] != null) { bsiGLV = GeneroLanguageVersionExtensions.ToLanguageVersion(backwardItemNode.Attributes["minLanguageVersion"].Value); } bool match = true; if (backwardItemNode.Attributes != null && backwardItemNode.Attributes["Match"] != null) { match = bool.Parse(backwardItemNode.Attributes["Match"].Value); } XmlNode backwardItem = childNodes[0]; if (backwardItem.Name == "Token") { TokenKind tokenKind; var token = Tokens.GetToken(backwardItem.InnerText); if (token != null) { tokenKind = token.Kind; } else { tokenKind = (TokenKind)Enum.Parse(typeof(TokenKind), backwardItem.InnerText); } backwardItems.Add(new BackwardTokenSearchItem(tokenKind, match, bsiGLV)); } else if (backwardItem.Name == "OrderedTokenSet") { List <TokenContainer> tokenSet = new List <TokenContainer>(); foreach (XmlNode tokenSetItem in backwardItem.ChildNodes) { object tokenItem = null; if (tokenSetItem.Attributes != null && tokenSetItem.Attributes["Type"].Value == "keyword") { var token = Tokens.GetToken(tokenSetItem.Attributes["Value"].Value); if (token != null) { tokenItem = token.Kind; } else { tokenItem = Enum.Parse(typeof(TokenKind), tokenSetItem.Attributes["Value"].Value); } } else if (tokenSetItem.Attributes != null && tokenSetItem.Attributes["Type"].Value == "category") { tokenItem = Enum.Parse(typeof(TokenCategory), tokenSetItem.Attributes["Value"].Value); } else { return(false); } if (tokenItem != null) { bool failIfMatch = false; var failValue = tokenSetItem.Attributes["FailIfMatch"]?.Value; if (failValue != null) { bool.TryParse(failValue, out failIfMatch); } tokenSet.Add(new TokenContainer { Token = tokenItem, FailIfMatch = failIfMatch }); } } backwardItems.Add(new BackwardTokenSearchItem(new OrderedTokenSet(tokenSet), match, bsiGLV)); } } } } break; } } possibilities.Add(new ContextPossibility(singleTokens.ToArray(), setProviders.ToArray(), backwardItems.ToArray(), contextPossibilityGLV)); } // add to the dictionary _contextMap.Add(key, new ContextEntry(possibilities, contextEntryGLV)); } } } else { return(false); } return(true); }
internal static void GotoSource(this LocationInfo location, IServiceProvider serviceProvider, GeneroLanguageVersion languageVersion) { if (location.Line > 0 && location.Column > 0) { VSGeneroPackage.NavigateTo( location.FilePath, Guid.Empty, location.Line - 1, location.Column - 1); } else if (location.DefinitionURL != null) { var urlStr = location.GetUrlString(languageVersion); Uri definitionUrl; if (Uri.TryCreate(urlStr, UriKind.Absolute, out definitionUrl)) { if (serviceProvider != null) { IVsWebBrowsingService service = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService; if (service != null) { if (VSGeneroPackage.Instance.AdvancedOptions4GL.OpenExternalBrowser) { __VSCREATEWEBBROWSER createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow; VSPREVIEWRESOLUTION resolution = VSPREVIEWRESOLUTION.PR_Default; int result = ErrorHandler.CallWithCOMConvention(() => service.CreateExternalWebBrowser((uint)createFlags, resolution, definitionUrl.AbsoluteUri)); if (ErrorHandler.Succeeded(result)) { return; } } else { IVsWindowFrame ppFrame; int result = ErrorHandler.CallWithCOMConvention(() => service.Navigate(definitionUrl.AbsoluteUri, 0, out ppFrame)); if (ErrorHandler.Succeeded(result)) { return; } } } } // Fall back to Shell Execute, but only for http or https URIs if (definitionUrl.Scheme != "http" && definitionUrl.Scheme != "https") { return; } try { Process.Start(definitionUrl.AbsoluteUri); } catch (Win32Exception) { } catch (FileNotFoundException) { } } } else { VSGeneroPackage.NavigateTo(location.FilePath, Guid.Empty, location.Index); } }
public PeekResultSource(IEnumerable <LocationInfo> locations, PeekableItemSourceProvider factory, GeneroLanguageVersion languageVersion) { _locations = locations; _factory = factory; _languageVersion = languageVersion; }
protected LanguageVersionSupported(GeneroLanguageVersion minLangVersion) { MinimumLanguageVersion = minLangVersion; }