⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symbol.cs

📁 charp compiler
💻 CS
📖 第 1 页 / 共 3 页
字号:
            
            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();
            */
            
        }
#endregion

#region Data                
        TypeEntry m_tClassDefined;
        
        MethodExpEntry m_symbolGet;
        MethodExpEntry m_symbolSet;
        
        System.Reflection.PropertyInfo m_info;
        AST.PropertyDecl m_node;
    
        Modifiers m_mods;
#endregion

#region Properties
        public AST.PropertyDecl Node
        {
            get { return m_node; }            
        }
        
        public TypeEntry PropertyType
        {
            get { return m_type; }        
        }
        
        public TypeEntry SymbolClass
        {
            get { return m_tClassDefined; }
        }
        
        public MethodExpEntry SymbolGet
        {
            get { return m_symbolGet; }
        }
        
        public MethodExpEntry SymbolSet
        {
            get { return m_symbolSet; }
        }
        
        public System.Reflection.PropertyInfo Info
        {
            get { return m_info; }
        }
        
        public bool IsStatic
        {
            get { return Mods.IsStatic; }
        }
        
        public bool IsVirtual
        {
            get { return Mods.IsVirtual; }
        }
        
        public bool IsAbstract
        {
            get { return Mods.IsAbstract; }
        }
        
        public Modifiers Mods
        {
            get { return this.m_mods; }
        }
#endregion        

#region Resolution
        public void SetInfo(ICLRtypeProvider provider)
        {
            Debug.Assert(m_info == null);
            
            // This will create a clr info for this property
            // as well as the accessors                    
            m_info = provider.CreateCLRProperty(this);
        }

#endregion
    
#region Checks        
        public override void DebugCheck(ISemanticResolver s)
        {
            Debug.Assert(Name != null);            
            Debug.Assert(Info != null);
            Debug.Assert(SymbolClass != null);
            
            if (Node != null)
            {
                Debug.Assert(Node.Symbol == this);
            }
            
            //SymbolClass.DebugCheck(s);
            //PropertyType.DebugCheck(s);
            
        }


        // Write out this Entry's name, attributes, (and if fRecursive, then nested scope too)
        public override void Dump(XmlWriter o, bool fRecursive)
        {
            o.WriteStartElement("PropertyExpEntry");
            o.WriteAttributeString("name", m_strName);
            o.WriteAttributeString("type", (m_type == null) ? "null" : m_type.ToString());
            o.WriteAttributeString("class", (m_tClassDefined == null) ? "null" : m_tClassDefined.ToString());
            
            o.WriteAttributeString("HasGet", (m_symbolGet != null) ? "true" : "false" );
            o.WriteAttributeString("HasSet", (m_symbolSet != null) ? "true" : "false" );           
            
            o.WriteAttributeString("Imported", (Node == null) ? "true" : "false");
                                                
            o.WriteEndElement();        
        }
#endregion       
    }

#endregion

#region Literal Fields
    //-----------------------------------------------------------------------------
    // Literal field
    //-----------------------------------------------------------------------------
    public class LiteralFieldExpEntry : FieldExpEntry
    {
    // Construction is the same as for Fields,
#region Construction
        public LiteralFieldExpEntry(
            string stName,                  // name of this field
            TypeEntry tType,                // type of this field
            TypeEntry tDefiningClassType,   // type of class we're defined in
            AST.FieldDecl nodeDecl          // AST node that we're defined at
            )
        : base(stName, tType, tDefiningClassType, nodeDecl)
        {
        }
        
        
        // For imported
        public LiteralFieldExpEntry(
            ISemanticResolver s,
            System.Reflection.FieldInfo fInfo        
        ) : base(s, fInfo)
        {
            Debug.Assert(fInfo.IsLiteral && fInfo.IsStatic);
            
            object o = fInfo.GetValue(null);
            
            // For enum fields, their literal value is an Enum, not an int.
            
                                
            Data = o;
            Type t = m_value.GetType();
            string st = m_value.ToString();
        }
        
#endregion
    // but we're associated with an object...
#region Properties        
        object m_value;
        public object Data
        {
            get { return m_value; }
            set { m_value = value; }
        }
#endregion

        
        public override void SetInfo(ICLRtypeProvider provider)
        {
            Debug.Assert(m_info == null);
            m_info = provider.CreateCLRLiteralField(this);
        }

    }
#endregion

