Beispiel #1
0
    // Returns the edge between the nodes given if one exists.
    // Otherwise, returns null
    public virtual EdgeType GetEdge(int from, int to)
    {
        if (
            (from >= this.nodes.Count) || (from <= NodeCommons.InvalidNodeId) ||
            this.nodes[from].Id == NodeCommons.InvalidNodeId
            )
        {
            ErrorPrinter.PrintError("SparseGraph", "GetEdge - line 202", "INVALID Edge.FromNode INDEX", "Cihan");
            return(null);
        }

        if (
            (to >= this.nodes.Count) || (to <= NodeCommons.InvalidNodeId) ||
            this.nodes[to].Id == NodeCommons.InvalidNodeId
            )
        {
            ErrorPrinter.PrintError("SparseGraph", "GetEdge - line 214", "INVALID Edge.ToNode INDEX", "Cihan");
            return(null);
        }

        foreach (EdgeType edge in this.edges[from])
        {
            if (edge.ToNode == to)
            {
                return(edge);
            }
        }

        ErrorPrinter.PrintError("SparseGraph", "GetEdge - line 229", "THE EDGE DOES NOT EXIST BETWEEN from: " + from + " to: " + to, "Cihan");
        return(null);
    }
Beispiel #2
0
    protected GraphSearchCommons.SearchValidationFlgas validateTheSearch(
        int sourceIndex, int targetIndex,
        AbstractGraph <NodeType, EdgeType> sourceGraph
        )
    {
        if (sourceIndex == NodeCommons.InvalidNodeId || targetIndex == NodeCommons.InvalidNodeId)
        {
            ErrorPrinter.PrintError(
                "GraphDFS", "validateTheSearch", "Has invalid indices for SOURCE: " +
                sourceIndex + " TARGET: " + targetIndex, "Cihan"
                );
            return(GraphSearchCommons.SearchValidationFlgas.invalidIndices);
        }

        if (sourceGraph.GetNode(sourceIndex) == null || sourceGraph.GetNode(targetIndex) == null)
        {
            ErrorPrinter.PrintError(
                "GraphDFS", "validateTheSearch", "Has invalid nodes in the grap! SOURCE: " +
                sourceIndex + " TARGET: " + targetIndex, "Cihan"
                );
            return(GraphSearchCommons.SearchValidationFlgas.invalidIndices);
        }

        if (sourceIndex == targetIndex)
        {
            return(GraphSearchCommons.SearchValidationFlgas.atTheTarget);
        }

        return(GraphSearchCommons.SearchValidationFlgas.valid);
    }
    }     // End of SparseGraph.AddEdge()

    // Adds an edge to the graph. The method ensures that the edge is valid before
    // adding it to the graph.
    // WARNING THIS VERSION MAY CREATE GARBAGE
    public override void AddEdge(EdgeType edge)
    {
        // Make sure the from and to nodes exist within the graph
        if ((edge.FromNode >= nextNodeIndex) || (edge.ToNode >= nextNodeIndex))
        {
            ErrorPrinter.PrintError("SparseGraph", "AddEdge", "THE EDGE HAS INVALID INDICES: from: " + edge.FromNode + " to: " + edge.ToNode, "Cihan");
            return;
        }

        // Make sure both nodes are active before adding the edge
        if (
            (this.nodes[edge.ToNode].Id != NodeCommons.InvalidNodeId) &&
            (this.nodes[edge.FromNode].Id != NodeCommons.InvalidNodeId)
            )
        {
            // Add the edge, first making sure it is unique
            if (IsUniqueEdge(edge.FromNode, edge.ToNode))
            {
                this.edges[edge.FromNode].AddLast(edge);
            }
            else
            {
                ErrorPrinter.PrintError("SparseGraph", "AddEdge", "THE EDGE IS NOT UNIQUE: from: " + edge.FromNode + " to: " + edge.ToNode, "Cihan");
            }
        }
    }   // End of AddEdge()
