コード例 #1
0
ファイル: symtab.cpp プロジェクト: syassami/cugly
Symbol* SymScope::insert( const char* name, Symbol * s )
{
    pair<ScopeTableType::iterator,bool> iret;
    typedef pair<const char*,Symbol*> hpair;
    iret = m_scopetable.insert( hpair(name,s) );
    if( iret.second == true ) {
        //insert was successfull
        //update the offset and size
        if (as_param) {
            // Inserts at positive values
            s->m_offset = m_paramsize;
            m_paramsize += s->get_size();
        }
        else {
            // Inserts at negative values
            m_localsize += s->get_size();
            s->m_offset = -m_localsize;
        }
        //set the scope
        s->m_symscope = this;
        return NULL;
    } else {
        //cannot insert, there was a duplicate entry
        //return a pointer to the conflicting symbol
        return iret.first->second;
    }
}
コード例 #2
0
ファイル: symtab.cpp プロジェクト: syassami/cugly
Symbol* SymScope::lookup( const char * name )
{
    //first check the current table;
    ScopeTableType::const_iterator i;
    i = m_scopetable.find( name );
    if ( i != m_scopetable.end() ) {
        return i->second;
    }

    //failing that, check all the parents;
    if ( m_parent != NULL ) {
        return m_parent->lookup( name );
    } else {
        //if this has no parents, then it cannot be found
        return NULL;
    }
}
コード例 #3
0
ファイル: symtab.cpp プロジェクト: syassami/cugly
bool SymScope::is_dup_string(const char* name)
{
    ScopeTableType::iterator si;

    si = m_scopetable.find( name );
    if ( si != m_scopetable.end() ) {
        //check if the pointers match
        if ( si->first == name ) return false;
    }

    list<SymScope*>::iterator li;
    for( li=m_child.begin(); li!=m_child.end(); ++li )
    {
        bool r = (*li)->is_dup_string(name);
        if ( r==false ) return false;
    }

    //if it gets this far, there is no duplicate
    return true;
}
コード例 #4
0
ファイル: symtab.cpp プロジェクト: Kazanovitz/compiler
Symbol* SymScope::insert( char* name, Symbol * s )
{
	pair<ScopeTableType::iterator,bool> iret;
	typedef pair<char*,Symbol*> hpair;
	iret = m_scopetable.insert( hpair(name,s) );
	if( iret.second == true ) {
		//insert was successfull
		return NULL;
	} else {
		//cannot insert, there was a duplicate entry
		//return a pointer to the conflicting symbol
		return iret.first->second;
	}	
}
コード例 #5
0
ファイル: symtab.cpp プロジェクト: syassami/cugly
void SymScope::dump(FILE* f, int nest_level)
{
    //recursively prints out the symbol table
    //from the head down through all the childrens

    ScopeTableType::iterator si;

    //indent appropriately
    fprintf(f,"# ");
    for( int i=0; i<nest_level; i++ ) {
        fprintf(f,"\t");
    }
    fprintf(f," +-- Symbol Scope (%d bytes at %x)---\n", m_localsize,
            this);

    for( si = m_scopetable.begin(); si != m_scopetable.end(); ++si )
    {
        //indent appropriately
        fprintf(f,"# ");
        for( int i=0; i<nest_level; i++ ) {
            fprintf(f,"\t");
        }
        fprintf( f, "| %s (offset=%d,scope=%x)\n", si->first, si->second->m_offset, si->second->m_symscope );
    }
    fprintf(f,"# ");
    for( int i=0; i<nest_level; i++ ) {
        fprintf(f,"\t");
    }
    fprintf(f,"+-------------\n#\n");

    //now print all the children
    list<SymScope*>::iterator li;
    for( li=m_child.begin(); li!=m_child.end(); ++li )
    {
        (*li)->dump(f, nest_level+1);
    }
}