#region Fields
    //-----------------------------------------------------------------------------
    // Fields
    //-----------------------------------------------------------------------------    
    public class FieldExpEntry : ExpEntry
    {
#region Construction
        public FieldExpEntry(
            string stName,                  // name of this field
            TypeEntry tType,                // type of this field
            TypeEntry tDefiningClassType,   // type of class we're defined in
            AST.FieldDecl nodeDecl          // AST node that we're defined at
            )
        {
            m_strName = stName;
            m_type = tType;
            m_nodeDecl = nodeDecl;
            m_tClassDefined = tDefiningClassType;
            
            Debug.Assert(m_type != null);
            Debug.Assert(m_nodeDecl != null); // @todo - allow this for imports?
            Debug.Assert(m_tClassDefined != null);
        }
        
        // Imported field        
        public FieldExpEntry(
            ISemanticResolver s,
            System.Reflection.FieldInfo fInfo            
            )
        {
            m_strName = fInfo.Name;
            m_type = s.ResolveCLRTypeToBlueType(fInfo.FieldType);
            m_nodeDecl = null;
            m_tClassDefined = s.ResolveCLRTypeToBlueType(fInfo.DeclaringType);
            
            m_info = fInfo;
        }
#endregion

#region Properties & Data
        
        protected System.Reflection.FieldInfo m_info;
        public System.Reflection.FieldInfo Info
        {
            get { return m_info; }
        }

        // Valid only after we've set the clr type
        public bool IsStatic 
        {
            get { return m_info.IsStatic; }
        }

        public virtual void SetInfo(ICLRtypeProvider provider)
        {
            Debug.Assert(m_info == null);
            m_info = provider.CreateCLRField(this);
        }

        protected AST.FieldDecl m_nodeDecl;        
        public AST.FieldDecl Node
        {
            get { return m_nodeDecl;  }
        }
        
        public TypeEntry FieldType
        {
            get { return m_type; }
        }
        
        protected TypeEntry m_tClassDefined;
        public TypeEntry SymbolClass
        {
            get { return m_tClassDefined; }
        }
        
        public override string ToString()
        {
            return "FieldExp:" + m_tClassDefined.ToString() + "." + m_strName;
        }
#endregion

#region Checks        
        public override void DebugCheck(ISemanticResolver s)
        {
            Debug.Assert(Name != null);
            if (Node != null)
            {
                Debug.Assert(Node.Symbol == this);
            }
            Debug.Assert(Info != null);
            Debug.Assert(SymbolClass != null);
            Debug.Assert(FieldType != null);

            SymbolClass.DebugCheck(s);
            FieldType.DebugCheck(s);
        }


        // Write out this Entry's name, attributes, (and if fRecursive, then nested scope too)
        public override void Dump(XmlWriter o, bool fRecursive)
        {
            o.WriteStartElement("FieldExpEntry");
            o.WriteAttributeString("name", m_strName);
            o.WriteAttributeString("type", (m_type == null) ? "null" : m_type.ToString());
            o.WriteAttributeString("class", (m_tClassDefined == null) ? "null" : m_tClassDefined.ToString());
                        
            o.WriteEndElement();        
        }         
#endregion        

    }
#endregion

#region Methods
    //-----------------------------------------------------------------------------
    // Since methods can be overloaded, we have to be able to efficiently
    // search through the scope for all the methods. So we create a linked
    // list of methods and insert a header into the scope
    //-----------------------------------------------------------------------------
    public class MethodHeaderEntry : SymEntry
    {
        public MethodHeaderEntry(
            string stName
            )
        {
            this.m_strName = stName;    
        }
        
        public override void Dump(XmlWriter o, bool fRecursive)
        {
            o.WriteStartElement("MethodHeaderEntry");
            o.WriteAttributeString("name", m_strName);
            o.WriteEndElement();
        }
            
        public void AddMethodNode(MethodExpEntry entry)
        {
            Debug.Assert(entry.m_next == null);
            entry.m_next = m_head;
            m_head = entry;            
        }
        
        public MethodExpEntry GetFirstMethod()
        {
            return m_head;
        }
        public MethodExpEntry GetNextMethod(MethodExpEntry entry)
        {
            Debug.Assert(entry != null);
            return entry.m_next;
        }
        
        // For iterations
        public MethodEnumerator GetEnumerator()
        {
            return new MethodEnumerator(GetFirstMethod());
        }
        
        // For maintiaing a linked list
        MethodExpEntry m_head;
        
        public override string ToString()
        {
            int count = 0;
            MethodExpEntry h = m_head;
            while(h != null)
            {
                 h = h.m_next;
                 count++;
            }
            return "MethodHeaderEntry (" + count + " overloads)";
        }
    }
        
       
    // A MethodEnumerator is obtained from a MethodHeader
    // to get all the methods that have the same name.
    public struct MethodEnumerator
    {
        public MethodEnumerator(MethodExpEntry mStart)
        {
            m_methodCurrent = null;
            m_method = mStart;
        }
        
        public bool MoveNext()
        {
            //m_method = header.GetNextMethod(m);
            m_methodCurrent = m_method;
            if (m_method == null) 
                return false;
            m_method = m_method.m_next;
            return true;
        }
        
        public MethodExpEntry Current
        {
            get { return m_methodCurrent; }
        }
        
        MethodExpEntry m_method;
        MethodExpEntry m_methodCurrent;
    }
    
    //-----------------------------------------------------------------------------
    // Method
    //-----------------------------------------------------------------------------    
    public class MethodExpEntry : ExpEntry
    {        
#region Construction
        // User-declared
        public MethodExpEntry(
            string stName,              // name of the method
            AST.MethodDecl nodeClass,       // node of ast defining us (can be null)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -