Beispiel #1
0
        // Ctor for imported properties
        public PropertyExpEntry(
            ISemanticResolver s,
            System.Reflection.PropertyInfo info
            )
        {
            m_info = info;

            m_strName = m_info.Name;

            // Class that we're defined in?
            System.Type tClrClass = info.DeclaringType;
            m_tClassDefined = s.ResolveCLRTypeToBlueType(tClrClass);

            // Symbol type
            this.m_type = s.ResolveCLRTypeToBlueType(info.PropertyType);

            // Spoof accessors
            if (info.CanRead) // Has Get
            {
                System.Reflection.MethodInfo mGet = info.GetGetMethod();
                m_symbolGet = new MethodExpEntry(s, mGet);
            }

            if (info.CanWrite) // Has Set
            {
                System.Reflection.MethodInfo mSet = info.GetSetMethod();
                m_symbolSet = new MethodExpEntry(s, mSet);
            }

            // Get modifiers
            System.Reflection.MethodInfo [] m = info.GetAccessors();

            m_mods = new Modifiers(m[0]);

            /*
             * m_mods = new Modifiers();
             * if (m[0].IsStatic) m_mods.SetStatic();
             * if (m[0].IsAbstract) m_mods.SetAbstract();
             * if (m[0].IsVirtual) m_mods.SetVirtual();
             */
        }
Beispiel #2
0
    CreateCLRMethod(
        SymbolEngine.MethodExpEntry symBlueMethod
    )
    {
        // Call DefineMethod on the TypeBuilder to get a MethodBuilder
        // MethodBuilder derives from MethodInfo
        string stMethodName         = symBlueMethod.Name;

        Debug.Assert(symBlueMethod.Node != null);
        
        AST.Modifiers mods = symBlueMethod.Node.Mods;        
        MethodAttributes attrMethod = (MethodAttributes) 0;
        
        // Everything seems to have this; but what does it do?
        attrMethod = MethodAttributes.HideBySig;
                
        if (mods.IsPublic)
            attrMethod |= MethodAttributes.Public;
        else if (mods.IsProtected)
            attrMethod |= MethodAttributes.Family;
        else if (mods.IsPrivate)
            attrMethod |= MethodAttributes.Private;
        else if (mods.IsInternal)
            attrMethod |= MethodAttributes.Assembly;
            
        
        if (symBlueMethod.IsSpecialName)
            attrMethod |= MethodAttributes.SpecialName;
            
        if (mods.IsStatic)
        {
            attrMethod |= MethodAttributes.Static;
        }
        
        if (mods.IsVirtual)
            attrMethod |= MethodAttributes.Virtual | MethodAttributes.NewSlot;
        
        if (mods.IsAbstract)
            attrMethod |= MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.NewSlot;
                
        if (mods.IsOverride)
        {
            attrMethod |= MethodAttributes.Virtual;
        }
        
        if (mods.IsSealed)
            attrMethod |= MethodAttributes.Final;
        
        
        
        // Overloaded operators have a magical bit sit
        if (symBlueMethod.Node.IsOpOverload)
            attrMethod |= MethodAttributes.SpecialName;
                
        // Get signature from the parameters        
        #if false
        Type [] alParamTypes = new Type[symBlueMethod.ParamCount];            
        for(int iParam = 0; iParam < symBlueMethod.ParamCount; iParam++)
        {            
            alParamTypes[iParam] = symBlueMethod.ParamCLRType(iParam);
        }        
        #else
        Type [] alParamTypes = symBlueMethod.ParamTypes(false);
        #endif       
        
        // Get class that we're defined in
        TypeBuilder bldClass = symBlueMethod.SymbolClass.CLRType as TypeBuilder;
        Debug.Assert(bldClass != null);
        
        bool fIsCtor = symBlueMethod.IsCtor;
        
        System.Reflection.MethodBase bld = null;           
                
        // Get the builder        
        if (fIsCtor)
        {   
            
            ConstructorBuilder bldCtor = bldClass.DefineConstructor(attrMethod, CallingConventions.Standard, alParamTypes);    

            if (AST.DelegateDecl.IsDelegate(symBlueMethod.SymbolClass.CLRType))
            {
                bldCtor.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);                
            }

            //return bldCtor;        
            bld = bldCtor;
        }
        else 
        {                        
            Type typeReturn = symBlueMethod.RetType.CLRType;
            Debug.Assert(typeReturn != null, "Semantic check should catch null return type");
            
            MethodBuilder bldMethod = bldClass.DefineMethod(stMethodName, attrMethod, typeReturn, alParamTypes);
            
            // The members of a delegate are special because they're implemented by the runtime.
            if (AST.DelegateDecl.IsDelegate(symBlueMethod.SymbolClass.CLRType))
            {
                bldMethod.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
            }
            
            
            //return bldMethod;
            bld = bldMethod;
        }
        
        
        // Double check that we set the attributes on the new CLR method properly.
        // Do this by converting back to blue modifier from CLR method and comparing
        // that modifier to the original.        
        
        #if DEBUG
        AST.Modifiers modsCheck = new AST.Modifiers(bld);
        string stPretty = symBlueMethod.PrettyDecoratedName;
        string stBlue = mods.ToString();
        string stCLR = modsCheck.ToString();
        
        // The 'new' modifier just tells the C# compiler to suppress warnings. There's
        // no IL bit for it, so we lose it when we roundtrip. So just add it to both
        // of them.
        mods.SetNew();
        modsCheck.SetNew();
        Debug.Assert(modsCheck == mods, "Modifer mismatch in creating CLR method");
        #endif
        
        return bld;
        
    }
Beispiel #3
0
 // Ctor for imported properties
 public PropertyExpEntry(        
     ISemanticResolver s,
     System.Reflection.PropertyInfo info
     )
 {
     m_info = info;
     
     m_strName = m_info.Name;
                
     // Class that we're defined in?
     System.Type tClrClass = info.DeclaringType;
     m_tClassDefined = s.ResolveCLRTypeToBlueType(tClrClass);
     
     // Symbol type
     this.m_type = s.ResolveCLRTypeToBlueType(info.PropertyType);
     
     // Spoof accessors
     if (info.CanRead) // Has Get
     {
         System.Reflection.MethodInfo mGet = info.GetGetMethod();
         m_symbolGet = new MethodExpEntry(s, mGet);
     }
     
     if (info.CanWrite) // Has Set
     {
         System.Reflection.MethodInfo mSet = info.GetSetMethod();
         m_symbolSet = new MethodExpEntry(s, mSet);
     }
     
     // Get modifiers
     System.Reflection.MethodInfo [] m = info.GetAccessors();
     
     m_mods = new Modifiers(m[0]);
     /*
     m_mods = new Modifiers();
     if (m[0].IsStatic) m_mods.SetStatic(); 
     if (m[0].IsAbstract) m_mods.SetAbstract(); 
     if (m[0].IsVirtual) m_mods.SetVirtual();
     */
     
 }