/// <summary>
 /// Walks the supplied System.CodeDom.CodeCompileUnit and produces a corresponding CompilationUnit.
 /// Enters declarations into the supplied Module and errors into the supplied ErrorNodeList. 
 /// Calls back to the supplied compiler to resolve assembly references and to create appropriate documents for code snippets.
 /// </summary>
 /// <param name="compiler">Called upon to resolve assembly references and to create Documents for snippets.</param>
 /// <param name="compilationUnit">The root of the CodeDOM tree to be translated into an IR CompileUnit.</param>
 /// <param name="targetModule">The module or assembly to which the compilation unit will be compiled.</param>
 /// <param name="errorNodes">Errors in the CodeDOM tree that are found during translation are added to this list.</param>
 /// <returns></returns>
 public CompilationUnit Translate(Compiler compiler, CodeCompileUnit compilationUnit, Module targetModule, ErrorNodeList errorNodes){
   Debug.Assert(compiler != null); 
   Debug.Assert(compilationUnit != null); 
   Debug.Assert(targetModule != null); 
   Debug.Assert(errorNodes != null);
   this.compiler = compiler;
   this.errorNodes = errorNodes;
   this.targetModule = targetModule;
   CodeSnippetCompileUnit cscu = compilationUnit as CodeSnippetCompileUnit;
   CompilationUnit cunit = cscu != null ? new CompilationUnitSnippet() : new CompilationUnit();
   this.Translate(compilationUnit.AssemblyCustomAttributes, targetModule.Attributes);
   StringCollection references = compilationUnit.ReferencedAssemblies;
   if (references != null && references.Count > 0){
     AssemblyReferenceList arefs = targetModule.AssemblyReferences;
     TrivialHashtable alreadyReferencedAssemblies = new TrivialHashtable();
     for (int i = 0, n = arefs.Count; i < n; i++)
       alreadyReferencedAssemblies[arefs[i].Assembly.UniqueKey] = this;
     foreach (string rAssemblyName in references)
       compiler.AddAssemblyReferenceToModule(null, targetModule, rAssemblyName, null, errorNodes, alreadyReferencedAssemblies, false);
   }
   Namespace defaultNamespace = new Namespace(Identifier.Empty, Identifier.Empty, null, null, new NamespaceList(), null);
   NamespaceList nspaceList = defaultNamespace.NestedNamespaces;
   CodeNamespaceCollection nspaces = compilationUnit.Namespaces;
   if (nspaces != null) 
     foreach (CodeNamespace cns in nspaces) 
       nspaceList.Add(this.Translate(cns));
   if (cscu == null) return cunit;
   Document doc = null;
   if (cscu.LinePragma == null)
     doc = compiler.CreateDocument(targetModule.Name, 1, cscu.Value);
   else{
     doc = compiler.CreateDocument(cscu.LinePragma.FileName, cscu.LinePragma.LineNumber, cscu.Value);
     cunit.Name = Identifier.For(cscu.LinePragma.FileName);
   }
   cunit.SourceContext = new SourceContext(doc);
   defaultNamespace.SourceContext = cunit.SourceContext;
   return cunit;
 }