Exemple #1
0
        public IFormType BuildForm(ITypeEnvironment env)
        {
            IFormType a    = Expr2.BuildForm(env);
            IFormType b    = Expr3.BuildForm(env);
            IFormType type = a.GetLeastUpperBound(b);

            return(type);
        }
Exemple #2
0
        public override bool Equals(object obj)
        {
            if (!(obj is TernaryExpr))
            {
                return(false);
            }

            TernaryExpr other = (TernaryExpr)obj;

            return(Expr1.Equals(other.Expr1) && Expr2.Equals(other.Expr2) && Expr3.Equals(other.Expr3));
        }
Exemple #3
0
        public IEnumerable <Inline> BuildDocument()
        {
            List <Inline> inlines = new List <Inline>();

            inlines.AddRange(Expr1.BuildDocument());
            inlines.Add(new Run(" ? "));
            inlines.AddRange(Expr2.BuildDocument());
            inlines.Add(new Run(" : "));
            inlines.AddRange(Expr3.BuildDocument());
            return(inlines);
        }
Exemple #4
0
        public ValueContainer Evaluate(IValueEnvironment env)
        {
            ValueContainer a     = Expr2.Evaluate(env);
            ValueContainer b     = Expr3.Evaluate(env);
            ValueContainer value = new ValueContainer(Convert.ToBoolean(Expr1.Evaluate(env).Value) ? a.Value : b.Value);

            Action onValueChanged = () => value.Value = Convert.ToBoolean(Expr1.Evaluate(env).Value) ? a.Value : b.Value;

            a.ValueChanged += onValueChanged;
            b.ValueChanged += onValueChanged;

            return(value);
        }
 public Expr3(KaitaiStream p__io, KaitaiStruct p__parent = null, Expr3 p__root = null) : base(p__io)
 {
     m_parent   = p__parent;
     m_root     = p__root ?? this;
     f_three    = false;
     f_isStrGe  = false;
     f_isStrNe  = false;
     f_isStrGt  = false;
     f_isStrLe  = false;
     f_isStrLt2 = false;
     f_testNot  = false;
     f_isStrLt  = false;
     f_four     = false;
     f_isStrEq  = false;
     _read();
 }
Exemple #6
0
 public virtual bool IsConst()
 {
     if (Expr1 != null && !Expr1.IsConst())
     {
         return(false);
     }
     if (Expr2 != null && !Expr2.IsConst())
     {
         return(false);
     }
     if (Expr3 != null && !Expr3.IsConst())
     {
         return(false);
     }
     // 仅支持部分操作符
     return(OpType switch
     {
         OpType.NEG => true,
         OpType.ADD => true,
         OpType.SUB => true,
         OpType.MUL => true,
         OpType.DIV => true,
         OpType.MOD => true,
         OpType.LOG_NOT => true,
         OpType.LOG_AND => true,
         OpType.LOG_OR => true,
         OpType.BIT_NOT => true,
         OpType.BIT_AND => true,
         OpType.BIT_XOR => true,
         OpType.BIT_OR => true,
         OpType.BIT_SL => true,
         OpType.BIT_SR => true,
         OpType.EQ => true,
         OpType.NE => true,
         OpType.GE => true,
         OpType.GT => true,
         OpType.LE => true,
         OpType.LT => true,
         OpType.CONDITIONAL => true,
         OpType.CAST => true,
         _ => false,
     });
Exemple #7
0
        public ITypeCheckType TypeCheck(ITypeEnvironment env)
        {
            ITypeCheckType a = Expr1.TypeCheck(env);
            ITypeCheckType b = Expr2.TypeCheck(env);
            ITypeCheckType c = Expr3.TypeCheck(env);

            if (!a.CompatibleWith(ExpressionUpperBound))
            {
                env.ReportError(String.Format("Inline 'if/else' evaluation failed. Incompatible type: '{0}'. Only the bool type is supported.",
                                              a), SourceStartPosition, SourceEndPosition);
            }

            if (!b.CompatibleWith(c))
            {
                env.ReportError(String.Format("Inline 'if/else' return value conflict. Incompatible types: '{0}', '{1}'. Only similar types can be used in the true/false bodies.",
                                              b, c), SourceStartPosition, SourceEndPosition);
            }

            return(b.GetLeastUpperBound(c));
        }
Exemple #8
0
 public override int GetHashCode()
 {
     return(Expr1.GetHashCode() ^ Expr2.GetHashCode() ^ Expr3.GetHashCode());
 }