static bool HandleDecl(DTokenDeclaration tk, AbstractType r) { if (r is PrimitiveType) return ResultComparer.IsPrimitiveTypeImplicitlyConvertible(((PrimitiveType)r).TypeToken, tk.Token); return false; }
static bool HandleDecl(DTokenDeclaration tk, AbstractType r) { if (r is PrimitiveType) return tk.Token == ((PrimitiveType)r).TypeToken; return false; }
/// <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); }
void IfCondition(IfStatement par) { var wkType = AllowWeakTypeParsing; AllowWeakTypeParsing = true; Lexer.PushLookAheadBackup(); ITypeDeclaration tp; if (laKind == Auto) { Step(); tp = new DTokenDeclaration(Auto) { Location=t.Location, EndLocation=t.EndLocation }; } else tp = Type(); AllowWeakTypeParsing = wkType; if (tp != null && ((laKind == Identifier && (Peek(1).Kind == Assign || Lexer.CurrentPeekToken.Kind == CloseParenthesis)) || IsEOF)) // if(a * b * c) is an expression, if(a * b = 123) may be a pointer variable { var dv = Declarator(tp, false, par.ParentNode) as DVariable; if (dv == null) { SynErr(t.Kind, "Invalid node type! - Variable expected!"); return; } if (laKind == Assign) { Step (); dv.Location = tp.Location; dv.Initializer = Expression(); dv.EndLocation = t.EndLocation; } par.IfVariable = dv; return; } Lexer.RestoreLookAheadBackup(); par.IfCondition = Expression(); }
public virtual void Visit(DTokenDeclaration td) { VisitInner(td); }
void IfCondition(IfStatement par) { var wkType = AllowWeakTypeParsing; AllowWeakTypeParsing = true; Lexer.PushLookAheadBackup(); ITypeDeclaration tp; if (laKind == Auto) { Step(); tp = new DTokenDeclaration(Auto) { Location=t.Location, EndLocation=t.EndLocation }; } else tp = Type(); AllowWeakTypeParsing = wkType; if (tp != null && laKind == Identifier) { var dv = Declarator(tp, false, par.ParentNode) as DVariable; if (dv == null) { SynErr(t.Kind, "Invalid node type! - Variable expected!"); return; } if (laKind == Assign) { Step (); dv.Location = tp.Location; dv.Initializer = Expression(); dv.EndLocation = t.EndLocation; par.IfVariable = dv; return; } } if (IsEOF && tp != null && !(tp is IdentifierDeclaration || tp is DTokenDeclaration && (tp as DTokenDeclaration).Token == DTokens.INVALID)) { /* * Ambigious situation: if(e| -- is this an inline declaration or the start of a postfix_access expression á la 'e.'? */ TrackerVariables.ExpectingNodeName = true; } else { Lexer.RestoreLookAheadBackup(); par.IfCondition = Expression(); } }
void IfCondition(IfStatement par) { var wkType = AllowWeakTypeParsing; AllowWeakTypeParsing = true; var la_backup = la; ITypeDeclaration tp = null; if (laKind == Auto) { Step(); tp = new DTokenDeclaration(t.Kind) { Location=t.Location, EndLocation=t.EndLocation }; } else tp = Type(); AllowWeakTypeParsing = wkType; if (tp != null && laKind == Identifier && ( Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind == Comma || Lexer.CurrentPeekToken.Kind == CloseParenthesis)) { var ifVars = new List<DVariable>(); do { if (laKind == Comma) Step(); var n = Declarator(tp, false); n.Location = tp.Location; // Initializer is optional if (laKind == Assign) { Step(); if (n is DVariable) ((DVariable)n).Initializer = Expression(par.ParentNode as IBlockNode); } n.EndLocation = t.EndLocation; } while (laKind == Comma); par.IfVariable = ifVars.ToArray(); } else { la = la_backup; par.IfCondition = Expression(); } }
public override void Visit(DTokenDeclaration td) { if (td.Token == DTokens.Incomplete) { if (handlesBaseClasses) { MemberFilter vis; if (handledClass.ClassType == DTokens.Interface) vis = MemberFilter.Interfaces | MemberFilter.Templates; else vis = MemberFilter.Classes | MemberFilter.Interfaces | MemberFilter.Templates; prv = new CtrlSpaceCompletionProvider (cdgen, handledClass, null, vis); } else if (td.InnerDeclaration != null) prv = new MemberCompletionProvider (cdgen, td.InnerDeclaration, scopedBlock, scopedStatement); else prv = new CtrlSpaceCompletionProvider (cdgen, scopedBlock, scopedStatement); halt = true; } else base.Visit (td); }
IEnumerable<INode> Decl(IBlockNode Scope, DAttribute StorageClass = null, bool isAlias = false) { 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 (Scope); } else if (!IsEOF) { // standalone this/super only allowed in alias declarations if (isAlias && (laKind == DTokens.This || laKind == DTokens.Super) && Lexer.CurrentPeekToken.Kind != DTokens.Dot) { ttd = new DTokenDeclaration (laKind) { Location = la.Location, EndLocation = la.EndLocation }; Step (); } else ttd = BasicType (Scope); } 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)) { yield break; } } else if (ttd is MemberFunctionAttributeDecl && (ttd as MemberFunctionAttributeDecl).InnerType == null) { yield break; } } // Declarators var firstNode = Declarator(ttd,false, Scope); if (firstNode == null) yield break; 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; yield return firstNode; // DeclaratorIdentifierList var otherNode = firstNode; while (laKind == Comma) { Step(); if (IsEOF || Expect (Identifier)) { 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 as DVariable).Initializer = Initializer (Scope); otherNode.EndLocation = t.EndLocation; yield return otherNode; } else break; } Expect(Semicolon); // Note: In DDoc, only the really last declaration will get the post semicolon comment appended otherNode.Description += CheckForPostSemicolonComment(); yield break; } // BasicType Declarator FunctionBody else if (firstNode is DMethod && (IsFunctionBody || IsEOF)) { firstNode.Description += CheckForPostSemicolonComment(); FunctionBody((DMethod)firstNode); firstNode.Description += CheckForPostSemicolonComment(); yield return firstNode; yield break; } else SynErr(OpenCurlyBrace, "; or function body expected after declaration stub."); if (IsEOF) yield return firstNode; }
public ITypeDeclaration IdentifierList(IBlockNode scope = null) { ITypeDeclaration td = null; switch (laKind) { case DTokens.This: case DTokens.Super: Step (); td = new DTokenDeclaration (t.Kind) { Location = t.Location, EndLocation = t.EndLocation }; if (!Expect (DTokens.Dot)) return td; break; } bool notInit = false; do { if (notInit) Step(); else notInit = true; ITypeDeclaration ttd; if (IsTemplateInstance) ttd = TemplateInstance(scope); else if (Expect(Identifier)) ttd = new IdentifierDeclaration(t.Value) { Location = t.Location, EndLocation = t.EndLocation }; else if (IsEOF) return new DTokenDeclaration(DTokens.Incomplete, td); else ttd = null; if (ttd != null) ttd.InnerDeclaration = td; td = ttd; } while (laKind == Dot); return td; }
ITypeDeclaration BasicType2() { // * if (laKind == (Times)) { Step(); return new PointerDecl() { Location=t.Location, EndLocation=t.EndLocation }; } // [ ... ] else if (laKind == (OpenSquareBracket)) { var startLoc = la.Location; Step(); // [ ] if (laKind == (CloseSquareBracket)) { Step(); return new ArrayDecl() { Location=startLoc, EndLocation=t.EndLocation }; } ITypeDeclaration cd = null; // [ Type ] if (!IsAssignExpression()) { var la_backup = la; bool weaktype = AllowWeakTypeParsing; AllowWeakTypeParsing = true; var keyType = Type(); AllowWeakTypeParsing = weaktype; if (keyType != null && laKind == CloseSquareBracket) cd = new ArrayDecl() { KeyType = keyType, Location=startLoc }; else la = la_backup; } if(cd==null) { var fromExpression = AssignExpression(); // [ AssignExpression .. AssignExpression ] if (laKind == DoubleDot) { Step(); cd = new ArrayDecl() { Location=startLoc ,KeyExpression= new PostfixExpression_Slice() { FromExpression=fromExpression, ToExpression=AssignExpression()}}; } else cd = new ArrayDecl() { KeyExpression=fromExpression,Location=startLoc }; } if (AllowWeakTypeParsing && laKind != CloseSquareBracket) return null; Expect(CloseSquareBracket); if(cd!=null) cd.EndLocation = t.EndLocation; return cd; } // delegate | function else if (laKind == (Delegate) || laKind == (Function)) { Step(); ITypeDeclaration td = null; var dd = new DelegateDeclaration() { Location=t.Location}; dd.IsFunction = t.Kind == Function; dd.Parameters = Parameters(null); td = dd; //TODO: add attributes to declaration while (FunctionAttribute[laKind]) { Step(); td = new DTokenDeclaration(t.Kind, td) { Location=t.Location, EndLocation=t.EndLocation }; } td.EndLocation = t.EndLocation; return td; } else SynErr(Identifier); return null; }
void IfCondition(IfStatement par) { if (Lexer.CurrentPeekToken.Kind == Times || IsAssignExpression()) par.IfCondition = Expression(); else { var sl = la.Location; ITypeDeclaration tp = null; if (laKind == Auto) { tp = new DTokenDeclaration(laKind); Step(); } else tp = BasicType(); DNode n = null; repeated_decl: n = Declarator(tp, false); n.StartLocation = sl; // Initializer is optional if (laKind == Assign) { Expect(Assign); (n as DVariable).Initializer = Expression(); } n.EndLocation = t.EndLocation; par.IfVariable=n as DVariable; if (laKind == Comma) { Step(); goto repeated_decl; } } }
public override void Visit(DTokenDeclaration td) { if (td.Token == DTokens.Incomplete && peek is TemplateInstanceExpression) LastCallExpression = peek; }
public static PrimitiveType Resolve(DTokenDeclaration token) { var tk = (token as DTokenDeclaration).Token; if (DTokens.BasicTypes[tk]) return new PrimitiveType(tk, 0, token); return null; }