Ejemplo n.º 1
0
/*
============
idProgram::FindFreeResultDef
============
*/
idVarDef *idProgram::FindFreeResultDef( idTypeDef *type, const char *name, idVarDef *scope, const idVarDef *a, const idVarDef *b )
{
	idVarDef *def;
	
	for( def = GetDefList( name ); def != NULL; def = def->Next() )
	{
		if( def == a || def == b )
		{
			continue;
		}
		if( def->TypeDef() != type )
		{
			continue;
		}
		if( def->scope != scope )
		{
			continue;
		}
		if( def->numUsers <= 1 )
		{
			continue;
		}
		return def;
	}
	
	return AllocDef( type, name, scope, false );
}
Ejemplo n.º 2
0
/*
============
idProgram::GetDef

If type is NULL, it will match any type
============
*/
idVarDef *idProgram::GetDef( const idTypeDef *type, const char *name, const idVarDef *scope ) const {
	idVarDef		*def;
	idVarDef		*bestDef;
	int				bestDepth;
	int				depth;

	bestDepth = 0;
	bestDef = NULL;
	for( def = GetDefList( name ); def != NULL; def = def->Next() ) {
		if ( def->scope->Type() == ev_namespace ) {
			depth = def->DepthOfScope( scope );
			if ( !depth ) {
				// not in the same namespace
				continue;
			}
		} else if ( def->scope != scope ) {
			// in a different function
			continue;
		} else {
			depth = 1;
		}

		if ( !bestDef || ( depth < bestDepth ) ) {
			bestDepth = depth;
			bestDef = def;
		}
	}

	// see if the name is already in use for another type
	if ( bestDef && type && ( bestDef->TypeDef() != type ) ) {
		throw idCompileError( va( "Type mismatch on redeclaration of %s", name ) );
	}

	return bestDef;
}