Exemplo n.º 1
0
 //------------------------------------------------------------
 // MethPropWithInst Constructor (2)
 //
 /// <summary></summary>
 /// <param name="mps"></param>
 /// <param name="ats"></param>
 /// <param name="TypeArguments"></param>
 //------------------------------------------------------------
 internal MethPropWithInst(
     METHPROPSYM mps,
     AGGTYPESYM ats,
     TypeArray TypeArguments)    // = NULL)
 {
     Set(mps, ats, TypeArguments);
 }
Exemplo n.º 2
0
        //------------------------------------------------------------
        // SymWithType.CreateCorrespondingInstance (static)
        //
        /// <summary>
        ///
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="ats"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        static internal SymWithType CreateCorrespondingInstance(SYM sym, AGGTYPESYM ats)
        {
            if (sym == null)
            {
                return(new SymWithType());
            }

            SymWithType swt = null;

            switch (sym.Kind)
            {
            case SYMKIND.METHSYM:
                return(new MethWithType(sym as METHSYM, ats) as SymWithType);

            case SYMKIND.PROPSYM:
                return(new PropWithType(sym as PROPSYM, ats) as SymWithType);

            case SYMKIND.EVENTSYM:
                return(new EventWithType(sym as EVENTSYM, ats) as SymWithType);

            case SYMKIND.MEMBVARSYM:
                return(new FieldWithType(sym as MEMBVARSYM, ats) as SymWithType);

            default:
                break;
            }
            return(new SymWithType(sym, ats));
        }
Exemplo n.º 3
0
        //------------------------------------------------------------
        // FUNCBREC.BindNubValue
        //
        /// <summary>
        /// Create an expr for exprSrc.Value where exprSrc->type is a NUBSYM.
        /// </summary>
        /// <param name="treeNode"></param>
        /// <param name="srcExpr"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        private EXPR BindNubValue(BASENODE treeNode, EXPR srcExpr)
        {
            DebugUtil.Assert(srcExpr != null && srcExpr.TypeSym.IsNUBSYM);

            // For new T?(x), the answer is x.
            if (IsNubCtor(srcExpr))
            {
                DebugUtil.Assert(
                    (srcExpr as EXPRCALL).ArgumentsExpr != null &&
                    (srcExpr as EXPRCALL).ArgumentsExpr.Kind != EXPRKIND.LIST);
                return((srcExpr as EXPRCALL).ArgumentsExpr);
            }

            TYPESYM    baseTypeSym = (srcExpr.TypeSym as NUBSYM).BaseTypeSym;
            AGGTYPESYM ats         = (srcExpr.TypeSym as NUBSYM).GetAggTypeSym();

            if (ats == null)
            {
                return(NewError(treeNode, baseTypeSym));
            }
            compiler.EnsureState(ats, AggStateEnum.Prepared);

            PROPSYM propertySym = compiler.MainSymbolManager.NullableValuePropertySym;

            if (propertySym == null)
            {
                string name = compiler.NameManager.GetPredefinedName(PREDEFNAME.CAP_VALUE);

                propertySym = compiler.MainSymbolManager.LookupAggMember(
                    name,
                    ats.GetAggregate(),
                    SYMBMASK.PROPSYM) as PROPSYM;
                if (propertySym == null ||
                    propertySym.IsStatic ||
                    propertySym.Access != ACCESS.PUBLIC ||
                    propertySym.ParameterTypes.Count > 0 ||
                    !propertySym.ReturnTypeSym.IsTYVARSYM ||
                    propertySym.GetMethodSym == null)
                {
                    compiler.Error(
                        treeNode,
                        CSCERRID.ERR_MissingPredefinedMember,
                        new ErrArg(ats),
                        new ErrArg(name));
                    return(NewError(treeNode, baseTypeSym));
                }
                compiler.MainSymbolManager.NullableValuePropertySym = propertySym;
            }

            CheckFieldUse(srcExpr, true);

            EXPRPROP propertyExpr = NewExpr(treeNode, EXPRKIND.PROP, baseTypeSym) as EXPRPROP;

            propertyExpr.SlotPropWithType.Set(propertySym, ats);
            propertyExpr.GetMethodWithType.Set(propertySym.GetMethodSym, ats);
            propertyExpr.ArgumentsExpr = null;
            propertyExpr.ObjectExpr    = srcExpr;

            return(propertyExpr);
        }
