コード例 #1
0
ファイル: AST.cs プロジェクト: chenzuo/blue
    void FixCtors(
        ISemanticResolver s,
        ICLRtypeProvider provider
    )
    {
        // Add default ctor
        bool fFoundCtor = m_symbol.HasMethodHeader(Name);
            
        // Note that structs don't have a default ctor, but can have other ctors                        
        // But add a default ctor for classes if we don't have one.
        if (!fFoundCtor && IsClass)
        {                
            CtorChainStatement stmtChain = new CtorChainStatement();
            Modifiers mods = new Modifiers();
            mods.SetPublic();

            MethodDecl mdecl = new MethodDecl(
                new Identifier(Name, this.Location), 
                null, 
                null, 
                new BlockStatement(new LocalVarDecl[0], new Statement[] { stmtChain }), 
                //new AST.Modifiers(AST.Modifiers.EFlags.Public)
                mods
                );

            stmtChain.FinishInit(mdecl);
                
            mdecl.ResolveMember(m_symbol,s, null);
            mdecl.Symbol.SetInfo(provider);
                
            // Add to the end of the m_alMethods array so that we get codegen'ed!
            AddMethodToList(mdecl);
                
            Debug.Assert(m_symbol.HasMethodHeader(Name));
        }

        // @todo - perhaps we could just make the static initializer a static-ctor..
        // If we don't have a static ctor, but we do have static data, then add
        // a static ctor
        if (m_nodeStaticInit != null) 
        {
            bool fFoundStaticCtor = false;
            foreach(MethodDecl m in m_alMethods)
            {
                if (m.Mods.IsStatic && m.IsCtor)
                {
                    fFoundStaticCtor = true;
                    break;
                }
            }

            if (!fFoundStaticCtor)
            {
                Modifiers mods = new Modifiers();
                mods.SetStatic();
                mods.SetPublic();
                    
                MethodDecl mdecl2 = new MethodDecl(
                    new Identifier(Name, this.Location),
                    null,
                    null,
                    new BlockStatement(null, new Statement[]{}),
                    //new Modifiers(AST.Modifiers.EFlags.Static | Modifiers.EFlags.Public)
                    mods
                    );
                mdecl2.ResolveMember(m_symbol, s, null);
                mdecl2.Symbol.SetInfo(provider);
                AddMethodToList(mdecl2);
            }
        } // end check static ctor
    } // fix ctors