Exemplo n.º 1
0
        public void SetInfo(ICLRtypeProvider provider)
        {
            //Debug.Assert(m_info == null);

            //m_info =
            provider.CreateCLREvent(this);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
//-----------------------------------------------------------------------------
// Primary Worker. This drives the different stages.
// Returns the error code for all expected end-user errors.
// Unexpected errors (bugs / holes in the compiler) will throw an exception.
//-----------------------------------------------------------------------------
        static int MainWorker(string[] arstSourceFiles)
        {
            if (arstSourceFiles == null)
            {
                PrintError_NoSourceFiles();
                return(1);
            }


            // Check if debugging the lexer. Just do first file
            // @todo - should we do all files?
            if (ShouldDebugQuit(EStage.cLexer))
            {
                string stDefault = arstSourceFiles[0];
                System.IO.StreamReader reader = new System.IO.StreamReader(stDefault);
                ILexer lex = new ManualParser.Lexer(stDefault, reader);

                return(TestLexer(lex));
            }

            //
            // Lex & Parse all source files.
            // It doesn't matter which order files are parsed in
            //
            AST.ProgramDecl root = ParseAllFiles(arstSourceFiles);
            if (root == null)
            {
                return(1);
            }

            if (ShouldDebugQuit(EStage.cParser))
            {
                return(0);
            }


            //
            // Symantic checks:
            //

            // Must startup codegen so that it can assign clr types
            m_codegen.BeginOutput(arstSourceFiles);

            System.Reflection.Assembly [] refs = LoadImportedAssemblies();
            if (StdErrorLog.HasErrors())
            {
                return(19);
            }

            ICLRtypeProvider provider = m_codegen.GetProvider(refs);

            ISemanticChecker check    = new SymbolEngine.SemanticChecker();
            bool             fCheckOk = check.DoCheck(root, provider, refs);

            if (!fCheckOk)
            {
                return(2);
            }

            // Dump parse tree after resolution
            if (s_fGenerateXML)
            {
                string stOutput = IO.Path.GetFileNameWithoutExtension(arstSourceFiles[0]);


                System.Xml.XmlWriter oSym = new System.Xml.XmlTextWriter(stOutput + "_sym.xml", null);
                check.DumpSymbolTable(oSym);

                System.Xml.XmlWriter oPost = new System.Xml.XmlTextWriter(stOutput + "_post.xml", null);
                AST.Node.DumpTree(root, oPost);
            }

            if (ShouldDebugQuit(EStage.cSymbolResolution))
            {
                return(0);
            }

            //
            // Codegen
            //

            m_codegen.DoCodeGen(root);

            m_codegen.EndOutput();

            // If we make it this far, we have no errors.
            return(0);
        }
Exemplo n.º 4
0
Arquivo: AST.cs Projeto: chenzuo/blue
 public abstract void ResolveTypesAsCLR(
     ISemanticResolver s,
     ICLRtypeProvider provider
 );
Exemplo n.º 5
0
Arquivo: AST.cs Projeto: chenzuo/blue
    public void ResolveTypesAsCLR(
        ISemanticResolver s,
        ICLRtypeProvider provider
    )
    {
        // We shouldn't have to update the scope stack since
        // we should only be looking at resolved symbols

        Scope prev = s.SetCurrentContext(m_context);
        
        // add all classes in this namespace
        {   
            foreach(TypeDeclBase e in m_arTypes)
                e.ResolveTypesAsCLR(s, provider);
        }
        
        s.RestoreContext(prev);
            
        // Recursively add all classes from nested namespaces
        foreach(NamespaceDecl n in NestedNamespaces)
            n.ResolveTypesAsCLR(s, provider);
    }
Exemplo n.º 6
0
Arquivo: AST.cs Projeto: chenzuo/blue
    // Semantic checking
    public override void ResolveMember(
        TypeEntry symDefiningClass, 
        ISemanticResolver s,
        ICLRtypeProvider provider
    )
    {
        //TypeEntry tRetType = null;
        if (!IsCtor)
        {
            m_tRetType.ResolveType(s);
            //tRetType = m_tRetType.TypeRec;
        } 
        else 
        {            
            ClassDecl nodeClass = symDefiningClass.Node;
            if (Mods.IsStatic)
            {
                // Checks on static ctors
                if (this.Params.Length != 0)
                {
                    //s.ThrowError_NoParamsOnStaticCtor(this);
                    ThrowError(SymbolError.NoParamsOnStaticCtor(this));
                }

                // Rename to avoid a naming collision w/ a default ctor.
                // Since no one will call a static ctor (and codegen ignores ctor names),
                // we can pick anything here.
                //this.m_strName = "$static_ctor";
                this.m_idName = new Identifier("$static_ctor", m_idName.Location);

                // Is there a static field initializer to chain to?
                if (nodeClass.StaticInitMethod != null)
                {
                    /*                           
                    Statement stmt = new ExpStatement(
                        new MethodCallExp(
                        null,
                        new Identifier(nodeClass.StaticInitMethod.Name, nodeClass.StaticInitMethod.Location),
                        new ArgExp[0]
                        ));
                    */
                    // If there are Static, ReadOnly fields, then they must be assigned directly
                    // in a constructor, not in a function called by the constructor.
                    Statement stmt = nodeClass.StaticInitMethod.Body;
                    Body.InjectStatementAtHead(stmt);                    
                }
            } // static ctor
            else 
            {
                if (nodeClass.InstanceInitMethod != null)
                {
                    // Chain to an instance-field initializer if we don't chain to
                    // a this() ctor.
                    CtorChainStatement chain = (this.Body.Statements[0]) as CtorChainStatement;
                    Debug.Assert(chain != null);
                    
                    if (chain.TargetType == CtorChainStatement.ETarget.cBase)
                    {       
                        /*                 
                        Statement stmt = new MethodCallStatement(
                            new MethodCallExp(
                                null,
                                new Identifier(nodeClass.InstanceInitMethod.Name, nodeClass.InstanceInitMethod.Location),
                                new ArgExp[0]
                            ));
                        */
                        // PEVerify barfs if we try to do an instance method call in the ctor,
                        // so just inject the raw method body. It's just a bunch of assigns anyway,
                        // so we're ok.
                        Statement stmt = nodeClass.InstanceInitMethod.Body;
                            
                        Body.InjectStatementAtHead(stmt);
                    }
                }
            } // instance ctor
        }
                       
        // Add new sym entry to our parent class's scope
        MethodExpEntry m = new MethodExpEntry(
            Name, 
            this, 
            symDefiningClass, 
            IsCtor ? null : m_tRetType.BlueType
        );
        
        m.m_scope = new Scope(
            "method: " + symDefiningClass.m_strName + "." + Name, 
            this,
            symDefiningClass.MemberScope);
        
        m_symbol = m;
        
        //s.PushScope(m.m_scope);
        Scope prev = s.SetCurrentContext(m.m_scope);
        
        // resolve params (because we'll need them for overloading)
        // Add param 0 for 'this' (if not static)
        // For structs, "this" is a reference, for classes, it's a value.
        if (!Mods.IsStatic)
        {
            ParamVarExpEntry e = new ParamVarExpEntry();
            e.m_strName = "this";
            
            TypeEntry t = m_symbol.SymbolClass;
            if (t.IsStruct)
            {
                t = new RefTypeEntry(t, s);
            }
            e.m_type = t; // 'this' is the type of the containg class   
            e.CodeGenSlot = 0;
            s.GetCurrentContext().AddSymbol(e);
        }
        
        // do rest of the params
        foreach(ParamVarDecl param in m_arParams)
        {
            param.ResolveVarDecl(s);
        }

        //s.PopScope(m.m_scope);
        s.RestoreContext(prev);
                
        symDefiningClass.AddMethodToScope(m);
    }
Exemplo n.º 7
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Resolve this
 public override void ResolveMember(
     TypeEntry symDefiningClass, 
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     m_tType.ResolveType(s);
     
 // Spoof bodies
             
     if (HasGet)
     {                        
         m_declGet.ResolveMember(symDefiningClass, s, null);
         m_declGet.Symbol.IsSpecialName = true;
     }
     if (HasSet)
     {   
         m_declSet.ResolveMember(symDefiningClass, s, null);
         m_declSet.Symbol.IsSpecialName = true;
     }
 
 // Create a symbol for the property
     m_symbol = new SymbolEngine.PropertyExpEntry(symDefiningClass, this, m_declGet, m_declSet);
     
     s.GetCurrentContext().AddSymbol(m_symbol);
 }
Exemplo n.º 8
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Resolve the events
 public override void ResolveMember(
     TypeEntry symDefiningClass, 
     ISemanticResolver s,
     ICLRtypeProvider provider        
     )
 {
     m_tType.ResolveType(s);
     
     m_symbol = new EventExpEntry(symDefiningClass, this);
     s.GetCurrentContext().AddSymbol(m_symbol);
     
     // If an event has no handlers
     if (m_addMethod == null && m_addMethod == null)
     {
         FixDefaultHandlers(symDefiningClass, s, provider);        
     }
     
     
     Debug.Assert(m_addMethod != null && m_removeMethod != null);
     Debug.Assert(m_addMethod.Symbol == null); // shouldn't have resolved handlers yet
     Debug.Assert(m_removeMethod.Symbol == null); 
     
     // The handlers should be treated just like normal methods..
     ClassDecl c = symDefiningClass.Node;
     c.AddMethodToList(m_addMethod);
     c.AddMethodToList(m_removeMethod);
     
            
 }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
Arquivo: AST.cs Projeto: chenzuo/blue
    public override void ResolveMemberDecls(
        ISemanticResolver s,
        ICLRtypeProvider provider
    )
    {
        Scope scope = m_symbol.MemberScope;
        
        int iLastValue = -1;
        Scope prev = s.SetCurrentContext(scope);
        
        for(int i = 0; i < this.Fields.Length; i++)
        {
            FieldDecl f = this.Fields[i];
            Exp e = f.InitialExp;
            //Debug.Assert(e != null);

            // Evaluate e to a literal...
            //Exp.TrySimplify(ref e);
            int iValue;
            if (e != null)
            {
                IntExp e2 = e as IntExp;
                Debug.Assert(e2 != null, "Can only assign to an integer literal"); //@todo - legit error
                iValue = e2.Value;
            } 
            else 
            {
                if (i == 0)
                    iValue = 0;
                else
                    iValue = iLastValue + 1;
            }

            // Need to create an object of type 'ThisEnum' with integer value iValue;
            //Type tEnum = this.Symbol.CLRType;
            // errors
            //System.ComponentModel.TypeConverter c = new System.ComponentModel.TypeConverter();
            //object o2 = c.ConvertTo(iValue, tEnum);
            
            // errors
            // object oValue = System.Enum.ToObject(tEnum, iValue);
            iLastValue = iValue;
            f.ResolveMemberAsLiteral(this.m_symbol, s, iValue);

            LiteralFieldExpEntry l = (LiteralFieldExpEntry) f.Symbol;
            l.SetInfo(provider);
        }
        
        //s.PopScope(scope);
        s.RestoreContext(prev);
    }
Exemplo n.º 11
0
Arquivo: AST.cs Projeto: chenzuo/blue
 public override void ResolveTypesAsCLR(
     ISemanticResolver s,
     ICLRtypeProvider provider
     )
 {
     if (m_symbol.CLRType != null)
         return;
         
     m_symbol.SetCLRType(provider); // enum
             
     s.AddClrResolvedType(this.Symbol);
 }
Exemplo n.º 12
0
Arquivo: AST.cs Projeto: chenzuo/blue
 public override void ResolveMemberDecls(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     this.m_nodeProxy.ResolveMemberDecls(s, provider);
 }
Exemplo n.º 13
0
Arquivo: AST.cs Projeto: chenzuo/blue
 public override void ResolveTypesAsCLR(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     this.m_nodeProxy.ResolveTypesAsCLR(s, provider);
 }
Exemplo n.º 14
0
//-----------------------------------------------------------------------------        
// Main checking routine
// Return true if successful, else false
//-----------------------------------------------------------------------------
    public bool DoCheck(
        AST.ProgramDecl p,
        ICLRtypeProvider provider,
        Assembly [] refs
    )
    {   
        Debug.Assert(provider != null);
        Debug.Assert(p != null);
    
        m_provider = provider;
        
        string stSubPhase = "";
        try
        {   
            m_scopeGlobal = new Scope("Global", null, null);
            
                
                            
            // Import symbols            
            stSubPhase = "importing assemblies";            
            ImportAssembly(GetMscorlib());
            AddDefaultTypes(m_scopeGlobal);
            foreach(Assembly a in refs)
            {
                ImportAssembly(a);
            }
            
            // Pass 1 - Resolve the namespaces and stub the types.
            // This will stub all scopes and create a lexical-scope tree.            
            stSubPhase = "resolving namespaces";            
            p.ResolveNamespace(this, m_scopeGlobal);
            
            
            // Pass 2 - Resolve Types (to both CLR & Blue)             
            stSubPhase = "resolving to clr types";            
            p.ResolveTypes(this, provider);
                		    		    		
            // Pass 3 - resolve class member declarations (Methods & fields)
            stSubPhase = "resolving member declarations";            
            p.ResolveMemberDecls(this, provider);
                		    		
            // Pass 4 - resolve method bodies
            stSubPhase = "resolving member bodies";            
            p.ResolveBodies(this);
                        
            // Final Debug verify before codegen
            stSubPhase = "final debug check";
            p.DebugCheck(this);
            m_scopeGlobal.DebugCheck(this);
            
            p.NotifyResolutionDone();
            
            return true;
        }
        
        // Strip away SymbolErrors; we've already reported them when we first threw them.
        catch (SymbolError.SymbolErrorException)
        {            
            return false;
        }
        catch(System.Exception e)
        {
            Blue.Driver.PrintError_InternalError(e, "Symbol Resolution(" + stSubPhase + ")");
            return false;
        }
    }
Exemplo n.º 15
0
 public virtual void SetInfo(ICLRtypeProvider provider)
 {
     Debug.Assert(m_info == null);
     m_info = provider.CreateCLRField(this);
 }
Exemplo n.º 16
0
 public override void SetInfo(ICLRtypeProvider provider)
 {
     Debug.Assert(m_info == null);
     m_info = provider.CreateCLRLiteralField(this);
 }
Exemplo n.º 17
0
 public override void SetInfo(ICLRtypeProvider provider)
 {
     Debug.Assert(m_info == null);
     m_info = provider.CreateCLRLiteralField(this);
 }
Exemplo n.º 18
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Called after we've resolved as a blue type
 // Pair this type with a CLR type obtained via the Provider
 // Recursively call on all inherited types (base class & interfaces)
 public override void ResolveTypesAsCLR(
     ISemanticResolver s,
     ICLRtypeProvider provider
     )
 {
     // Since this can be called recursively, bail if we're already resolved.
     if (this.Symbol.IsInit)
         return;
     
     
     // S is already set to the context that we're evaluating in.
     Scope prev = s.SetCurrentContext(this.Symbol.MemberScope.LexicalParent);
     
     FixBaseTypes(s, provider); // this is recursive        
     CreateCLRType(s, provider);
     
     s.RestoreContext(prev);
 }
Exemplo n.º 19
0
Arquivo: AST.cs Projeto: chenzuo/blue
// Resolve the member given a symbol for the class we're defined in, a resolver, 
// and a provider
    public abstract void ResolveMember(
        TypeEntry symDefiningClass, 
        ISemanticResolver s, 
        ICLRtypeProvider provider
    );
Exemplo n.º 20
0
Arquivo: AST.cs Projeto: chenzuo/blue
    // Now that all the types have been stubbed and established their context,
    // we can recursively run through and resolve all of our base types.
    void FixBaseTypes(
        ISemanticResolver s,  
        ICLRtypeProvider provider
    )
    {
        TypeEntry tSuper = null;
        
        BeginCheckCycle(s);
        
        ArrayList alInterfaces = new ArrayList();
        
        // Decide who our super class is and which interfaces we're inheriting
        foreach(TypeSig sig in this.m_arSuper)
        {
            sig.ResolveType(s);
            
            TypeEntry t = sig.BlueType;
            
            // Make sure this base type is resolved. Do this recursively
            ClassDecl c = t.Node;
            if (c != null)
            {
                c.ResolveTypesAsCLR(s, provider);
            }
            
            if (t.IsClass)
            {
                Debug.Assert(this.IsClass, "Only a class can have a super-class");
                
                if (tSuper != null)
                {
                    ThrowError(SymbolError.OnlySingleInheritence(this));                
                }
                tSuper = t;
            } else {
                // Both structs & interfaces can only derive from interfaces (not classes)
                if (!t.IsInterface)
                    ThrowError(SymbolError.MustDeriveFromInterface(this, t));
                alInterfaces.Add(t);
            }
        }
        
        TypeEntry [] tInterfaces = new TypeEntry[alInterfaces.Count];
        for(int i = 0; i < alInterfaces.Count; i++)
            tInterfaces[i] = (TypeEntry) alInterfaces[i];
        
        // If no super class is specified, then we use as follows:
        // 'Interface' has no super class,
        // 'Class'     has 'System.Object'
        // 'Struct'    has 'System.ValueType'        
        if (!IsInterface && (tSuper == null))
        {
            if (IsClass)
                tSuper = s.ResolveCLRTypeToBlueType(typeof(object));
            if (IsStruct)
                tSuper = s.ResolveCLRTypeToBlueType(typeof(System.ValueType));                
        }
        
        
        Debug.Assert(IsInterface ^ (tSuper != null));

        // Just to sanity check, make sure the symbol stub is still there
        #if DEBUG               
        TypeEntry sym = (TypeEntry) s.GetCurrentContext().LookupSymbolInThisScopeOnly(m_strName);        
        Debug.Assert(sym == m_symbol);
        #endif

        m_symbol.InitLinks(tSuper, tInterfaces);
                
        // Make sure all of our base types are resolved        
        foreach(TypeEntry t in this.Symbol.BaseInterfaces)
        {               
            t.EnsureResolved(s);
        }
            
        if (Symbol.Super != null)                   
            Symbol.Super.EnsureResolved(s);
                
        // Final call. Set super scope
        m_symbol.FinishInit();
        
        
        EndCheckCycle();
    }
Exemplo n.º 21
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Resolve member
 public override void ResolveMember(
     TypeEntry symDefiningClass, 
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     m_tType.ResolveType(s);
     TypeEntry t = m_tType.BlueType;
     
     m_symbol = new FieldExpEntry(m_stName, t, symDefiningClass, this);
     s.GetCurrentContext().AddSymbol(m_symbol);
     m_symbol.SetInfo(provider);
 }
Exemplo n.º 22
0
Arquivo: AST.cs Projeto: chenzuo/blue
    // Requires that all of our base types have been resolved.
    void CreateCLRType(
        ISemanticResolver s,
        ICLRtypeProvider provider)
    {
    // Should have already resolved as a blue type
        Debug.Assert(this.Symbol != null);

        BeginCheckCycle(s);

        // Now that all of our dependent classes have their clr type set,
        // we can go ahead and set ours.
        // Note that a derived class may have already set ours, so we have
        // to check
        if (Symbol.CLRType == null)
        {
            // Get the clr type and then update the symbol engine
            this.Symbol.SetCLRType(provider);
            s.AddClrResolvedType(this.Symbol);
        }
        Debug.Assert(this.Symbol.CLRType != null);

        // Nested classes
        foreach(TypeDeclBase t in this.m_alNestedTypes)
        {
            t.ResolveTypesAsCLR(s, provider);        
        }

        EndCheckCycle();
    }
Exemplo n.º 23
0
Arquivo: AST.cs Projeto: chenzuo/blue
    // Resolve the types
    public void ResolveTypes(
        ISemanticResolver s,
        ICLRtypeProvider provider)
    {	       

    // Then go through and resolve them to CLR types.
        foreach(NamespaceDecl n in m_nGlobal)
            n.ResolveTypesAsCLR(s, provider);    
    }
Exemplo n.º 24
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Make sure that all of our base types are resolved.
 void FixBaseMemberDecls(ISemanticResolver s, ICLRtypeProvider provider)
 {   
     if (this.IsClass)
     {
         if (this.Symbol.Super.Node != null)
             this.Symbol.Super.Node.ResolveMemberDecls(s, provider);
     }
             
     foreach(TypeEntry t in this.Symbol.BaseInterfaces)
     {
         if (t.Node != null)
             t.Node.ResolveMemberDecls(s, provider);
     }
 }
Exemplo n.º 25
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Resolve the member declarations within a class.
 // Since these can refer to other classes, we must have
 // resolved all types before resolving any members
 public void ResolveMemberDecls(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     foreach(NamespaceDecl n in m_nGlobal)
         n.ResolveMemberDecls(s, provider);
 }
Exemplo n.º 26
0
Arquivo: AST.cs Projeto: chenzuo/blue
    // Resolve all the fields in this type. Only class/struct should call
    // this. 
    void FixFields(ISemanticResolver s, ICLRtypeProvider provider)
    {
        Debug.Assert(!IsInterface);
        
        int cInstance = 0;
        int cStatic = 0;

        foreach(FieldDecl f in m_alFields)
        {
            f.ResolveMember(m_symbol, s, provider);
            //f.Symbol.SetInfo(provider);

            if (f.InitialExp != null)
                if (f.Mods.IsStatic) 
                    cStatic++; 
                else 
                    cInstance++;
        }


        Statement [] stmtStatic = new Statement[cStatic];
        Statement [] stmtInstance = new Statement[cInstance];

        cStatic = 0;
        cInstance = 0;
        // Fields can have assignments. Make 2 helper functions to do
        // assignment for static & instance fields
        foreach(FieldDecl f in m_alFields)
        {
            if (f.InitialExp != null)
            {           
                Statement stmt = new ExpStatement(new AssignStmtExp(
                    new SimpleObjExp(new Identifier(f.Name, f.Location)), f.InitialExp));

                if (f.Mods.IsStatic)
                {
                    stmtStatic[cStatic] = stmt;
                    cStatic++;
                } 
                else 
                {
                    if (IsStruct)
                    {
                        //ThrowError_NoFieldInitForStructs(s, f);
                        ThrowError(SymbolError.NoFieldInitForStructs(f));
                    }
                    
                    stmtInstance[cInstance] = stmt;
                    cInstance ++;
                }
            } // end has initializer expression
        }

        Debug.Assert(cStatic == stmtStatic.Length);
        Debug.Assert(cInstance == stmtInstance.Length);

        // Create methods to initialize the static & instance fields.
        // Then the ctors can call these methods
        if (cStatic != 0)
        {
            Modifiers mods = new Modifiers();
            mods.SetStatic();
            mods.SetPrivate();
            
            m_nodeStaticInit = new MethodDecl(
                new Identifier(".StaticInit", this.Location), 
                new ResolvedTypeSig(typeof(void), s),                    
                new ParamVarDecl[0],
                new BlockStatement(null, stmtStatic),                     
                mods
                );

            //AddMethodToList(m_nodeStaticInit);
        } 
        if (cInstance != 0)
        {   
            Modifiers mods = new Modifiers();
            mods.SetPrivate();
            
            m_nodeInstanceInit = new MethodDecl(
                new Identifier(".InstanceInit", this.Location),                     
                new ResolvedTypeSig(typeof(void), s),
                new ParamVarDecl[0],
                new BlockStatement(null, stmtInstance),                     
                mods
                );
            AddMethodToList(m_nodeInstanceInit);
        }        
    } // end fields
Exemplo n.º 27
0
Arquivo: AST.cs Projeto: chenzuo/blue
 public void ResolveMemberDecls(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     // Do for all types in this namespace
     foreach(TypeDeclBase e in m_arTypes)
             e.ResolveMemberDecls(s, provider);
     
         
     // Recursively do all classes from nested namespaces
     foreach(NamespaceDecl n in NestedNamespaces)
         n.ResolveMemberDecls(s, provider);
     
 }
Exemplo n.º 28
0
Arquivo: AST.cs Projeto: chenzuo/blue
 void FixMethods(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {        
     #if DEBUG
     Debug.Assert(!m_fLockMethodList);
     m_fLockMethodList = true;
     #endif
     
     // Resolve all methods, do some inheritence checks too:
     // - if a class has any abstract members, it must be abstract        
     bool fHasAbstractMember = false;
     foreach(MethodDecl m in m_alMethods)
     {
         // set provider=null since we have to tweak members based off inheritence checks
         m.ResolveMember(m_symbol, s, null);            
         if (m.Mods.IsAbstract)
             fHasAbstractMember = true;
     }
     
     Debug.Assert(!fHasAbstractMember || !this.IsStruct, "Only classes / interfaces can have abstract members");
     
     // If we have any abstract members, then the class must be abstract
     if (fHasAbstractMember && !this.Mods.IsAbstract)            
         PrintError(SymbolError.ClassMustBeAbstract(this));
                     
     
     // Do some checks that will modify how we create the CLR type.
     if (!IsInterface)
     {            
         // Make sure that we implement all methods from all the interfaces
         // that we inherit from
         foreach(TypeEntry t in this.Symbol.BaseInterfaces)
             EnsureMethodsImplemented(s, t);
     }
             
     foreach(MethodDecl m in m_alMethods)
     {            
         m.Symbol.SetInfo(provider);
         // If a method is 'override', an exact match must exist in a super clas that:
         //      a) is marked 'override' also
         //      b) is marked 'virtual'
         if (m.Mods.IsOverride)
         {
             TypeEntry t = this.Symbol.Super;
                             
             MethodExpEntry mSuper = t.LookupExactMethod(m.Symbol); // search super classes
             if (mSuper == null)                    
             {                    
                 PrintError(SymbolError.NoMethodToOverride(m.Symbol));
             }                
                             
             // Further checks if we found an method that matched sigs
             else
             {
                 // Get the CLR representaitons for this & the super
                 System.Reflection.MethodBase i1 = m.Symbol.Info;
                 System.Reflection.MethodBase i2 = mSuper.Info;                    
                 
                 // if final, error
                 if (i2.IsFinal)
                 {   
                     PrintError(SymbolError.CantOverrideFinal(m.Symbol, mSuper));
                 }
                     
                 // If !virtual, error
                 if (!i2.IsVirtual)
                 {   
                     PrintError(SymbolError.CantOverrideNonVirtual(m.Symbol, mSuper));
                 }
                 
                 // Check same visibility access                                        
                 bool fMatch = 
                     (i1.IsPublic == i2.IsPublic) &&
                     (i1.IsPrivate == i2.IsPrivate) &&
                     (i1.IsFamily == i2.IsFamily) &&
                     (i1.IsAssembly == i2.IsAssembly);
                 if (!fMatch)
                 {   
                     PrintError(SymbolError.VisibilityMismatch(m.Symbol));
                 }                        
             }                
         } // IsOverride
     } // foreach Method
 }
Exemplo n.º 29
0
Arquivo: AST.cs Projeto: chenzuo/blue
 public abstract void ResolveMemberDecls(
     ISemanticResolver s,
     ICLRtypeProvider provider
 );
Exemplo n.º 30
0
Arquivo: AST.cs Projeto: 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
Exemplo n.º 31
0
 public void SetInfo(ICLRtypeProvider provider)
 {
     Debug.Assert(m_infoMethod == null);
     m_infoMethod = provider.CreateCLRMethod(this);
 }
Exemplo n.º 32
0
Arquivo: AST.cs Projeto: chenzuo/blue
 } // fix ctors
 
 // Resolve all events in the class
 void FixEvents(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {
     if (this.IsStruct)
         return;
     
     if (Events == null)
         return;
         
     foreach(EventDecl e in this.Events)
     {
         e.ResolveMember(m_symbol, s, provider);          
     }            
 }
Exemplo n.º 33
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Called after all the methods are decled.
 void PostFixEvents(
     ISemanticResolver s,
     ICLRtypeProvider provider
     )
 {   
     #if DEBUG
     Debug.Assert(m_fLockMethodList, "Don't PostResolve Events until after methods");
     #endif     
     
     if (Events == null)
         return;
         
     foreach(EventDecl e in this.Events)
     {
         e.PostResolveMember(s);
         //  e.FieldSymbol.SetInfo(provider);
     }            
 }
Exemplo n.º 34
0
Arquivo: AST.cs Projeto: chenzuo/blue
 // Resolve the members (fields & methods)
 public override void ResolveMemberDecls(
     ISemanticResolver s,
     ICLRtypeProvider provider
 )
 {   
     // If we've already been resolved, then skip
     if (this.Symbol.MemberScope.IsLocked)
         return;
         
     // We need our base types to have resolved members so that we can 
     // do inheritence checks.            
     FixBaseMemberDecls(s, provider);    
     
     // Setup our context to do evaluation
     Scope prev = s.SetCurrentContext(m_symbol.MemberScope);
     s.SetCurrentClass(m_symbol);            
             
     // Add our members to our scope
     {
         // Do events first because they generate methods & fields
         FixEvents(s, provider);
     
         if (!IsInterface)
             this.FixFields(s, provider);
         
         // Resolve properties before methods, since properties create methods
         foreach(PropertyDecl p in m_alProperties)
         {
             p.ResolveMember(m_symbol, s, provider);                            
         }
         
         // This can change both the normal methods as well as accessor methods on properties.
         FixMethods(s, provider);
         
         // Set property symbols after we've touched up the methods.
         foreach(PropertyDecl p in m_alProperties)
         {
             p.Symbol.SetInfo(provider);
         }
         
         PostFixEvents(s, provider);
               
         // Nested types
         foreach(TypeDeclBase t in this.m_alNestedTypes)
         {
             t.ResolveMemberDecls(s, provider);        
         }              
                
                 
         // If we have no ctor at all, then add a default one.
         // (default ctor - takes no parameters, chains to base's default ctor)
         if (!IsInterface)
             FixCtors(s, provider);
         
         // We're done adding to the scope, so lock it.
         m_symbol.MemberScope.LockScope();
     }
     
     s.SetCurrentClass(null);        
     s.RestoreContext(prev);
 }
Exemplo n.º 35
0
 public virtual void SetInfo(ICLRtypeProvider provider)
 {
     Debug.Assert(m_info == null);
     m_info = provider.CreateCLRField(this);
 }
Exemplo n.º 36
0
 public void SetInfo(ICLRtypeProvider provider)
 {
     //Debug.Assert(m_info == null);
                 
     //m_info = 
     provider.CreateCLREvent(this);            
 }