Exemplo n.º 4
0
 //------------------------------------------------------------
 // MethWithInst Constructor (2)
 //
 /// <summary></summary>
 /// <param name="meth"></param>
 /// <param name="ats"></param>
 /// <param name="typeArgs"></param>
 //------------------------------------------------------------
 internal MethWithInst(
     METHSYM meth,
     AGGTYPESYM ats,
     TypeArray typeArgs)    // = NULL)
 {
     Set(meth, ats, typeArgs);
 }
Exemplo n.º 5
0
        //------------------------------------------------------------
        // FUNCBREC.GetActionInvokeMethod
        //
        /// <summary></summary>
        /// <param name="arity"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal METHSYM GetActionInvokeMethod(int arity)
        {
            if (arity < 0 || arity >= systemActionDelegateCount)
            {
                return(null);
            }
            InitSystemActionInvokeMethodSyms();

            METHSYM invokeSym = systemActionInvokeMethodSyms[arity];

            if (invokeSym != null)
            {
                return(invokeSym);
            }

            AGGTYPESYM actionAts = GetActionTypeSym(arity);

            if (actionAts == null)
            {
                return(null);
            }

            invokeSym = Compiler.MainSymbolManager.LookupAggMember(
                "Invoke",
                actionAts.GetAggregate(),
                SYMBMASK.METHSYM) as METHSYM;

            systemActionInvokeMethodSyms[arity] = invokeSym;
            return(invokeSym);
        }
Exemplo n.º 6
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedMethodInfo2 (obsolete)
        //
        /// <summary></summary>
        /// <param name="methInfo"></param>
        /// <param name="aggTypeSym"></param>
        /// <param name="methTypeArguments"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static MethodInfo GetConstructedMethodInfo2(
            MethodInfo methInfo,
            AGGTYPESYM aggTypeSym,
            TypeArray methTypeArguments)
        {
            DebugUtil.Assert(methInfo != null);

            bool       isGenericType = false;
            Type       type          = null;
            MethodInfo methInfo2     = null;

            if (aggTypeSym != null)
            {
                type = aggTypeSym.GetConstructedType(null, null, false);
                if (type != null && type.IsGenericType)
                {
                    isGenericType = true;
                }
            }

            if (!methInfo.IsGenericMethod && !isGenericType)
            {
                return(methInfo);
            }

            if (isGenericType)
            {
                string name       = methInfo.Name;
                Type[] paramTypes = SubstParameterTypes(
                    methInfo.GetParameters(),
                    type.GetGenericArguments());

                try
                {
                    methInfo2 = type.GetMethod(
                        name,
                        paramTypes);
                }
                catch (NotSupportedException)
                {
                    methInfo2 = System.Reflection.Emit.TypeBuilder.GetMethod(
                        type,
                        methInfo);
                }
            }
            else
            {
                methInfo2 = methInfo;
            }

            if (methInfo.IsGenericMethod)
            {
                throw new NotImplementedException("");
            }

            return(methInfo2);
        }
Exemplo n.º 7
0
        //------------------------------------------------------------
        // FUNCBREC.BindNubNew
        //
        /// <summary>
        /// Create an expr for new T?(exprSrc) where T is exprSrc-&gt;type.
        /// </summary>
        /// <param name="treeNode"></param>
        /// <param name="srcExpr"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        private EXPR BindNubNew(BASENODE treeNode, EXPR srcExpr)
        {
            DebugUtil.Assert(srcExpr != null);

            // Create a NUBSYM instance whose base bype is represented by srcExpr.TypeSym.
            NUBSYM nubSym = Compiler.MainSymbolManager.GetNubType(srcExpr.TypeSym);

            // Get a TYPESYM instance representing Nullable<> for nubSym.
            AGGTYPESYM aggTypeSym = nubSym.GetAggTypeSym();

            if (aggTypeSym == null)
            {
                return(NewError(treeNode, nubSym));
            }
            Compiler.EnsureState(aggTypeSym, AggStateEnum.Prepared);

            METHSYM methSym = Compiler.MainSymbolManager.NullableCtorMethodSym;

            if (methSym == null)
            {
                string name = Compiler.NameManager.GetPredefinedName(PREDEFNAME.CTOR);

                for (SYM sym = Compiler.MainSymbolManager.LookupAggMember(name, aggTypeSym.GetAggregate(), SYMBMASK.ALL);
                     ;
                     sym = sym.NextSameNameSym)
                {
                    if (sym == null)
                    {
                        Compiler.Error(treeNode, CSCERRID.ERR_MissingPredefinedMember,
                                       new ErrArg(aggTypeSym), new ErrArg(name));
                        return(NewError(treeNode, nubSym));
                    }
                    if (sym.IsMETHSYM)
                    {
                        methSym = sym as METHSYM;
                        if (methSym.ParameterTypes.Count == 1 && methSym.ParameterTypes[0].IsTYVARSYM &&
                            methSym.Access == ACCESS.PUBLIC)
                        {
                            break;
                        }
                    }
                }
                Compiler.MainSymbolManager.NullableCtorMethodSym = methSym;
            }

            EXPRCALL resExpr = NewExpr(treeNode, EXPRKIND.CALL, nubSym) as EXPRCALL;

            resExpr.MethodWithInst.Set(methSym, aggTypeSym, BSYMMGR.EmptyTypeArray);
            resExpr.ArgumentsExpr = srcExpr;
            resExpr.ObjectExpr    = null;
            resExpr.Flags        |= EXPRFLAG.NEWOBJCALL | EXPRFLAG.CANTBENULL;

            return(resExpr);
        }
