当前位置: 首页>>代码示例>>C#>>正文


C# AST.InferType方法代码示例

本文整理汇总了C#中Microsoft.JScript.AST.InferType方法的典型用法代码示例。如果您正苦于以下问题:C# AST.InferType方法的具体用法?C# AST.InferType怎么用?C# AST.InferType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.JScript.AST的用法示例。


在下文中一共展示了AST.InferType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CallableExpression

 internal CallableExpression(AST expression)
   : base(expression.context, ""){
   this.expression = expression;
   JSLocalField field = new JSLocalField("", null, 0, Missing.Value);
   this.expressionInferredType = expression.InferType(field);
   field.inferred_type = this.expressionInferredType;
   this.member = field;
   this.members = new MemberInfo[]{field};
 }
开发者ID:ArildF,项目名称:masters,代码行数:9,代码来源:callableexpression.cs

示例2: SetPartialValue

 internal override void SetPartialValue(AST partial_value){
   //ResolveLHValue has already been called and has already checked if the target is accessible and assignable
   if (this.members == null || this.members.Length == 0) return; //Assignment to an undeclared variable. Nothing further to do.
   if (this.member is JSLocalField){
     //If we are dealing with an assignment to an untyped local variable, we need to tell the type inferencer about the assignment
     JSLocalField lfield = (JSLocalField)this.member;
     if (lfield.type == null){
       IReflect ir = partial_value.InferType(lfield);
       if (ir == Typeob.String && partial_value is Plus)
         lfield.SetInferredType(Typeob.Object, partial_value);
       else
         lfield.SetInferredType(ir, partial_value);
       //but then we are done
       return;
     }
     lfield.isDefined = true;
   }
   Binding.AssignmentCompatible(this.InferType(null), partial_value, partial_value.InferType(null), this.isFullyResolved);
 }
开发者ID:ArildF,项目名称:masters,代码行数:19,代码来源:lookup.cs

示例3: SetPartialValue

      internal void SetPartialValue(ASTList argList, IReflect[] argIRs, AST partial_value, bool inBrackets){
        if (this.members == null || this.members.Length == 0){
          this.HandleNoSuchMemberError();
          this.isAssignmentToDefaultIndexedProperty = true;
          return; //Have to do a runtime lookup
        }

        this.PartiallyEvaluate(); //The rhside value of the binding delivers the object with the default indexed property we are assigning to
        IReflect ir = this.InferType(null);
        this.isAssignmentToDefaultIndexedProperty = true;
        if (ir == Typeob.Object){
          JSVariableField jsvf = this.member as JSVariableField;
          if (jsvf == null || !jsvf.IsLiteral || !(jsvf.value is ClassScope))
            return; //Not enough is known at compile time to give an error
          ir = Typeob.Type;
          goto giveError;
        }
        
        //Might be an assignment to an array element
        if ((ir is TypedArray || (ir is Type && ((Type)ir).IsArray))){
          bool gaveAnError = false;
          //Check dimension
          int n = argIRs.Length;
          int m = ir is TypedArray ? ((TypedArray)ir).rank : ((Type)ir).GetArrayRank();
          if (n != m){
            this.context.HandleError(JSError.IncorrectNumberOfIndices, this.isFullyResolved);
            gaveAnError = true;
          }
          //Check type of indices
          for (int i = 0; i < m; i++){
            if (!gaveAnError && i < n && argIRs[i] != Typeob.Object &&
                (!Convert.IsPrimitiveNumericType(argIRs[i]) || Convert.IsBadIndex(argList[i]))){
              argList[i].context.HandleError(JSError.TypeMismatch, this.isFullyResolved);       
              gaveAnError = true;
            }
          }
          this.isArrayElementAccess = true;
          this.isAssignmentToDefaultIndexedProperty = false;
          this.defaultMember = member;
          this.defaultMemberReturnIR = ir;
          
          IReflect elemIR = ir is TypedArray ? ((TypedArray)ir).elementType : ((Type)ir).GetElementType();
          Binding.AssignmentCompatible(elemIR, partial_value, partial_value.InferType(null), this.isFullyResolved);
          return;
        }
        
        MemberInfo[] defaultMembers = JSBinder.GetDefaultMembers(ir);
        if (defaultMembers != null && defaultMembers.Length > 0 && this.member != null){
          try{
            PropertyInfo prop = JSBinder.SelectProperty(defaultMembers, argIRs);
            if (prop == null){ 
              this.context.HandleError(JSError.NotIndexable, Convert.ToTypeName(ir));
              return;
            }
            if (JSProperty.GetSetMethod(prop, true) == null){
              if (ir == Typeob.String)
                this.context.HandleError(JSError.UselessAssignment);
              else
                this.context.HandleError(JSError.AssignmentToReadOnly, this.isFullyResolved&&this.Engine.doFast);
              return;
            }
            if (!Binding.CheckParameters(prop.GetIndexParameters(), argIRs, argList, this.context, 0, false, true)){
              return;
            }
            this.defaultMember = this.member;
            this.defaultMemberReturnIR = ir;
            this.members = defaultMembers;
            this.member = prop;
          }catch(AmbiguousMatchException){
            this.context.HandleError(JSError.AmbiguousMatch, this.isFullyResolved);
            this.member = null;
          }
          return;
        }
        
      giveError:
        this.member = null;
        if (!inBrackets)
          this.context.HandleError(JSError.IllegalAssignment);
        else
          this.context.HandleError(JSError.NotIndexable, Convert.ToTypeName(ir));
      }
开发者ID:ArildF,项目名称:masters,代码行数:82,代码来源:binding.cs


注:本文中的Microsoft.JScript.AST.InferType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。