Пример #1
0
 internal void Verify(FrontendCompiler context, PackageItem parentItem)
 {
     if (this.Name == BackgroundTaskType.Invalid)
     {
         context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("AdditionalTask", "Name"), parentItem));
     }
 }
Пример #2
0
 internal void Verify(FrontendCompiler context, PackageItem parentItem)
 {
     if (String.IsNullOrEmpty(this.Name))
     {
         context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute(this.typeName, "Name"), parentItem));
     }
 }
Пример #3
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            this.ParentFolder = this.Parent as Folder;

            // If the resource has a name, break it down into it's constituent parts: [folderid:\][relative\path\to\][name[\]]
            if (!String.IsNullOrEmpty(this.Name))
            {
                // If the name starts with a parent folder identifier.
                int idSeparator = this.Name.IndexOf(':');
                if (idSeparator > -1)
                {
                    this.ParentFolderIdFromName = this.Name.Substring(0, idSeparator);
                    this.Name = this.Name.Substring(idSeparator + 1).TrimStart(FileSystemResourceManager.DirectorySplitChars);
                }

                // Do not include a trailing backslash in the search.
                int endOfName     = this.Name.EndsWith("\\", StringComparison.Ordinal) ? this.Name.Length - 2 : this.Name.Length - 1;
                int lastBackslash = this.Name.LastIndexOfAny(FileSystemResourceManager.DirectorySplitChars, endOfName);
                if (lastBackslash > -1)
                {
                    this.ParentRelativePathFromName = this.Name.Substring(0, lastBackslash + 1);
                    this.Name = this.Name.Substring(lastBackslash + 1);
                }
            }

            if (this.ParentFolder != null && !String.IsNullOrEmpty(this.ParentFolderIdFromName))
            {
                // TODO: send error that Name attribute overrode ParentFolder string.
            }

            //FileSystemResourceManager manager = (FileSystemResourceManager)context.GetService(typeof(FileSystemResourceManager));
            //manager.AddResource(context, this);
        }
Пример #4
0
 protected override void OnResolveEnd(FrontendCompiler context)
 {
     if (this.Image != null)
     {
         this.Image.ResolveFiles(context, this);
     }
 }
Пример #5
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            if (String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.Source))
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.FileMissingNameAndSource(), this));
            }
            else if (String.IsNullOrEmpty(this.Name) || this.Name.EndsWith("\\", StringComparison.Ordinal))
            {
                this.Name = IO.Path.Combine(this.Name ?? String.Empty, IO.Path.GetFileName(this.Source));
            }

            // TODO: error if name ends with "\".

            base.OnResolveBegin(context);

            // TODO: error if name is empty.

            if (String.IsNullOrEmpty(this.Source))
            {
                // TODO: walk the parent tree to see if a source is available.

                this.Source = IO.Path.Combine(this.ParentRelativePathFromName ?? String.Empty, this.Name);
            }
            else if (this.Source.EndsWith("\\", StringComparison.Ordinal))
            {
                this.Source = IO.Path.Combine(this.Source, this.ParentRelativePathFromName ?? String.Empty, this.Name);
            }
        }
Пример #6
0
        /// <summary>
        /// Compiles the added files into a target output appropriate for the output path extension.
        /// </summary>
        /// <param name="type">Package type to generate.</param>
        /// <param name="architecture">Package architecture to generate.</param>
        /// <param name="languages">Package languages to generate.</param>
        /// <param name="outputPath">Path to generate output. Output path file extension determines the output type.</param>
        public void Compile(PackageType type, PackageArchitecture architecture, CultureInfo[] languages, string outputPath)
        {
            FrontendCompiler frontend = new FrontendCompiler(architecture, this.referenceAssemblies);

            frontend.Messages += this.Messages;

            foreach (KeyValuePair <string, string> define in this.PreprocessorDefines)
            {
                frontend.Substitutions.Add(define.Key, define.Value);
            }

            foreach (Swix root in this.roots)
            {
                frontend.AddRoot(root);
            }

            foreach (string path in this.sourceFiles)
            {
                frontend.Parse(path);
            }

            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Resolve();
            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Harvest();
            if (frontend.EncounteredError)
            {
                return;
            }

            Intermediate[] intermediates = frontend.GetIntermediates();

            CompilerFileManager fileManager = this.FileManager ?? new CompilerFileManager();

            fileManager.Architecture = architecture;
            fileManager.Language     = languages.Length == 0 ? null : languages[0];
            fileManager.OutputPath   = outputPath;
            foreach (string searchPath in this.SearchPaths)
            {
                fileManager.SearchPaths.Add(searchPath);
            }

            using (BackendCompiler backend = BackendCompiler.Create(type, outputPath))
            {
                backend.Messages    += this.Messages;
                backend.Architecture = architecture;
                backend.FileManager  = fileManager;
                backend.Languages    = languages;

                backend.Generate(intermediates, outputPath);
            }
        }
