コード例 #1
0
ファイル: symtab.cpp プロジェクト: ConnorShanks/cs160
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 %p)---\n", m_scopesize, (void*)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=%p)\n", si->first, si->second->m_offset, (void*)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);
	}
}
コード例 #2
0
ファイル: symtab.cpp プロジェクト: Kazanovitz/compiler
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
	for( int i=0; i<nest_level; i++ ) { fprintf(f,"\t"); }
	fprintf(f,"+-- Symbol Scope ---\n");

	for( si = m_scopetable.begin(); si != m_scopetable.end(); ++si )
	{
		//indent appropriately
		for( int i=0; i<nest_level; i++ ) { fprintf(f,"\t"); }
		fprintf( f, "| %s \n", si->first );
	}
	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);
	}
}
コード例 #3
0
ファイル: symtab.cpp プロジェクト: ConnorShanks/cs160
Symbol* SymScope::lookup( const char * name )
{
	//first check the current table;
	ScopeTableType::const_iterator i;
	i = m_scopetable.find( (char*) name );
	if ( i != m_scopetable.end() ) {
		return i->second;
	}
	return NULL;
}
コード例 #4
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;
    }
}
コード例 #5
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;
}