Beispiel #4
0
    // Adds a node to the graph and returns its index
    // WARNING THIS MAY CREATE GARBAGE COLLECTION
    public virtual int AddNode(NodeType node)
    {
        if (node.Id < this.nodes.Count)
        {
            // Make sure the client is not trying to add a node with the same ID as a currently active node
            if (this.nodes[node.Id].Id != NodeCommons.InvalidNodeId)
            {
                ErrorPrinter.PrintError("SparseGraph", "AddNode - line 89", "Attempting to add a node with a duplicate ID", "Cihan");
                return(NodeCommons.InvalidNodeId);
            }

            // So the new node passed won't wander around
            this.nodes.Remove(this.nodes[node.Id]);
            this.nodes.Insert(node.Id, node);

            return(nextNodeIndex);
        }
        else
        {
            // Make sure the new node has been indexed correctly
            if (node.Id == NodeCommons.InvalidNodeId)
            {
                ErrorPrinter.PrintError("SparseGraph", "AddNode - line 104", "Invalid index", "Cihan");
                return(NodeCommons.InvalidNodeId);
            }

            this.nodes.Add(node);
            this.edges.Add(new LinkedList <EdgeType>());

            return(nextNodeIndex++);
        }
    }
Beispiel #5
0
        public override void Execute(BackupOptions options, ILogger logger)
        {
            var stacks = (options.Stacks.Any() ? options.Stacks : AppDirectory.GetStacks()).ToList();

            stacks = stacks.Distinct().ToList();

            if (!stacks.Any())
            {
                var message = "Selection did not match any valid targets for backup";
                logger.Error(message, new { selection = options.Stacks });
                ErrorPrinter.Error(message);
                return;
            }

            Directory.CreateDirectory(options.BackupDirectory);

            logger.Trace("writing archives in parallel", new { stack_count = stacks.Count(), stacks = string.Join(",", stacks) });

            new ParallelTaskManager <string, TaskState>(stacks, GetRow, (stack, progress) => Execute(logger, stack, progress, options), HandleProgress,
                                                        new[] { 0, 5 })
            .Execute(Settings.UserConfig.Parallelism);

            if (_encounteredError)
            {
                ErrorPrinter.Warn("Some backups were unsuccessful, skipping backup deletion.");
                logger.Warn("some backups were unsuccessful, skipping backup deletion");
                return;
            }

            PruneBackups(logger, stacks, options.BackupDirectory, options.NumberOfBackups);
        }
Beispiel #6
0
    // Adds a node to the graph and returns its index
    //
    // This version handles memory allocation on its own and minimise the garbage
    // creation. If a formerly invalid node is trying to adding (reactivation)
    // instead of creating a new node, the invalidated one is reactivated.
    public virtual int AddNode(params object[] initializerList)
    {
        int nodeId = (int)initializerList[0];

        if (nodeId < this.nodes.Count)
        {
            // Make sure the client is not trying to add a node with the same ID as a currently active node
            if (this.nodes[nodeId].Id != NodeCommons.InvalidNodeId)
            {
                ErrorPrinter.PrintError("SparseGraph", "AddNode - line 89", "Attempting to add a node with a duplicate ID", "Cihan");
                return(NodeCommons.InvalidNodeId);
            }

            this.nodes[nodeId].Init(initializerList);

            return(nextNodeIndex);
        }
        else
        {
            // Make sure the new node has been indexed correctly
            if (nodeId == NodeCommons.InvalidNodeId)
            {
                ErrorPrinter.PrintError("SparseGraph", "AddNode - line 104", "Invalid index", "Cihan");
                return(NodeCommons.InvalidNodeId);
            }

            NodeType newNode = Activator.CreateInstance <NodeType>();
            newNode.Init(initializerList);

            this.nodes.Add(newNode);
            this.edges.Add(new LinkedList <EdgeType>());

            return(nextNodeIndex++);
        }
    }
