示例#1
0
        public void Negate()
        {
            if (IsNegated)
            {
                return;
            }
            IsNegated = true;

            if (Condition != null)
            {
                if (!(Condition is SurroundingParenthesesExpression) && IsStaticIfCondition)
                {
                    Condition = new SurroundingParenthesesExpression
                    {
                        Expression  = Condition,
                        Location    = Condition.Location,
                        EndLocation = Condition.EndLocation
                    }
                }
                ;

                Condition = new UnaryExpression_Not
                {
                    UnaryExpression = Condition,
                    Location        = Condition.Location
                };
            }
        }
        public ISymbolValue Visit(UnaryExpression_Not x)
        {
            var v = x.UnaryExpression.Accept(this);

            if(v is VariableValue)
                    v = EvaluateValue(v as VariableValue, ValueProvider);
                var pv = v as PrimitiveValue;
                if(pv == null){
                    EvalError(x.UnaryExpression, "Expression must be a primitive value",v);
                    return null;
                }

                return new PrimitiveValue(!IsFalseZeroOrNull(pv),x);
        }
        public ISymbolValue Visit(UnaryExpression_Not x)
        {
            var v = x.UnaryExpression.Accept(this);

            if (v is VariableValue)
            {
                v = EvaluateValue(v as VariableValue, ValueProvider);
            }
            var pv = v as PrimitiveValue;

            if (pv == null)
            {
                EvalError(x.UnaryExpression, "Expression must be a primitive value", v);
                return(null);
            }

            return(new PrimitiveValue(!IsFalseZeroOrNull(pv), x));
        }
        ISemantic E(UnaryExpression_Not x)
        {
            var v = E(x.UnaryExpression);

            if (eval)
            {
                if (v is VariableValue)
                {
                    v = EvaluateValue(v as VariableValue, ValueProvider);
                }
                var pv = v as PrimitiveValue;
                if (pv == null)
                {
                    EvalError(x.UnaryExpression, "Expression must be a primitive value", v);
                    return(null);
                }

                return(new PrimitiveValue(!IsFalseZeroOrNull(pv), x));
            }
            return(v);
        }
 public void Visit(UnaryExpression_Not x)
 {
 }
 public AbstractType Visit(UnaryExpression_Not x)
 {
     return(x.UnaryExpression.Accept(this));
 }
		ISemantic E(UnaryExpression_Not x)
		{
			var v = E(x.UnaryExpression);
			
			if(eval)
			{
				if(v is VariableValue)
					v = EvaluateValue(v as VariableValue, ValueProvider);
				var pv = v as PrimitiveValue;
				if(pv == null){
					EvalError(x.UnaryExpression, "Expression must be a primitive value",v);
					return null;
				}
				
				return new PrimitiveValue(!IsFalseZeroOrNull(pv),x);
			}
			return v;			
		}
		public void Visit(UnaryExpression_Not x)
		{
			
		}
示例#9
0
        IExpression UnaryExpression(IBlockNode Scope = null)
        {
            switch (laKind)
            {
                // Note: PowExpressions are handled in PowExpression()
                case BitwiseAnd:
                case Increment:
                case Decrement:
                case Times:
                case Minus:
                case Plus:
                case Not:
                case Tilde:
                    Step();
                    SimpleUnaryExpression sue;
                    switch (t.Kind)
                    {
                        case BitwiseAnd:
                            sue = new UnaryExpression_And();
                            break;
                        case Increment:
                            sue = new UnaryExpression_Increment();
                            break;
                        case Decrement:
                            sue = new UnaryExpression_Decrement();
                            break;
                        case Times:
                            sue = new UnaryExpression_Mul();
                            break;
                        case Minus:
                            sue = new UnaryExpression_Sub();
                            break;
                        case Plus:
                            sue = new UnaryExpression_Add();
                            break;
                        case Tilde:
                            sue = new UnaryExpression_Cat();
                            break;
                        case Not:
                            sue = new UnaryExpression_Not();
                            break;
                        default:
                            SynErr(t.Kind, "Illegal token for unary expressions");
                            return null;
                    }
                    sue.Location = t.Location;
                    sue.UnaryExpression = UnaryExpression(Scope);
                    return sue;

                // CastExpression
                case Cast:
                    Step();
                    var ce = new CastExpression { Location= t.Location };

                    if (Expect(OpenParenthesis))
                    {
                        if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type!
                            ce.Type = Type();
                        Expect(CloseParenthesis);
                    }
                    ce.UnaryExpression = UnaryExpression(Scope);
                    ce.EndLocation = t.EndLocation;
                    return ce;

                // DeleteExpression
                case Delete:
                    Step();
                    return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) };

                // PowExpression
                default:
                    var left = PostfixExpression(Scope);

                    if (laKind != Pow)
                        return left;

                    Step();
                    var pe = new PowExpression();
                    pe.LeftOperand = left;
                    pe.RightOperand = UnaryExpression(Scope);

                    return pe;
            }
        }
