示例#1
0
        public virtual CompilerResults CompileProject(Project project, Cci.ErrorNodeList errors)
        {
            if (project == null)
            {
                Debug.Assert(false); return(null);
            }
            CompilerResults results;

            Cci.Compilation symbolTableCompilation = project.Compilation;
            try {
                Cci.Compilation buildCompilation = this.compiler.CurrentCompilation = symbolTableCompilation.CloneCompilationUnits();
                buildCompilation.TargetModule    = this.compiler.CreateModule(project.CompilerParameters, errors);
                this.compiler.CurrentCompilation = buildCompilation;
                if (project.CompilerParameters is Cci.CompilerOptions &&
                    ((Cci.CompilerOptions)project.CompilerParameters).EmitManifest)
                {
                    results = this.compiler.CompileAssemblyFromIR(buildCompilation, errors);
                }
                else
                {
                    results = this.compiler.CompileModuleFromIR(buildCompilation, errors);
                }
                if (buildCompilation.TargetModule is Cci.AssemblyNode && symbolTableCompilation.TargetModule is Cci.AssemblyNode)
                {
                    ((Cci.AssemblyNode)symbolTableCompilation.TargetModule).Version = ((Cci.AssemblyNode)buildCompilation.TargetModule).Version;
                }
                buildCompilation.TargetModule     = null;
                buildCompilation.CompilationUnits = null;
                buildCompilation = null;
            }catch (Exception e) {
                results = new CompilerResults(options.TempFiles);
                string offendingAssembly = project.CompilerParameters == null ? "" : project.CompilerParameters.OutputAssembly;
                results.Errors.Add(new CompilerError(offendingAssembly, 1, 1, "", "Internal Compiler Error: " + e.ToString() + "\n"));
                results.NativeCompilerReturnValue = 1;
            }finally{
                this.compiler.CurrentCompilation = symbolTableCompilation;
            }
            return(results);
        }
示例#2
0
 public override IScanner GetScanner(string fileName)
 {
     Cci.Compilation compilation = this.GetCompilationFor(fileName);
     return(new VsScanner(compilation.CompilerParameters as SpecSharpCompilerOptions));
 }
示例#3
0
 public virtual Project GetCompilerProject(XmlElement config, Cci.ErrorNodeList errors)
 {
     if (config == null)
     {
         return(null);
     }
     lock (ProjectManager.BuildLock){
         Project project = this.scProject;
         if (project == null)
         {
             Debug.Assert(false); return(null);
         }
         bool refresh = this.LastModifiedTime != project.LastModifiedTime || this.lastConfig != config;
         if (!refresh)
         {
             Debug.Assert(project.CompilerParameters != null);
             this.RefreshPerBuildCompilerParameters();
             return(project);
         }
         Cci.Compilation compilation = project.Compilation = this.compiler.CreateCompilation(null, null, null, null);
         this.compiler.CurrentCompilation = compilation;
         project.LastModifiedTime         = this.LastModifiedTime;
         Microsoft.VisualStudio.Package.ProjectOptions vscOptions = this.GetProjectOptions(config);
         Cci.CompilerOptions options = this.GetCompilerOptions(vscOptions);
         if (options == null)
         {
             Debug.Assert(false); return(null);
         }
         project.CompilerParameters = options;
         string         dir       = this.ProjectFolder;
         XmlDocument    doc       = this.projFile;
         Cci.StringList fileNames = new Cci.StringList();
         Cci.CompilationUnitSnippetList cuSnippets = new Cci.CompilationUnitSnippetList();
         Cci.CompilationUnitList        cUnits     = new Cci.CompilationUnitList();
         foreach (XmlElement e in doc.SelectNodes("//Files/Include/File"))
         {
             if (e == null)
             {
                 continue;
             }
             string relpath = e.GetAttribute("RelPath");
             string file    = Path.Combine(dir, relpath);
             Cci.CompilationUnitSnippet snippet = null;
             int key = Cci.Identifier.For(file).UniqueIdKey;
             if (!File.Exists(file))
             {
                 errors.Add(this.compiler.CreateErrorNode(Cci.Error.NoSuchFile, file));
                 continue;
             }
             snippet = this.GetCompilationUnitSnippetFor(file, e.GetAttribute("BuildAction"));
             if (snippet == null)
             {
                 continue;
             }
             fileNames.Add(file);
             cuSnippets.Add(snippet);
             cUnits.Add(snippet);
             snippet.Compilation = compilation;
         }
         project.CompilationUnitSnippets    = cuSnippets;
         project.FullPathsToSources         = fileNames;
         compilation.CompilationUnits       = cUnits;
         compilation.CompilerParameters     = options;
         compilation.ReferencedCompilations = this.GetReferencedCompilations(config, errors);
         this.compiler.ConstructSymbolTable(compilation, errors);
         this.compiler.CurrentCompilation = null;
         return(project);
     }
 }