Ejemplo n.º 1
0
        public SourcePackage CreateSourcePackage()
        {
            var upk = new SourcePackage(
                Name,
                Version,
                Filename,
                SourceDirectory ?? RootDirectory,
                CacheDirectory,
                SourcePackageFlags.Cached | (
                    IsTransitive 
                        ? SourcePackageFlags.Transitive 
                        : 0),
                BuildCondition);

            upk.SourceFiles.AddRange(SourceFiles);
            upk.ExtensionsFiles.AddRange(ExtensionsFiles);
            upk.ForeignSourceFiles.AddRange(ForeignSourceFiles);
            upk.BundleFiles.AddRange(BundleFiles);
            upk.StuffFiles.AddRange(StuffFiles);

            foreach (var p in InternalsVisibleTo)
                upk.InternalsVisibleTo.Add(p);
            foreach (var b in ExtensionsBackends)
                upk.CachedExtensionsBackends.Add(b);
            foreach (var b in Namespaces)
                upk.CachedNamespaces.Add(b);

            return upk;
        }
Ejemplo n.º 2
0
        public static AstReader Open(SourcePackage upk, string filename)
        {
            var r = new AstReader(upk, filename);

            r.VerifyMagic(AstSerialization.Magic);
            return(r);
        }
Ejemplo n.º 3
0
        public SourcePackage CreateSourcePackage(bool isStartup = false)
        {
            var upk = new SourcePackage(
                Name,
                Version,
                FullPath,
                RootDirectory,
                CacheDirectory,
                SourcePackageFlags.Project | (
                    IsTransitive
                        ? SourcePackageFlags.Transitive
                        : 0) | (
                    isStartup
                        ? SourcePackageFlags.Startup
                        : 0),
                BuildCondition);

            upk.AdditionalFiles.AddRange(AdditionalFiles);
            upk.BundleFiles.AddRange(BundleFiles);
            upk.SourceFiles.AddRange(SourceFiles);
            upk.ExtensionsFiles.AddRange(ExtensionsFiles);
            upk.ForeignSourceFiles.AddRange(ForeignSourceFiles);
            upk.StuffFiles.AddRange(StuffFiles);
            upk.UXFiles.AddRange(UXFiles);

            foreach (var p in InternalsVisibleTo)
            {
                upk.InternalsVisibleTo.Add(p.String);
            }

            return(upk);
        }
Ejemplo n.º 4
0
        public override bool Parse(SourcePackage upk, string filename, List <AstDocument> result)
        {
            var p = new Parser(Log, upk, filename, File.ReadAllText(filename));

            p.Parse(result);
            return(!p.HasErrors);
        }
Ejemplo n.º 5
0
        public override BackendResult Build(SourcePackage package)
        {
            if (package.CanLink)
            {
                package.Tag = _linker.AddAssemblyFile(Path.Combine(_outputDir, package.Name + ".dll"));
                return(null);
            }

            var g = new CilGenerator(Disk, Data, Essentials,
                                     this, _linker, package, _outputDir);

            g.Configure(Environment.Debug);

            using (Log.StartProfiler(g.GetType().FullName + ".Generate"))
                g.Generate();

            if (Log.HasErrors)
            {
                return(null);
            }

            using (Log.StartProfiler(g.GetType().FullName + ".Save"))
                g.Save();

            return(new CilResult(g.Assembly, _linker.TypeMap, g.Locations));
        }
Ejemplo n.º 6
0
        public PackageItem(SourcePackage upk)
        {
            Package            = upk;
            SourceFiles        = new PackageFolderItem(upk, "Source Files");
            ExtensionsFiles    = new PackageFolderItem(upk, "Extensions Files");
            BundleFiles        = new PackageFolderItem(upk, "Bundle Files");
            ForeignSourceFiles = new PackageFolderItem(upk, "Foreign Source Files");
            AdditionalFiles    = new PackageFolderItem(upk, "Additional Files");
            StuffFiles         = new PackageFolderItem(upk, "Stuff Files");

            if (upk.Version != null)
            {
                Suffix = "(" + upk.Version + ")";
            }

            foreach (var reference in upk.References)
            {
                References.AddChild(new ReferenceItem(reference));
            }
            foreach (var f in upk.SourceFiles)
            {
                SourceFiles.AddFile(upk.SourceDirectory, f.UnixPath);
            }
            foreach (var f in upk.ExtensionsFiles)
            {
                ExtensionsFiles.AddFile(upk.SourceDirectory, f.UnixPath);
            }
            foreach (var f in upk.BundleFiles)
            {
                BundleFiles.AddFile(upk.SourceDirectory, f.UnixPath);
            }
            foreach (var f in upk.ForeignSourceFiles)
            {
                ForeignSourceFiles.AddFile(upk.SourceDirectory, f.UnixPath);
            }
            foreach (var f in upk.AdditionalFiles)
            {
                AdditionalFiles.AddFile(upk.SourceDirectory, f.UnixPath);
            }
            foreach (var f in upk.StuffFiles)
            {
                StuffFiles.AddFile(upk.SourceDirectory, f.UnixPath);
            }

            SourceFiles.Collapse();
            ExtensionsFiles.Collapse();
            BundleFiles.Collapse();
            ForeignSourceFiles.Collapse();
            AdditionalFiles.Collapse();
            StuffFiles.Collapse();

            AddChild(References);
            AddChild(Resources);
            AddChild(SourceFiles);
            AddChild(ExtensionsFiles);
            AddChild(BundleFiles);
            AddChild(ForeignSourceFiles);
            AddChild(AdditionalFiles);
            AddChild(StuffFiles);
        }
