static void Connect(ILangElement element, ILangElement parent) { if (element != null) { element.ContainingElement = parent; } }
public override void VisitElement(ILangElement element) { Debug.Assert(element is TypeRef); var stack = _results.Count; base.VisitElement(element); Debug.Assert(_results.Count == stack + 1); }
public override void VisitElement(ILangElement element) { if (element != null) { Assert.IsNotNull(element.ContainingElement); base.VisitElement(element); } }
public override void VisitElement(ILangElement element) { // TODO - PHPDocBlock is not created by Lexer and CompliantLexer, without the factory if (element != null && !(element is PHPDocBlock)) { Assert.IsTrue(_visitedElements.Add(element)); base.VisitElement(element); } }
/// <summary> /// Gets list of direct child nodes. /// Cannot be <c>null</c>. /// </summary> public ReadOnlySpan <ILangElement> GetChildren(ILangElement element) { if (element != null) { _childrenCount = 0; element.VisitMe(this); return(_children.AsSpan(0, _childrenCount)); } // return(ReadOnlySpan <ILangElement> .Empty); }
void AddChild(ILangElement element) { if (element != null) { if (_childrenCount == _children.Length) { Array.Resize(ref _children, (_children.Length + 2) * 2); } _children[_childrenCount++] = element; } }
/// <summary> /// Iterates through containing elements to find closest element of type <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">Type of element to look for.</typeparam> /// <returns>Reference to element of type <typeparamref name="T"/> or <c>null</c> is not containing.</returns> public static T LookupContainingElement <T>(this ILangElement element) where T : ILangElement { for (; element != null; element = element.ContainingElement) { if (element is T t) { return(t); } } return(default(T)); }
public LambdaFunctionExpr( Text.Span span, Text.Span headingSpan, Signature signature, IList <FormalParam> useParams, ILangElement /*!*/ body, TypeRef returnType) : base(span) { this.Signature = signature; this.UseParams = useParams; this.body = body; this.ReturnType = returnType; _headingEnd = headingSpan.End; }
protected virtual bool IsScopeElement(ILangElement element) { return (element is IStatement || element is GlobalCode || // element is TypeDecl || // handled in TokenVisitor element is TraitsUse.TraitAdaptation || element is MethodDecl || element is LambdaFunctionExpr || element is CatchItem || element is FieldDeclList || element is FinallyItem); }
public override void VisitElement(ILangElement element) { if (IsScopeElement(element)) { using (new ScopeHelper(this, element)) { base.VisitElement(element); } } else { base.VisitElement(element); } }
public override void VisitElement(ILangElement element) { if (element != null) { Assert.IsTrue(element.Span.IsValid); Assert.IsTrue(element is PHPDocBlock || inclusion.Last().Contains(element.Span)); if (element is FunctionDecl) { CheckFunctionDecl((FunctionDecl)element); } else if (element is MethodDecl) { CheckMethodDecl((MethodDecl)element); } else if (element is LambdaFunctionExpr) { CheckLambdaDecl((LambdaFunctionExpr)element); } else if (element is TypeDecl) { CheckTypeDecl((TypeDecl)element); } else if (element is StringLiteral) { CheckStringValue((StringLiteral)element); } if (element is NamespaceDecl && ((NamespaceDecl)element).IsSimpleSyntax) { inclusion.Add(Span.Combine(element.Span, ((NamespaceDecl)element).Body.Span)); } else if (element is VarLikeConstructUse && ((VarLikeConstructUse)element).IsMemberOf != null) { inclusion.Add(Span.Combine(((VarLikeConstructUse)element).IsMemberOf.Span, element.Span)); } else { inclusion.Add(element.Span); } base.VisitElement(element); inclusion.RemoveAt(inclusion.Count - 1); if (element is NamespaceDecl) { Assert.IsNotNull(((NamespaceDecl)element).Body); } } }
public static Location GetLocation(this SyntaxTree tree, ILangElement expr) => tree.GetLocation(expr.Span.ToTextSpan());
public DummyInsideBlockStmt(ILangElement originalBlock) { this.OriginalBlock = originalBlock ?? throw new ArgumentNullException(nameof(originalBlock)); }
public override void VisitElement(ILangElement element) { AddChild(element); // do not visit the child }
/// <summary> /// Visit language element and all children recursively. /// Depth-first search. /// </summary> /// <param name="element">Any LanguageElement. Can be null.</param> public virtual void VisitElement(ILangElement element) { element?.VisitMe(this); }