Exemple #1
0
        private AssignCommand parseAssign()
        {
            AssignCommand assignCommand = new AssignCommand(CurrentToken.Line, new IdentifierPE(CurrentToken.Line, parseIdentifier()));

            if (accept(_assign))
            {
                if (Peek() == _operator)
                {
                    assignCommand.Expression = parseExpression();
                }
                else
                {
                    switch (CurrentToken.getType())
                    {
                    case _condition: assignCommand.AssignTo = new ConditionPE(CurrentToken.Line, parseCondition());
                        break;

                    case _identifier: assignCommand.AssignTo = new IdentifierPE(CurrentToken.Line, parseIdentifier());
                        break;

                    case _literalString: assignCommand.AssignTo = new LiteralString(CurrentToken.Line, parseLiteral());
                        break;

                    case _literalInt: assignCommand.AssignTo = new LiteralInt(CurrentToken.Line, parseLiteral());
                        break;
                    }
                }
                return(assignCommand);
            }
            return(null);
        }
Exemple #2
0
 public void visit(AssignCommand that)
 {
     Console.Write("{0} = ", that.Name);
     // we must explicitly walk all children of all nodes...
     that.Expression.visit(this);
     Console.WriteLine(";");
 }
Exemple #3
0
        private void DoAnalyse(Command node)
        {
            if (node is LetCommand)
            {
                LetCommand letCommand = (LetCommand)node;
                DeclarationCheck(letCommand.SequentialDeclaration);
                AnalyseCommands(letCommand.SequentialCommand);
                RemoveScope(letCommand.SequentialDeclaration);
            }

            if (node is AssignCommand)
            {
                AssignCommand assignCommand = (AssignCommand)node;
                string        type          = "";
                AnalyseAssignment(assignCommand, type);
            }

            if (node is IfCommand)
            {
                IfCommand ifCommand = (IfCommand)node;
                AnalyzeCondition(ifCommand.Expression);
                DoAnalyse(ifCommand.ThenCommand);
                DoAnalyse(ifCommand.ElseCommand);
            }
        }
Exemple #4
0
        public void Execute_Success()
        {
            //Arrange
            Commons.currentTeam  = new Team("TeamName");
            Commons.currentBoard = new Board("BoardName");
            Commons.currentTeam.Boards.Add(Commons.currentBoard);
            var fakeMember    = new Member("TestMemberName");
            var fakeCurrTeam  = Commons.currentTeam;
            var fakeCurrBoard = Commons.currentBoard;

            fakeCurrTeam.Members.Add(fakeMember);
            var listParams = new List <string>()
            {
                "TestMemberName", "WorkItemTitle"
            };

            var workItem = new Bug("WorkItemTitle", "WorkItemDescription", Priority.High, Severity.Critical);

            fakeCurrBoard.WorkItems.Add(workItem);

            var sut = new AssignCommand(listParams);

            //Act
            var result = sut.Execute();

            //Assert
            Assert.AreEqual(result, "TestMemberName has been assigned to WorkItemTitle");
        }
Exemple #5
0
        public void Execute_NonAssigneeType_ThrowEx()
        {
            //Arrange
            Commons.currentTeam  = new Team("TeamName");
            Commons.currentBoard = new Board("BoardName");
            Commons.currentTeam.Boards.Add(Commons.currentBoard);
            var fakeMember    = new Member("TestMemberName");
            var fakeCurrTeam  = Commons.currentTeam;
            var fakeCurrBoard = Commons.currentBoard;

            fakeCurrTeam.Members.Add(fakeMember);
            var listParams = new List <string>()
            {
                "TestMemberName", "WorkItemTitle"
            };

            var workItem = new Feedback("WorkItemTitle", "WorkItemDescription", 3);

            fakeCurrBoard.WorkItems.Add(workItem);

            var sut = new AssignCommand(listParams);

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(), $"Work item WorkItemTitle is of type feedback and it is not supposed to have assignee.");
        }