Exemplo n.º 8
0
        //------------------------------------------------------------
        // SymWithType.Set (1)
        //
        /// <summary>
        /// <para>If sym is null, ats is set null.</para>
        /// <para>If sym is not null, sym and ats should have the same parent.</para>
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="ats"></param>
        //------------------------------------------------------------
        internal void Set(SYM sym, AGGTYPESYM ats)
        {
            if (sym == null)
            {
                ats = null;
            }
            DebugUtil.Assert(ats == null || sym.ParentSym == ats.GetAggregate());

            if (ats != null && sym.ParentSym != ats.GetAggregate())
            {
                return;
            }

            this.Sym        = sym;
            this.AggTypeSym = ats;
        }
Exemplo n.º 9
0
        //------------------------------------------------------------
        // FUNCBREC.BindNubGetValOrDef
        //
        /// <summary>
        /// Create an expr for exprSrc.GetValueOrDefault()
        /// where exprSrc->type is a NUBSYM.
        /// </summary>
        /// <param name="treeNode"></param>
        /// <param name="srcExpr"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        private EXPR BindNubGetValOrDef(BASENODE treeNode, EXPR srcExpr)
        {
            DebugUtil.Assert(srcExpr != null && srcExpr.TypeSym.IsNUBSYM);

            TYPESYM baseTypeSym = (srcExpr.TypeSym as NUBSYM).BaseTypeSym;

            // If srcExpr is null, just return the appropriate default value.
            if (srcExpr.GetConst() != null)
            {
                return(AddSideEffects(treeNode, NewExprZero(treeNode, baseTypeSym), srcExpr, true, true));
            }

            // For new T?(x), the answer is x.
            if (IsNubCtor(srcExpr))
            {
                DebugUtil.Assert(
                    (srcExpr as EXPRCALL).ArgumentsExpr != null &&
                    (srcExpr as EXPRCALL).ArgumentsExpr.Kind != EXPRKIND.LIST);
                return((srcExpr as EXPRCALL).ArgumentsExpr);
            }

            AGGTYPESYM aggTypeSym = (srcExpr.TypeSym as NUBSYM).GetAggTypeSym();

            if (aggTypeSym == null)
            {
                return(NewError(treeNode, baseTypeSym));
            }
            Compiler.EnsureState(aggTypeSym, AggStateEnum.Prepared);

            METHSYM methSym = EnsureNubGetValOrDef(treeNode);

            if (methSym == null)
            {
                return(NewError(treeNode, baseTypeSym));
            }

            CheckFieldUse(srcExpr, true);

            EXPRCALL resExpr = NewExpr(treeNode, EXPRKIND.CALL, baseTypeSym) as EXPRCALL;

            resExpr.MethodWithInst.Set(methSym, aggTypeSym, BSYMMGR.EmptyTypeArray);
            resExpr.ArgumentsExpr = null;
            resExpr.ObjectExpr    = srcExpr;

            return(resExpr);
        }
