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


C# Emitter.FindType方法代码示例

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


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

示例1: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var type = Expression.GetExpressionType(emitter);
              if (type.IsAnyOf("int", "float", "complex"))
              {
            if(type == "complex")
            {
              // simple case: the complex is a constant
              if(Expression is ComplexNode)
              {
            (Expression as ComplexNode).Imaginary *= -1;
            Expression.Compile(emitter);
              }
              // complex case: complex is an expression result
              else
              {
            Expression.Compile(emitter);

            // tmp = ...
            var tmpVar = emitter.CurrentMethod.Scope.Introduce("complex", emitter.FindType("complex").Type);
            emitter.EmitSaveVariable(tmpVar);

            // tmp.real
            emitter.EmitLoadVariableAddress(tmpVar);
            emitter.EmitCall(emitter.AssemblyImport(typeof(SN.Complex).GetMethod("get_Real")));

            // tmp.imaginary * -1
            emitter.EmitLoadVariableAddress(tmpVar);
            emitter.EmitCall(emitter.AssemblyImport(typeof(SN.Complex).GetMethod("get_Imaginary")));
            emitter.EmitLoadFloat(-1);
            emitter.EmitMul();

            // new complex
            emitter.EmitNewObj(emitter.FindMethod("complex", ".ctor", "float", "float"));
              }
            }
            else
            {
              // multiply by -1
              Expression.Compile(emitter);
              if (type == "int")
            emitter.EmitLoadInt(-1);
              else
            emitter.EmitLoadFloat(-1);
              emitter.EmitMul();
            }
              }
              else
            Error(String.Format(Resources.errInvertType, type));
        }
开发者ID:menozz,项目名称:mirelle,代码行数:50,代码来源:OperatorInvertNode.cs

示例2: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            // check if constructor exists
              TypeNode type = null;
              try
              {
            type = emitter.FindType(Name);
              }
              catch
              {
            Error(String.Format(Resources.errTypeNotFound, Name));
              }

              // check if type is an enum?
              if (type.Enum)
              {
            // the constructor in an enum is pseudo-private
            // so that it can only be called from another method
            // of the same enum type
            if(emitter.CurrentMethod == null || emitter.CurrentMethod.Owner != type)
              Error(String.Format(Resources.errConstructEnum, Name));
              }

              MethodNode method = null;
              var signature = GetSignature(emitter);
              try
              {
            method = emitter.FindMethod(Name, ".ctor", signature);
              }
              catch
              {
            Error(String.Format(Resources.errConstructorNotFound, Name, signature.Join(" ")));
              }

              // parameters
              for (int idx = 0; idx < Parameters.Count; idx++)
              {
            Parameters[idx].Compile(emitter);
            emitter.EmitUpcastBasicType(Parameters[idx].GetExpressionType(emitter), method.Parameters[idx].Type.Signature);
              }

              emitter.EmitNewObj(method);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:43,代码来源:NewNode.cs

示例3: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var currType = emitter.CurrentType;
              var currMethod = emitter.CurrentMethod;
              emitter.CurrentType = emitter.FindType(PlannerID);

              // convert the IdentifierGet to IdentifierInvoke with two faux arguments
              AppendActionParameters(emitter);

              // extract closured variables
              var detector = new Utils.ClosureDetector();
              Closures = detector.Process(Action, emitter);
              DeclareClosuredVariables(emitter);

              // generate closured code for emitter
              CompileBody(emitter);

              emitter.CurrentType = currType;
              emitter.CurrentMethod = currMethod;

              CompileInitiation(emitter);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:22,代码来源:SimulatePlannerNode.cs

示例4: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var currType = emitter.CurrentType;
              var currMethod = emitter.CurrentMethod;
              emitter.CurrentType = emitter.FindType(EmitterID);

              // extract closured variables
              var detector = new Utils.ClosureDetector();
              ActionClosures = detector.Process(Action, emitter);
              if (Condition != null)
            ConditionClosures = detector.Process(Condition, emitter);
              MergeClosures();
              DeclareClosuredVariables(emitter);

              // generate closured code for emitter
              CompileBody(emitter);

              emitter.CurrentType = currType;
              emitter.CurrentMethod = currMethod;

              CompileInitiation(emitter);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:22,代码来源:EmitNode.cs