Exemple #6
0
        // Commands

        public Void VisitAssignCommand(AssignCommand ast, Frame frame)
        {
            var valSize = ast.Expression.Visit(this, frame);

            EncodeAssign(ast.Vname, frame.Expand(valSize), valSize);
            return(null);
        }
        public Void VisitAssignCommand(AssignCommand ast, Frame frame)
        {
            int valSize = ast.Expression.Visit(this, frame);

            EncodeAssign(ast.Identifier, frame.Expand(valSize), valSize);

            return(null);
        }
        public Void VisitAssignCommand(AssignCommand ast, Void arg)
        {
            TypeDenoter identifierType = ast.Identifier.Visit(this, null).Type;
            TypeDenoter expressionType = ast.Expression.Visit(this, null);

            CheckAndReportError(ast.Identifier.IsVariable, "LHS of assignment is not a variable", ast.Identifier);
            CheckAndReportError(expressionType.Equals(identifierType), "assignment incompatibilty", ast);
            return(null);
        }
Exemple #9
0
        public void ShouldAssignJobToMachine()
        {
            var machine       = new Machine(new Job());
            var assignCommand = new AssignCommand(machine);

            machineController.SetCommand(assignCommand);
            machineController.Command.Execute();
            Assert.AreEqual(machine.JobStatus, JobStatus.Assgined);
        }
        public void AssignCommand_AssignMemberToWorkItem()
        {
            var factory = new Mock <IFactory>();
            var command = new AssignCommand(new List <string>()
            {
                "Member1", "2"
            }, database, factory.Object);

            Assert.AreEqual("Work item: '2' assigned to 'Member1'.", command.Execute());
        }
        // Commands

        public Void VisitAssignCommand(AssignCommand ast, Void arg)
        {
            var vnameType      = ast.Vname.Visit(this);
            var expressionType = ast.Expression.Visit(this);

            CheckAndReportError(ast.Vname.IsVariable, "LHS of assignment is not a variable",
                                ast.Vname);
            CheckAndReportError(expressionType.Equals(vnameType), "assignment incompatibilty", ast);
            return(null);
        }
Exemple #12
0
        public void Execute_Less_Params_ThrowEx()
        {
            //Arrange
            var listParams = new List <string>()
            {
                "TeamMemberName"
            };

            var sut = new AssignCommand(listParams);

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(), "Parameters count is not valid!");
        }
Exemple #13
0
        public object visitAssignCommand(AssignCommand command, object arg)
        {
            Type vType = (Type)command.vname.visit(this, null);
            Type eType = (Type)command.exp.visit(this, null);

            if (!command.vname.Variable)
            {
                UI.Error("Contextual Error\nRule V:= Expr\nV is not a variable!");
            }

            if (!eType.Equals(vType))
            {
                UI.Error("Contextual Error\nRule V:= Expr\n V and Expr are not of equivalent Types!");
            }

            return(null);
        }
Exemple #14
0
        private void AnalyseAssignment(AssignCommand assignCommand, string type)
        {
            variableExists(assignCommand.Identifier);
            type = table[assignCommand.Identifier.getName()];

            if (assignCommand.Expression != null)
            {
                Expression expression = assignCommand.Expression;
                AnalysePrimaryExpression(expression.getP1, type);
                AnalysePrimaryExpression(expression.getP2, type);
                AnalyzeOperator(expression.GetOperator(), type);
            }

            if (assignCommand.AssignTo != null)
            {
                variableExists(assignCommand.AssignTo);
                CheckType(type, assignCommand.AssignTo);
            }
        }