Exemplo n.º 10
0
        //------------------------------------------------------------
        // CLSDREC.DefineExtensionMethodCore
        //
        /// <summary></summary>
        /// <param name="methodSym"></param>
        //------------------------------------------------------------
        internal void DefineExtensionMethodCore(METHSYM methodSym)
        {
            DebugUtil.Assert(methodSym != null);

            DebugUtil.Assert(methodSym.ParameterTypes.Count > 0);
            TypeArray  paramTypes = methodSym.ParameterTypes;
            AGGTYPESYM ats        = paramTypes[0] as AGGTYPESYM;

            if (ats == null)
            {
                return;
            }
            AGGSYM targetAggSym = ats.GetAggregate();

            METHSYM instanceMethSym = Compiler.MainSymbolManager.CreateGlobalSym(
                SYMKIND.METHSYM,
                methodSym.Name,
                targetAggSym) as METHSYM;

            instanceMethSym.ContainingAggDeclSym = targetAggSym.FirstDeclSym;
            instanceMethSym.IsUnsafe             = methodSym.IsUnsafe;

            instanceMethSym.TypeVariables = methodSym.TypeVariables;

            TypeArray instParamTypes = new TypeArray();

            for (int i = 1; i < paramTypes.Count; ++i)
            {
                instParamTypes.Add(paramTypes[i]);
            }
            instanceMethSym.ParameterTypes
                = Compiler.MainSymbolManager.AllocParams(instParamTypes);
            instanceMethSym.ReturnTypeSym = methodSym.ReturnTypeSym;
            instanceMethSym.Access        = methodSym.Access;
            instanceMethSym.IsStatic      = false;

            instanceMethSym.IsParameterArray = methodSym.IsParameterArray;
            instanceMethSym.IsVarargs        = methodSym.IsVarargs;

            instanceMethSym.StaticExtensionMethodSym = methodSym;
        }
Exemplo n.º 11
0
        //------------------------------------------------------------
        // FUNCBREC.CreateAutoImplementedGetAccessor
        //
        /// <summary></summary>
        /// <param name="methodSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal EXPR CreateAutoImplementedGetAccessor(METHSYM methodSym)
        {
            CreateNewScope();
            SCOPESYM scopeSym = this.currentScopeSym;

            this.currentScopeSym.ScopeFlags = SCOPEFLAGS.NONE;

            this.currentBlockExpr          = NewExprBlock(treeNode);
            this.currentBlockExpr.ScopeSym = this.currentScopeSym;

            SymWithType symWithType = new SymWithType();
            AGGTYPESYM  parentAts   = methodSym.ParentAggSym.GetThisType();

            symWithType.Set(
                methodSym.PropertySym.BackFieldSym,
                parentAts);

            EXPR fieldExpr = BindToField(
                null,
                BindThisImplicit(null),
                FieldWithType.Convert(symWithType),
                BindFlagsEnum.RValueRequired);

            //TYPESYM retTypeSym = methodSym.ReturnTypeSym;

            EXPRRETURN returnExpr = NewExpr(null, EXPRKIND.RETURN, null) as EXPRRETURN;

            returnExpr.ObjectExpr = fieldExpr;

            this.currentBlockExpr.StatementsExpr = returnExpr;
            EXPRBLOCK blockExpr = this.currentBlockExpr;

            this.currentBlockExpr = blockExpr.OwingBlockExpr;

            CloseScope();

            CorrectAnonMethScope(blockExpr.ScopeSym);

            return(blockExpr);
        }
Exemplo n.º 12
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedFieldInfo
        //
        /// <summary></summary>
        /// <param name="compiler"></param>
        /// <param name="fieldSym"></param>
        /// <param name="aggTypeSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static FieldInfo GetConstructedFieldInfo(
            COMPILER compiler,
            MEMBVARSYM fieldSym,
            AGGTYPESYM aggTypeSym)
        {
            DebugUtil.Assert(compiler != null && compiler.Emitter != null);
            EMITTER emitter = compiler.Emitter;

            DebugUtil.Assert(emitter != null && fieldSym != null && aggTypeSym != null);

            SymUtil.EmitParentSym(emitter, aggTypeSym);
            SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null);
            emitter.EmitMembVarDef(fieldSym);

            Type      parentType   = aggTypeSym.Type;
            FieldInfo fieldDefInfo = fieldSym.FieldInfo;
            Exception ex           = null;

            if (!parentType.IsGenericType)
            {
                return(fieldDefInfo);
            }

            FieldInfo cstrFieldInfo = null;

            try
            {
                cstrFieldInfo = parentType.GetField(fieldDefInfo.Name);
            }
            catch (NotSupportedException)
            {
                cstrFieldInfo = ReflectionUtil.GetFieldInfo(
                    parentType,
                    fieldDefInfo,
                    out ex);
            }
            return(cstrFieldInfo);
        }