Пример #7
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            if (String.IsNullOrEmpty(this.Id))
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.GroupMissingId(), this));
            }
        }
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            if (this.SupportedFileExtensions.Count == 0)
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredElement("FileSavePicker", "FileExtension"), this));
            }
            else
            {
                this.SupportedFileExtensions.ForEach(df => df.Verify(context, this));
            }
        }
Пример #9
0
        internal bool BeginResolve(FrontendCompiler context)
        {
            bool began = false;

            if (!this.resolved && !this.resolving)
            {
                began          = true;
                this.resolving = true; // mark the resource resolving to prevent infinite loops.

                this.OnResolveBegin(context);
            }

            return(began);
        }
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            if (this.Name == BackgroundTaskType.Invalid)
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("BackgroundTask", "Name"), this));
            }

            foreach (AdditionalTask at in this.AdditionalTasks)
            {
                at.Verify(context, this);
            }
        }
Пример #11
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            if (String.IsNullOrEmpty(this.Extension))
            {
                // TODO: error message that extension is required.
            }
            else if (!this.Extension.StartsWith(".", StringComparison.Ordinal))
            {
                // TODO: warn that we are automatically prefixing a dot on the extension.
                this.Extension = String.Concat(".", this.Extension);
            }
        }
        protected override void OnResolveEnd(FrontendCompiler context)
        {
            base.OnResolveEnd(context);

            // If the File wasn't explicitly set, default it to the parent if the parent is a file.
            if (this.File == null)
            {
                this.File = this.Parent as File;
            }
            else if (this.Parent is File)
            {
                // TODO: display a warning that we overrode the implicit (via parent) file with an explicit file reference.
            }
        }
Пример #13
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            if (this.SupportedDataFormats.Count == 0)
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredElement("ShareTarget", "DataFormat"), this));
            }
            else
            {
                foreach (SupportedDataFormat df in this.SupportedDataFormats)
                {
                    df.Verify(context, this);
                }
            }
        }
Пример #14
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            if (this.External)
            {
                // TODO: error if id is empty.
                // TODO: error if name is *not* empty.
                // TODO: error if parent is a folder.
                this.SetPath(String.Concat(this.Id, ":\\"));
            }
            else if (!String.IsNullOrEmpty(this.Name) && !this.Name.EndsWith("\\", StringComparison.Ordinal))
            {
                this.Name += "\\";
            }

            base.OnResolveBegin(context);
        }
Пример #15
0
        public void Parse(FrontendCompiler frontend)
        {
            if (this.TextView != null)
            {
                using (TextSnapshotToTextReader reader = new TextSnapshotToTextReader(this.TextView.TextBuffer.CurrentSnapshot))
                {
                    frontend.Parse(reader, this.Path);
                }
            }
            else
            {
                frontend.Parse(this.Path);
            }

            this.NeedsCompilation = false;
        }
Пример #16
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            base.OnResolveBegin(context);

            if (this.Foreground == TileForeground.Invalid)
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("Tile", "Foreground"), this));
            }

            if (String.IsNullOrEmpty(this.Background))
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("Tile", "Background"), this));
            }

            // TODO: verify the colors are valid
        }
Пример #17
0
        internal void EndResolve(FrontendCompiler context)
        {
            if (this.resolving)
            {
                // Process all the delayed lookup items first.
                foreach (DelayedItemLookup lookup in this.DelayedLookup.Values)
                {
                    lookup.Resolve(context);
                }

                this.OnResolveEnd(context);

                this.resolved  = true;
                this.resolving = false;
            }
        }
