示例#1
0
        public void AddFile(TempProjectFileEntry fileEntry)
        {
            lock (this.fileLock)
            {
                if (this.Files == null)
                {
                    this.Files = new List<TempProjectFileEntry>();
                }

                this.Files.Add(fileEntry);
            }
        }
示例#2
0
        private CompilationJob CreateJob(TempProject project, TempProjectFileEntry entry)
        {
            var job = new CompilationJob
            {
                IsCompressed = entry.IsCompressed,
                NameSpace = this.compilerState.BaseNameSpace
            };

            if (entry.RelativePath != null && !entry.RelativePath.IsNull)
            {
                string fileNameSpace = this.compiler.GetNameSpace(entry.RelativePath);
                job.NameSpace = string.Join(Compiler.NameSpaceSeparator.ToString(CultureInfo.InvariantCulture), job.NameSpace, fileNameSpace);
            }

            job.NameSpace = this.GetNameSpace(project.RootNameSpace, entry);

            CarbonDirectory fileTargetDirectory = this.targetDirectory.ToDirectory(SourceTargetDir);
            if (entry.RelativePath != null)
            {
                fileTargetDirectory = fileTargetDirectory.ToDirectory(entry.RelativePath);
            }

            job.SourceFile = this.targetDirectory.ToFile(entry.File);
            job.TargetFile = fileTargetDirectory.ToFile(entry.RelativeFile);

            if (entry.Classes != null)
            {
                foreach (string @class in entry.Classes)
                {
                    var classNameSpace = string.Concat(job.NameSpace, Compiler.NameSpaceSeparator, @class);
                    if (this.includeJobDictionary.ContainsKey(classNameSpace))
                    {
                        System.Diagnostics.Trace.TraceWarning("Multiple class definitions for " + classNameSpace);
                        continue;
                    }

                    this.includeJobDictionary.Add(classNameSpace, job);
                }
            }

            return job;
        }
示例#3
0
        private string GetNameSpace(string rootNameSpace, TempProjectFileEntry entry)
        {
            if (entry.RelativePath == null)
            {
                return rootNameSpace;
            }

            string relativePath = entry.RelativePath.GetPath();
            if (string.IsNullOrEmpty(relativePath))
            {
                return rootNameSpace;
            }

            relativePath = relativePath.ToLowerInvariant().Replace(@"\", ".").TrimEnd('.');
            return string.Format("{0}.{1}", rootNameSpace, relativePath);
        }
示例#4
0
        // -------------------------------------------------------------------
        // Private
        // -------------------------------------------------------------------
        private void TranslateFile(TempProject project, CarbonFile sourceFile, CarbonFile targetFile)
        {
            Diagnostic.RegisterThread("Translate." + sourceFile.FileName);

            CarbonDirectory targetRelativeSubDir = targetFile.GetDirectory() ?? new CarbonDirectory(string.Empty);
            CarbonDirectory fullTargetPath = this.targetDirectory.ToDirectory(this.config.Current.IntermediateSubDirectory, targetRelativeSubDir);
            CarbonFile fullTargetFile = fullTargetPath.ToFile(targetFile.FileName + TempExtension);
            CarbonFile relativeTargetFile = this.config.Current.IntermediateSubDirectory.ToDirectory(targetRelativeSubDir).ToFile(targetFile.FileName + TempExtension);

            if (this.config.Current.Verbose)
            {
                System.Diagnostics.Trace.TraceInformation("Translating {0} -> {1}", sourceFile, fullTargetFile);
            }

            IList<Token> tokens = this.TokenizeFile(sourceFile);
            if (tokens == null)
            {
                throw new InvalidDataException();
            }

            project.AddStat(TempProjectStat.Files);
            project.AddStat(TempProjectStat.Tokens, tokens.Count);
            var fileEntry = new TempProjectFileEntry
                                {
                                    IsCompressed = this.config.Current.CompressIntermediate,
                                    RelativeFile = new CarbonFile(targetFile.FileName),
                                    RelativePath = targetFile.GetDirectory(),
                                    File = relativeTargetFile,
                                };

            var data = new TranslationData(tokens)
                           {
                               ProjectData = project,
                               SourceFile = sourceFile,
                               TargetFile = fullTargetFile,
                               FileEntry = fileEntry
                           };

            // Register the file entry into the project
            project.AddFile(fileEntry);

            try
            {
                TempFileFull file = this.TranslateToTempFile(data);
                this.SaveTempFile(data, file);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.TraceError("Failed to translate {0}: {1}", fileEntry.File, e);
                this.SaveTempFile(data, new TempFileFull() { Name = data.TargetFile.FileName });
            }

            Diagnostic.UnregisterThread();
        }