Beispiel #7
0
    // Adds an edge to the graph.
    public override void AddEdge(params object[] initializerList)
    {
        if (initializerList.Length < 2)
        {
            ErrorPrinter.PrintError("SparseGraph", "AddEdge-with initList", "THERE IS NOT ENOUGH INFO IN THE INIT-LIST", "Cihan");
            return;
        }
        else
        {
            int from = (int)initializerList[0];
            int to   = (int)initializerList[1];

            // Make sure the from and to nodes exist within the graph
            if ((from >= nextNodeIndex) || (to >= nextNodeIndex))
            {
                ErrorPrinter.PrintError("SparseGraph", "AddEdge-with initLis", "THE EDGE HAS INVALID INDICES: from: " + from + " to: " + to, "Cihan");
                return;
            }

            // Make sure both nodes are active before adding the edge
            if (
                (this.nodes[to].Id != NodeCommons.InvalidNodeId) &&
                (this.nodes[from].Id != NodeCommons.InvalidNodeId)
                )
            {
                if (from > to)
                {
                    HelperMethods.Swap <int>(ref from, ref to);
                    initializerList[0] = from;
                    initializerList[1] = to;
                }

                // Add the edge, first making sure it is unique
                if (IsUniqueEdge(from, to))
                {
                    EdgeType newEdge = Activator.CreateInstance <EdgeType>();
                    newEdge.Init(initializerList);
                    this.edges[newEdge.FromNode].AddLast(newEdge);

                    // Insert to adjacency list too
                    adjacencyList[from].AddLast(to);
                    adjacencyList[to].AddLast(from);
                }
                else
                {
                    ErrorPrinter.PrintError("SparseGraph", "AddEdge", "THE EDGE IS NOT UNIQUE: from: " + from + " to: " + to, "Cihan");
                }
            }
            else
            {
                ErrorPrinter.PrintError(
                    "SparseGraph", "AddEdge", "THE EDGE HAS INACTIVE NODES: fromNode: " +
                    this.nodes[from].Id + " toNode: " + this.nodes[to].Id,
                    "Cihan"
                    );
            }
        } // End of else it is safe to assign
    }     // End of SparseGraph.AddEdge()
Beispiel #8
0
    // Returns the node with a given id/index if one exists and active
    // Returns null otherwise
    public NodeType GetNode(int nodeId)
    {
        if (nodeId >= this.nodes.Count || nodeId <= NodeCommons.InvalidNodeId)
        {
            ErrorPrinter.PrintError("SparseGraph", "GetNode", "INVALID NODE INDEX", "Cihan");
            return(null);
        }

        return(this.nodes[nodeId]);
    }
Beispiel #9
0
 public virtual void Init(params object[] initializerList)
 {
     if (initializerList.Length < 1)
     {
         ErrorPrinter.PrintError("SparseGraph", "Init", "THERE IS NOT ENOUGH INFO IN THE INIT-LIST", "Cihan");
     }
     else
     {
         this.NodeId = (int)initializerList[0];
     }
 }
Beispiel #10
0
        public static ProcessResult Run(string stack, string arguments, bool printOutput)
        {
            if (!AppDirectory.StackExists(stack))
            {
                Output.Logger.Error("stack not found", new { stack });
                ErrorPrinter.Error($"Stack '{stack}' not found.");
                return(new ProcessResult(1));
            }

            return(RunIn(AppDirectory.GetStackDirectory(stack), arguments, printOutput));
        }
Beispiel #11
0
    }   // End of AddEdge()

    // Removes the edge if presents.
    public override void RemoveEdge(int from, int to)
    {
        if ((from >= this.nodes.Count) || (to >= this.nodes.Count))
        {
            ErrorPrinter.PrintError("SparseGraph", "RemoveEdge", "THE INVALID EDGE BETWEEN from: " + from + " to: " + to, "Cihan");
        }
        else
        {
            EdgeCommons.RemoveFromLinkedList <EdgeType>(this.edges, from, to);
        }
    }
