Esempio n. 1
0
        /// <summary>
        ///     Converts the return value into a call to Contract.Result
        /// </summary>
        public override IExpression Rewrite(IReturnValue returnValue)
        {
            var mref         = contractProvider.ContractMethods.Result;
            var methodToCall = new GenericMethodInstanceReference
            {
                CallingConvention = CallingConvention.Generic,
                ContainingType    = mref.ContainingType,
                GenericArguments  = new List <ITypeReference> {
                    returnValue.Type
                },
                GenericMethod = mref,
                InternFactory = host.InternFactory,
                Name          = mref.Name,
                Type          = returnValue.Type
            };
            var methodCall = new MethodCall
            {
                IsStaticCall = true,
                MethodToCall = methodToCall,
                Type         = returnValue.Type,
                Locations    = new List <ILocation>(returnValue.Locations)
            };

            return(methodCall);
        }
 public override void Visit(IReturnValue returnValue)
 {
     if (Process(returnValue))
     {
         visitor.Visit(returnValue);
     }
     base.Visit(returnValue);
 }
Esempio n. 3
0
 private static TokenBinaryExpression BuildExpression(char opt, IReturnValue left, IReturnValue right)
 {
     return new TokenBinaryExpression()
     {
         Left = left,
         Operator = opt,
         Right = right
     };
 }
Esempio n. 4
0
        public override String ToString()
        {
            IEnumerator   itr = Iterator;
            StringBuilder sb  = new StringBuilder();

            while (itr.MoveNext())
            {
                IReturnValue rval = (IReturnValue)itr.Current;
                sb.Append(rval.StringValue).Append('\n');
            }
            return(sb.ToString());
        }
Esempio n. 5
0
        /// <summary> The method uses the function to evaluate the fact
        /// </summary>
        /// <param name="">factInstance
        /// </param>
        /// <returns>
        ///
        /// </returns>
        public virtual bool evaluate(IFact factInstance, Rete engine)
        {
            for (int idx = 0; idx < params_Renamed.Length; idx++)
            {
                if (params_Renamed[idx] is BoundParam)
                {
                    ((BoundParam)params_Renamed[idx]).Facts = new IFact[] { factInstance };
                }
            }
            IReturnVector rv   = function.executeFunction(engine, params_Renamed);
            IReturnValue  rval = rv.firstReturnValue();

            return(rval.BooleanValue);
        }
Esempio n. 6
0
        private void Init(string fileName)
        {
            _FileName = fileName;
            var t = Directory.GetCurrentDirectory();

            if (!File.Exists(fileName))
            {
                throw new System.Exception("FILE_NAME_FROM_GRAPH_READER_STORE_IS_INVALID");
            }
            ReturnValue = new CSV_Return_Value
            {
                FileValues   = new Dictionary <string, List <string> >(),
                FileLocation = fileName,
                Headers      = new string[0]
            };
        }
