private void _processImports( ref IList<AbstractNode> nodes )
{
// We only need to iterate over the top-level of nodes
for ( int i = 1; i < nodes.Count; i++ )
{
AbstractNode cur = nodes[ i ];
if ( cur is ImportAbstractNode )
{
ImportAbstractNode import = (ImportAbstractNode)cur;
// Only process if the file's contents haven't been loaded
if ( !_imports.ContainsKey( import.Source ) )
{
// Load the script
IList<AbstractNode> importedNodes = _loadImportPath( import.Source );
if ( importedNodes != null && importedNodes.Count != 0 )
{
_processImports( ref importedNodes );
_processObjects( ref importedNodes, importedNodes );
}
if ( importedNodes != null && importedNodes.Count != 0 )
_imports.Add( import.Source, importedNodes );
}
// Handle the target request now
// If it is a '*' import we remove all previous requests and just use the '*'
// Otherwise, ensure '*' isn't already registered and register our request
if ( import.Target == "*" )
{
throw new NotImplementedException();
//_importRequests.Remove(
// mImportRequests.erase(mImportRequests.lower_bound(import->source),
// mImportRequests.upper_bound(import->source));
//_importRequests.Add( import.Source, "*" );
}
else
{
throw new NotImplementedException();
// ImportRequestMap::iterator iter = mImportRequests.lower_bound(import->source),
// end = mImportRequests.upper_bound(import->source);
// if(iter == end || iter->second != "*")
//{
// _importRequests.Add( import.Source, import.Target );
//}
}
#if UNREACHABLE_CODE
nodes.RemoveAt( i );
i--;
#endif
}
}
// All import nodes are removed
// We have cached the code blocks from all the imported scripts
// We can process all import requests now
foreach ( KeyValuePair<string, IList<AbstractNode>> it in _imports )
{
if ( _importRequests.ContainsKey( it.Key ) )
{
string j = _importRequests[ it.Key ];
if ( j == "*" )
{
// Insert the entire AST into the import table
_importTable.InsertRange( 0, it.Value );
continue; // Skip ahead to the next file
}
else
{
// Locate this target and insert it into the import table
IList<AbstractNode> newNodes = _locateTarget( it.Value, j );
if ( newNodes != null && newNodes.Count > 0 )
_importTable.InsertRange( 0, newNodes );
}
}
}
}