Exemplo n.º 1
0
 public override void VisitChildren(ContainerExpression x)
 {
     if (!halt)
     {
         base.VisitChildren(x);
     }
 }
Exemplo n.º 2
0
 public override void VisitChildren(ContainerExpression x)
 {
     if (PushSelectionRange(x))
     {
         base.VisitChildren(x);
     }
 }
Exemplo n.º 3
0
 public virtual void VisitChildren(ContainerExpression x)
 {
     foreach (var sx in x.SubExpressions)
     {
         sx.Accept(this);
     }
 }
 /// <summary>
 /// Creates a new instance with some parameters.
 /// </summary>
 /// <param name="child">The child to add.</param>
 /// <param name="query">The associated query context.</param>
 /// <param name="line">The line where the tree expression starts.</param>
 /// <param name="column">The column in the line where the tree exp. starts.</param>
 public TreeExpression(ContainerExpression child, QueryContext query, int line, int column)
     : base(child)
 {
     Query       = query;
     StartColumn = column;
     StartLine   = line;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new instance with some parameters.
 /// </summary>
 /// <param name="child">The child to add.</param>
 /// <param name="query">The associated query context.</param>
 /// <param name="line">The line where the tree expression starts.</param>
 /// <param name="column">The column in the line where the tree exp. starts.</param>
 public TreeExpression(ContainerExpression child, QueryContext query, int line, int column)
     : base(child)
 {
     Query = query;
     StartColumn = column;
     StartLine = line;
 }
Exemplo n.º 6
0
 public override void VisitChildren(ContainerExpression x)
 {
     if (!halt)
     {
         shownKeywords.Push(ExprMemberFilter);
         base.VisitChildren(x);
         if (!halt)
         {
             shownKeywords.Pop();
         }
     }
 }
		public virtual void VisitChildren(ContainerExpression x)
		{
			if(x.SubExpressions != null)
				foreach (var sx in x.SubExpressions)
					if(sx != null)
						sx.Accept(this);
		}
		protected Expression ParseOperand()
		{
			if (this.token == ComputedExpressionToken.LeftParen)
			{
				Consume();

				var retval = ParseExpression();

				Expect(ComputedExpressionToken.RightParen);

				return retval;
			}

			Expression current = null;

			if (this.token == ComputedExpressionToken.Keyword && this.tokenizer.CurrentKeyword == ComputedExpressionKeyword.@this)
			{
				current = this.targetObject;
				Consume();

				if (this.token == ComputedExpressionToken.Period)
				{
					Consume();
				}
			}
			else if (this.token == ComputedExpressionToken.Keyword && this.tokenizer.CurrentKeyword == ComputedExpressionKeyword.@true)
			{
				Consume();

				return Expression.Constant(true);
			}
			else if (this.token == ComputedExpressionToken.Keyword && this.tokenizer.CurrentKeyword == ComputedExpressionKeyword.@false)
			{
				Consume();

				return Expression.Constant(false);
			}
			else if (this.token == ComputedExpressionToken.Keyword && this.tokenizer.CurrentKeyword == ComputedExpressionKeyword.@null)
			{
				Consume();

				return Expression.Constant(null);
			}

			if (this.token == ComputedExpressionToken.Identifier)
			{
				while (true)
				{
					var identifier = this.tokenizer.CurrentIdentifier;

					Consume();

					if (this.token == ComputedExpressionToken.LeftParen)
					{
						if (current is ContainerExpression containerExpression && containerExpression.Namespace != null)
						{
							throw new InvalidOperationException($"Namespace '{containerExpression.Namespace}' not expected");
						}

						// Calling a static method on a referenced type is supported as if the type was imported 'using static'

						if (current == null)
						{
							if (DoesStaticMethodResolve(identifier, out var type))
							{
								current = new ContainerExpression(type);
							}
							else
							{
								current = this.targetObject;
							}
						}

						current = ParseMethodCall(current, identifier);
					}
					else if (identifier == "value" && current == null)
					{
						current = Expression.Property(this.targetObject, this.propertyInfo);
					}
					else if (current is ContainerExpression container)
					{
						if (container.Type != null)
						{
							var member = current.Type.GetMember(identifier, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault();

							if (member is PropertyInfo || member is FieldInfo)
							{
								current = Expression.MakeMemberAccess(null, member);
							}
							else if (member is Type nestedType)
							{
								current = new ContainerExpression(nestedType);
							}
							else
							{
								throw new InvalidOperationException($"Unable to resolve '{identifier}' on type '{container.Type}'");
							}
						}
						else
						{
							var s = container.Namespace + "." + identifier;

							if (TryGetType(s, out var type))
							{
								current = new ContainerExpression(type);
							}
							else if (DoesNamespaceResolve(s))
							{
								current = container.Append(identifier);
							}
							else
							{
								TryGetType(s, out var type2);

								throw new InvalidOperationException($"Unable to resolve identifier '{s}'");
							}
						}
					}
					else if (current != null)
					{
						if (current.Type.IsEnum)
						{
							var value = Enum.Parse(current.Type, identifier);

							current = Expression.Constant(value);
						}
						else
						{
							var member = current.Type.GetMember(identifier, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SingleOrDefault();

							if (member is PropertyInfo || member is FieldInfo)
							{
								current = Expression.MakeMemberAccess(current, member);
							}
							else if (member is Type nestedType)
							{
								current = new ContainerExpression(nestedType);
							}
							else
							{
								throw new InvalidOperationException($"Unable to resolve property '{identifier}' on type '{current.Type}'");
							}
						}
					}
					else
					{
						var member = this.targetObject.Type.GetMember(identifier, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SingleOrDefault();

						if (member is PropertyInfo || member is FieldInfo)
						{
							current = Expression.MakeMemberAccess(this.targetObject, member);
						}
						else if (member is Type nestedType)
						{
							current = new ContainerExpression(nestedType);
						}
						else if (TryGetType(identifier, out var type))
						{
							current = new ContainerExpression(type);
						}
						else if (DoesNamespaceResolve(identifier))
						{
							current = new ContainerExpression(identifier);
						}
						else
						{
							throw new InvalidOperationException($"Unable to resolve identifier '{identifier}'");
						}
					}

					if (this.token == ComputedExpressionToken.Period)
					{
						Consume();

						if (this.token != ComputedExpressionToken.Identifier)
						{
							throw new InvalidOperationException();
						}

						continue;
					}

					return current;
				}
			}

			var multiplier = 1;

			if (this.token == ComputedExpressionToken.Subtract)
			{
				multiplier = -1;
			}
			
			switch (this.token)
			{
			case ComputedExpressionToken.IntegerLiteral:
				Consume();

				return Expression.Constant(multiplier * (int)this.tokenizer.CurrentInteger);
			case ComputedExpressionToken.LongLiteral:
				Consume();

				return Expression.Constant(multiplier * this.tokenizer.CurrentInteger);
			case ComputedExpressionToken.StringLiteral:
				Consume();

				return Expression.Constant(this.tokenizer.CurrentString);
			default:
				if (current != null)
				{
					return current;
				}
				break;
			}
			
			throw new InvalidOperationException();
		}
Exemplo n.º 9
0
 public override void VisitChildren(ContainerExpression x)
 {
     if(!halt)
         base.VisitChildren (x);
 }
		public override void VisitChildren (ContainerExpression x)
		{
			if (!halt) {
				shownKeywords.Push (ExprMemberFilter);
				base.VisitChildren (x);
				if (!halt)
					shownKeywords.Pop ();
			}
		}
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="child">The child to add.</param>
 /// <param name="engine">The engine that has been used.</param>
 public TreeExpression(ContainerExpression child, ParseEngine engine)
     : this(child, engine.Query, engine.CurrentLine, engine.CurrentColumn)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="child">The child to add.</param>
 /// <param name="engine">The engine that has been used.</param>
 public TreeExpression(ContainerExpression child, ParseEngine engine)
     : this(child, engine.Query, engine.CurrentLine, engine.CurrentColumn)
 {
 }