Beispiel #12
0
        private static void CheckPlatform(ILogger logger)
        {
            logger.Trace("checking platform");

            var supportedPlatforms = new[] { Platform.Linux, Platform.Windows };
            var platform           = Environment.GetCurrentPlatform();

            if (!supportedPlatforms.Contains(platform))
            {
                logger.Warn("the current platform is not supported, proceed with caution", new { platform });
                ErrorPrinter.Warn($"The current platform ({platform}) is not supported, proceed with caution.");
            }
        }
Beispiel #13
0
    // Nodes are not actually removed for keeping the indices (refers as Id in here)
    // steady. The node that will be removed marked as invalid and the edges leading
    // to this node are removed (destroyed).
    public override void RemoveNode(int nodeId)
    {
        if (nodeId >= this.nodes.Count)
        {
            ErrorPrinter.PrintError("SparseGraph", "RemoveNode", "INVALID NODE INDEX", "Cihan");
        }
        else
        {
            // Set this node's index to invalid_node_index
            this.nodes[nodeId].MarkAsInvalid();

            // If a digraph remove the edges the slow way
            RemoveInvalidEdges();
        }
    }
Beispiel #14
0
        public override void Execute(DownOptions options, ILogger logger)
        {
            var stacks = options.Stacks.Any() ? options.Stacks : Docker.GetComposeStacks();

            if (!stacks.Any())
            {
                logger.Error("no running stacks found");
                ErrorPrinter.Error("There are no running stacks.");
                return;
            }

            logger.Trace("stopping stacks in parallel", new { stack_count = stacks.Count(), stacks = string.Join(",", stacks) });

            new ParallelTaskManager <string, TaskState>(stacks, GetRow, (stack, progress) => Execute(stack, progress, options, logger), HandleProgress, new[] { 0, 5 })
            .Execute(Settings.UserConfig.Parallelism);
        }
Beispiel #15
0
        private void PruneBackups(ILogger logger, IList <string> stacks, string backupDirectory, int numberToKeep)
        {
            Output.Fancy.Write("Deleting old backups ... ", Color.Info);
            logger.Trace("determining archives to be deleted");

            var filesToDelete = Directory.GetFiles(backupDirectory)
                                .Select(p => new FileInfo(p))
                                .GroupBy(f => Regex.Match(f.Name, @"(.*)_").Groups[1].Value) // group by stack
                                .Where(g => stacks.Contains(g.Key))                          // filter out stacks we don't care about
                                .SelectMany(g => g
                                            .OrderByDescending(f => f.CreationTime)
                                            .Skip(numberToKeep)) // select the oldest files over the limit
                                .ToList();

            var failCount = 0;

            foreach (var file in filesToDelete)
            {
                try
                {
                    logger.Trace("deleting archive", new { target = file.FullName });
                    file.Delete();
                }
                catch (Exception ex)
                {
                    failCount++;

                    if (failCount == 1)
                    {
                        Output.Fancy.WriteLine();
                    }

                    ErrorPrinter.HandledException($"Deleting archive [{file.FullName}] failed", ex);
                    logger.Error("archive deletion failed", new { target = file.FullName });
                }
            }

            Output.Fancy.WriteLine($"{filesToDelete.Count - failCount} backups deleted.", Color.Success);
            if (failCount > 0)
            {
                ErrorPrinter.Error($"Deletion of {failCount} backups failed.");
            }

            logger.Info("archives deleted", new { total_count = filesToDelete.Count, failed_count = failCount });
        }
Beispiel #16
0
    }   // End of AddEdge()

    // Removes the edge if presents.
    public override void RemoveEdge(int from, int to)
    {
        if ((from >= this.nodes.Count) || (to >= this.nodes.Count))
        {
            ErrorPrinter.PrintError("SparseGraph", "RemoveEdge", "THE INVALID EDGE BETWEEN from: " + from + " to: " + to, "Cihan");
            return;
        }

        if (from > to)
        {
            HelperMethods.Swap <int>(ref from, ref to);
        }

        EdgeCommons.RemoveFromLinkedList <EdgeType>(this.edges, from, to);

        // Remove from adjacency list too
        adjacencyList[from].Remove(to);
        adjacencyList[to].Remove(from);
    }