Ejemplo n.º 7
0
        internal BuildEnvironment(
            Backend backend,
            SourcePackage project,
            CompilerOptions options,
            ExtensionRoot extensions,
            ILFactory ilf,
            Compiler compiler)
            : base(compiler)
        {
            if (string.IsNullOrEmpty(options.Configuration))
            {
                options.Configuration = "Debug";
            }
            if (string.IsNullOrEmpty(options.BuildTarget))
            {
                throw new ArgumentNullException(nameof(options.BuildTarget));
            }
            if (string.IsNullOrEmpty(options.OutputDirectory))
            {
                throw new ArgumentNullException(nameof(options.OutputDirectory));
            }

            Extensions      = extensions;
            Options         = options;
            BundleDirectory = Path.Combine(project.CacheDirectory, "bundle");
            CacheDirectory  = Path.Combine(project.CacheDirectory, options.BuildTarget, options.Configuration);
            Essentials      = ilf.Essentials;
            MacroExpander   = new MacroExpander(backend, this, extensions, ilf, compiler);
            Compiler        = compiler;

            Set("Target", options.BuildTarget);
            Set("Configuration", options.Configuration);
            Set("OutputDirectory", OutputDirectory = ExpandSingleLine(options.OutputDirectory).UnixToNative());
        }
Ejemplo n.º 8
0
        public MetadataGenerator(Disk disk, IBuildData data, IEssentials essentials,
                                 MetadataBackend backend, CilLinker linker, SourcePackage package,
                                 string outputDir)
            : base(disk)
        {
            _data       = data;
            _essentials = essentials;
            _backend    = backend;
            _package    = package;
            _linker     = linker;
            _outputDir  = outputDir;
            _assembly   = _linker.Universe.DefineDynamicAssembly(
                new AssemblyName(package.Name)
            {
                Version = package.ParseVersion(Log)
            },
                AssemblyBuilderAccess.Save,
                outputDir);
            var module = _assembly.DefineDynamicModule(
                package.Name,
                package.Name + ".dll",
                true);

            _types = new CilTypeFactory(backend, essentials, linker, module);
        }
Ejemplo n.º 9
0
        internal static CacheReader CreateReader(SourcePackage upk, string filename)
        {
            var r = new CacheReader(upk, filename);

            r.VerifyMagic(Magic);
            return(r);
        }
Ejemplo n.º 10
0
        public void ParseSourceCode(SourcePackage upk, string filename, string text)
        {
            var ast = new List <AstDocument>();

            new Parser(Log, upk, filename, text).Parse(ast);
            AstProcessor.AddRange(ast);
        }
Ejemplo n.º 11
0
 public BundleFile(SourcePackage package, string bundleName, string targetName, string sourcePath)
 {
     Package    = package;
     BundleName = bundleName;
     TargetName = targetName;
     SourcePath = sourcePath;
 }
Ejemplo n.º 12
0
        public Compiler(Log log, Backend backend, SourcePackage package, CompilerOptions options)
            : base(log)
        {
            // This is a block of dependency injection to initialize the Compiler
            var il         = new Namespace();
            var extensions = new ExtensionRoot();

            Backend = backend;
            var disk = Disk = new Disk(log, true);

            Shell = new Shell(log);
            var essentials   = Essentials = new Essentials();
            var resolver     = NameResolver = new NameResolver(this);
            var ilf          = ILFactory = new ILFactory(backend, il, essentials, resolver, this);
            var data         = Data = new BuildData(il, extensions, ilf);
            var environment  = Environment = new BuildEnvironment(backend, package, options, extensions, ilf, this);
            var input        = Input = new SourceReader(log, package, environment);
            var blockBuilder = BlockBuilder = new BlockBuilder(backend, il, ilf, resolver, this);
            var typeBuilder  = TypeBuilder = new TypeBuilder(environment, ilf, resolver, this);
            var bundle       = BundleBuilder = new BundleBuilder(backend, environment, ilf, this);

            AstProcessor = new AstProcessor(il, blockBuilder, typeBuilder, resolver, environment);
            UxlProcessor = new UxlProcessor(disk, backend.Name, il, extensions, environment, ilf);
            Plugins      = new PluginCache(log, bundle, ilf, environment);
            var pass = Pass = new CompilerPass(disk, data, environment, ilf, backend, input.Package, typeBuilder, resolver);

            Utilities      = new Utilities(il, pass);
            ILVerifier     = new ILVerifier(pass);
            ConstantFolder = new ConstantFolder(pass);
            ILStripper     = new ILStripper(pass);
        }