Exemplo n.º 13
0
        //------------------------------------------------------------
        // MethPropWithInst.Set (1)
        //
        /// <summary></summary>
        /// <param name="mps"></param>
        /// <param name="ats"></param>
        /// <param name="TypeArguments"></param>
        //------------------------------------------------------------
        internal void Set(METHPROPSYM mps, AGGTYPESYM ats, TypeArray TypeArguments)
        {
            if (mps == null)
            {
                ats           = null;
                TypeArguments = null;
            }

            DebugUtil.Assert(
                ats == null ||
                mps != null && mps.ClassSym == ats.GetAggregate());
            DebugUtil.Assert(
                TypeArguments == null ||
                TypeArguments.Count == 0 ||
                mps != null && mps.IsMETHSYM);
            DebugUtil.Assert(
                TypeArguments == null ||
                !mps.IsMETHSYM ||
                (mps as METHSYM).TypeVariables.Count == TypeArguments.Count);

            this.Sym           = mps;
            this.AggTypeSym    = ats;
            this.TypeArguments = TypeArguments;
        }
Exemplo n.º 14
0
 //------------------------------------------------------------
 // FieldWithType Constructor (2)
 //
 /// <summary></summary>
 /// <param name="field"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal FieldWithType(MEMBVARSYM field, AGGTYPESYM ats)
 {
     Set(field, ats);
 }
Exemplo n.º 15
0
 //------------------------------------------------------------
 // FieldWithType.Set (1)
 //
 /// <summary></summary>
 /// <param name="field"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal void Set(MEMBVARSYM field, AGGTYPESYM ats)
 {
     base.Set(field, ats);
 }
Exemplo n.º 16
0
 //------------------------------------------------------------
 // EventWithType Constructor (2)
 //
 /// <summary></summary>
 /// <param name="evt"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal EventWithType(EVENTSYM evt, AGGTYPESYM ats)
 {
     Set(evt, ats);
 }
Exemplo n.º 17
0
 //------------------------------------------------------------
 // EventWithType.Set (1)
 //
 /// <summary></summary>
 /// <param name="evt"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal void Set(EVENTSYM evt, AGGTYPESYM ats)
 {
     base.Set(evt, ats);
 }
Exemplo n.º 18
0
 //------------------------------------------------------------
 // PropWithType Constructor (2)
 //
 /// <summary></summary>
 /// <param name="prop"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal PropWithType(PROPSYM prop, AGGTYPESYM ats)
 {
     Set(prop, ats);
 }
Exemplo n.º 19
0
 //------------------------------------------------------------
 // PropWithType.Set (1)
 //
 /// <summary></summary>
 /// <param name="prop"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal void Set(PROPSYM prop, AGGTYPESYM ats)
 {
     base.Set(prop, ats);
 }
Exemplo n.º 20
0
 //------------------------------------------------------------
 // MethWithType Constructor (2)
 //
 /// <summary></summary>
 /// <param name="meth"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal MethWithType(METHSYM meth, AGGTYPESYM ats)
 {
     Set(meth, ats);
 }
Exemplo n.º 21
0
 //------------------------------------------------------------
 // SymWithType Constructor (2)
 //
 /// <summary></summary>
 /// <param name="sym"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal SymWithType(SYM sym, AGGTYPESYM ats)
 {
     Set(sym, ats);
 }
Exemplo n.º 22
0
 //------------------------------------------------------------
 // MethPropWithType Constructor (2)
 //
 /// <summary></summary>
 /// <param name="mps"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal MethPropWithType(METHPROPSYM mps, AGGTYPESYM ats)
 {
     Set(mps, ats);
 }
Exemplo n.º 23
0
 //------------------------------------------------------------
 // MethPropWithType.Set (1)
 //
 /// <summary></summary
 /// <param name="mps"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal void Set(METHPROPSYM mps, AGGTYPESYM ats)
 {
     base.Set(mps, ats);
 }