Beispiel #17
0
        /// <summary>
        /// This function connects errors to the respective UI block where the error was found.
        /// This function is called by <see cref="CompileButton_Click(object, RoutedEventArgs)"/> when
        /// errors are found.
        /// </summary>
        private void FillErrorsDictionary()
        {
            Utilities.BlockToLineErrors.Clear();
            foreach (int element in ErrorPrinter.GetErrorLines())
            {
                if (Utilities.BlockToLineErrors.ContainsKey(Utilities.linesOfCode[element - 1].owner))
                {
                    List <string> addedStrings = Utilities.BlockToLineErrors[Utilities.linesOfCode[element - 1].owner].Item1;
                    addedStrings = (List <string>)addedStrings.Concat(ErrorPrinter.GetErrorsAtLine(element));

                    Utilities.BlockToLineErrors[Utilities.linesOfCode[element - 1].owner] = new Tuple <List <string>, SolidColorBrush>(addedStrings, Utilities.GetRandomBrushForErrors());
                }
                else
                {
                    Utilities.BlockToLineErrors.Add(Utilities.linesOfCode[element - 1].owner, new Tuple <List <string>, SolidColorBrush>(ErrorPrinter.GetErrorsAtLine(element), Utilities.GetRandomBrushForErrors()));
                    BlocksWithErrorsInOrder.Add(Utilities.linesOfCode[element - 1].owner);
                }
            }
        }
Beispiel #18
0
    // Nodes are not actually removed for keeping the indices (refers as Id in here)
    // steady. The node that will be removed marked as invalid and the edges leading
    // to this node are removed (destroyed).
    public override void RemoveNode(int nodeId)
    {
        if (nodeId >= this.nodes.Count)
        {
            ErrorPrinter.PrintError("SparseGraph", "RemoveNode", "INVALID NODE INDEX", "Cihan");
        }
        else
        {
            // Mark the node as invalid
            this.nodes[nodeId].MarkAsInvalid();

            // We need while() because of iterator invalidation
            var edge = adjacencyList[nodeId].First;
            if (edge != null)
            {
                while (edge != null)
                {
                    var nextEdge = edge.Next;

                    var to = adjacencyList[edge.Value].First;
                    if (to != null)
                    {
                        while (to != null)
                        {
                            var nextTo = to.Next;

                            if (to.Value == nodeId)
                            {
                                RemoveEdge(edge.Value, nodeId);
                                break;
                            }

                            to = nextTo;
                        }
                    }

                    edge = nextEdge;
                }
            }

            adjacencyList[nodeId].Clear();
        }
    }
Beispiel #19
0
 public override void Init(params object[] initializerList)
 {
     if (initializerList.Length < 1)
     {
         ErrorPrinter.PrintError("SparseGraph", "Init-with initList", "THERE IS NOT ENOUGH INFO IN THE INIT-LIST", "Cihan");
     }
     else
     {
         this.NodeId = (int)initializerList[0];
         if (initializerList.Length > 1)
         {
             this.NodePos = (Vector2)initializerList[1];
         }
         else
         {
             this.NodePos = new Vector2();
         }
     }
 }
Beispiel #20
0
    // Sets the cost of an edge if one exists
    public virtual void SetEdgeCost(int from, int to, float cost)
    {
        // Check if the nodes are valid
        if (from >= this.nodes.Count || to >= this.nodes.Count)
        {
            ErrorPrinter.PrintError("SparseGraph", "SetEdgeCost", "INVALID INDEX! From: " + from + " to: " + to, "Cihan");
            return;
        }

        // Set cost of each from-to edges
        foreach (var edge in this.edges[from])
        {
            if (edge.ToNode == to)
            {
                edge.Cost = cost;
                break;
            }
        }
    }
