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); }
/// <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); }
/// <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); }
List<INode> Decl(bool HasStorageClassModifiers,IBlockNode Scope, DAttribute StorageClass = null) { var startLocation = la.Location; var initialComment = GetComments(); ITypeDeclaration ttd = null; CheckForStorageClasses(Scope as DBlockNode); // Autodeclaration if(StorageClass == null) StorageClass = DTokens.ContainsStorageClass(DeclarationAttributes); if (laKind == Enum) { Step(); PushAttribute(StorageClass = new Modifier(Enum) { Location = t.Location, EndLocation = t.EndLocation },false); } // If there's no explicit type declaration, leave our node's type empty! if ((StorageClass != Modifier.Empty && laKind == (Identifier) && (DeclarationAttributes.Count > 0 || Lexer.CurrentPeekToken.Kind == OpenParenthesis))) // public auto var=0; // const foo(...) {} { if (Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind ==OpenParenthesis) { } else if (Lexer.CurrentPeekToken.Kind == Semicolon) { SemErr(t.Kind, "Initializer expected for auto type, semicolon found!"); } else ttd = BasicType(); } else ttd = BasicType(); if (IsEOF) { /* * T! -- tix.Arguments == null * T!(int, -- last argument == null * T!(int, bool, -- ditto * T!(int) -- now every argument is complete */ var tix=ttd as TemplateInstanceExpression; if (tix != null) { if (tix.Arguments == null || tix.Arguments.Length == 0 || (tix.Arguments [tix.Arguments.Length - 1] is TokenExpression && (tix.Arguments [tix.Arguments.Length - 1] as TokenExpression).Token == DTokens.INVALID)) { LastParsedObject = ttd; return null; } } else if (ttd is MemberFunctionAttributeDecl && (ttd as MemberFunctionAttributeDecl).InnerType == null) { LastParsedObject = ttd; return null; } } // Declarators var firstNode = Declarator(ttd,false, Scope); if (firstNode == null) return null; firstNode.Description = initialComment; firstNode.Location = startLocation; // Check for declaration constraints if (laKind == (If)) Constraint(firstNode); // BasicType Declarators ; if (laKind==Assign || laKind==Comma || laKind==Semicolon) { // DeclaratorInitializer if (laKind == (Assign)) { TrackerVariables.InitializedNode = firstNode; var dv = firstNode as DVariable; if(dv!=null) dv.Initializer = Initializer(Scope); } firstNode.EndLocation = t.EndLocation; var ret = new List<INode>(); ret.Add(firstNode); // DeclaratorIdentifierList while (laKind == Comma) { Step(); if (Expect(Identifier)) { var otherNode = new DVariable(); LastParsedObject = otherNode; /// Note: In DDoc, all declarations that are made at once (e.g. int a,b,c;) get the same pre-declaration-description! otherNode.Description = initialComment; otherNode.AssignFrom(firstNode); otherNode.Location = t.Location; otherNode.Name = t.Value; otherNode.NameLocation = t.Location; if (laKind == (Assign)) { TrackerVariables.InitializedNode = otherNode; otherNode.Initializer = Initializer(Scope); } otherNode.EndLocation = t.EndLocation; ret.Add(otherNode); } else break; } if (Expect(Semicolon)) LastParsedObject = null; // Note: In DDoc, only the really last declaration will get the post semicolon comment appended if (ret.Count > 0) ret[ret.Count - 1].Description += CheckForPostSemicolonComment(); return ret; } // BasicType Declarator FunctionBody else if (firstNode is DMethod && (IsFunctionBody || IsEOF)) { firstNode.Description += CheckForPostSemicolonComment(); FunctionBody((DMethod)firstNode); firstNode.Description += CheckForPostSemicolonComment(); var ret = new List<INode> (); ret.Add (firstNode); return ret; } else SynErr(OpenCurlyBrace, "; or function body expected after declaration stub."); return null; }
private INode[] EnumDeclaration(INode Parent) { Expect(Enum); var ret = new List<INode>(); var mye = new DEnum() { Location = t.Location, Description = GetComments(), Parent=Parent }; LastParsedObject = mye; ApplyAttributes(mye); if (laKind != Identifier && IsBasicType()) mye.Type = Type(); else if (laKind == Auto) { Step(); mye.Attributes.Add(new Modifier(Auto)); } if (laKind == (Identifier)) { // Normal enum identifier if (Lexer.CurrentPeekToken.Kind == (Assign) || // enum e = 1234; Lexer.CurrentPeekToken.Kind == (OpenCurlyBrace) || // enum e { A,B,C, } Lexer.CurrentPeekToken.Kind == (Semicolon) || // enum e; Lexer.CurrentPeekToken.Kind == Colon) { // enum e : uint {..} Step (); mye.Name = t.Value; mye.NameLocation = t.Location; } else { if (mye.Type == null) mye.Type = Type(); if (Expect(Identifier)) { mye.Name = t.Value; mye.NameLocation = t.Location; } } } else if (IsEOF) ExpectingNodeName = true; if (IsDeclaratorSuffix) { DeclaratorSuffixes(mye); } // Enum inhertance type if (laKind == (Colon)) { Step(); mye.Type = Type(); } // Variables with 'enum' as base type if (laKind == (Assign) || laKind == (Semicolon)) { do { var enumVar = new DVariable(); LastParsedObject = enumVar; enumVar.AssignFrom(mye); enumVar.Attributes.Add(new Modifier(Enum)); if (mye.Type != null) enumVar.Type = mye.Type; else enumVar.Type = new DTokenDeclaration(Enum); if (laKind == (Comma)) { Step(); Expect(Identifier); enumVar.Name = t.Value; enumVar.NameLocation = t.Location; } if (laKind == (Assign)) { //Step(); -- expected by initializer enumVar.Initializer = Initializer(); // Seems to be specified wrongly - theoretically there must be an AssignExpression(); } enumVar.EndLocation = t.Location; ret.Add(enumVar); } while (laKind == Comma); Expect(Semicolon); } else if (laKind == OpenCurlyBrace) // Normal enum block { EnumBody(mye); ret.Add(mye); } mye.Description += CheckForPostSemicolonComment(); return ret.ToArray(); }
void BuildCompletionData(UserDefinedType tr, ItemVisibility visMod) { var n = tr.Definition; if (n is DClassLike) // Add public static members of the class and including all base classes { var propertyMethodsToIgnore = new List <string>(); var curlevel = tr; var tvisMod = visMod; while (curlevel != null) { foreach (var i in curlevel.Definition as DBlockNode) { var dn = i as DNode; if (i != null && dn == null) { CompletionDataGenerator.Add(i); continue; } bool add = false; if (tvisMod.HasFlag(ItemVisibility.All)) { add = true; } else { if (tvisMod.HasFlag(ItemVisibility.ProtectedMembers)) { add |= dn.ContainsAttribute(DTokens.Protected); } if (tvisMod.HasFlag(ItemVisibility.ProtectedStaticMembers)) { add |= dn.ContainsAttribute(DTokens.Protected) && (dn.IsStatic || IsTypeNode(i)); } if (tvisMod.HasFlag(ItemVisibility.PublicMembers)) { add |= dn.IsPublic; } if (tvisMod.HasFlag(ItemVisibility.PublicStaticMembers)) { add |= dn.IsPublic && (dn.IsStatic || IsTypeNode(i)); } if (tvisMod.HasFlag(ItemVisibility.StaticMembers)) { add |= dn.IsStatic || IsTypeNode(i); } } if (add) { if (CanItemBeShownGenerally(dn)) { // Convert @property getters&setters to one unique property if (dn is DMethod && dn.ContainsPropertyAttribute()) { if (!propertyMethodsToIgnore.Contains(dn.Name)) { var dm = dn as DMethod; bool isGetter = dm.Parameters.Count < 1; var virtPropNode = new DVariable(); virtPropNode.AssignFrom(dn); if (!isGetter) { virtPropNode.Type = dm.Parameters[0].Type; } CompletionDataGenerator.Add(virtPropNode); propertyMethodsToIgnore.Add(dn.Name); } } else { CompletionDataGenerator.Add(dn); } } // Add members of anonymous enums else if (dn is DEnum && string.IsNullOrEmpty(dn.Name)) { foreach (var k in dn as DEnum) { CompletionDataGenerator.Add(k); } } } } curlevel = curlevel.Base as UserDefinedType; // After having shown all items on the current node level, // allow showing public (static) and/or protected items in the more basic levels then if (tvisMod.HasFlag(ItemVisibility.All)) { if ((n as DClassLike).ContainsAttribute(DTokens.Static)) { tvisMod = ItemVisibility.ProtectedStaticMembers | ItemVisibility.PublicStaticMembers; } else { tvisMod = ItemVisibility.ProtectedMembers | ItemVisibility.PublicMembers; } } } } else if (n is DEnum) { var de = n as DEnum; foreach (var i in de) { if (i is DEnumValue) { CompletionDataGenerator.Add(i); } } } }