示例#10
0
        IExpression UnaryExpression(IBlockNode Scope = null)
        {
            // Note: PowExpressions are handled in PowExpression()

            if (laKind == (BitwiseAnd) || laKind == (Increment) ||
                laKind == (Decrement) || laKind == (Times) ||
                laKind == (Minus) || laKind == (Plus) ||
                laKind == (Not) || laKind == (Tilde))
            {
                Step();

                SimpleUnaryExpression ae;

                switch (t.Kind)
                {
                    case BitwiseAnd:
                        ae = new UnaryExpression_And();
                        break;
                    case Increment:
                        ae = new UnaryExpression_Increment();
                        break;
                    case Decrement:
                        ae = new UnaryExpression_Decrement();
                        break;
                    case Times:
                        ae = new UnaryExpression_Mul();
                        break;
                    case Minus:
                        ae = new UnaryExpression_Sub();
                        break;
                    case Plus:
                        ae = new UnaryExpression_Add();
                        break;
                    case Tilde:
                        ae = new UnaryExpression_Cat();
                        break;
                    case Not:
                        ae = new UnaryExpression_Not();
                        break;
                    default:
                        SynErr(t.Kind, "Illegal token for unary expressions");
                        return null;
                }

                LastParsedObject = ae;

                ae.Location = t.Location;

                ae.UnaryExpression = UnaryExpression(Scope);

                return ae;
            }

            // CastExpression
            if (laKind == (Cast))
            {
                Step();
                var ae = new CastExpression { Location= t.Location };

                if (Expect(OpenParenthesis))
                {
                    if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type!
                        ae.Type = Type();
                    Expect(CloseParenthesis);
                }

                ae.UnaryExpression = UnaryExpression(Scope);

                ae.EndLocation = t.EndLocation;

                return ae;
            }

            // DeleteExpression
            if (laKind == (Delete))
            {
                Step();
                return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) };
            }

            // PowExpression
            var left = PostfixExpression(Scope);

            if (laKind != Pow)
                return left;

            Step();
            var pe = new PowExpression();
            pe.LeftOperand = left;
            pe.RightOperand = UnaryExpression(Scope);

            return pe;
        }
示例#11
0
        IExpression UnaryExpression(IBlockNode Scope = null)
        {
            // Note: PowExpressions are handled in PowExpression()

            if (laKind == (BitwiseAnd) || laKind == (Increment) ||
                laKind == (Decrement) || laKind == (Times) ||
                laKind == (Minus) || laKind == (Plus) ||
                laKind == (Not) || laKind == (Tilde))
            {
                Step();

                SimpleUnaryExpression ae = null;

                switch (t.Kind)
                {
                    case BitwiseAnd:
                        ae = new UnaryExpression_And();
                        break;
                    case Increment:
                        ae = new UnaryExpression_Increment();
                        break;
                    case Decrement:
                        ae = new UnaryExpression_Decrement();
                        break;
                    case Times:
                        ae = new UnaryExpression_Mul();
                        break;
                    case Minus:
                        ae = new UnaryExpression_Sub();
                        break;
                    case Plus:
                        ae = new UnaryExpression_Add();
                        break;
                    case Tilde:
                        ae = new UnaryExpression_Cat();
                        break;
                    case Not:
                        ae = new UnaryExpression_Not();
                        break;
                }

                LastParsedObject = ae;

                ae.Location = t.Location;

                ae.UnaryExpression = UnaryExpression(Scope);

                return ae;
            }

            // ( Type ) . Identifier
            if (laKind == OpenParenthesis)
            {
                var wkParsing = AllowWeakTypeParsing;
                AllowWeakTypeParsing = true;
                var curLA = la;
                Step();
                var td = Type();

                AllowWeakTypeParsing = wkParsing;

                if (td!=null && ((t.Kind!=OpenParenthesis && laKind == CloseParenthesis && Peek(1).Kind == Dot && Peek(2).Kind == Identifier) ||
                    (IsEOF || Peek(1).Kind==EOF || Peek(2).Kind==EOF))) // Also take it as a type declaration if there's nothing following (see Expression Resolving)
                {
                    Step();  // Skip to )
                    Step();  // Skip to .
                    Step();  // Skip to identifier

                    var accExpr = new UnaryExpression_Type() { Type=td, AccessIdentifier=t.Value };

                    accExpr.Location = curLA.Location;
                    accExpr.EndLocation = t.EndLocation;

                    return accExpr;
                }
                else
                {
                    // Reset the current token with the earlier one to enable Expression parsing
                    la = curLA;
                    Peek(1);
                }

            }

            // CastExpression
            if (laKind == (Cast))
            {
                Step();
                var ae = new CastExpression { Location= t.Location };

                if (Expect(OpenParenthesis))
                {
                    if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type!
                        ae.Type = Type();
                    Expect(CloseParenthesis);
                }

                ae.UnaryExpression = UnaryExpression(Scope);

                ae.EndLocation = t.EndLocation;

                return ae;
            }

            // NewExpression
            if (laKind == (New))
                return NewExpression(Scope);

            // DeleteExpression
            if (laKind == (Delete))
            {
                Step();
                return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) };
            }

            // PowExpression
            var left = PostfixExpression(Scope);

            if (laKind != Pow)
                return left;

            Step();
            var pe = new PowExpression();
            pe.LeftOperand = left;
            pe.RightOperand = UnaryExpression(Scope);

            return pe;
        }
示例#12
0
        public void Negate()
        {
            if(IsNegated)
                return;
            IsNegated=true;

            if (Condition != null)
            {
                if (!(Condition is SurroundingParenthesesExpression) && IsStaticIfCondition)
                    Condition = new SurroundingParenthesesExpression
                    {
                        Expression = Condition,
                        Location = Condition.Location,
                        EndLocation = Condition.EndLocation
                    };

                Condition = new UnaryExpression_Not
                {
                    UnaryExpression = Condition,
                    Location = Condition.Location
                };
            }
        }
 ISemantic E(UnaryExpression_Not x)
 {
     return E(x.UnaryExpression);
 }