Beispiel #21
0
        public void Execute(string stack, IProgress <TaskState> progress, UpOptions options, ILogger logger)
        {
            logger.Trace("starting stack", new { stack });

            var result = DockerCompose.Up(stack, options.PassthroughArguments, !options.Attach, options.ForceRecreate, false);

            if (result.ExitCode == 0)
            {
                logger.Info("started stack", new { stack });
                progress.Report(TaskState.Success);
            }
            else
            {
                logger.Error("starting stack failed", new { stack });
                logger.Debug("starting stack failed", new { stack, compose_stdout = result.Output, compose_stderr = result.Error });

                ErrorPrinter.SubProcessError($"Starting stack {stack} failed.", "docker-compose up", result);
                progress.Report(TaskState.Failure);
            }
        }
Beispiel #22
0
        public void Execute(string stack, IProgress <TaskState> progress, DownOptions options, ILogger logger)
        {
            logger.Trace("stopping stack", new { stack });

            var result = DockerCompose.Down(stack, options.PassthroughArguments, options.RemoveOrphans, false);

            if (result.ExitCode == 0)
            {
                logger.Info("stopped stack", new { stack });
                progress.Report(TaskState.Success);
            }
            else
            {
                logger.Error("stopping stack failed", new { stack });
                logger.Debug("stopping stack failed", new { stack, compose_stdout = result.Output, compose_stderr = result.Error });

                ErrorPrinter.SubProcessError($"Stopping stack {stack} failed.", "docker-compose down", result);
                progress.Report(TaskState.Failure);
            }
        }
Beispiel #23
0
    public virtual void Init(params object[] initializerList)
    {
        if (initializerList.Length < 2)
        {
            ErrorPrinter.PrintError("SparseGraph", "Init", "THERE IS NOT ENOUGH INFO IN THE INIT-LIST", "Cihan");
        }
        else
        {
            this.NodeFrom = (int)initializerList[0];
            this.NodeTo   = (int)initializerList[1];

            if (initializerList.Length > 2)
            {
                this.NodeCost = Convert.ToSingle(initializerList[2]);
            }
            else
            {
                this.NodeCost = 1.0f;
            }
        }
    }
Beispiel #24
0
        private static int HandleException(Exception ex)
        {
            if (ex is FatalException fatalEx)
            {
                PerformanceTesting.Checkpoint("Fatal Exception");
                ErrorPrinter.Fatal(fatalEx.Message);

                if (fatalEx.InnerException != null)
                {
                    ErrorPrinter.HandledException(null, fatalEx.InnerException);
                }

                return(fatalEx.ExitCode);
            }

            PerformanceTesting.Checkpoint("Unhandled Exception");

            Output.Logger.Fatal(null, ex);
            ErrorPrinter.UnhandledException(ex);

            return(1);
        }
Beispiel #25
0
        public override void Execute(UpdateOptions options, ILogger logger)
        {
            var stacks = options.Stack.Any() ? options.Stack : Docker.GetComposeStacks();

            if (!stacks.Any())
            {
                logger.Error("no running stacks found");
                ErrorPrinter.Error("There are no running stacks.");
                return;
            }

            logger.Trace("updating stacks in parallel", new { stack_count = stacks.Count(), stacks = string.Join(",", stacks) });

            new ParallelTaskManager <string, (TaskState, TaskState)>(stacks, GetRow, (stack, progress) => Execute(stack, progress, options, logger), HandleProgress,
                                                                     new[] { 0, 5, 0 }, new[] { "Stack", "Pull", "Restart" })
            .Execute(Settings.UserConfig.Parallelism);

            if (options.RemoveDanglingImages)
            {
                RemoveDanglingImages(logger);
            }
        }