Esempio n. 7
0
        protected void parse(Rete engine, CLIPSParser parser, IList factlist)
        {
            Object itm = null;

            try
            {
                while ((itm = parser.basicExpr()) != null)
                {
                    // System.Console.WriteLine("obj is " + itm.getClass().Name);
                    if (itm is Defrule)
                    {
                        Defrule rule = (Defrule)itm;
                        engine.RuleCompiler.addRule(rule);
                    }
                    else if (itm is Deftemplate)
                    {
                        Deftemplate dt = (Deftemplate)itm;
                        Console.WriteLine("template=" + dt.Name);
                        engine.declareTemplate(dt);
                    }
                    else if (itm is FunctionAction)
                    {
                        FunctionAction fa = (FunctionAction)itm;
                    }
                    else if (itm is IFunction)
                    {
                        IReturnVector rv  = ((IFunction)itm).executeFunction(engine, null);
                        IEnumerator   itr = rv.Iterator;
                        while (itr.MoveNext())
                        {
                            IReturnValue rval = (IReturnValue)itr.Current;
                            Console.WriteLine(rval.StringValue);
                        }
                    }
                }
            }
            catch
            {
                // Console.WriteLine(e.Message);
                parser.ReInit(Console.OpenStandardInput());
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     计算带返回值的语句或表达式
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private ScriptValue ReturnValue(IReturnValue value)
        {
            switch (value)
            {
            case TokenLiteral literal:
                return(new ScriptValue {
                    DataType = literal.DataType, Value = literal.Value
                });

            case TokenVariableRef varRef:
                return(_stack.Get(varRef.Variable));

            case TokenJudgmentExpression expr:
                return(Judgment(expr));

            case TokenBinaryExpression binExpr:
                return(SumBinaryExpression(binExpr));

            case TokenFunctionCallStement call:
                return(ExcuteCall(call));
            }

            throw new Exception("不支持的取值方式.");
        }
Esempio n. 9
0
 public void Visit(IReturnValue returnValue)
 {
     this.result = this.rewriter.Rewrite(returnValue);
 }
Esempio n. 10
0
 public virtual void onASTElement(IReturnValue returnValue) { }
 public override void TraverseChildren(IReturnValue returnValue) {
   //this.sourceEmitterOutput.Write("result");
   this.sourceEmitterOutput.Write("Contract.Result<");
   this.PrintTypeReference(returnValue.Type);
   this.sourceEmitterOutput.Write(">()");
 }
Esempio n. 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="returnValue"></param>
 public ReturnValue(IReturnValue returnValue)
     : base(returnValue)
 {
 }
Esempio n. 13
0
 public virtual void addReturnValue(IReturnValue val)
 {
     items.Add(val);
 }
Esempio n. 14
0
 public virtual void onASTElement(IReturnValue returnValue)
 {
 }
Esempio n. 15
0
 /// <summary>
 /// Returns a shallow copy of the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public ReturnValue Copy(IReturnValue returnValue)
 {
     return new ReturnValue(returnValue);
 }
Esempio n. 16
0
 /// <summary>
 /// Performs some computation with the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public virtual void Visit(IReturnValue returnValue)
 {
 }
Esempio n. 17
0
 public override void Visit(IReturnValue returnValue)
 {
     allElements.Add(new InvokInfo(Traverser, "IReturnValue", returnValue));
 }
Esempio n. 18
0
 public override void TraverseChildren(IReturnValue returnValue)
 {
     base.TraverseChildren(returnValue);
     ((ReturnValue)returnValue).Type = this.containingType;
 }
Esempio n. 19
0
      /// <summary>
      /// Converts the return value into a call to Contract.Result
      /// </summary>
      public override IExpression Rewrite(IReturnValue returnValue) {

        var mref = this.contractProvider.ContractMethods.Result;
        var methodToCall = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference() {
          CallingConvention = CallingConvention.Generic,
          ContainingType = mref.ContainingType,
          GenericArguments = new List<ITypeReference> { returnValue.Type },
          GenericMethod = mref,
          InternFactory = this.host.InternFactory,
          Name = mref.Name,
          Type = returnValue.Type,
        };
        var methodCall = new MethodCall() {
          IsStaticCall = true,
          MethodToCall = methodToCall,
          Type = returnValue.Type,
          Locations = new List<ILocation>(returnValue.Locations),
        };
        return methodCall;
      }
Esempio n. 20
0
 /// <summary>
 /// Throws an exception when executed: IReturnValue nodes
 /// must be replaced before converting the Code Model to IL.
 /// </summary>
 public override void TraverseChildren(IReturnValue returnValue)
 {
     Contract.Assume(false, "IReturnValue nodes must be replaced before trying to convert the Code Model to IL.");
 }
Esempio n. 21
0
        public void MergeMessages(IReturnValue retVal)
        {
            if (retVal != null)
            {
                if ((retVal.Succeeded) && (retVal.HasWarning))
                    AdditionalMessages.Add(new UIMessage(retVal.Message, UIMessage.MessageTypes.Warning));
                else if (retVal.Succeeded)
                    AdditionalMessages.Add(new UIMessage(retVal.Message, UIMessage.MessageTypes.General));
                else
                    AdditionalMessages.Add(new UIMessage(retVal.Message, UIMessage.MessageTypes.Error));

                foreach (UIMessage msg in retVal.AdditionalMessages)
                    AdditionalMessages.Add(msg);
            }
        }
Esempio n. 22
0
 /// <summary>
 /// Visits the specified return value.
 /// </summary>
 /// <param name="returnValue">The return value.</param>
 public override void Visit(IReturnValue returnValue)
 {
     ReturnValue mutableReturnValue = new ReturnValue(returnValue);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableReturnValue);
 }
Esempio n. 23
0
 /// <summary>
 /// Traverses the children of the return value expression.
 /// </summary>
 public virtual void TraverseChildren(IReturnValue returnValue)
 {
     Contract.Requires(returnValue != null);
       this.TraverseChildren((IExpression)returnValue);
 }
Esempio n. 24
0
 /// <summary>
 /// Returns a deep copy of the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public ReturnValue Copy(IReturnValue returnValue)
 {
     var mutableCopy = this.shallowCopier.Copy(returnValue);
       this.CopyChildren((Expression)mutableCopy);
       return mutableCopy;
 }
Esempio n. 25
0
 /// <summary>
 /// Performs some computation with the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public virtual void Visit(IReturnValue returnValue)
 {
     this.Visit((IExpression)returnValue);
 }
Esempio n. 26
0
 public void Visit(IReturnValue returnValue)
 {
     this.result = this.copier.Copy(returnValue);
 }
Esempio n. 27
0
 public void Visit(IReturnValue returnValue)
 {
     throw new NotImplementedException();
 }
        public override void TraverseChildren(IReturnValue returnValue)
{ MethodEnter(returnValue);
            base.TraverseChildren(returnValue);
     MethodExit();   }
 public override void Visit(IReturnValue returnValue)
 {
     if(Process(returnValue)){visitor.Visit(returnValue);}
     base.Visit(returnValue);
 }
Esempio n. 30
0
 /// <summary>
 /// Traverses the return value expression.
 /// </summary>
 public void Traverse(IReturnValue returnValue)
 {
     Contract.Requires(returnValue != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(returnValue);
       if (this.StopTraversal) return;
       this.TraverseChildren(returnValue);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(returnValue);
 }
 /// <summary>
 /// Rewrites the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public virtual IExpression Rewrite(IReturnValue returnValue)
 {
     return returnValue;
 }
Esempio n. 32
0
 public void Visit(IReturnValue returnValue)
 {
     this.traverser.Traverse(returnValue);
 }
Esempio n. 33
0
 public override void TraverseChildren(IReturnValue returnValue) {
   base.TraverseChildren(returnValue);
   ((ReturnValue)returnValue).Type = this.containingType;
 }
Esempio n. 34
0
 public void Visit(IReturnValue returnValue)
 {
     Contract.Requires(returnValue != null);
       throw new NotImplementedException();
 }
Esempio n. 35
0
    /// <summary>
    /// Returns a shallow copy of the given return value expression.
    /// </summary>
    /// <param name="returnValue"></param>
    public ReturnValue Copy(IReturnValue returnValue) {
      Contract.Requires(returnValue != null);
      Contract.Ensures(Contract.Result<ReturnValue>() != null);

      return new ReturnValue(returnValue);
    }
Esempio n. 36
0
    public override void Visit(IReturnValue returnValue) {
      if (this.sink.RetVariable == null) {
        throw new TranslationException(String.Format("Don't know what to do with return value {0}", returnValue.ToString()));
      }
      TranslatedExpressions.Push(new Bpl.IdentifierExpr(returnValue.Token(),
        this.sink.RetVariable));

    }
Esempio n. 37
0
    /// <summary>
    /// Returns a deep copy of the given return value expression.
    /// </summary>
    /// <param name="returnValue"></param>
    public ReturnValue Copy(IReturnValue returnValue) {
      Contract.Requires(returnValue != null);
      Contract.Ensures(Contract.Result<ReturnValue>() != null);

      var mutableCopy = this.shallowCopier.Copy(returnValue);
      this.CopyChildren((Expression)mutableCopy);
      return mutableCopy;
    }
Esempio n. 38
0
 public override void TraverseChildren(IReturnValue returnValue)
 {
     base.sourceEmitterOutput.Write("result");
 }
 /// <summary>
 /// Performs some computation with the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public virtual void Visit(IReturnValue returnValue)
 {
 }
Esempio n. 40
0
 public override void TraverseChildren(IReturnValue returnValue) {
   base.sourceEmitterOutput.Write("result");
 }
Esempio n. 41
0
 /// <summary>
 /// Visits the specified return value.
 /// </summary>
 /// <param name="returnValue">The return value.</param>
 public override void Visit(IReturnValue returnValue)
 {
     ReturnValue mutableReturnValue = returnValue as ReturnValue;
     if (alwaysMakeACopy || mutableReturnValue == null) mutableReturnValue = new ReturnValue(returnValue);
     this.resultExpression = this.myCodeMutator.Visit(mutableReturnValue);
 }
Esempio n. 42
0
 private static  TokenJudgmentExpression  BuildTokenJudgmentExpression(JudgmentExpressionType opt, IReturnValue left, IReturnValue right)
 {
     return new TokenJudgmentExpression()
     {
         Left = left,
         Operator = opt,
         Right = right
     };
 }
Esempio n. 43
0
 /// <summary>
 /// Rewrites the given return value expression.
 /// </summary>
 /// <param name="returnValue"></param>
 public virtual IExpression Rewrite(IReturnValue returnValue)
 {
     var mutableReturnValue = returnValue as ReturnValue;
       if (mutableReturnValue == null) return returnValue;
       this.RewriteChildren(mutableReturnValue);
       return mutableReturnValue;
 }
Esempio n. 44
0
 public override void TraverseChildren(IReturnValue returnValue)
 {
     MethodEnter(returnValue);
     base.TraverseChildren(returnValue);
     MethodExit();
 }
Esempio n. 45
0
 /// <summary>
 /// Visits the specified return value.
 /// </summary>
 /// <param name="returnValue">The return value.</param>
 public override void Visit(IReturnValue returnValue)
 {
     ReturnValue mutableReturnValue = returnValue as ReturnValue;
     if (mutableReturnValue == null) {
       this.resultExpression = returnValue;
       return;
     }
     this.resultExpression = this.myCodeMutator.Visit(mutableReturnValue);
 }