Exemplo n.º 1
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.º 2
0
Arquivo: AST.cs Projeto: chenzuo/blue
    // Resolve the bodies of methods
    public void ResolveBodies(ISemanticResolver s)
    {
        if (Mods.IsAbstract)
            return;

        Scope scope = m_symbol.m_scope;
        
        //s.PushScope(scope);
        Scope prev = s.SetCurrentContext(scope);
        s.SetCurrentMethod(m_symbol);        
        
        m_stmtBody.ResolveStatement(s);

        // Do a second pass, for goto statements to resolve against labels.        
        m_stmtBody.ResolveStatement2(s);
   
        s.SetCurrentMethod(null);
        //s.PopScope(scope);
        s.RestoreContext(prev);
    
    }
Exemplo n.º 3
0
Arquivo: AST.cs Projeto: chenzuo/blue
/*    
    void EnterNamespace(ISemanticResolver s)
    {
        m_symbol.SetCurrentNode(this);
        s.PushScope(m_symbol.ChildScope);
    }
    
    void ExitNamespace(ISemanticResolver s)
    {
        m_symbol.SetCurrentNode(null);
        s.PopScope(m_symbol.ChildScope);
    }
*/    

    // Resolve the using declarations
    public void ResolveUsingDecls(ISemanticResolver s)
    {
        // All using declarations are resolved at global scope,
        // so don't enter / exit namespaces here
        //EnterNamespace(s);

        
        // Resolve all the using clauses in this namespace block
        Scope prev = s.SetCurrentContext(this.m_context);
        
        foreach(UsingDirective u in this.m_arUsingDirectives)
            u.Resolve(s, m_context);
            
        s.RestoreContext(prev);            
            
        // Recursively add all classes from nested namespaces
        foreach(NamespaceDecl n in NestedNamespaces)
            n.ResolveUsingDecls(s);

        //ExitNamespace(s);

        m_fResolvedUsing = true;
    }
Exemplo n.º 4
0
Arquivo: AST.cs Projeto: chenzuo/blue
// Resolve the bodies of methods
    public override void ResolveBodies(ISemanticResolver s)
    {
        Scope scope = m_symbol.MemberScope;
        
        //s.PushScope(scope);
        Scope prev = s.SetCurrentContext(scope);
        s.SetCurrentClass(m_symbol);
         
        foreach(MethodDecl m in m_alMethods)
        {
            m.ResolveBodies(s);
        }
        
        foreach(PropertyDecl p in m_alProperties)
        {
            p.ResolveBodies(s);
        }
        
        // Nested
        foreach(TypeDeclBase t in this.m_alNestedTypes)
        {
            t.ResolveBodies(s);
        }
        
        s.SetCurrentClass(null);
        //s.PopScope(scope);
        s.RestoreContext(prev);
    }
Exemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
0
    public override void ResolveStatement2(ISemanticResolver s)
    {
        Scope prev = null;
        if (m_scopeLocals != null)
            //s.PushScope(m_scopeLocals);
            prev = s.SetCurrentContext(m_scopeLocals);

        foreach(Statement stmt in Statements)
        {
            stmt.ResolveStatement2(s);
        }

        if (m_scopeLocals != null)
            //s.PopScope(m_scopeLocals);
            s.RestoreContext(prev);
    }
Exemplo n.º 10
0
    // Semantic resolution
    public override void ResolveStatement(ISemanticResolver s)
    {        
        Scope prev = null;
        if (this.m_arLocals.Length != 0)
        {
            //s.PushScope(m_scopeLocals);
            m_scopeLocals = new Scope("block_scope", null, s.GetCurrentContext());
            prev = s.SetCurrentContext(m_scopeLocals);
        }
            
        foreach(LocalVarDecl v in Locals)
        {
            v.ResolveVarDecl(s);
        }
                
        foreach(Statement stmt in Statements)
        {
            stmt.ResolveStatement(s);
        }

        if (m_scopeLocals != null)
            //s.PopScope(m_scopeLocals);
            s.RestoreContext(prev);
            
    }