/// <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); }
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); }
/// <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); }
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(); }
List<INode> Decl(IBlockNode Scope, DAttribute StorageClass = null) { var startLocation = la.Location; var initialComment = GetComments(); ITypeDeclaration ttd = null; CheckForStorageClasses(Scope); // 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 if(!IsEOF) 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)) { return null; } } else if (ttd is MemberFunctionAttributeDecl && (ttd as MemberFunctionAttributeDecl).InnerType == null) { 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)) { var init = Initializer (Scope); var dv = firstNode as DVariable; if (dv != null) dv.Initializer = init; } firstNode.EndLocation = t.EndLocation; var ret = new List<INode>(); ret.Add(firstNode); // DeclaratorIdentifierList while (laKind == Comma) { Step(); if (IsEOF || Expect (Identifier)) { var otherNode = new DVariable (); // 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; if (t.Kind == DTokens.Identifier) otherNode.Name = t.Value; else if(IsEOF) otherNode.NameHash = IncompleteIdHash; otherNode.NameLocation = t.Location; if (laKind == OpenParenthesis) TemplateParameterList (otherNode); if (laKind == Assign) otherNode.Initializer = Initializer (Scope); otherNode.EndLocation = t.EndLocation; ret.Add (otherNode); } else break; } Expect(Semicolon); // 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."); if (IsEOF) return new List<INode>{ firstNode }; 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 (IsBasicType() && laKind != Identifier) mye.Type = Type(); else if (laKind == Auto) { Step(); mye.Attributes.Add(new DAttribute(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; } } } if (IsDeclaratorSuffix) { var _unused = new List<INode>(); var bt2=DeclaratorSuffixes(out mye.TemplateParameters, out _unused, mye.Attributes); if (bt2 != null) { bt2.InnerDeclaration = mye.Type; mye.Type = bt2; } } // 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 DAttribute(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 { // Normal enum block Expect(OpenCurlyBrace); var OldPreviousComment = PreviousComment; PreviousComment = ""; mye.BlockStartLocation = t.Location; bool init = true; // While there are commas, loop through while ((init && laKind != (Comma)) || laKind == (Comma)) { if (!init) Step(); init = false; if (laKind == CloseCurlyBrace) break; var ev = new DEnumValue() { Location = la.Location, Description = GetComments(), Parent = mye }; LastParsedObject = ev; if (laKind == Identifier && ( Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind == Comma || Lexer.CurrentPeekToken.Kind == CloseCurlyBrace)) { Step(); ev.Name = t.Value; ev.NameLocation = t.Location; } else { ev.Type = Type(); Expect(Identifier); ev.Name = t.Value; ev.NameLocation = t.Location; } if (laKind == (Assign)) { Step(); ev.Initializer = AssignExpression(); } ev.EndLocation = t.EndLocation; ev.Description += CheckForPostSemicolonComment(); mye.Add(ev); } Expect(CloseCurlyBrace); PreviousComment = OldPreviousComment; mye.EndLocation = t.EndLocation; // Important: Add the enum block, whereas it CAN be unnamed, to the return array ret.Add(mye); } mye.Description += CheckForPostSemicolonComment(); return ret.ToArray(); }
INode[] Decl(bool HasStorageClassModifiers,IBlockNode Scope=null) { var startLocation = la.Location; var initialComment = GetComments(); ITypeDeclaration ttd = null; CheckForStorageClasses(); // Skip ref token if (laKind == (Ref)) { if (!DAttribute.ContainsAttribute(DeclarationAttributes, Ref)) PushAttribute(new DAttribute(Ref), false); Step(); } // Autodeclaration var StorageClass = DTokens.ContainsStorageClass(DeclarationAttributes.ToArray()); // If there's no explicit type declaration, leave our node's type empty! if ((StorageClass.Token != DAttribute.Empty.Token && laKind == (Identifier) && DeclarationAttributes.Count > 0)) // public auto var=0; // const foo(...) {} { if (PK(Assign) || PK(OpenParenthesis)) { } else if (PK(Semicolon)) { SemErr(StorageClass.Token, "Initializer expected for auto type, semicolon found!"); } else ttd = BasicType(); } else ttd = BasicType(); /* * 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 (IsEOF && tix!=null && (tix.Arguments == null || tix.Arguments[tix.Arguments.Length-1] is TokenExpression && ((TokenExpression)tix.Arguments[tix.Arguments.Length-1]).Token == DTokens.INVALID)) { LastParsedObject = ttd; return null; } // Declarators var firstNode = Declarator(ttd,false); firstNode.Description = initialComment; firstNode.Location = startLocation; ApplyAttributes(firstNode as DNode); // Check for declaration constraints if (laKind == (If)) Constraint(); // 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(); 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); } 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.ToArray(); } // BasicType Declarator FunctionBody else if (firstNode is DMethod && (laKind == In || laKind == Out || laKind == Body || laKind == OpenCurlyBrace)) { firstNode.Description += CheckForPostSemicolonComment(); FunctionBody((DMethod)firstNode); firstNode.Description += CheckForPostSemicolonComment(); return new[]{ firstNode}; } else SynErr(OpenCurlyBrace, "; or function body expected after declaration stub."); return null; }
private INode[] EnumDeclaration() { Expect(Enum); var ret = new List<INode>(); var mye = new DEnum() { StartLocation = t.Location, Description = GetComments() }; LastParsedObject = mye; ApplyAttributes(mye); if (IsBasicType() && laKind != Identifier) mye.Type = Type(); else if (laKind == Auto) { Step(); mye.Attributes.Add(new DAttribute(Auto)); } if (laKind == (Identifier)) { // Normal enum identifier if (Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (OpenCurlyBrace) || Lexer.CurrentPeekToken.Kind == (Semicolon) || Lexer.CurrentPeekToken.Kind == Colon) { Step(); mye.Name = t.Value; } else { mye.Type = Type(); Expect(Identifier); mye.Name = t.Value; } } // Enum inhertance type if (laKind == (Colon)) { Step(); mye.Type = Type(); } // Variables with 'enum' as base type if (laKind == (Assign) || laKind == (Semicolon)) { another_enumvalue: var enumVar = new DVariable(); LastParsedObject = enumVar; enumVar.AssignFrom(mye); enumVar.Attributes.Add(new DAttribute(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; } if (laKind == (Assign)) { Step(); enumVar.Initializer = AssignExpression(); } enumVar.EndLocation = t.Location; ret.Add(enumVar); // If there are more than one definitions, loop back if (laKind == (Comma)) goto another_enumvalue; Expect(Semicolon); } else { // Normal enum block Expect(OpenCurlyBrace); var OldPreviousComment = PreviousComment; PreviousComment = ""; mye.BlockStartLocation = t.Location; bool init = true; // While there are commas, loop through while ((init && laKind != (Comma)) || laKind == (Comma)) { if (!init) Step(); init = false; if (laKind == (CloseCurlyBrace)) break; var ev = new DEnumValue() { StartLocation = t.Location, Description = GetComments() }; LastParsedObject = ev; if (laKind == (Identifier) && (Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (Comma) || Lexer.CurrentPeekToken.Kind == (CloseCurlyBrace))) { Step(); ev.Name = t.Value; } else { ev.Type = Type(); Expect(Identifier); ev.Name = t.Value; } if (laKind == (Assign)) { Step(); ev.Initializer = AssignExpression(); } ev.EndLocation = t.EndLocation; ev.Description += CheckForPostSemicolonComment(); mye.Add(ev); } Expect(CloseCurlyBrace); PreviousComment = OldPreviousComment; mye.EndLocation = t.EndLocation; // Important: Add the enum block, whereas it CAN be unnamed, to the return array ret.Add(mye); } mye.Description += CheckForPostSemicolonComment(); return ret.ToArray(); }
INode[] Decl(bool HasStorageClassModifiers,IBlockNode Scope=null) { var startLocation = la.Location; var initialComment = GetComments(); ITypeDeclaration ttd = null; CheckForStorageClasses(); // Skip ref token if (laKind == (Ref)) { if (!DAttribute.ContainsAttribute(DeclarationAttributes, Ref)) PushAttribute(new DAttribute(Ref), false); Step(); } // Autodeclaration var StorageClass = DTokens.ContainsStorageClass(DeclarationAttributes.ToArray()); // If there's no explicit type declaration, leave our node's type empty! if ((StorageClass.Token != DAttribute.Empty.Token && laKind == (Identifier) && DeclarationAttributes.Count > 0 && (PK(Assign) || PK(OpenParenthesis)))) // public auto var=0; // const foo(...) {} { } else ttd = BasicType(); // Declarators var firstNode = Declarator(ttd,false); firstNode.Description = initialComment; firstNode.StartLocation = startLocation; ApplyAttributes(firstNode as DNode); // Check for declaration constraints if (laKind == (If)) Constraint(); // BasicType Declarators ; if (laKind==Assign || laKind==Comma || laKind==Semicolon) { // DeclaratorInitializer if (laKind == (Assign)) { TrackerVariables.InitializedNode = firstNode; if(firstNode is DVariable) (firstNode as DVariable).Initializer = Initializer(Scope); } firstNode.EndLocation = t.EndLocation; var ret = new List<INode>(); ret.Add(firstNode); // DeclaratorIdentifierList while (laKind == (Comma)) { Step(); 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.StartLocation = t.Location; otherNode.Name = t.Value; if (laKind == (Assign)) { TrackerVariables.InitializedNode = otherNode; otherNode.Initializer = Initializer(Scope); } otherNode.EndLocation = t.EndLocation; ret.Add(otherNode); } Expect(Semicolon); // 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.ToArray(); } // BasicType Declarator FunctionBody else if (firstNode is DMethod && (laKind == In || laKind == Out || laKind == Body || laKind == OpenCurlyBrace)) { firstNode.Description += CheckForPostSemicolonComment(); FunctionBody(firstNode as DMethod); firstNode.Description += CheckForPostSemicolonComment(); return new[]{ firstNode}; } else SynErr(OpenCurlyBrace, "; or function body expected after declaration stub."); return null; }
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); } }