Esempio n. 1
0
        // Value
        public EXPR BindValue(EXPR exprSrc)
        {
            Debug.Assert(exprSrc != null && exprSrc.type.IsNullableType());

            // For new T?(x), the answer is x.
            if (CNullable.IsNullableConstructor(exprSrc))
            {
                Debug.Assert(exprSrc.asCALL().GetOptionalArguments() != null && !exprSrc.asCALL().GetOptionalArguments().isLIST());
                return(exprSrc.asCALL().GetOptionalArguments());
            }

            CType         typeBase = exprSrc.type.AsNullableType().GetUnderlyingType();
            AggregateType ats      = exprSrc.type.AsNullableType().GetAts(GetErrorContext());

            if (ats == null)
            {
                EXPRPROP rval = GetExprFactory().CreateProperty(typeBase, exprSrc);
                rval.SetError();
                return(rval);
            }

            // UNDONE: move this to transform pass ...
            PropertySymbol prop = GetSymbolLoader().getBSymmgr().propNubValue;

            if (prop == null)
            {
                prop = GetSymbolLoader().getPredefinedMembers().GetProperty(PREDEFPROP.PP_G_OPTIONAL_VALUE);
                GetSymbolLoader().getBSymmgr().propNubValue = prop;
            }

            PropWithType     pwt       = new PropWithType(prop, ats);
            MethWithType     mwt       = new MethWithType(prop != null ? prop.methGet : null, ats);
            MethPropWithInst mpwi      = new MethPropWithInst(prop, ats);
            EXPRMEMGRP       pMemGroup = GetExprFactory().CreateMemGroup(exprSrc, mpwi);
            EXPRPROP         exprRes   = GetExprFactory().CreateProperty(typeBase, null, null, pMemGroup, pwt, mwt, null);

            if (prop == null)
            {
                exprRes.SetError();
            }

            return(exprRes);
        }