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


C# Context.ResolveType方法代码示例

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


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

示例1: emitCode

        protected override void emitCode(Context ctx, bool mustReturn)
        {
            var type = Type ?? ctx.ResolveType(TypeSignature);
            var gen = ctx.CurrentMethod.Generator;

            gen.EmitConstant(type);
            gen.EmitCall(_HandleMethod);
        }
开发者ID:menozz,项目名称:lens,代码行数:8,代码来源:TypeofOperatorNode.cs

示例2: compile

        protected override void compile(Context ctx, bool mustReturn)
        {
            var type = Type ?? ctx.ResolveType(TypeSignature);
            var gen = ctx.CurrentILGenerator;
            var method = typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) });

            gen.EmitConstant(type);
            gen.EmitCall(method);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:9,代码来源:TypeofOperatorNode.cs

示例3: resolve

        protected override Type resolve(Context ctx, bool mustReturn)
        {
            if (Type == null)
                Type = ctx.ResolveType(TypeSignature);

            var idxType = Size.Resolve(ctx);
            if (!typeof (int).IsExtendablyAssignableFrom(idxType))
                error(Size, CompilerMessages.ArraySizeNotInt, idxType);

            return Type.MakeArrayType();
        }
开发者ID:menozz,项目名称:lens,代码行数:11,代码来源:NewObjectArrayNode.cs

示例4: ProcessClosures

        public override void ProcessClosures(Context ctx)
        {
            base.ProcessClosures(ctx);

            var type = ExceptionType != null ? ctx.ResolveType(ExceptionType) : typeof(Exception);
            if (type != typeof(Exception) && !type.IsSubclassOf(typeof(Exception)))
                error(CompilerMessages.CatchTypeNotException, type);

            if(!string.IsNullOrEmpty(ExceptionVariable))
                _ExceptionVariable = ctx.Scope.DeclareLocal(ExceptionVariable, type, false);
        }
开发者ID:menozz,项目名称:lens,代码行数:11,代码来源:CatchNode.cs

示例5: Resolve

        public override IEnumerable<PatternNameBinding> Resolve(Context ctx, Type expressionType)
        {
            if (!IsWildcard)
                yield return new PatternNameBinding(Name, expressionType);

            if (Type != null)
            {
                var specifiedType = ctx.ResolveType(Type);
                if(!specifiedType.IsExtendablyAssignableFrom(expressionType) && !expressionType.IsExtendablyAssignableFrom(specifiedType))
                    Error(CompilerMessages.PatternTypeMatchImpossible, specifiedType, expressionType);
            }
        }
开发者ID:menozz,项目名称:lens,代码行数:12,代码来源:MatchNameRule.cs

示例6: Resolve

        public override IEnumerable<PatternNameBinding> Resolve(Context ctx, Type expressionType)
        {
            var typeEntity = ctx.FindType(Identifier.FullSignature);
            if(typeEntity == null || (!typeEntity.Kind.IsAnyOf(TypeEntityKind.Type, TypeEntityKind.TypeLabel)))
                Error(Identifier, CompilerMessages.PatternNotValidType, Identifier.FullSignature);

            Type = ctx.ResolveType(Identifier);
            if (!Type.IsExtendablyAssignableFrom(expressionType) && !expressionType.IsExtendablyAssignableFrom(Type))
                Error(CompilerMessages.PatternTypeMatchImpossible, Type, expressionType);

            try
            {
                var field = typeEntity.ResolveField("Tag");
                return LabelRule.Resolve(ctx, field.Type);
            }
            catch(KeyNotFoundException)
            {
                Error(CompilerMessages.PatternTypeNoTag, Identifier.FullSignature);
                return NoBindings();
            }
        }
开发者ID:menozz,项目名称:lens,代码行数:21,代码来源:MatchTypeRule.cs