Beispiel #26
0
        public void Execute(ILogger logger, string stack, IProgress <TaskState> progress, BackupOptions options)
        {
            logger.Trace("writing archive", new { stack });

            var stackDirectory = AppDirectory.GetStackDirectory(stack);
            var archivePath    = Path.Combine(options.BackupDirectory, $"{stack}_{DateTime.Now.ToUnixTimestampMillis()}.zip");

            try
            {
                ZipFile.CreateFromDirectory(stackDirectory, archivePath, options.CompressionLevel, false);
                logger.Info("writing archive succeeded", new { stack, source = stackDirectory, target = archivePath });

                progress.Report(TaskState.Success);
            }
            catch (Exception ex)
            {
                _encounteredError = true;
                progress.Report(TaskState.Failure);

                ErrorPrinter.HandledException($"Writing archive of stack {stack} failed", ex);
                logger.Error("writing archive failed", ex, new { stack, source = stackDirectory, target = archivePath });
            }
        }
Beispiel #27
0
        /// <summary>
        /// This event is invoked when the user clicks the Compile button.
        /// The function prepares to compile by resetting all necessary values back
        /// to default and then begins compilation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CompileButton_Click(object sender, RoutedEventArgs e)
        {
            Utilities.linesOfCodeCount = 0;
            Utilities.linesOfCode      = new List <CodeLine>();
            ErrorPrinter.errorCount    = 0;
            ErrorPrinter.errorList     = new Dictionary <int, List <string> >();
            FunctionDirectory.Reset();
            MemoryManager.Reset();
            QuadrupleManager.Reset();
            UserControl main = new UserControl();

            ///*
            Utilities.BlockToLineErrors.Clear();
            BlocksWithErrorsInOrder.Clear();
            Utilities.errorsInLines.Clear();

            AssetListViewContainer.PrintCode();
            VariableListViewContainer.PrintCode();
            FunctionListViewContainer.PrintCode();

            Utilities.linesOfCode.Add(new CodeLine("instructions {", main, Utilities.linesOfCodeCount + 1));
            Utilities.linesOfCodeCount++;

            InstructionListViewContainer.PrintCode();

            Utilities.linesOfCode.Add(new CodeLine("}", main, Utilities.linesOfCodeCount + 1));
            Utilities.linesOfCodeCount++;

            WriteCodeToFile(out string filePath);
            //*/

            /*
             * string directoryPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MarblesOutput");
             * Directory.CreateDirectory(directoryPath);
             * string filePath = Path.Combine(directoryPath, "testMarblesCode2.txt");
             */

            AnalyzeCode(filePath);

            MemoryManager.PrintMemory();
            QuadrupleManager.PrintQuadruples();

            Debug.WriteLine(ErrorPrinter.errorCount + " error(s) found.");
            ErrorPrinter.PrintErrors();

            if (ErrorPrinter.errorCount == 0)
            {
                Utilities.GreenCompile();
                Utilities.EnableRunButton();
                CompileButton.Background = Utilities.CompileButtonColor;
                CompileButton.IsEnabled  = Utilities.CompileButtonEnabled;
            }
            else
            {
                Utilities.RedCompile();
                Utilities.DisableRunButton();

                FillErrorsDictionary();
                SetErrorsInUI();

                CompileButton.Background = Utilities.CompileButtonColor;
                CompileButton.IsEnabled  = Utilities.CompileButtonEnabled;
            }
        }
