Exemple #1
0
        static void Main(string[] args)
        {
            var dtoUser = GetExpression()(new User()
            {
                Name = "叶伟密"
            });

            Console.WriteLine(dtoUser.Name);
            Console.ReadLine();
        }
Exemple #2
0
        private IExpression ParseCall()
        {
            var expr = ParsePrimary();

            while (true)
            {
                if (CurrentTokenMatches(TokenType.LeftParen))
                {
                    expr = ParseCall(expr);
                }
                else if (CurrentTokenMatches(TokenType.Dot))
                {
                    if (!TryConsume(TokenType.Identifier, out var token))
                    {
                        throw new ParseException("Expected prop name after '.'", CurrentToken);
                    }

                    expr = new GetExpression(token, expr);
                }
                else
                {
                    return(expr);
                }
            }
        }
Exemple #3
0
        public object VisitGetExpression(GetExpression expression)
        {
            var obj = Evaluate(expression.Obj);

            if (obj is LoxInstance loxInstance)
            {
                return(loxInstance[expression.Name]);
            }

            throw new LoxRunTimeException(expression.Name, "Only instances have properties.");
        }
Exemple #4
0
        public void NullArguments()
        {
            var obj      = new MyBindableObject();
            var getter   = new GetExpression();
            var property = obj.GetType().GetProperty(nameof(MyBindableObject.MyStringValue));

            new Action(() => obj.Bind(null, getter)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
            new Action(() => obj.Bind(property, null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(getter));
            new Action(() => obj.HasValue <int>(null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
            new Action(() => obj.GetValue <int>(null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
            new Action(() => obj.ResetValue <int>(null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
            new Action(() => obj.SetValue(null, 1)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
            new Action(() => obj[null] = 1).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
            new Action(() => obj[null].As <int>()).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property));
        }
Exemple #5
0
        void FromSource(GetExpression expression)
        {
            Expect(2);
            var col = new ExpressionGeneration.CollectionDescriptor(); expression.AddCollection(col); col.Name = t.val;

            if (la.kind == 2)
            {
                Get();
                col.Alias = t.val;
            }
            while (la.kind == 32 || la.kind == 33)
            {
                if (la.kind == 32)
                {
                    Get();
                }
                else
                {
                    Get();
                }
                if (la.kind == 34 || la.kind == 35)
                {
                    if (la.kind == 34)
                    {
                        Get();
                    }
                    else
                    {
                        Get();
                    }
                }
                Expect(36);
                Expect(2);
                var col2 = new ExpressionGeneration.CollectionDescriptor(); expression.AddCollection(col); col2.Name = t.val;
                if (la.kind == 2)
                {
                    Get();
                    col2.Alias = t.val;
                }
                Expect(30);
                Expect(2);
                Expect(37);
                Expect(2);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="transit"> transit time in seconds</param>
        public void ChangeEspression(NPCExpression expression, float transit = 0)
        {
            changeMorphs.Clear();

            GetExpression = expression.Clone();

            //get values to change
            foreach (var morph in morphes)
            {
                if (morph.MorphDegree != 0)
                {
                    //reset morph to zero
                    if (!GetExpression.expressionList.ContainsKey(morph.Name))
                    {
                        GetExpression.SetExpression(morph.Name, 0);
                    }
                }
            }

            //get morph pointers
            foreach (var morphName in GetExpression.expressionList.Keys)
            {
                var morph = Array.Find(morphes, (a) => a.Name == morphName);
                if (morph != null)
                {
                    changeMorphs.Add(morph, GetExpression.expressionList[morphName]);
                }
                else
                {
                    logger.Warning(String.Format("Morph {0} not found in model", morphName));
                }
            }


            if (transit > 0)
            {
                timer = transit;
            }
            else
            {
                timer = 1;
                PerformExpressionChange(1);
            }
        }
Exemple #7
0
 void OrderLimitClause(GetExpression expression)
 {
     if (la.kind == 17)
     {
         Get();
         Expect(19);
         if (la.kind == 3)
         {
             Get();
             expression.Ordering = t.val.Substring(1, t.val.Length - 2);
         }
         else if (la.kind == 2)
         {
             Get();
             expression.Ordering = t.val;
         }
         else
         {
             SynErr(43);
         }
         if (la.kind == 20)
         {
             Get();
             expression.OrderDescending = true;
         }
         if (la.kind == 21)
         {
             Get();
             Expect(1);
             expression.Take = Int32.Parse(t.val);
             if (la.kind == 16)
             {
                 Get();
                 Expect(1);
                 expression.Skip = expression.Take; expression.Take = Int32.Parse(t.val);
             }
         }
     }
 }
Exemple #8
0
        private Expression Call()
        {
            var expression = Primary();

            while (true)
            {
                if (Match(TokenType.OpenParen))
                {
                    expression = FinishCall(expression);
                }
                else if (Match(TokenType.Dot))
                {
                    var name = Consume(TokenType.Identifier, "Expect property name after '.'.");
                    expression = new GetExpression(expression, name);
                }
                else
                {
                    break;
                }
            }

            return(expression);
        }
Exemple #9
0
        void SelectPart(GetExpression expression)
        {
            Expect(2);
            var sel = new SelectDimensionExpression(); expression.AddSelect(sel); sel.Target = t.val; sel.Source = t.val;

            if (la.kind == 6)
            {
                Get();
                sel.Aggregate = sel.Source; sel.Source = sel.Target = null;
                if (la.kind == 2)
                {
                    Get();
                    sel.Source = t.val;
                }
                Expect(7);
            }
            if (la.kind == 26)
            {
                Get();
                Expect(2);
                sel.Target = t.val;
            }
        }
Exemple #10
0
        private Expression Call()
        {
            var expression = Primary();

            while (true)
            {
                if (Match(TokenType.LEFT_PAREN))
                {
                    expression = FinishCall(expression);
                }
                else if (Match(TokenType.DOT))
                {
                    var name = Consume(TokenType.IDENTIFIER, "Expect property name after '.'.");

                    expression = new GetExpression(expression, name);
                }
                else
                {
                    break;
                }
            }

            return(expression);
        }
Exemple #11
0
 public override void Accept(GetExpression getAttr)
 {
     getAttr.Visit(functionCompiler);
 }
Exemple #12
0
 public string VisitGetExpression(GetExpression expression)
 {
     return(Parenthesize2(".", expression.Object, expression.Name.Lexeme));
 }
Exemple #13
0
 public override void Accept(GetExpression getAttr)
 {
     getAttr.Visit(parentVisitor);
     methodBuilder.EmitInstruction(getAttr.Location, Opcode.LoadLocal, temporary);
     methodBuilder.EmitInstruction(getAttr.Location, Opcode.BinOp, (int)BinaryOperation.Equals);
 }
Exemple #14
0
        public override void Accept(BinaryExpression binop)
        {
            if (binop.Operation == BinaryOperation.Assign)
            {
                binop.Right.Visit(this);
                if (binop.Left is NameExpression)
                {
                    NameExpression ident = (NameExpression)binop.Left;
                    Symbol         sym   = symbolTable.GetSymbol(ident.Value);
                    if (sym.Type == SymbolType.Local)
                    {
                        methodBuilder.EmitInstruction(ident.Location, Opcode.StoreLocal, sym.Index);
                        methodBuilder.EmitInstruction(ident.Location, Opcode.LoadLocal, sym.Index);
                    }
                    else
                    {
                        int globalIndex = methodBuilder.Module.DefineConstant(new IodineName(ident.Value));
                        methodBuilder.EmitInstruction(ident.Location, Opcode.StoreGlobal, globalIndex);
                        methodBuilder.EmitInstruction(ident.Location, Opcode.LoadGlobal, globalIndex);
                    }
                }
                else if (binop.Left is GetExpression)
                {
                    GetExpression getattr = binop.Left as GetExpression;
                    getattr.Target.Visit(this);
                    int attrIndex = methodBuilder.Module.DefineConstant(new IodineName(getattr.Field));
                    methodBuilder.EmitInstruction(getattr.Location, Opcode.StoreAttribute, attrIndex);
                    getattr.Target.Visit(this);
                    methodBuilder.EmitInstruction(getattr.Location, Opcode.LoadAttribute, attrIndex);
                }
                else if (binop.Left is IndexerExpression)
                {
                    IndexerExpression indexer = binop.Left as IndexerExpression;
                    indexer.Target.Visit(this);
                    indexer.Index.Visit(this);
                    methodBuilder.EmitInstruction(indexer.Location, Opcode.StoreIndex);
                    binop.Left.Visit(this);
                }
            }
            else if (binop.Operation == BinaryOperation.InstanceOf)
            {
                binop.Right.Visit(this);
                binop.Left.Visit(this);
                methodBuilder.EmitInstruction(binop.Location, Opcode.InstanceOf);
            }
            else if (binop.Operation == BinaryOperation.NotInstanceOf)
            {
                binop.Right.Visit(this);
                binop.Left.Visit(this);
                methodBuilder.EmitInstruction(binop.Location, Opcode.InstanceOf);
                methodBuilder.EmitInstruction(binop.Location, Opcode.UnaryOp, (int)UnaryOperation.BoolNot);
            }
            else if (binop.Operation == BinaryOperation.DynamicCast)
            {
                binop.Right.Visit(this);
                binop.Left.Visit(this);
                methodBuilder.EmitInstruction(binop.Location, Opcode.DynamicCast);
            }
            else if (binop.Operation == BinaryOperation.NullCoalescing)
            {
                binop.Right.Visit(this);
                binop.Left.Visit(this);
                methodBuilder.EmitInstruction(binop.Location, Opcode.NullCoalesce);
            }
            else
            {
                IodineLabel shortCircuitTrueLabel  = methodBuilder.CreateLabel();
                IodineLabel shortCircuitFalseLabel = methodBuilder.CreateLabel();
                IodineLabel endLabel = methodBuilder.CreateLabel();
                binop.Left.Visit(this);

                /*
                 * Short circuit evaluation
                 */
                switch (binop.Operation)
                {
                case BinaryOperation.BoolAnd:
                    methodBuilder.EmitInstruction(binop.Location, Opcode.Dup);
                    methodBuilder.EmitInstruction(binop.Location, Opcode.JumpIfFalse,
                                                  shortCircuitFalseLabel);
                    break;

                case BinaryOperation.BoolOr:
                    methodBuilder.EmitInstruction(binop.Location, Opcode.Dup);
                    methodBuilder.EmitInstruction(binop.Location, Opcode.JumpIfTrue,
                                                  shortCircuitTrueLabel);
                    break;
                }
                binop.Right.Visit(this);
                methodBuilder.EmitInstruction(binop.Location, Opcode.BinOp, (int)binop.Operation);
                methodBuilder.EmitInstruction(binop.Location, Opcode.Jump, endLabel);
                methodBuilder.MarkLabelPosition(shortCircuitTrueLabel);
                methodBuilder.EmitInstruction(binop.Location, Opcode.Pop);
                methodBuilder.EmitInstruction(binop.Location, Opcode.LoadTrue);
                methodBuilder.EmitInstruction(binop.Location, Opcode.Jump, endLabel);
                methodBuilder.MarkLabelPosition(shortCircuitFalseLabel);
                methodBuilder.EmitInstruction(binop.Location, Opcode.Pop);
                methodBuilder.EmitInstruction(binop.Location, Opcode.LoadFalse);
                methodBuilder.MarkLabelPosition(endLabel);
            }
        }
Exemple #15
0
 public override void Accept(GetExpression getAttr)
 {
     getAttr.Target.Visit(this);
     methodBuilder.EmitInstruction(getAttr.Location, Opcode.LoadAttribute,
                                   methodBuilder.Module.DefineConstant(new IodineName(getAttr.Field)));
 }
Exemple #16
0
        public object VisitGetExpression(GetExpression expression)
        {
            Resolve(expression.Obj);

            return(null);
        }
Exemple #17
0
 public Unit VisitGetExpression(GetExpression expression)
 {
     Resolve(expression.Object);
     return(Unit.Value);
 }
Exemple #18
0
 public override void Accept(GetExpression getAttr)
 {
     getAttr.VisitChildren(this);
 }
Exemple #19
0
	void SelectPart(GetExpression expression) {
		Expect(2);
		var sel = new SelectDimensionExpression(); expression.AddSelect(sel); sel.Target = t.val; sel.Source = t.val; 
		if (la.kind == 6) {
			Get();
			sel.Aggregate = sel.Source; sel.Source = sel.Target = null; 
			if (la.kind == 2) {
				Get();
				sel.Source = t.val; 
			}
			Expect(7);
		}
		if (la.kind == 26) {
			Get();
			Expect(2);
			sel.Target = t.val; 
		}
	}
Exemple #20
0
 public virtual void Accept(GetExpression getAttr)
 {
 }
Exemple #21
0
 public override void Accept(GetExpression getAttr)
 {
     getAttr.Visit(parentVisitor);
 }
Exemple #22
0
	void OrderLimitClause(GetExpression expression) {
		if (la.kind == 17) {
			Get();
			Expect(19);
			if (la.kind == 3) {
				Get();
				expression.Ordering = t.val.Substring(1, t.val.Length - 2); 
			} else if (la.kind == 2) {
				Get();
				expression.Ordering = t.val; 
			} else SynErr(43);
			if (la.kind == 20) {
				Get();
				expression.OrderDescending = true; 
			}
			if (la.kind == 21) {
				Get();
				Expect(1);
				expression.Take = Int32.Parse(t.val); 
				if (la.kind == 16) {
					Get();
					Expect(1);
					expression.Skip = expression.Take; expression.Take = Int32.Parse(t.val); 
				}
			}
		}
	}
Exemple #23
0
	void FromSource(GetExpression expression) {
		Expect(2);
		var col = new ExpressionGeneration.CollectionDescriptor(); expression.AddCollection(col); col.Name = t.val; 
		if (la.kind == 2) {
			Get();
			col.Alias = t.val; 
		}
		while (la.kind == 32 || la.kind == 33) {
			if (la.kind == 32) {
				Get();
			} else {
				Get();
			}
			if (la.kind == 34 || la.kind == 35) {
				if (la.kind == 34) {
					Get();
				} else {
					Get();
				}
			}
			Expect(36);
			Expect(2);
			var col2 = new ExpressionGeneration.CollectionDescriptor(); expression.AddCollection(col); col2.Name = t.val; 
			if (la.kind == 2) {
				Get();
				col2.Alias = t.val;  
			}
			Expect(30);
			Expect(2);
			Expect(37);
			Expect(2);
		}
	}