using System;
using System.Collections.Generic;

namespace Newtonsoft.Json.Linq.JsonPath
{
	internal class QueryScanFilter : PathFilter
	{
		public QueryExpression Expression { get; set; }

		public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
		{
			using (IEnumerator<JToken> enumerator = current.GetEnumerator())
			{
				goto IL_0060;
				for (;;)
				{
					IEnumerator<JToken> enumerator2;
					JToken jtoken;
					JToken t;
					try
					{
						IL_00CD:
						while (enumerator2.MoveNext())
						{
							jtoken = enumerator2.Current;
							if (this.Expression.IsMatch(root, jtoken))
							{
								goto IL_010E;
							}
						}
						goto JumpOutOfTryFinally-4;
						IL_0053:
						goto IL_0102;
						IL_0060:
						if (!enumerator.MoveNext())
						{
							goto IL_0138;
						}
						t = enumerator.Current;
						JContainer jcontainer;
						if ((jcontainer = t as JContainer) == null)
						{
							goto IL_00E9;
						}
						enumerator2 = jcontainer.DescendantsAndSelf().GetEnumerator();
						goto IL_00CD;
					}
					finally
					{
						if (enumerator2 != null)
						{
							enumerator2.Dispose();
						}
					}
					goto JumpOutOfTryFinally-4;
					IL_0102:
					t = null;
					goto IL_0060;
					IL_010E:
					yield return jtoken;
					continue;
					JumpOutOfTryFinally-4:
					enumerator2 = null;
					goto IL_0102;
					IL_00E9:
					if (!this.Expression.IsMatch(root, t))
					{
						goto IL_0102;
					}
					yield return t;
					goto IL_0053;
				}
				IL_0138:;
			}
			IEnumerator<JToken> enumerator = null;
			yield break;
			yield break;
		}
	}
}
