Exemplo n.º 1
0
 public BlockStatement(
     LocalVarDecl[] arLocals, // can be null if we have no locals
     Statement[] arStatements // never null
 )
 {
     // If we have any locals in this block statement, then we
     // also need to have a scope to hold them.
     if (arLocals == null)
     {
         m_arLocals = new LocalVarDecl[0];
     } else {
         m_arLocals = arLocals;
         // @todo - decorate name w/ filerange?
         //m_scopeLocals = new Scope("block_scope", null);
     }
     
     // May have an empty statement block, so arStatements.Length could be 0
     // but at least expect an array.
     Debug.Assert(arStatements != null);
     m_arStatements = arStatements;
     
     // @todo - fix this
     if (arStatements.Length == 0)
         this.m_filerange = new FileRange();
     else 
         this.m_filerange = arStatements[0].Location;
 }
Exemplo n.º 2
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.º 3
0
 // Inject a statement at the beginning
 // Must resolve after doing this.
 public void InjectStatementAtHead(Statement sNew)
 {   
     Statement[] ar2 = new Statement[this.Statements.Length + 1];
     ar2[0] = sNew;
     for(int i = 0; i < Statements.Length; i++)        
         ar2[i + 1] = Statements[i];
     
     this.m_arStatements = ar2;
 }
Exemplo n.º 4
0
 public ClassMember(Statement statement)
 {
     Statement = statement;
 }