示例5: DeclareClosuredVariables

        /// <summary>
        /// Create fields in the emitter type to save local variables intos
        /// </summary>
        private void DeclareClosuredVariables(Emitter.Emitter emitter)
        {
            var flowSimType = emitter.FindType(PlannerID);

              foreach (var curr in Closures)
              {
            var fld = emitter.CreateField(flowSimType, "_" + curr.Key, new SignatureNode(curr.Value));
            emitter.PrepareField(fld);
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:13,代码来源:SimulatePlannerNode.cs

示例6: CompileInitiation

        /// <summary>
        /// Generate code to setup the currently defined emitter
        /// </summary>
        /// <param name="emitter"></param>
        private void CompileInitiation(Emitter.Emitter emitter)
        {
            var flowSimType = emitter.FindType(PlannerID);
              var tmpVar = emitter.CurrentMethod.Scope.Introduce(PlannerID, flowSimType.Type);

              // tmp = new flowsimN()
              emitter.EmitNewObj(emitter.FindMethod(PlannerID, ".ctor"));
              emitter.EmitSaveVariable(tmpVar);

              SaveClosuredVariables(emitter, tmpVar);

              // call FlowSimulation.Start(planner)
              emitter.EmitLoadVariable(tmpVar);
              var method = emitter.AssemblyImport(typeof(FlowSimulation).GetMethod("Start", new[] { typeof(Planner) }));
              emitter.EmitCall(method);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:20,代码来源:SimulatePlannerNode.cs

示例7: Resolve

        /// <summary>
        /// Resolve the identifier meaning
        /// </summary>
        public void Resolve(Emitter.Emitter emitter)
        {
            // already resolved?
              if (Kind != IdentifierKind.Unresolved) return;

              // atmark?
              if (AtmarkPrefix)
              {
            if (emitter.CurrentType == null)
              Error(Resources.errFieldOutsideType);

            OwnerType = emitter.CurrentType.Name;

            var field = emitter.FindField(emitter.CurrentType.Name, Name);
            if (field != null)
              Kind = field.Static ? IdentifierKind.StaticField : IdentifierKind.Field;
            else
              Error(String.Format(Resources.errFieldNotFound, Name, emitter.CurrentType.Name));

            // additional check: dynamic field from static method
            if (emitter.CurrentMethod.Static && !field.Static)
              Error(String.Format(Resources.errDynamicFromStatic, field.Name));
              }

              // other prefix?
              else if (TypePrefix != null || ExpressionPrefix != null)
              {
            OwnerType = (TypePrefix != null ? TypePrefix.Data : ExpressionPrefix.GetExpressionType(emitter));

            if (OwnerType == "null")
              Error(Resources.errNullAccessor);

            if(OwnerType.EndsWith("[]") && Name == "size")
            {
              Kind = IdentifierKind.SizeProperty;
              return;
            }

            // check class existence
            emitter.FindType(OwnerType);

            // field ?
            try
            {
              emitter.FindField(OwnerType, Name);
              Kind = (TypePrefix != null ? IdentifierKind.StaticField : IdentifierKind.Field);
              return;
            }
            catch { }

            // method ?!
            MethodNode method = null;
            try
            {
              method = emitter.FindMethod(OwnerType, Name);
            }
            catch
            {
              Error(String.Format(Resources.errTypeIdentifierUnresolved, OwnerType, Name));
            }

            if (ExpressionPrefix == null && !method.Static)
              Error(String.Format(Resources.errNonStaticMethod, Name));

            Kind = (TypePrefix != null ? IdentifierKind.StaticMethod : IdentifierKind.Method);
              }

              else
              {
            MethodNode method = null;

            // local variable
            if (emitter.CurrentMethod.Scope.Exists(Name))
            {
              Kind = IdentifierKind.Variable;
              return;
            }

            // parameter
            if(emitter.CurrentMethod.Parameters.Contains(Name))
            {
              Kind = IdentifierKind.Parameter;
              return;
            }

            // search for a method
            try
            {
              method = emitter.FindMethod(emitter.CurrentType != null ? emitter.CurrentType.Name : "", true, Name);
            }
            catch
            {
              Error(String.Format(Resources.errIdentifierUnresolved, Name));
            }

            OwnerType = method.Owner.Name;
            if(method.Static)
//.........这里部分代码省略.........
开发者ID:menozz,项目名称:mirelle,代码行数:101,代码来源:IdentifierGetNode.cs

示例8: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var fromType = Expression.GetExpressionType(emitter);
              var toType = ToType;
              var simpleTypes = new[] { "bool", "int", "float", "long", "complex" };

              if (emitter.ResolveType(toType) == null)
            Error(String.Format(Resources.errTypeNotFound, toType));

              // compile the expression itself
              Expression.Compile(emitter);

              // idiotic case?
              if (fromType == toType) return;

              if(fromType == "null")
              {
            if(toType.IsAnyOf(simpleTypes))
              Error(String.Format(Resources.errInvalidNullCast, toType));

            // no actual casting is required
              }
              // cast simple types
              else if(fromType.IsAnyOf(simpleTypes))
              {
            if (toType.IsAnyOf(simpleTypes))
            {
              switch(toType)
              {
            case "bool": emitter.EmitConvertToBool(); break;
            case "int": emitter.EmitConvertToInt(); break;
            case "float": emitter.EmitConvertToFloat(); break;
            default: throw new NotImplementedException();
              }
            }
            else
              Error(String.Format(Resources.errInvalidCast, fromType, toType));
              }
              else
              {
            // complex type to simple type: search for a conversion method
            if(toType.IsAnyOf(simpleTypes))
            {
              // to_b, to_f, to_i
              string methodName = "to_" + toType[0];
              MethodNode converter = null;
              try
              {
            converter = emitter.FindMethod(fromType, methodName);
              }
              catch
              {
            Error(String.Format(Resources.errInvalidCast, fromType, toType));
              }

              // call the method
              emitter.EmitCall(converter);
            }
            else
            {
              if (fromType.Contains("[]") || toType.Contains("[]"))
            Error(Resources.errCastArray);

              if(!emitter.TypeCastable(fromType, toType))
            Error(String.Format(Resources.errInvalidCast, fromType, toType));

              var type = emitter.FindType(toType);
              emitter.EmitCast(type.Type);
            }
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:71,代码来源:AsNode.cs

示例9: Resolve

        private void Resolve(Emitter.Emitter emitter)
        {
            // already resolved?
              if (Kind != IdentifierKind.Unresolved) return;

              // atmark?
              if (AtmarkPrefix)
              {
            OwnerType = emitter.CurrentType.Name;

            var field = emitter.FindField(emitter.CurrentType.Name, Name);
            if (field != null)
              Kind = field.Static ? IdentifierKind.StaticField : IdentifierKind.Field;
            else
              Error(String.Format(Resources.errFieldNotFound, Name, emitter.CurrentType.Name));

            // additional check: dynamic field from static method
            if (emitter.CurrentMethod.Static && !field.Static)
              Error(String.Format(Resources.errDynamicFromStatic, field.Name));

            IdentifierType = field.Type.Signature;
              }

              // other prefix?
              else if (TypePrefix != null || ExpressionPrefix != null)
              {
            OwnerType = (TypePrefix != null ? TypePrefix.Data : ExpressionPrefix.GetExpressionType(emitter));

            // check class existence
            var type = emitter.FindType(OwnerType);
            if (type == null)
              Error(String.Format(Resources.errTypeNotFound, OwnerType), TypePrefix);

            // field ?
            var field = emitter.FindField(OwnerType, Name);
            Kind = (TypePrefix != null ? IdentifierKind.StaticField : IdentifierKind.Field);
            IdentifierType = field.Type.Signature;
              }

              else
              {
            // local variable
            if (emitter.CurrentMethod.Scope.Exists(Name))
            {
              Kind = IdentifierKind.Variable;
              IdentifierType = emitter.CurrentMethod.Scope.Find(Name).Type;
            }

            // parameter
            else if (emitter.CurrentMethod.Parameters.Contains(Name))
            {
              Kind = IdentifierKind.Parameter;
              IdentifierType = emitter.CurrentMethod.Parameters[Name].Type.Signature;
            }

            // no luck at all
            else
              Error(String.Format(Resources.errIdentifierUnresolved, Name));
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:60,代码来源:IdentifierSetNode.cs

示例10: CompileInitiation

        /// <summary>
        /// Generate code to setup the currently defined emitter
        /// </summary>
        /// <param name="emitter"></param>
        private void CompileInitiation(Emitter.Emitter emitter)
        {
            var emitterType = emitter.FindType(EmitterID);
              var tmpVar = emitter.CurrentMethod.Scope.Introduce(EmitterID, emitterType.Type);

              // tmp = new emitterN()
              emitter.EmitNewObj(emitter.FindMethod(EmitterID, ".ctor"));
              emitter.EmitSaveVariable(tmpVar);

              // step
              if (Step != null)
              {
            // validate step
            var stepType = Step.GetExpressionType(emitter);
            if (!stepType.IsAnyOf("int", "float"))
              Error(Resources.errEmitStepExpected);

            // tmp.Step = step
            emitter.EmitLoadVariable(tmpVar);
            Step.Compile(emitter);
            if (stepType == "int")
              emitter.EmitConvertToFloat();
            emitter.EmitSaveField(emitter.FindField(EmitterID, "step"));
              }

              // distribution
              if (Distribution != null)
              {
            // validate distr
            if (Distribution.GetExpressionType(emitter) != "distr")
              Error(Resources.errEmitDistributionExpected);

            // tmp.Distr = distr
            emitter.EmitLoadVariable(tmpVar);
            Distribution.Compile(emitter);
            emitter.EmitSaveField(emitter.FindField(EmitterID, "distr"));
              }

              // limit
              if (Limit != null)
              {
            // validate distr
            if (Limit.GetExpressionType(emitter) != "int")
              Error(Resources.errEmitLimitExpected);

            // tmp.Distr = distr
            emitter.EmitLoadVariable(tmpVar);
            Limit.Compile(emitter);
            emitter.EmitSaveField(emitter.FindField(EmitterID, "limit"));
              }

              SaveClosuredVariables(emitter, tmpVar);

              // register emitter in the system
              emitter.EmitLoadVariable(tmpVar);
              var registerMethod = emitter.AssemblyImport(typeof(Simulation).GetMethod("RegisterEmitter", new[] { typeof(EventEmitter) }));
              emitter.EmitCall(registerMethod);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:62,代码来源:EmitNode.cs

示例11: Resolve

        public void Resolve(Emitter.Emitter emitter)
        {
            // build signature
              var signature = GetSignature(emitter);
              MethodNode method;

              // type prefix ?
              if(TypePrefix != null)
              {
            OwnerType = TypePrefix.Data;
            Static = true;

            // check class existence
            emitter.FindType(OwnerType);
            method = emitter.FindMethod(TypePrefix.Data, Name, signature);

            if (!method.Static)
              Error(String.Format(Resources.errNonStaticMethod, Name));
              }

              // expression prefix ?
              else if(ExpressionPrefix != null)
              {
            OwnerType = ExpressionPrefix.GetExpressionType(emitter);
            if (OwnerType == "null")
              Error(Resources.errNullAccessor);

            emitter.FindMethod(OwnerType, Name, signature);
              }

              // local or visible method ?
              else
              {
            // try to find method in local type, if there's one
            var tmpOwner = emitter.CurrentType != null ? emitter.CurrentType.Name : "";
            method = emitter.FindMethod(tmpOwner, true, Name, signature);

            OwnerType = method.Owner.Name;
            Static = method.Static;
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:41,代码来源:IdentifierInvokeNode.cs


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