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


C# Context.ResolveGlobalProperty方法代码示例

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


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

示例1: resolve

        protected override Type resolve(Context ctx, bool mustReturn)
        {
            if(Identifier == "_")
                error(CompilerMessages.UnderscoreNameUsed);

            // local variable
            var local = Local ?? ctx.Scope.FindLocal(Identifier);
            if (local != null)
            {
                // only local constants are cached
                // because mutable variables could be closured later on
                if (local.IsConstant && local.IsImmutable && ctx.Options.UnrollConstants)
                    _LocalConstant = local;

                return local.Type;
            }

            // static function declared in the script
            try
            {
                var methods = ctx.MainType.ResolveMethodGroup(Identifier);
                if (methods.Length > 1)
                    error(CompilerMessages.FunctionInvocationAmbiguous, Identifier);

                _Method = methods[0];
                return FunctionalHelper.CreateFuncType(_Method.ReturnType, _Method.GetArgumentTypes(ctx));
            }
            catch (KeyNotFoundException) { }

            // algebraic type without a constructor
            var type = ctx.FindType(Identifier);
            if (type != null && type.Kind == TypeEntityKind.TypeLabel)
            {
                try
                {
                    type.ResolveConstructor(new Type[0]);
                    _Type = type;
                    return _Type.TypeInfo;
                }
                catch (KeyNotFoundException) { }
            }

            // global property
            try
            {
                _Property = ctx.ResolveGlobalProperty(Identifier);
                return _Property.PropertyType;
            }
            catch (KeyNotFoundException)
            {
                error(CompilerMessages.IdentifierNotFound, Identifier);
            }

            return typeof (UnitType);
        }
开发者ID:menozz,项目名称:lens,代码行数:55,代码来源:GetIdentifierNode.cs

示例2: compile

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

            var exprType = Value.GetExpressionType(ctx);
            ctx.CheckTypedExpression(Value, exprType, true);

            var nameInfo = LocalName ?? ctx.CurrentScope.FindName(Identifier);
            if (nameInfo != null)
            {
                if (nameInfo.IsImmutable && !IsInitialization)
                    Error(CompilerMessages.IdentifierIsConstant, Identifier);

                if (!nameInfo.Type.IsExtendablyAssignableFrom(exprType))
                    Error(CompilerMessages.IdentifierTypeMismatch, exprType, nameInfo.Type);

                if (nameInfo.IsClosured)
                {
                    if (nameInfo.ClosureDistance == 0)
                        assignClosuredLocal(ctx, nameInfo);
                    else
                        assignClosuredRemote(ctx, nameInfo);
                }
                else
                {
                    assignLocal(ctx, nameInfo);
                }

                return;
            }

            try
            {
                var pty = ctx.ResolveGlobalProperty(Identifier);

                if(!pty.HasSetter)
                    Error(CompilerMessages.GlobalPropertyNoSetter, Identifier);

                var type = pty.PropertyType;
                if(!type.IsExtendablyAssignableFrom(exprType))
                    Error(CompilerMessages.GlobalPropertyTypeMismatch, exprType, type);

                var cast = Expr.Cast(Value, type);
                if (pty.SetterMethod != null)
                {
                    cast.Compile(ctx, true);
                    gen.EmitCall(pty.SetterMethod.MethodInfo);
                }
                else
                {
                    var method = typeof (GlobalPropertyHelper).GetMethod("Set").MakeGenericMethod(type);

                    gen.EmitConstant(ctx.ContextId);
                    gen.EmitConstant(pty.PropertyId);
                    Expr.Cast(Value, type).Compile(ctx, true);
                    gen.EmitCall(method);
                }
            }
            catch (KeyNotFoundException)
            {
                Error(CompilerMessages.VariableNotFound, Identifier);
            }
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:63,代码来源:SetIdentifierNode.cs

示例3: resolve

        protected override Type resolve(Context ctx, bool mustReturn)
        {
            if (Identifier == "_")
                error(CompilerMessages.UnderscoreNameUsed);

            var nameInfo = Local ?? ctx.Scope.FindLocal(Identifier);
            if (nameInfo != null)
            {
                if (nameInfo.IsImmutable && !IsInitialization)
                    error(CompilerMessages.IdentifierIsConstant, Identifier);
            }
            else
            {
                try
                {
                    _Property = ctx.ResolveGlobalProperty(Identifier);

                    if (!_Property.HasSetter)
                        error(CompilerMessages.GlobalPropertyNoSetter, Identifier);
                }
                catch (KeyNotFoundException)
                {
                    error(CompilerMessages.VariableNotFound, Identifier);
                }
            }

            var destType = nameInfo != null ? nameInfo.Type : _Property.PropertyType;
            ensureLambdaInferred(ctx, Value, destType);

            var exprType = Value.Resolve(ctx);
            ctx.CheckTypedExpression(Value, exprType, true);

            if (!destType.IsExtendablyAssignableFrom(exprType))
            {
                error(
                    nameInfo != null ? CompilerMessages.IdentifierTypeMismatch : CompilerMessages.GlobalPropertyTypeMismatch,
                    exprType,
                    destType
                );
            }

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

示例4: resolveExpressionType

        protected override Type resolveExpressionType(Context ctx, bool mustReturn = true)
        {
            var local = LocalName ?? ctx.CurrentScope.FindName(Identifier);
            if (local != null)
            {
                // only local constants are cached
                // because mutable variables could be closured later on
                if (local.IsConstant && local.IsImmutable && ctx.Options.UnrollConstants)
                    m_LocalConstant = local;

                return local.Type;
            }

            try
            {
                var methods = ctx.MainType.ResolveMethodGroup(Identifier);
                if (methods.Length > 1)
                    Error(CompilerMessages.FunctionInvocationAmbiguous, Identifier);

                m_Method = methods[0];
                return FunctionalHelper.CreateFuncType(m_Method.ReturnType, m_Method.GetArgumentTypes(ctx));
            }
            catch (KeyNotFoundException) { }

            try
            {
                m_Property = ctx.ResolveGlobalProperty(Identifier);
                return m_Property.PropertyType;
            }
            catch (KeyNotFoundException)
            {
                Error(CompilerMessages.IdentifierNotFound, Identifier);
            }

            return typeof (Unit);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:36,代码来源:GetIdentifierNode.cs


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