コード例 #1
0
        private static bool ValidateAffectsAsterisk(string param1, string param2)
        {
            StmtRef stmtRef1 = new StmtRef(param1);
            StmtRef stmtRef2 = new StmtRef(param2);

            return(stmtRef1.IsGrammarCorrect() && stmtRef2.IsGrammarCorrect());
        }
コード例 #2
0
        private static bool ValidateUses(string param1, string param2)
        {
            VarRef varRef = new VarRef(param2);

            if (varRef.IsGrammarCorrect())
            {
                ProcRef procRef = new ProcRef(param1);
                StmtRef stmtRef = new StmtRef(param1);

                return(procRef.IsGrammarCorrect() || stmtRef.IsGrammarCorrect());
            }
            return(false);
        }
コード例 #3
0
ファイル: SuchThat.cs プロジェクト: PawelStp/AITSIIII
        private bool IsTypeCorrect(StmtRef stmtRef)
        {
            Type stmtRefType = stmtRef.EntryTypeReference.GetType();

            if (stmtRefType == typeof(Ident))
            {
                Type type = Declarations.GetDeclarationByName(stmtRef.entry).GetType();
                if (type == typeof(Statement))
                {
                    stmtRef.Type = new Statement("");
                }
                else if (type == typeof(If))
                {
                    stmtRef.Type = new If("");
                }
                else if (type == typeof(While))
                {
                    stmtRef.Type = new While("");
                }
                else if (type == typeof(Assign))
                {
                    stmtRef.Type = new Assign("");
                }
                else if (type == typeof(Call))
                {
                    stmtRef.Type = new Call("");
                }
                else
                {
                    return(false);
                }

                return(true);
            }

            else if (stmtRefType == typeof(IntegerRule))
            {
                return(true);
            }

            else if (stmtRefType == typeof(Placeholder))
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
ファイル: SuchThat.cs プロジェクト: PawelStp/AITSIIII
        public MethodResultList FollowsAsterisk(StmtRef stmtRef1, StmtRef stmtRef2)
        {
            Type             stmtRef1_Type = stmtRef1.EntryTypeReference.GetType();
            Type             stmtRef2_Type = stmtRef2.EntryTypeReference.GetType();
            MethodResultList followsReturn = new MethodResultList(stmtRef1, stmtRef2);

            if (stmtRef1_Type == typeof(Ident) || stmtRef1_Type == typeof(Placeholder))
            {
                NodeType statementNode1_Type = NodeType.Statement;
                if (stmtRef1_Type == typeof(Ident))
                {
                    statementNode1_Type = ConvertStatementToPkbType(stmtRef1.Type);
                }

                if (stmtRef2_Type == typeof(Ident) || stmtRef2_Type == typeof(Placeholder))
                {
                    NodeType statement2_NodeType = NodeType.Statement;
                    if (stmtRef2_Type == typeof(Ident))
                    {
                        statement2_NodeType = ConvertStatementToPkbType(stmtRef2.Type);
                    }

                    List <UsedStatementElement> usedStatements1 = GetAllStatements(statementNode1_Type);
                    List <UsedStatementElement> usedStatements2 = GetAllStatements(statement2_NodeType);

                    foreach (UsedStatementElement use1 in usedStatements1)
                    {
                        foreach (UsedStatementElement use2 in usedStatements2)
                        {
                            if (Pkb.FollowsStar(use1.statementNumber, use2.statementNumber))
                            {
                                followsReturn.List1.Add(new StmtRef("" + use1.statementNumber));
                                followsReturn.List2.Add(new StmtRef("" + use2.statementNumber));
                            }
                        }
                    }
                }
                else if (stmtRef2_Type == typeof(IntegerRule))
                {
                    List <UsedStatementElement> usedStatements1 = GetAllStatements(statementNode1_Type);

                    foreach (UsedStatementElement use1 in usedStatements1)
                    {
                        if (Pkb.FollowsStar(use1.statementNumber, int.Parse(stmtRef2.entry)))
                        {
                            followsReturn.List1.Add(new StmtRef("" + use1.statementNumber));
                            followsReturn.List2.Add(new StmtRef(stmtRef2.entry));
                        }
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid StmtRef type: expected 'Ident', 'Placeholder' or 'Integer' for {stmtRef2.entry}");
                }
            }
            else if (stmtRef1_Type == typeof(IntegerRule))
            {
                if (stmtRef2_Type == typeof(Ident) || stmtRef2_Type == typeof(Placeholder))
                {
                    NodeType statement2_NodeType = NodeType.Statement;
                    if (stmtRef2_Type == typeof(Ident))
                    {
                        statement2_NodeType = ConvertStatementToPkbType(stmtRef2.Type);
                    }

                    List <UsedStatementElement> usedStatements2 = GetAllStatements(statement2_NodeType);

                    foreach (UsedStatementElement use2 in usedStatements2)
                    {
                        if (Pkb.FollowsStar(int.Parse(stmtRef1.entry), use2.statementNumber))
                        {
                            followsReturn.List1.Add(new StmtRef(stmtRef1.entry));
                            followsReturn.List2.Add(new StmtRef("" + use2.statementNumber));
                        }
                    }
                }
                else if (stmtRef2_Type == typeof(IntegerRule))
                {
                    if (Pkb.FollowsStar(int.Parse(stmtRef1.entry), int.Parse(stmtRef2.entry)))
                    {
                        followsReturn.List1.Add(new StmtRef(stmtRef1.entry));
                        followsReturn.List2.Add(new StmtRef(stmtRef2.entry));
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid StmtRef type: expected 'Ident', 'Placeholder' or 'Integer' for {stmtRef2.entry}");
                }
            }
            else
            {
                throw new SuchThatException($"#Invalid StmtRef type: expected 'Ident', 'Placeholder' or 'Integer' for {stmtRef1.entry}");
            }

            return(followsReturn);
        }
コード例 #5
0
ファイル: SuchThat.cs プロジェクト: PawelStp/AITSIIII
        public MethodResultList Uses(StmtRef stmtRef, VarRef varRef)
        {
            Type             stmtRefType = stmtRef.EntryTypeReference.GetType();
            Type             varRefType  = varRef.EntryTypeReference.GetType();
            MethodResultList usesReturn  = new MethodResultList(stmtRef, varRef);

            if (stmtRefType == typeof(Ident))
            {
                NodeType statementNodeType = ConvertStatementToPkbType(stmtRef.Type);

                if (varRefType == typeof(Ident) || varRefType == typeof(Placeholder))
                {
                    List <string> allVariables = Pkb.UsedVariables;

                    foreach (string v in allVariables)
                    {
                        List <int> statementNumbers = Pkb.UsesStmtThatModVar(v, statementNodeType);

                        foreach (int sn in statementNumbers)
                        {
                            usesReturn.List1.Add(new StmtRef("" + sn));
                            usesReturn.List2.Add(new VarRef(v));
                        }
                    }
                }
                else if (varRefType == typeof(BracesIdent))
                {
                    string     varNameWithoutBraces = varRef.entry.Substring(1, varRef.entry.Length - 2);
                    List <int> statementNumbers     = Pkb.UsesStmtThatModVar(varNameWithoutBraces, statementNodeType);

                    foreach (int sn in statementNumbers)
                    {
                        usesReturn.List1.Add(new StmtRef("" + sn));
                        usesReturn.List2.Add(new VarRef(varNameWithoutBraces));
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid VarRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {varRef.entry}");
                }
            }
            else if (stmtRefType == typeof(IntegerRule))
            {
                if (varRefType == typeof(Ident) || varRefType == typeof(Placeholder))
                {
                    List <string> variables = Pkb.UsesVarModInStmt(int.Parse(stmtRef.entry));

                    foreach (string v in variables)
                    {
                        usesReturn.List1.Add(new StmtRef(stmtRef.entry));
                        usesReturn.List2.Add(new VarRef(v));
                    }
                }
                else if (varRefType == typeof(BracesIdent))
                {
                    List <string> variables            = Pkb.UsesVarModInStmt(int.Parse(stmtRef.entry));
                    string        varNameWithoutBraces = varRef.entry.Substring(1, varRef.entry.Length - 2);

                    foreach (string v in variables)
                    {
                        if (varNameWithoutBraces == v)
                        {
                            usesReturn.List1.Add(new StmtRef(stmtRef.entry));
                            usesReturn.List2.Add(new VarRef(v));
                        }
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid VarRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {varRef.entry}");
                }
            }
            else if (stmtRefType == typeof(Placeholder))
            {
                throw new SuchThatException($"#Invalid StmtRef type: expected 'Ident' or 'Integer' for {stmtRef.entry}");
            }
            else
            {
                throw new SuchThatException($"#Invalid StmtRef type: expected 'Ident' or 'BracesIdent' for {stmtRef.entry}");
            }

            return(usesReturn);
        }
コード例 #6
0
ファイル: SuchThat.cs プロジェクト: PawelStp/AITSIIII
        public MethodResultList DoSuchThatMethod(string methodName, string param1, string param2)
        {
            switch (methodName)
            {
            case "MODIFIES":
            {
                //helper objects needed to check the type, param1 can be either PROCEDURE or STATEMENT
                VarRef varRef = new VarRef(param2);
                varRef.IsGrammarCorrect();
                ProcRef procRef = new ProcRef(param1);
                procRef.IsGrammarCorrect();
                StmtRef stmtRef = new StmtRef(param1);
                stmtRef.IsGrammarCorrect();

                //present on DeclarationsArray and has required type
                if (!IsTypeCorrect(varRef))
                {
                    throw new SuchThatException($"#{varRef.entry} isn't declared as VARIABLE type");
                }

                if (IsTypeCorrect(procRef))
                {
                    return(Modifies(procRef, varRef));
                }
                else
                if (IsTypeCorrect(stmtRef))
                {
                    return(Modifies(stmtRef, varRef));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first param is neither 'PROCEDURE' or 'STATEMENT'");
                }
            }

            case "USES":
            {
                //helper objects needed to check the type, param1 can be either PROCEDURE or STATEMENT
                VarRef varRef = new VarRef(param2);
                varRef.IsGrammarCorrect();
                ProcRef procRef = new ProcRef(param1);
                procRef.IsGrammarCorrect();
                StmtRef stmtRef = new StmtRef(param1);
                stmtRef.IsGrammarCorrect();

                //present on DeclarationsArray and has required type
                if (!IsTypeCorrect(varRef))
                {
                    throw new SuchThatException($"#{varRef.entry} isn't declared as VARIABLE type");
                }

                bool stmtFlag = IsTypeCorrect(stmtRef);
                bool procFlag = IsTypeCorrect(procRef);

                if (procFlag)
                {
                    return(Uses(procRef, varRef));
                }
                else
                if (stmtFlag)
                {
                    return(Uses(stmtRef, varRef));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first param is neither 'PROCEDURE' or 'STATEMENT'");
                }
            }

            case "CALLS":
            {
                ProcRef procRef1 = new ProcRef(param1);
                procRef1.IsGrammarCorrect();
                ProcRef procRef2 = new ProcRef(param2);
                procRef2.IsGrammarCorrect();

                if (IsTypeCorrect(procRef1) && IsTypeCorrect(procRef2))
                {
                    return(Calls(procRef1, procRef2));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first or second param isn't 'PROCEDURE'");
                }
            }

            //case "CALLS*":
            //    {
            //        ProcRef procRef1 = new ProcRef(param1);
            //        procRef1.IsGrammarCorrect();
            //        ProcRef procRef2 = new ProcRef(param2);
            //        procRef2.IsGrammarCorrect();

            //        if (IsTypeCorrect(procRef1) && IsTypeCorrect(procRef2))
            //            return CallsAsterisk(procRef1, procRef2);
            //        else
            //            throw new SuchThatException($"#{methodName} first or second param isn't 'PROCEDURE'");
            //    }

            case "PARENT":
            {
                StmtRef stmtRef1 = new StmtRef(param1);
                stmtRef1.IsGrammarCorrect();
                StmtRef stmtRef2 = new StmtRef(param2);
                stmtRef2.IsGrammarCorrect();

                if (IsTypeCorrect(stmtRef1) && IsTypeCorrect(stmtRef2))
                {
                    return(Parent(stmtRef1, stmtRef2));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first or second param isn't 'STATEMENT'");
                }
            }

            case "PARENT*":
            {
                StmtRef stmtRef1 = new StmtRef(param1);
                stmtRef1.IsGrammarCorrect();
                StmtRef stmtRef2 = new StmtRef(param2);
                stmtRef2.IsGrammarCorrect();

                if (IsTypeCorrect(stmtRef1) && IsTypeCorrect(stmtRef2))
                {
                    return(ParentAsterisk(stmtRef1, stmtRef2));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first or second param isn't 'STATEMENT'");
                }
            }

            case "FOLLOWS":
            {
                StmtRef stmtRef1 = new StmtRef(param1);
                stmtRef1.IsGrammarCorrect();
                StmtRef stmtRef2 = new StmtRef(param2);
                stmtRef2.IsGrammarCorrect();

                if (IsTypeCorrect(stmtRef1) && IsTypeCorrect(stmtRef2))
                {
                    return(Follows(stmtRef1, stmtRef2));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first or second param isn't 'STATEMENT'");
                }
            }

            case "FOLLOWS*":
            {
                StmtRef stmtRef1 = new StmtRef(param1);
                stmtRef1.IsGrammarCorrect();
                StmtRef stmtRef2 = new StmtRef(param2);
                stmtRef2.IsGrammarCorrect();

                if (IsTypeCorrect(stmtRef1) && IsTypeCorrect(stmtRef2))
                {
                    return(FollowsAsterisk(stmtRef1, stmtRef2));
                }
                else
                {
                    throw new SuchThatException($"#{methodName} first or second param isn't 'STATEMENT'");
                }
            }

            case "NEXT":
                return(NotImplemented());

            case "NEXT*":
                return(NotImplemented());

            case "AFFECTS":
                return(NotImplemented());

            case "AFFECTS*":
                return(NotImplemented());

            default:
                throw new NotImplementedException($"#Invalid methodName for Such That. Got: {methodName}");
            }
        }
コード例 #7
0
ファイル: SuchThat.cs プロジェクト: PawelStp/AITSIIII
        //void Next*(LineRef lineRef1, LineRef lineRef2);

        public void Affects(StmtRef stmtRef1, StmtRef stmtRef2)
        {
        }