Exemplo n.º 24
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedConstructorInfo
        //
        /// <summary></summary>
        /// <param name="compiler"></param>
        /// <param name="methodSym"></param>
        /// <param name="aggTypeSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static ConstructorInfo GetConstructedConstructorInfo(
            COMPILER compiler,
            METHSYM methodSym,
            AGGTYPESYM aggTypeSym)
        {
            DebugUtil.Assert(compiler != null && compiler.Emitter != null);
            EMITTER emitter = compiler.Emitter;

            DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null);

            SymUtil.EmitParentSym(emitter, aggTypeSym);
            SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null);
            emitter.EmitMethodDef(methodSym);

            Type            parentType   = aggTypeSym.Type;
            ConstructorInfo cnstrDefInfo = methodSym.ConstructorInfo;

            DebugUtil.Assert(cnstrDefInfo != null);

            bool isGenericType = parentType.IsGenericType;

            //--------------------------------------------------------
            // (1) Non-generic Type
            //--------------------------------------------------------
            if (!isGenericType)
            {
                return(cnstrDefInfo);
            }

            //--------------------------------------------------------
            // (2) Generic Type
            //--------------------------------------------------------
            TypeArray paramTypeArray  = methodSym.ParameterTypes;
            TypeArray paramTypeArray2 = null;

            Type[] paramTypes = null;

            if (paramTypeArray != null && paramTypeArray.Count > 0)
            {
                paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray(
                    paramTypeArray,
                    aggTypeSym.AllTypeArguments,
                    null,
                    SubstTypeFlagsEnum.NormNone);

                paramTypes = SymUtil.GetSystemTypesFromTypeArray(
                    paramTypeArray2,
                    methodSym.ClassSym,
                    methodSym);
            }
            else
            {
                paramTypes = Type.EmptyTypes;
            }

            ConstructorInfo constructedInfo = null;
            Exception       ex = null;

            try
            {
                constructedInfo = parentType.GetConstructor(paramTypes);
            }
            catch (NotSupportedException)
            {
                constructedInfo = GetConstructorInfo(parentType, cnstrDefInfo, out ex);
            }
            return(constructedInfo);
        }
Exemplo n.º 25
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedMethodInfo
        //
        /// <summary></summary>
        /// <param name="compiler"></param>
        /// <param name="methodSym"></param>
        /// <param name="aggTypeSym"></param>
        /// <param name="methTypeArguments"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static MethodInfo GetConstructedMethodInfo(
            COMPILER compiler,
            METHSYM methodSym,
            AGGTYPESYM aggTypeSym,
            TypeArray methTypeArguments)
        {
            DebugUtil.Assert(compiler != null && compiler.Emitter != null);
            EMITTER emitter = compiler.Emitter;

            DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null);

            SymUtil.EmitParentSym(emitter, aggTypeSym);
            SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null);
            emitter.EmitMethodDef(methodSym);

            Type       parentType    = aggTypeSym.Type;
            MethodInfo methodDefInfo = methodSym.MethodInfo;

            bool isGenericType   = parentType.IsGenericType;
            bool isGenericMethod = methodDefInfo.IsGenericMethod;

            //--------------------------------------------------------
            // (1-1) Non-generic Type, non-generic method
            //--------------------------------------------------------
            if (!isGenericType && !isGenericMethod)
            {
                return(methodDefInfo);
            }

            //--------------------------------------------------------
            // Parameter types
            //--------------------------------------------------------
            TypeArray paramTypeArray  = methodSym.ParameterTypes;
            TypeArray paramTypeArray2 = null;

            Type[] paramTypes = null;

            if (paramTypeArray != null && paramTypeArray.Count > 0)
            {
                paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray(
                    paramTypeArray,
                    aggTypeSym.AllTypeArguments,
                    methTypeArguments,
                    SubstTypeFlagsEnum.NormNone);

                paramTypes = SymUtil.GetSystemTypesFromTypeArray(
                    paramTypeArray2,
                    methodSym.ClassSym,
                    methodSym);
            }
            else
            {
                paramTypes = Type.EmptyTypes;
            }

            //--------------------------------------------------------
            // (1-2) Non-generic Type, generic method
            //--------------------------------------------------------
            if (!isGenericType)
            {
                DebugUtil.Assert(methTypeArguments != null);

                Exception ex       = null;
                Type[]    typeArgs = SymUtil.GetSystemTypesFromTypeArray(
                    methTypeArguments,
                    methodSym.ClassSym,
                    methodSym);
                return(ReflectionUtil.GetGenericMethod(
                           methodDefInfo,
                           typeArgs,
                           out ex));
            }
            //--------------------------------------------------------
            // (2) Generic Type
            //--------------------------------------------------------
            else
            {
                string     methodName   = methodDefInfo.Name;
                MethodInfo cstrMethInfo = null;
                Exception  ex           = null;

                try
                {
                    cstrMethInfo = parentType.GetMethod(methodName, paramTypes);
                }
                catch (NotSupportedException)
                {
                    cstrMethInfo = GetMethodInfo(parentType, methodDefInfo, out ex);
                }

                if (!isGenericMethod)
                {
                    return(cstrMethInfo);
                }

                DebugUtil.Assert(methTypeArguments != null);
                Type[] typeArgs = SymUtil.GetSystemTypesFromTypeArray(
                    methTypeArguments,
                    methodSym.ClassSym,
                    methodSym);

                return(ReflectionUtil.GetGenericMethod(
                           cstrMethInfo,
                           typeArgs,
                           out ex));
            }
        }