示例7: compile

        protected override void compile(Context ctx, bool mustReturn)
        {
            var gen = ctx.CurrentILGenerator;

            var exprType = Expression.GetExpressionType(ctx);
            var desiredType = ctx.ResolveType(TypeSignature);

            SafeModeCheckType(ctx, desiredType);

            // types are identical
            if (exprType == desiredType)
            {
                gen.EmitConstant(true);
                return;
            }

            // valuetype can only be cast to object
            if (exprType.IsValueType)
            {
                gen.EmitConstant(desiredType == typeof(object));
                return;
            }

            Expression.Compile(ctx, true);

            // check if not null
            if (desiredType == typeof (object))
            {
                gen.EmitNull();
                gen.EmitCompareEqual();
                gen.EmitConstant(false);
                gen.EmitCompareEqual();
            }
            else
            {
                gen.EmitCast(desiredType, false);
                gen.EmitNull();
                gen.EmitCompareGreater(false);
            }
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:40,代码来源:IsOperatorNode.cs

示例8: GetArgumentType

        /// <summary>
        /// Calculates argument type.
        /// </summary>
        public Type GetArgumentType(Context ctx)
        {
            if (Type == null)
            {
                Type = ctx.ResolveType(TypeSignature);

                if (IsRefArgument)
                    Type = Type.MakeByRefType();
                else if (IsVariadic)
                    Type = Type.MakeArrayType();
            }

            return Type;
        }
开发者ID:menozz,项目名称:lens,代码行数:17,代码来源:FunctionArgument.cs

示例9: resolveGetMember

        /// <summary>
        /// Resolves the method if the expression was a member getter (obj.field or type::field).
        /// </summary>
        private void resolveGetMember(Context ctx, GetMemberNode node)
        {
            _InvocationSource = node.Expression;
            var type = _InvocationSource != null
                ? _InvocationSource.Resolve(ctx)
                : ctx.ResolveType(node.StaticType);

            checkTypeInSafeMode(ctx, type);

            if (node.TypeHints != null && node.TypeHints.Count > 0)
                _TypeHints = node.TypeHints.Select(x => ctx.ResolveType(x, true)).ToArray();

            try
            {
                // resolve a normal method
                try
                {
                    _Method = ctx.ResolveMethod(
                        type,
                        node.MemberName,
                        _ArgTypes,
                        _TypeHints,
                        (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                    );

                    if (_Method.IsStatic)
                        _InvocationSource = null;

                    return;
                }
                catch (KeyNotFoundException)
                {
                    if (_InvocationSource == null)
                        throw;
                }

                // resolve a callable field
                try
                {
                    ctx.ResolveField(type, node.MemberName);
                    resolveExpression(ctx, node);
                    return;
                }
                catch (KeyNotFoundException) { }

                // resolve a callable property
                try
                {
                    ctx.ResolveProperty(type, node.MemberName);
                    resolveExpression(ctx, node);
                    return;
                }
                catch (KeyNotFoundException) { }

                Arguments = (Arguments[0] is UnitNode)
                    ? new List<NodeBase> {_InvocationSource}
                    : new[] {_InvocationSource}.Union(Arguments).ToList();

                var oldArgTypes = _ArgTypes;
                _ArgTypes = Arguments.Select(a => a.Resolve(ctx)).ToArray();
                _InvocationSource = null;

                try
                {
                    // resolve a local function that is implicitly used as an extension method
                    _Method = ctx.ResolveMethod(
                        ctx.MainType.TypeInfo,
                        node.MemberName,
                        _ArgTypes,
                        resolver: (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                    );

                    return;
                }
                catch (KeyNotFoundException) { }

                // resolve a declared extension method
                // most time-consuming operation, therefore is last checked
                try
                {
                    if(!ctx.Options.AllowExtensionMethods)
                        throw new KeyNotFoundException();

                    _Method = ctx.ResolveExtensionMethod(
                        type,
                        node.MemberName,
                        oldArgTypes,
                        _TypeHints,
                        (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
                    );
                }
                catch (KeyNotFoundException)
                {
                    var msg = node.StaticType != null
                        ? CompilerMessages.TypeStaticMethodNotFound
                        : CompilerMessages.TypeMethodNotFound;

//.........这里部分代码省略.........
开发者ID:menozz,项目名称:lens,代码行数:101,代码来源:InvocationNode.cs

示例10: compile

        protected override void compile(Context ctx, bool mustReturn)
        {
            var gen = ctx.CurrentILGenerator;

            var backup = ctx.CurrentTryBlock;
            ctx.CurrentTryBlock = this;

            EndLabel = gen.BeginExceptionBlock();

            Code.Compile(ctx, false);
            gen.EmitLeave(EndLabel);

            var catchTypes = new Dictionary<Type, bool>();
            var catchAll = false;
            foreach (var curr in CatchClauses)
            {
                if(catchAll)
                    Error(curr, CompilerMessages.CatchClauseUnreachable);

                var currType = curr.ExceptionType != null ? ctx.ResolveType(curr.ExceptionType) : typeof (Exception);

                if(catchTypes.ContainsKey(currType))
                    Error(curr, CompilerMessages.CatchTypeDuplicate, currType);

                if (currType == typeof (Exception))
                    catchAll = true;

                curr.Compile(ctx, false);
            }

            if (Finally != null)
            {
                gen.BeginFinallyBlock();
                Finally.Compile(ctx, false);
            }

            gen.EndExceptionBlock();

            ctx.CurrentTryBlock = backup;
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:40,代码来源:TryNode.cs

示例11: resolve

        protected override Type resolve(Context ctx, bool mustReturn)
        {
            var prevTypes = new List<Type>();

            foreach(var curr in CatchClauses)
            {
                var currType = curr.ExceptionType != null ? ctx.ResolveType(curr.ExceptionType) : typeof(Exception);

                foreach (var prevType in prevTypes)
                {
                    if(currType == prevType)
                        error(curr, CompilerMessages.CatchTypeDuplicate, currType);
                    else if(prevType.IsExtendablyAssignableFrom(currType))
                        error(curr, CompilerMessages.CatchClauseUnreachable, currType, prevType);
                }

                prevTypes.Add(currType);
            }

            return base.resolve(ctx, mustReturn);
        }
开发者ID:menozz,项目名称:lens,代码行数:21,代码来源:TryNode.cs

示例12: resolve

        private void resolve(Context ctx)
        {
            Action check = () =>
            {
                if (Expression == null && !m_IsStatic)
                    Error(CompilerMessages.DynamicMemberFromStaticContext, MemberName);

                if(m_Method == null && TypeHints.Count > 0)
                    Error(CompilerMessages.TypeArgumentsForNonMethod, m_Type, MemberName);

                m_IsResolved = true;
            };

            m_Type = StaticType != null
                ? ctx.ResolveType(StaticType)
                : Expression.GetExpressionType(ctx);

            // special case: array length
            if (m_Type.IsArray && MemberName == "Length")
            {
                check();
                return;
            }

            // check for field
            try
            {
                m_Field = ctx.ResolveField(m_Type, MemberName);
                m_IsStatic = m_Field.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException) { }

            // check for property
            try
            {
                m_Property = ctx.ResolveProperty(m_Type, MemberName);

                if(!m_Property.CanGet)
                    Error(CompilerMessages.PropertyNoGetter, m_Type, MemberName);

                m_IsStatic = m_Property.IsStatic;

                check();
                return;
            }
            catch (KeyNotFoundException)
            { }

            var argTypes = TypeHints.Select(t => t.FullSignature == "_" ? null : ctx.ResolveType(t)).ToArray();
            var methods = ctx.ResolveMethodGroup(m_Type, MemberName).Where(m => checkMethodArgs(ctx, argTypes, m)).ToArray();

            if (methods.Length == 0)
                Error(argTypes.Length == 0 ? CompilerMessages.TypeIdentifierNotFound : CompilerMessages.TypeMethodNotFound, m_Type.Name, MemberName);

            if (methods.Length > 1)
                Error(CompilerMessages.TypeMethodAmbiguous, m_Type.Name, MemberName);

            m_Method = methods[0];
            if (m_Method.ArgumentTypes.Length > 16)
                Error(CompilerMessages.CallableTooManyArguments);

            m_IsStatic = m_Method.IsStatic;

            check();
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:68,代码来源:GetMemberNode.cs

示例13: resolve

        protected override Type resolve(Context ctx, bool mustReturn)
        {
            var type = Value != null
                ? Value.Resolve(ctx)
                : ctx.ResolveType(Type);

            ctx.CheckTypedExpression(Value, type);

            if (Local == null)
            {
                if (Name == "_")
                    error(CompilerMessages.UnderscoreName);

                try
                {
                    var name = ctx.Scope.DeclareLocal(Name, type, IsImmutable);
                    if (Value != null && Value.IsConstant && ctx.Options.UnrollConstants)
                    {
                        name.IsConstant = true;
                        name.ConstantValue = Value.ConstantValue;
                    }
                }
                catch (LensCompilerException ex)
                {
                    ex.BindToLocation(this);
                    throw;
                }
            }

            return base.resolve(ctx, mustReturn);
        }
开发者ID:menozz,项目名称:lens,代码行数:31,代码来源:NameDeclarationNodeBase.cs

示例14: Resolve

        public override IEnumerable<PatternNameBinding> Resolve(Context ctx, Type expressionType)
        {
            var typeEntity = ctx.FindType(Identifier.FullSignature);
            if (typeEntity == null || (!typeEntity.Kind.IsAnyOf(TypeEntityKind.Record)))
                Error(Identifier, CompilerMessages.PatternNotValidRecord, Identifier.FullSignature);

            Type = ctx.ResolveType(Identifier);
            if (!Type.IsExtendablyAssignableFrom(expressionType) && !expressionType.IsExtendablyAssignableFrom(Type))
                Error(CompilerMessages.PatternTypeMatchImpossible, Type, expressionType);

            var duplicate = FieldRules.GroupBy(x => x.Name).FirstOrDefault(x => x.Count() > 1);
            if(duplicate != null)
                Error(CompilerMessages.PatternRecordFieldDuplicated, duplicate.Key);

            var subBindings = new List<PatternNameBinding>();
            foreach (var fieldRule in FieldRules)
            {
                try
                {
                    var field = typeEntity.ResolveField(fieldRule.Name.FullSignature);
                    subBindings.AddRange(fieldRule.Rule.Resolve(ctx, field.Type));
                }
                catch (KeyNotFoundException)
                {
                    Error(fieldRule.Name, CompilerMessages.PatternRecordNoField, Identifier.FullSignature, fieldRule.Name.FullSignature);
                }
            }

            return subBindings;
        }
开发者ID:menozz,项目名称:lens,代码行数:30,代码来源:MatchRecordRule.cs

示例15: GetArgumentType

        /// <summary>
        /// Calculates argument type.
        /// </summary>
        public Type GetArgumentType(Context ctx)
        {
            if (Type != null)
                return Type;

            var type = ctx.ResolveType(TypeSignature);
            if (IsRefArgument)
                type = type.MakeByRefType();

            return type;
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:14,代码来源:FunctionArgument.cs


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