예제 #1
0
 static void Connect(ILangElement element, ILangElement parent)
 {
     if (element != null)
     {
         element.ContainingElement = parent;
     }
 }
예제 #2
0
파일: TypeRef.cs 프로젝트: DEVSENSE/Parsers
            public override void VisitElement(ILangElement element)
            {
                Debug.Assert(element is TypeRef);
                var stack = _results.Count;

                base.VisitElement(element);
                Debug.Assert(_results.Count == stack + 1);
            }
예제 #3
0
            public override void VisitElement(ILangElement element)
            {
                if (element != null)
                {
                    Assert.IsNotNull(element.ContainingElement);

                    base.VisitElement(element);
                }
            }
예제 #4
0
 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);
     }
 }
예제 #5
0
            /// <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);
            }
예제 #6
0
            void AddChild(ILangElement element)
            {
                if (element != null)
                {
                    if (_childrenCount == _children.Length)
                    {
                        Array.Resize(ref _children, (_children.Length + 2) * 2);
                    }

                    _children[_childrenCount++] = element;
                }
            }
예제 #7
0
        /// <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));
        }
예제 #8
0
        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;
        }
예제 #9
0
 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);
 }
예제 #10
0
 public override void VisitElement(ILangElement element)
 {
     if (IsScopeElement(element))
     {
         using (new ScopeHelper(this, element))
         {
             base.VisitElement(element);
         }
     }
     else
     {
         base.VisitElement(element);
     }
 }
예제 #11
0
            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());
예제 #13
0
 public DummyInsideBlockStmt(ILangElement originalBlock)
 {
     this.OriginalBlock = originalBlock ?? throw new ArgumentNullException(nameof(originalBlock));
 }
예제 #14
0
            public override void VisitElement(ILangElement element)
            {
                AddChild(element);

                // do not visit the child
            }
예제 #15
0
 /// <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);
 }