Exemplo n.º 26
0
        //------------------------------------------------------------
        // MetaDataHelper.GetExplicitImplTypeName
        //
        /// <summary></summary>
        /// <param name="typeSym"></param>
        /// <param name="strBuilder"></param>
        //------------------------------------------------------------
        public void GetExplicitImplTypeName(TYPESYM typeSym, StringBuilder strBuilder)
        {
#if DEBUG
            if (!(typeSym != null))
            {
                ;
            }
#endif
            DebugUtil.Assert(typeSym != null);

            TYPESYM   nakedTypeSym = typeSym.GetNakedType(false);
            TypeArray typeArgs     = null;

            switch (nakedTypeSym.Kind)
            {
            default:
                DebugUtil.Assert(false, "Unhandled type in GetExplicitImplTypeName");
                return;

            case SYMKIND.TYVARSYM:
                strBuilder.Append(nakedTypeSym.Name);
                break;

            case SYMKIND.NUBSYM:
                nakedTypeSym = (nakedTypeSym as NUBSYM).GetAggTypeSym();
                if (nakedTypeSym == null)
                {
                    DebugUtil.Assert(false, "Why did GetAts return null?");
                    return;
                }
                // Fall through.
                goto case SYMKIND.AGGTYPESYM;

            case SYMKIND.AGGTYPESYM:
            {
                AGGTYPESYM outerAggTypeSym = (nakedTypeSym as AGGTYPESYM).OuterTypeSym;
                AGGSYM     aggSym          = nakedTypeSym.GetAggregate();

                if (outerAggTypeSym != null)
                {
                    GetExplicitImplTypeName(outerAggTypeSym, strBuilder);
                    strBuilder.Append('.');
                }
                else
                {
                    DebugUtil.Assert(aggSym.ParentBagSym != null && !aggSym.ParentBagSym.IsAGGSYM);
                    int cch = strBuilder.Length;
                    GetFullName(aggSym.ParentBagSym, strBuilder, aggSym);
                    if (cch < strBuilder.Length)
                    {
                        strBuilder.Append('.');
                    }
                }
                strBuilder.Append(aggSym.Name);

                typeArgs = (nakedTypeSym as AGGTYPESYM).TypeArguments;
            }
            break;

            case SYMKIND.ERRORSYM:
            {
                ERRORSYM errSym    = nakedTypeSym as ERRORSYM;
                SYM      parentSym = errSym.ParentSym;

                if (parentSym != null && parentSym.IsTYPESYM)
                {
                    GetExplicitImplTypeName(parentSym as TYPESYM, strBuilder);
                    strBuilder.Append('.');
                }
                else if (parentSym != null && parentSym.IsNSAIDSYM)
                {
                    parentSym = (parentSym as NSAIDSYM).NamespaceSym;
                    int cch = strBuilder.Length;
                    GetFullName(parentSym, strBuilder, errSym);
                    if (cch < strBuilder.Length)
                    {
                        strBuilder.Append('.');
                    }
                }
                strBuilder.Append(errSym.ErrorName);

                typeArgs = errSym.TypeArguments;
            }
            break;
            }

            if (typeArgs != null && typeArgs.Count > 0)
            {
                strBuilder.Append('<');
                for (int i = 0; i < typeArgs.Count; ++i)
                {
                    if (i > 0)
                    {
                        strBuilder.Append(',');
                    }
                    GetExplicitImplTypeName(typeArgs[i], strBuilder);
                }
                strBuilder.Append('>');
            }

            // Add ptr and array modifiers
            AddTypeModifiers(typeSym, strBuilder);
        }