Ejemplo n.º 13
0
        public static Compiler.Core.Compiler Create(Log log, SourcePackage project)
        {
            var backend = new ILCacheBackend();

            var compiler = new Compiler.Core.Compiler(log, backend, project, new CompilerOptions
            {
                Debug = true,
                CodeCompletionMode = true,
                OutputDirectory    = Path.Combine(project.SourceDirectory, "Output"),
                BuildTarget        = "UXValidator",
                Strip = false
            });

            ParseUxDummyFiles(compiler, project);
            compiler.ParseSourceFiles();
            compiler.InitializeIL();
            compiler.Backend.Begin(compiler);

            try
            {
                compiler.TypeBuilder.BuildTypes();
            }
            catch (Exception)
            {
            }

            return(compiler);
        }
Ejemplo n.º 14
0
 BestMainClassSelector(List <DataType> foundMainClasses, Log log, SourcePackage mainProject, DataType mainClassAttribute)
 {
     _foundMainClasses = foundMainClasses;
     _log                = log;
     _mainProject        = mainProject;
     _mainClassAttribute = mainClassAttribute;
 }
Ejemplo n.º 15
0
 public ImportContext(Source src, DataType[] types, object[] arguments)
 {
     Source        = src;
     TypeArguments = types;
     Arguments     = arguments;
     Package       = src.Package;
 }
Ejemplo n.º 16
0
 public static void Serialize(this IEnumerable <UxlDocument> list, SourcePackage upk, string filename)
 {
     using (var w = UxlDocument.CreateWriter(upk, filename))
         foreach (var e in list)
         {
             e.Write(w);
         }
 }
Ejemplo n.º 17
0
 protected XmlParserBase(Log log, SourcePackage upk, string filename)
     : base(log)
 {
     File            = new SourceFile(upk, filename);
     StartErrorCount = log.ErrorCount;
     Source          = XmlPreprocessor.ProcessFile(filename);
     Reader          = new XmlTextReader(Source, XmlNodeType.Document, null);
 }
Ejemplo n.º 18
0
 public SuggestionDependentData(SourcePackage mainPackage, Compiler compiler, AbsoluteFilePath filePath, string srcCode, int caretOffset)
 {
     MainPackage = mainPackage;
     Compiler    = compiler;
     FilePath    = filePath;
     SrcCode     = srcCode;
     CaretOffset = caretOffset;
 }
Ejemplo n.º 19
0
 public GotoDefinitionData(SourcePackage mainPackage, Compiler compiler, AbsoluteFilePath filePath, string srcCode, int caretOffset)
 {
     MainPackage = mainPackage;
     Compiler    = compiler;
     FilePath    = filePath;
     SrcCode     = srcCode;
     CaretOffset = caretOffset;
 }
Ejemplo n.º 20
0
 public static void Serialize(this IEnumerable <AstDocument> list, SourcePackage upk, string filename, AstSerializationFlags flags)
 {
     using (var w = AstWriter.Create(upk, filename, flags))
         foreach (var e in list)
         {
             w.WriteDocument(e);
         }
 }
Ejemplo n.º 21
0
 public bool IsVisibleInPackage(SourcePackage package)
 {
     return
         (Level == VisibilityLevel.Global ||
          (Level == VisibilityLevel.Package && Package.Equals(package)) ||
          (Level == VisibilityLevel.SameTypeOrSubclassOfOrPackage && Package.Equals(package)) ||
          Package.InternalsVisibleTo.Contains(package.Name));
 }
Ejemplo n.º 22
0
 public SourceReader(Log log, SourcePackage upk, IFrontendEnvironment env)
     : base(log)
 {
     _upk     = upk;
     _env     = env;
     AstCache = new AstCache(log, _filenames);
     UxlCache = new UxlCache(log, _filenames);
     ResolvePackageOrder(upk, new HashSet <SourcePackage>());
 }