Beispiel #28
0
    public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text

    /// <summary>
    /// Registers a syntaxis error and passes it on to <see cref="ErrorPrinter"/>.
    /// </summary>
    /// <param name="line"></param>
    /// <param name="col"></param>
    /// <param name="n"></param>
    public virtual void SynErr(int line, int col, int n)
    {
        string s;

        switch (n)
        {
        case 0: s = "EOF expected"; break;

        case 1: s = "Valid ID expected"; break;

        case 2: s = "Boolean expected"; break;

        case 3: s = "Boolean expected"; break;

        case 4: s = "Numeric constant expected"; break;

        case 5: s = "Text constant expected"; break;

        case 6: s = "\"instructions\" expected"; break;

        case 7: s = "\"{\" expected"; break;

        case 8: s = "\"}\" expected"; break;

        case 9: s = "\"function\" expected"; break;

        case 10: s = "\"(\" expected"; break;

        case 11: s = "\",\" expected"; break;

        case 12: s = "\")\" expected"; break;

        case 13: s = "\"text\" expected"; break;

        case 14: s = "\"number\" expected"; break;

        case 15: s = "\"bool\" expected"; break;

        case 16: s = "\"var\" expected"; break;

        case 17: s = "\";\" expected"; break;

        case 18: s = "\"asset\" expected"; break;

        case 19: s = "\"call\" expected"; break;

        case 20: s = "\"stop\" expected"; break;

        case 21: s = "\"do\" expected"; break;

        case 22: s = "\".\" expected"; break;

        case 23: s = "\"move_x\" expected"; break;

        case 24: s = "\"move_y\" expected"; break;

        case 25: s = "\"rotate\" expected"; break;

        case 26: s = "\"set_position\" expected"; break;

        case 27: s = "\"spin\" expected"; break;

        case 28: s = "\"for\" expected"; break;

        case 29: s = "\"loops\" expected"; break;

        case 30: s = "\"while\" expected"; break;

        case 31: s = "\"if\" expected"; break;

        case 32: s = "\"set\" expected"; break;

        case 33: s = "\"=\" expected"; break;

        case 34: s = "\"or\" expected"; break;

        case 35: s = "\"and\" expected"; break;

        case 36: s = "\"+\" expected"; break;

        case 37: s = "\"-\" expected"; break;

        case 38: s = "\"*\" expected"; break;

        case 39: s = "\"/\" expected"; break;

        case 40: s = "\">\" expected"; break;

        case 41: s = "\"<\" expected"; break;

        case 42: s = "\"==\" expected"; break;

        case 43: s = "\"<=\" expected"; break;

        case 44: s = "\">=\" expected"; break;

        case 45: s = "\"!=\" expected"; break;

        case 46: s = "\"value\" expected"; break;

        case 47: s = "\"label\" expected"; break;

        case 48: s = "\"position_x\" expected"; break;

        case 49: s = "\"position_y\" expected"; break;

        case 50: s = "\"width\" expected"; break;

        case 51: s = "\"height\" expected"; break;

        case 52: s = "\"return\" expected"; break;

        case 53: s = "??? expected"; break;

        case 54: s = "invalid INSTRUCTION"; break;

        case 55: s = "invalid TYPE_FUNC"; break;

        case 56: s = "invalid TYPE_VAR"; break;

        case 57: s = "invalid ASSET BEHAVIOR"; break;

        case 58: s = "invalid ASSET PROPERTY"; break;

        case 59: s = "invalid OPERATOR"; break;

        case 60: s = "invalid VALUE"; break;

        case 61: s = "invalid VALUE"; break;

        case 62: s = "invalid BOOL"; break;

        default: s = "error " + n; break;
        }
        ErrorPrinter.AddError(line, s);
        count++;
        throw new Exception(s);
    }
Beispiel #29
0
 /// <summary>
 /// Registers a semantic error (with line and message) and passes it on to <see cref="ErrorPrinter"/>.
 /// </summary>
 /// <param name="line"></param>
 /// <param name="col"></param>
 /// <param name="s"></param>
 public virtual void SemErr(int line, int col, string s)
 {
     ErrorPrinter.AddError(line, s);
     count++;
     throw new Exception(s);
 }
Beispiel #30
0
 /// <summary>
 /// Registers a semantic error (only with a message) and passes it on to <see cref="ErrorPrinter"/>.
 /// </summary>
 /// <param name="s"></param>
 public virtual void SemErr(string s)
 {
     ErrorPrinter.AddError(s);
     count++;
     throw new Exception(s);
 }