Пример #18
0
        protected override void OnResolveBegin(FrontendCompiler context)
        {
            if (String.IsNullOrEmpty(this.Name))
            {
                context.OnMessage(new CompilerMessageEventArgs(CompilerMessage.ApplicationNameRequired(), this));

                if (String.IsNullOrEmpty(this.Id))
                {
                    this.Id = "$invalid_application_id$";
                }
            }
            else if (String.IsNullOrEmpty(this.Id))
            {
                this.Id = this.Name.Replace('.', '_');
            }

            base.OnResolveBegin(context);
        }
Пример #19
0
        public void Compile()
        {
            if (!this.NeedsCompilation)
            {
                return;
            }

            lock (compileLock)
            {
                FrontendCompiler frontend = new FrontendCompiler(PackageArchitecture.Unknown, null);

                List <CompilerMessageEventArgs> compilerMessages = new List <CompilerMessageEventArgs>();
                frontend.Messages += (s, e) => { compilerMessages.Add(e); };

                try
                {
                    // Parse all the files in the set, then resolve and harvest them.
                    this.files.ForEach(file =>
                    {
                        file.Parse(frontend);
                    });
                    frontend.Resolve();
                    frontend.Harvest();
                }
                catch (Exception ex)
                {
                    // create/add message here?
                    System.Diagnostics.Debug.WriteLine("compiler exception: {0}", ex.Message);
                }
                finally
                {
                    // update the messages...
                    this.messages = compilerMessages;

                    // GetIntermediates() returns an array of IEnumerable...
                    // we just want to flatten that to a single list.
                    var newItems = frontend.GetIntermediates().SelectMany(i => i.Items);
                    this.Items = new List <PackageItem>(newItems);

                    this.OnCompileComplete();
                }
            }
        }
Пример #20
0
        private void Process()
        {
            var p = new ProjectManager();

            p.LoadCode(new DirectoryInfo(inputPath));

            var frontend = new FrontendCompiler();

            Console.WriteLine("Syntax checks starts...");
            frontend.CheckErrors(p);
            Console.WriteLine("No syntax errors found, backend compiler starts");
            backendCompiler.SetTable(frontend.SourceCode);
            backendCompiler.Translate(new DirectoryInfo(outputPath));
            if (compilerExecutor != null)
            {
                Console.WriteLine("Target build starts...");
                compilerExecutor.ExecuteCompilerCall();
                Console.WriteLine("Target build successful");
            }
        }
Пример #21
0
        internal Group ResolveGroup(FrontendCompiler context)
        {
            if (!this.resolvedGroup)
            {
                // See if the group was explicitly provided.
                DelayedItemLookup groupLookup;
                if (this.DelayedLookup.TryGetValue("Group", out groupLookup))
                {
                    PackageItem item = groupLookup.Resolve(context, true);
                    if (item != null && !(item is Group))
                    {
                        this.Group = new Group(false, groupLookup.Lookup, this);
                        context.AddItem(this.LineNumber, this.Group);
                    }

                    this.DelayedLookup.Remove("Group"); // remove the delayed look up so we don't try to look it up again in the future.
                }

                // If a group wasn't explicitly provided, try to default to the group from the parent.
                if (this.Group == null)
                {
                    if (this.Parent != null)
                    {
                        this.Group = this.Parent.ResolveGroup(context);
                        if (this.Group != null && this.Group != this.Parent)
                        {
                            this.Group.Items.Add(this);
                        }
                    }
                }
                else if (this.Parent is Group)
                {
                    // TODO: send warning message that we overrode the implicit (via parent) group with an explicit group.
                }

                this.resolvedGroup = true;
            }

            return((this is Group) ? (Group)this : this.Group);
        }
Пример #22
0
 internal void ResolveFiles(FrontendCompiler context, PackageItem parentItem)
 {
     // TODO: set this.Files with the files that match this.NonqualifiedName.
     // TOOD: error if this.Files is empty set.
 }
Пример #23
0
 /// <summary>
 /// Called when the item resolution is beginning. Default implementation does nothing.
 /// </summary>
 /// <param name="context">Frontend compiler context to aid in resolution.</param>
 protected virtual void OnResolveBegin(FrontendCompiler context)
 {
 }