Ejemplo n.º 23
0
 public ForeignFilePass(
     ExtensionRoot extensions,
     SourcePackage package,
     CppBackend backend)
     : base(backend)
 {
     Extensions = extensions;
     Package    = package;
     Backend    = backend;
 }
        //--------------------------------------------------------------------------
        // IDisposable Members
        //--------------------------------------------------------------------------

        /// <summary>
        /// <see cref="MS.Internal.Documents.Application.Document"/>
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    // our base is StreamDocument, as these packages support
                    // the stream we want our base to release them first
                    ReleaseStreams();

                    // The only code that actually requires this assert are the
                    // calls to Close. Regardless I've put the assert around the
                    // whole block since the rest of the code under it is almost
                    // all just checking packages for null or setting them to null.
                    // This is much cleaner than having three separate asserts (and
                    // three more try/finally blocks) for each Close call.
                    try
                    {
                        if (DestinationPackage != null)
                        {
                            if (DestinationPackage == SourcePackage)
                            {
                                SourcePackage = null;
                            }
                            DestinationPackage.Close();
                            DestinationPackage = null;
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (WorkspacePackage != null)
                            {
                                WorkspacePackage.Close();
                                WorkspacePackage = null;
                            }
                        }
                        finally
                        {
                            if (SourcePackage != null)
                            {
                                SourcePackage.Close();
                                SourcePackage = null;
                            }
                        }
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 25
0
 public PackageGenerator(
     IEnvironment env,
     SourcePackage upk,
     Log log,
     Disk disk)
 {
     _env  = env;
     _upk  = upk;
     _log  = log;
     _disk = disk;
 }
Ejemplo n.º 26
0
        public static AstWriter Create(SourcePackage upk, string filename, AstSerializationFlags flags)
        {
            if (upk.IsUnknown)
            {
                throw new InvalidOperationException("AstWriter: Unknown source package");
            }

            var w = new AstWriter(upk, filename, flags);

            w.Write(AstSerialization.Magic);
            return(w);
        }
Ejemplo n.º 27
0
 public CompilerPass(CompilerPass parent)
     : base(parent)
 {
     Backend      = parent.Backend;
     Package      = parent.Package;
     TypeBuilder  = parent.TypeBuilder;
     Data         = parent.Data;
     Environment  = parent.Environment;
     Essentials   = parent.Essentials;
     ILFactory    = parent.ILFactory;
     NameResolver = parent.NameResolver;
 }
Ejemplo n.º 28
0
 public static void Deserialize(SourcePackage upk, string filename, List <AstDocument> resultAsync)
 {
     using (var r = AstReader.Open(upk, filename))
     {
         while (r.BaseStream.Position < r.BaseStream.Length)
         {
             var ast = r.ReadDocument();
             lock (resultAsync)
                 resultAsync.Add(ast);
         }
     }
 }
Ejemplo n.º 29
0
        internal static CacheWriter CreateWriter(SourcePackage upk, string filename)
        {
            if (upk.IsUnknown)
            {
                throw new InvalidOperationException("UxlDocument: Unknown source package");
            }

            var w = new CacheWriter(upk, filename);

            w.Write(Magic);
            return(w);
        }
Ejemplo n.º 30
0
        void AddExtensionsFiles(SourcePackage upk, string backendName, List <Task> tasks, List <IEnumerable <UxlDocument> > files)
        {
            // 1) See if SourcePackage already has UXL cached in memory

            List <UxlDocument> result;

            if (upk.TryGetCache(backendName, out result))
            {
                Log.UltraVerbose("Using UXL from memory cache in " + upk);
                files.Add(result);
                return;
            }

            // 2) If no cache was available we must load from disk

            result = new List <UxlDocument>();
            upk.Cache[backendName] = result;
            files.Add(result);

            if (upk.IsCached)
            {
                if (backendName == null ||
                    !_env.Test(upk.Source, upk.BuildCondition) ||
                    !upk.CachedExtensionsBackends.Contains(backendName))
                {
                    return;
                }

                BeginTask(tasks,
                          () =>
                {
                    try
                    {
                        UxlCache.Deserialize(upk, Path.Combine(upk.CacheDirectory, backendName + "." + UxlCache.MagicString), result);
                    }
                    catch (Exception e)
                    {
                        Log.Error(upk.Source, ErrorCode.E0000, "Failed to load UXL cache: " + e.Message);
                    }
                });
            }
            else
            {
                foreach (var rf in upk.ExtensionsFiles)
                {
                    if (_env.Test(_upk.Source, rf.Condition))
                    {
                        BeginTask(tasks, () => UxlCache.Load(upk, rf.UnixPath, result));
                    }
                }
            }
        }
Ejemplo n.º 31
0
 public void AddPackage(SourcePackage package)
 {
     _packages.Add(package);
 }