/// <summary> /// Adds init, max, min to the completion list /// </summary> public static void AddIntegralTypeProperties(int TypeToken, ResolveResult rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { var intType = new DTokenDeclaration(TypeToken); if (!DontAddInitProperty) { var prop_Init = new DVariable() { Type = intType, Initializer = new IdentifierExpression(0, LiteralFormat.Scalar) }; if (relatedNode != null) { prop_Init.AssignFrom(relatedNode); } // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(IntegralProps, cdg, intType); }
public static void AddFloatingTypeProperties(int TypeToken, ResolveResult rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { var intType = new DTokenDeclaration(TypeToken); if (!DontAddInitProperty) { var prop_Init = new DVariable() { Type = intType, Initializer = new PostfixExpression_Access() { PostfixForeExpression = new TokenExpression(TypeToken), TemplateOrIdentifier = new IdentifierDeclaration("nan") } }; if (relatedNode != null) { prop_Init.AssignFrom(relatedNode); } // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(FloatingTypeProps, cdg, intType); }
protected override bool HandleItem(INode n) { switch (n.NameHash) { case -1: case 0: case 1: return(false); default: if (n.NameHash == D_Parser.Parser.DTokens.IncompleteIdHash) { return(false); } break; } var dv = n as DVariable; if (isVarInst || !(n is DMethod || dv != null || n is TemplateParameter.Node) || (n as DNode).IsStatic || n is DEnumValue || (dv != null && (dv.IsConst || dv.IsAlias))) { if (n is DModule) { gen.AddModule(n as DModule); } else { gen.Add(n); } } return(false); }
protected override bool HandleItem(INode n) { if (!alreadyTakenNames.Contains(n.NameHash)) { gen.Add(n); } return(false); }
public static void ListProperties(ICompletionDataGenerator gen, MemberFilter vis, AbstractType t, bool isVariableInstance) { foreach (var n in ListProperties(t, !isVariableInstance)) { if (AbstractVisitor.CanAddMemberOfType(vis, n)) { gen.Add(n); } } }
public static void AddArrayProperties(ResolveResult rr, ICompletionDataGenerator cdg, ArrayDecl ArrayDecl = null) { CreateArtificialProperties(ArrayProps, cdg, ArrayDecl); cdg.Add(new DVariable { Name = "ptr", Description = "Returns pointer to the array", Type = new PointerDecl(ArrayDecl == null ? new DTokenDeclaration(DTokens.Void) : ArrayDecl.ValueType) }); }
public static void AddArrayProperties(ISemantic rr, ICompletionDataGenerator cdg, ArrayDecl ArrayDecl = null) { CreateArtificialProperties(ArrayProps, cdg, ArrayDecl); cdg.Add(new DVariable { Name = "ptr", Description = "Returns pointer to the array", Type = new PointerDecl(ArrayDecl == null ? new DTokenDeclaration(DTokens.Void) : ArrayDecl.ValueType) }); }
public static void Generate(ISemantic rr, ResolutionContext ctxt, IEditorData ed, ICompletionDataGenerator gen) { if(ed.ParseCache!=null) foreach (var pc in ed.ParseCache) if (pc != null && pc.UfcsCache != null && pc.UfcsCache.CachedMethods != null) { var r=pc.UfcsCache.FindFitting(ctxt, ed.CaretLocation, rr); if(r!=null) foreach (var m in r) gen.Add(m); } }
// Associative Arrays' properties have to be inserted manually static void CreateArtificialProperties(StaticProperty[] Properties, ICompletionDataGenerator cdg, ITypeDeclaration DefaultPropType = null) { foreach (var prop in Properties) { var p = new DVariable() { Name = prop.Name, Description = prop.Description, Type = prop.OverrideType != null ? prop.OverrideType : DefaultPropType }; cdg.Add(p); } }
protected override bool HandleItem(INode n) { var dv = n as DVariable; if (isVarInst || !(n is DMethod || dv != null || n is TemplateParameter.Node) || (n as DNode).IsStatic || n is DEnumValue || (dv != null && (dv.IsConst || dv.IsAlias))) { if (n is DModule) { gen.AddModule(n as DModule); } else { gen.Add(n); } } return(false); }
public static void Generate(ISemantic rr, ResolutionContext ctxt, IEditorData ed, ICompletionDataGenerator gen) { if (ed.ParseCache != null) { foreach (var pc in ed.ParseCache) { if (pc != null && pc.UfcsCache != null && pc.UfcsCache.CachedMethods != null) { var r = pc.UfcsCache.FindFitting(ctxt, ed.CaretLocation, rr); if (r != null) { foreach (var m in r) { gen.Add(m); } } } } } }
/// <summary> /// Adds init, sizeof, alignof, mangleof, stringof to the completion list /// </summary> public static void AddGenericProperties(ResolveResult rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { if (!DontAddInitProperty) { var prop_Init = new DVariable(); if (relatedNode != null) { prop_Init.AssignFrom(relatedNode); } // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(GenericProps, cdg); }
public static void AddAssocArrayProperties(ResolveResult rr, ICompletionDataGenerator cdg, ArrayDecl ad) { var ll = new List <INode>(); ll.Add(new DVariable() { Name = "sizeof", Description = "Returns the size of the reference to the associative array; it is typically 8.", Type = new IdentifierDeclaration("size_t"), Initializer = new IdentifierExpression(8, LiteralFormat.Scalar) }); /*ll.Add(new DVariable() { * Name="length", * Description="Returns number of values in the associative array. Unlike for dynamic arrays, it is read-only.", * Type=new IdentifierDeclaration("size_t") * });*/ if (ad != null) { ll.Add(new DVariable() { Name = "keys", Description = "Returns dynamic array, the elements of which are the keys in the associative array.", Type = new ArrayDecl() { ValueType = ad.KeyType } }); ll.Add(new DVariable() { Name = "values", Description = "Returns dynamic array, the elements of which are the values in the associative array.", Type = new ArrayDecl() { ValueType = ad.ValueType } }); ll.Add(new DVariable() { Name = "rehash", Description = "Reorganizes the associative array in place so that lookups are more efficient. rehash is effective when, for example, the program is done loading up a symbol table and now needs fast lookups in it. Returns a reference to the reorganized array.", Type = ad }); ll.Add(new DVariable() { Name = "byKey", Description = "Returns a delegate suitable for use as an Aggregate to a ForeachStatement which will iterate over the keys of the associative array.", Type = new DelegateDeclaration() { ReturnType = new ArrayDecl() { ValueType = ad.KeyType } } }); ll.Add(new DVariable() { Name = "byValue", Description = "Returns a delegate suitable for use as an Aggregate to a ForeachStatement which will iterate over the values of the associative array.", Type = new DelegateDeclaration() { ReturnType = new ArrayDecl() { ValueType = ad.ValueType } } }); ll.Add(new DMethod() { Name = "get", Description = "Looks up key; if it exists returns corresponding value else evaluates and returns defaultValue.", Type = ad.ValueType, Parameters = new List <INode> { new DVariable() { Name = "key", Type = ad.KeyType }, new DVariable() { Name = "defaultValue", Type = ad.ValueType, Attributes = new List <DAttribute> { new DAttribute(DTokens.Lazy) } } } }); } foreach (var prop in ll) { cdg.Add(prop); } }
public static void ListProperties(ICompletionDataGenerator gen, ResolutionContext ctxt, MemberFilter vis, AbstractType t, bool isVariableInstance) { foreach (var n in ListProperties(t, ctxt, !isVariableInstance)) if (AbstractVisitor.CanAddMemberOfType(vis, n)) gen.Add(n); }
public static void AddAssocArrayProperties(ISemantic rr, ICompletionDataGenerator cdg, ArrayDecl ad) { var ll = new List<INode>(); /*ll.Add(new DVariable() { Name = "sizeof", Description = "Returns the size of the reference to the associative array; it is typically 8.", Type = new IdentifierDeclaration("size_t"), Initializer = new IdentifierExpression(8, LiteralFormat.Scalar) });*/ ll.Add(new DVariable() { Name="length", Description="Returns number of values in the associative array. Unlike for dynamic arrays, it is read-only.", Type = new IdentifierDeclaration("size_t"), Initializer= ad!=null? ad.KeyExpression : null }); if (ad != null) { ll.Add(new DVariable() { Name = "keys", Description = "Returns dynamic array, the elements of which are the keys in the associative array.", Type = new ArrayDecl() { ValueType = ad.KeyType } }); ll.Add(new DVariable() { Name = "values", Description = "Returns dynamic array, the elements of which are the values in the associative array.", Type = new ArrayDecl() { ValueType = ad.ValueType } }); ll.Add(new DVariable() { Name = "rehash", Description = "Reorganizes the associative array in place so that lookups are more efficient. rehash is effective when, for example, the program is done loading up a symbol table and now needs fast lookups in it. Returns a reference to the reorganized array.", Type = ad }); ll.Add(new DVariable() { Name = "byKey", Description = "Returns a delegate suitable for use as an Aggregate to a ForeachStatement which will iterate over the keys of the associative array.", Type = new DelegateDeclaration() { ReturnType = new ArrayDecl() { ValueType = ad.KeyType } } }); ll.Add(new DVariable() { Name = "byValue", Description = "Returns a delegate suitable for use as an Aggregate to a ForeachStatement which will iterate over the values of the associative array.", Type = new DelegateDeclaration() { ReturnType = new ArrayDecl() { ValueType = ad.ValueType } } }); ll.Add(new DMethod() { Name = "get", Description = "Looks up key; if it exists returns corresponding value else evaluates and returns defaultValue.", Type = ad.ValueType, Parameters = new List<INode> { new DVariable(){ Name="key", Type=ad.KeyType }, new DVariable(){ Name="defaultValue", Type=ad.ValueType, Attributes=new List<DAttribute>{ new DAttribute(DTokens.Lazy)} } } }); } foreach (var prop in ll) cdg.Add(prop); }
/// <summary> /// Adds init, max, min to the completion list /// </summary> public static void AddIntegralTypeProperties(int TypeToken, ISemantic rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { var intType = new DTokenDeclaration(TypeToken); if (!DontAddInitProperty) { var prop_Init = new DVariable() { Type = intType, Initializer = new IdentifierExpression(0, LiteralFormat.Scalar) }; if (relatedNode != null) prop_Init.AssignFrom(relatedNode); // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(IntegralProps, cdg, intType); }
/// <summary> /// Adds init, sizeof, alignof, mangleof, stringof to the completion list /// </summary> public static void AddGenericProperties(ISemantic rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { if (!DontAddInitProperty) { var prop_Init = new DVariable(); if (relatedNode != null) prop_Init.AssignFrom(relatedNode); // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(GenericProps, cdg); }
public static void AddFloatingTypeProperties(int TypeToken, ISemantic rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { var intType = new DTokenDeclaration(TypeToken); if (!DontAddInitProperty) { var prop_Init = new DVariable() { Type = intType, Initializer = new PostfixExpression_Access() { PostfixForeExpression = new TokenExpression(TypeToken), AccessExpression = new IdentifierExpression("nan") } }; if (relatedNode != null) prop_Init.AssignFrom(relatedNode); // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(FloatingTypeProps, cdg, intType); }
public void BuildCompletionData(IEditorData Editor, string EnteredText, out string lastResultPath) { lastResultPath = null; IStatement curStmt = null; var curBlock = DResolver.SearchBlockAt(Editor.SyntaxTree, Editor.CaretLocation, out curStmt); if (curBlock == null) { return; } IEnumerable <INode> listedItems = null; // Usually shows variable members #region DotCompletion if (EnteredText == ".") { alreadyAddedModuleNameParts.Clear(); var resolveResults = DResolver.ResolveType( Editor, new ResolverContext { ScopedBlock = curBlock, ParseCache = Editor.ParseCache, ImportCache = Editor.ImportCache, ScopedStatement = curStmt } ); if (resolveResults == null) //TODO: Add after-space list creation when an unbound . (Dot) was entered which means to access the global scope { return; } /* * Note: When having entered a module name stub only (e.g. "std." or "core.") it's needed to show all packages that belong to that root namespace */ foreach (var rr in resolveResults) { lastResultPath = ResolveResult.GetResolveResultString(rr); BuildCompletionData(rr, curBlock); } } #endregion else if (EnteredText == null || EnteredText == " " || EnteredText.Length < 1 || IsIdentifierChar(EnteredText[0])) { // 1) Get current context the caret is at. ParserTrackerVariables trackVars = null; var parsedBlock = DResolver.FindCurrentCaretContext( Editor.ModuleCode, curBlock, Editor.CaretOffset, Editor.CaretLocation, out trackVars); bool CaretAfterLastParsedObject = false; if (trackVars != null && trackVars.LastParsedObject != null) { if (trackVars.LastParsedObject is IExpression) { CaretAfterLastParsedObject = Editor.CaretLocation > (trackVars.LastParsedObject as IExpression).EndLocation; } else if (trackVars.LastParsedObject is INode) { CaretAfterLastParsedObject = Editor.CaretLocation > (trackVars.LastParsedObject as INode).EndLocation; } } // 2) If in declaration and if node identifier is expected, do not show any data if (trackVars == null || (trackVars.LastParsedObject is INode && !CaretAfterLastParsedObject && trackVars.ExpectingIdentifier) || (trackVars.LastParsedObject is TokenExpression && !CaretAfterLastParsedObject && DTokens.BasicTypes[(trackVars.LastParsedObject as TokenExpression).Token] && !string.IsNullOrEmpty(EnteredText) && IsIdentifierChar(EnteredText[0])) ) { return; } var visibleMembers = DResolver.MemberTypes.All; if (trackVars.LastParsedObject is ImportStatement && !CaretAfterLastParsedObject) { visibleMembers = DResolver.MemberTypes.Imports; } else if (trackVars.LastParsedObject is NewExpression && (trackVars.IsParsingInitializer || !CaretAfterLastParsedObject)) { visibleMembers = DResolver.MemberTypes.Imports | DResolver.MemberTypes.Types; } else if (EnteredText == " ") { return; } // In class bodies, do not show variables else if (!(parsedBlock is BlockStatement) && !trackVars.IsParsingInitializer) { visibleMembers = DResolver.MemberTypes.Imports | DResolver.MemberTypes.Types | DResolver.MemberTypes.Keywords; } // In a method, parse from the method's start until the actual caret position to get an updated insight if (visibleMembers.HasFlag(DResolver.MemberTypes.Variables) && curBlock is DMethod) { if (parsedBlock is BlockStatement) { var blockStmt = parsedBlock as BlockStatement; // Insert the updated locals insight. // Do not take the caret location anymore because of the limited parsing of our code. var scopedStmt = blockStmt.SearchStatementDeeply(blockStmt.EndLocation /*Editor.CaretLocation*/); var decls = BlockStatement.GetItemHierarchy(scopedStmt, Editor.CaretLocation); foreach (var n in decls) { CompletionDataGenerator.Add(n); } } } if (visibleMembers != DResolver.MemberTypes.Imports) // Do not pass the curStmt because we already inserted all updated locals a few lines before! { listedItems = DResolver.EnumAllAvailableMembers(curBlock, null /*, curStmt*/, Editor.CaretLocation, Editor.ParseCache, visibleMembers); } //TODO: Split the keywords into such that are allowed within block statements and non-block statements // Insert typable keywords if (visibleMembers.HasFlag(DResolver.MemberTypes.Keywords)) { foreach (var kv in DTokens.Keywords) { CompletionDataGenerator.Add(kv.Key); } } #region Add module name stubs of importable modules if (visibleMembers.HasFlag(DResolver.MemberTypes.Imports)) { var nameStubs = new Dictionary <string, string>(); var availModules = new List <IAbstractSyntaxTree>(); foreach (var mod in Editor.ParseCache) { if (string.IsNullOrEmpty(mod.ModuleName)) { continue; } var parts = mod.ModuleName.Split('.'); if (!nameStubs.ContainsKey(parts[0]) && !availModules.Contains(mod)) { if (parts[0] == mod.ModuleName) { availModules.Add(mod); } else { nameStubs.Add(parts[0], GetModulePath(mod.FileName, parts.Length, 1)); } } } foreach (var kv in nameStubs) { CompletionDataGenerator.Add(kv.Key, PathOverride: kv.Value); } foreach (var mod in availModules) { CompletionDataGenerator.Add(mod.ModuleName, mod); } } #endregion } // Add all found items to the referenced list if (listedItems != null) { foreach (var i in listedItems) { if (CanItemBeShownGenerally(i) /* && dm.IsStatic*/) { CompletionDataGenerator.Add(i); } } } }