Exemple #15
0
        Command parseCommand()
        {
            Command C = null;
            if (CurrentToken == null)
                return null;

            switch (CurrentToken.getType())
            {
                case If:
                    accept(If);
                    Expression E = parseExpression();
                    accept(Then);
                    Command C1 = parseCommand();
                    accept(Else);
                    Command C2 = parseCommand();
                    C = new IfCommand(E, C1, C2);
                    break;

                case Identifier:
                    Identifier I = parseIdentifier();
                    accept(Becomes);
                    Expression E1 = parseExpression();
                    C = new AssignCommand(I, E1);
                    break;

                case Let:
                    accept(Let);
                    Declaration D = parseDeclaration();
                    accept(In);
                    Command C3 = parseCommand();
                    C = new letCommand(D, C3);
                    break;

                default:
                    Console.WriteLine("Syntax Error in Command at token: " + CurrentToken.getSpelling());
                    C = null;
                    break;

            }

            return C;
        }
Exemple #16
0
        public void Execute_NonExistingWorkItem_ThrowEx()
        {
            //Arrange
            Commons.currentTeam  = new Team("TeamName");
            Commons.currentBoard = new Board("BoardName");
            Commons.currentTeam.Boards.Add(Commons.currentBoard);

            var fakeCurrTeam  = Commons.currentTeam;
            var fakeCurrBoard = Commons.currentBoard;

            var listParams = new List <string>()
            {
                "TestMemberName", "WorkItemTitle"
            };

            var sut = new AssignCommand(listParams);

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(), $"Work item with title WorkItemTitle does not exist in board {fakeCurrBoard.Name}.");
        }
Exemple #17
0
        public void visit(AssignCommand that)
        {
            // determine the type of the right-hand-side (RHS) by visiting it
            that.Expression.visit(this);

            // check that the symbol exists - by trying to look it up
            Declaration declaration = _symbols.Lookup(that.Name);

            if (declaration == null)
            {
                throw new CheckerError(that.Position, "Variable '" + that.Name + "' not declared in assignment statement");
            }

            // check that the symbol is indeed a variable
            switch (declaration.Kind)
            {
            case SymbolKind.Constant:
                throw new CheckerError(that.Position, "Cannot assign to a constant");

            case SymbolKind.Function:
                throw new CheckerError(that.Position, "Cannot assign to a function");

            case SymbolKind.Parameter:
                throw new CheckerError(that.Position, "Cannot call parameter");

            case SymbolKind.Variable:
                break;

            default:
                throw new CheckerError(that.Position, "Unknown symbol kind: " + declaration.Kind.ToString());
            }

            // check that the types of the left-hand-side is equal to the type of the right-hand-side
            TypeKind firstType = declaration.Type.Kind;
            TypeKind otherType = that.Expression.Type.Kind;

            if (firstType != otherType)
            {
                throw new CheckerError(that.Position, "Type mismatch in assignment");
            }
        }
Exemple #18
0
        public void Execute_NonExistingMember_ThrowEx()
        {
            //Arrange
            Commons.currentTeam  = new Team("TeamName");
            Commons.currentBoard = new Board("BoardName");
            Commons.currentTeam.Boards.Add(Commons.currentBoard);
            var fakeCurrTeam  = Commons.currentTeam;
            var fakeCurrBoard = Commons.currentBoard;

            var listParams = new List <string>()
            {
                "TestMemberName", "WorkItemTitle"
            };

            var workItem = new Bug("WorkItemTitle", "WorkItemDescription", Priority.High, Severity.Critical);

            fakeCurrBoard.WorkItems.Add(workItem);

            var sut = new AssignCommand(listParams);

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(), $"Member with name TestMemberName does not exist in team {fakeCurrTeam.Name}.");
        }
Exemple #19
0
        public async Task <IActionResult> Assign(AssignCommand command)
        {
            await _mediator.Send(command);

            return(Ok());
        }
Exemple #20
0
 unsafe long?IFormatter <AssignCommand> .GetLength(AssignCommand command)
 => sizeof(AssignCommand);
Exemple #21
0
 ValueTask IFormatter <AssignCommand> .SerializeAsync <TWriter>(AssignCommand command, TWriter writer, CancellationToken token)
 => writer.WriteAsync(command, token);