Exemplo n.º 27
0
        //------------------------------------------------------------
        // ReflectionUtil.IsTypeBuilderInstruction
        //
        /// <summary></summary>
        /// <param name="typeSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static bool IsTypeBuilderInstruction(TYPESYM typeSym)
        {
            if (typeSym == null)
            {
                return(false);
            }
            Type type  = null;
            int  count = 0;
            int  index = 0;

            switch (typeSym.Kind)
            {
            //----------------------------------------------------
            // AGGTYPESYM
            //----------------------------------------------------
            case SYMKIND.AGGTYPESYM:
                AGGTYPESYM ats = typeSym as AGGTYPESYM;
                DebugUtil.Assert(ats != null);
                if (ats.AllTypeArguments == null ||
                    ats.AllTypeArguments.Count == 0)
                {
                    return(false);
                }

                AGGSYM aggSym = ats.GetAggregate();
                DebugUtil.Assert(aggSym != null);
                if (aggSym.TypeBuilder != null)
                {
                    return(true);
                }
                TypeArray typeArgs = ats.AllTypeArguments;
                for (int i = 0; i < typeArgs.Count; ++i)
                {
                    if (IsTypeBuilderInstruction(typeArgs[i]))
                    {
                        return(true);
                    }
                }
                return(false);

            //----------------------------------------------------
            // ARRAYSYM
            //----------------------------------------------------
            case SYMKIND.ARRAYSYM:
                return(IsTypeBuilderInstruction(typeSym.ParentSym as TYPESYM));

            //----------------------------------------------------
            // VOIDSYM
            //----------------------------------------------------
            case SYMKIND.VOIDSYM:
                return(false);

            //----------------------------------------------------
            // PARAMMODSYM
            //----------------------------------------------------
            case SYMKIND.PARAMMODSYM:
                return(IsTypeBuilderInstruction(typeSym.ParentSym as TYPESYM));

            //----------------------------------------------------
            // TYVARSYM
            //----------------------------------------------------
            case SYMKIND.TYVARSYM:
                return(true);

            //----------------------------------------------------
            // PTRSYM
            //----------------------------------------------------
            case SYMKIND.PTRSYM:
                return(IsTypeBuilderInstruction((typeSym as PTRSYM).BaseTypeSym));

            //----------------------------------------------------
            // NUBSYM
            //----------------------------------------------------
            case SYMKIND.NUBSYM:
                return(IsTypeBuilderInstruction((typeSym as NUBSYM).BaseTypeSym));

            //----------------------------------------------------
            // otherwise
            //----------------------------------------------------
            case SYMKIND.NULLSYM:
            case SYMKIND.ERRORSYM:
                break;

            case SYMKIND.MODOPTTYPESYM:
                throw new NotImplementedException("SymbolUtil.MakeSystemType: MODOPTTYPESYM");

            case SYMKIND.ANONMETHSYM:
            case SYMKIND.METHGRPSYM:
            case SYMKIND.UNITSYM:
                break;

            default:
                break;
            }
            return(false);
        }
Exemplo n.º 28
0
 //------------------------------------------------------------
 // MethWithType.Set (1)
 //
 /// <summary></summary>
 /// <param name="meth"></param>
 /// <param name="ats"></param>
 //------------------------------------------------------------
 internal void Set(METHSYM meth, AGGTYPESYM ats)
 {
     base.Set(meth, ats);
 }
Exemplo n.º 29
0
 //------------------------------------------------------------
 // SymWithType.Clear
 //
 /// <summary></summary>
 //------------------------------------------------------------
 internal void Clear()
 {
     Sym        = null;
     AggTypeSym = null;
 }
Exemplo n.º 30
0
 //------------------------------------------------------------
 // MethWithInst.Set (1)
 //
 /// <summary></summary>
 /// <param name="meth"></param>
 /// <param name="ats"></param>
 /// <param name="typeArgs"></param>
 //------------------------------------------------------------
 internal void Set(METHSYM meth, AGGTYPESYM ats, TypeArray typeArgs)
 {
     base.Set(meth, ats, typeArgs);
 }