コード例 #1
0
ファイル: SuchThat.cs プロジェクト: PawelStp/aisti
        public MethodResultList NotImplemented()
        {
            ProcRef pr = new ProcRef("komarch");

            pr.IsGrammarCorrect();
            VarRef vr = new VarRef("_");

            vr.IsGrammarCorrect();
            MethodResultList mrl = new MethodResultList(typeof(ProcRef), typeof(VarRef));

            mrl.List1.Add(pr);
            mrl.List2.Add(vr);
            mrl.ListType1   = typeof(Ident);
            mrl.ListType2   = typeof(Placeholder);
            mrl.QueryParam1 = "komarch";
            mrl.QueryParam2 = "_";
            return(mrl);
        }
コード例 #2
0
ファイル: SuchThat.cs プロジェクト: PawelStp/aisti
        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);
        }
コード例 #3
0
ファイル: SuchThat.cs プロジェクト: PawelStp/aisti
        public MethodResultList Calls(ProcRef procRef1, ProcRef procRef2)
        {
            Type             procRef1_Type = procRef1.EntryTypeReference.GetType();
            Type             procRef2_Type = procRef2.EntryTypeReference.GetType();
            MethodResultList callsReturn   = new MethodResultList(procRef1, procRef2);

            if (procRef1_Type == typeof(Ident) || procRef1_Type == typeof(Placeholder))
            {
                if (procRef2_Type == typeof(Ident) || procRef2_Type == typeof(Placeholder))
                {
                    List <string> allProcedures = Pkb.UsedProcedures;

                    foreach (string p in allProcedures)
                    {
                        List <string> calledProcedures = Pkb.CalledByProcedure(p);

                        foreach (string cp in calledProcedures)
                        {
                            callsReturn.List1.Add(new ProcRef(p));
                            callsReturn.List2.Add(new ProcRef(cp));
                        }
                    }
                }
                else if (procRef2_Type == typeof(BracesIdent))
                {
                    string procNameWithoutBraces = procRef2.entry.Substring(1, procRef2.entry.Length - 2);

                    List <string> proceduresThatCall = Pkb.ProceduresThatCall(procNameWithoutBraces);

                    foreach (string ptc in proceduresThatCall)
                    {
                        callsReturn.List1.Add(new ProcRef(ptc));
                        callsReturn.List2.Add(new ProcRef(procNameWithoutBraces));
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid procRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {procRef2.entry}");
                }
            }
            else if (procRef1_Type == typeof(BracesIdent))
            {
                string procName1_WithoutBraces = procRef1.entry.Substring(1, procRef1.entry.Length - 2);

                if (procRef2_Type == typeof(Ident) || procRef2_Type == typeof(Placeholder))
                {
                    List <string> calledProcedures = Pkb.CalledByProcedure(procName1_WithoutBraces);

                    foreach (string cp in calledProcedures)
                    {
                        callsReturn.List1.Add(new ProcRef(procName1_WithoutBraces));
                        callsReturn.List2.Add(new ProcRef(cp));
                    }
                }
                else if (procRef2_Type == typeof(BracesIdent))
                {
                    string procName2_WithoutBraces = procRef2.entry.Substring(1, procRef2.entry.Length - 2);

                    if (Pkb.Calls(procName1_WithoutBraces, procName2_WithoutBraces))
                    {
                        callsReturn.List1.Add(new ProcRef(procName1_WithoutBraces));
                        callsReturn.List2.Add(new ProcRef(procName2_WithoutBraces));
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid procRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {procRef2.entry}");
                }
            }
            else
            {
                throw new SuchThatException($"#Invalid procRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {procRef1.entry}");
            }

            return(callsReturn);
        }
コード例 #4
0
ファイル: SuchThat.cs プロジェクト: PawelStp/aisti
        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);
        }
コード例 #5
0
ファイル: SuchThat.cs プロジェクト: PawelStp/aisti
        public MethodResultList Uses(ProcRef procRef, VarRef varRef)
        {
            Type             procRefType   = procRef.EntryTypeReference.GetType();
            Type             varRefType    = varRef.EntryTypeReference.GetType();
            MethodResultList usesReturn    = new MethodResultList(procRef, varRef);
            List <string>    allProcedures = Pkb.UsedProcedures;

            if (procRefType == typeof(Ident))
            {
                if (varRefType == typeof(Ident) || varRefType == typeof(Placeholder))
                {
                    foreach (string ptc in allProcedures)
                    {
                        List <string> variables = Pkb.UsesAllProcModVar(ptc);
                        foreach (string v in variables)
                        {
                            usesReturn.List1.Add(new ProcRef(ptc));
                            usesReturn.List2.Add(new VarRef(v));
                        }
                    }
                }
                else if (varRefType == typeof(BracesIdent))
                {
                    string varNameWithoutBraces = varRef.entry.Substring(1, varRef.entry.Length - 2);

                    List <string> procedures = Pkb.UsesAllVarModProc(varNameWithoutBraces);
                    foreach (string p in procedures)
                    {
                        usesReturn.List1.Add(new ProcRef(p));
                        usesReturn.List2.Add(new VarRef(varNameWithoutBraces));
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid VarRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {varRef.entry}");
                }
            }
            else if (procRefType == typeof(BracesIdent))
            {
                if (varRefType == typeof(Ident) || varRefType == typeof(Placeholder))
                {
                    string procNameWithoutBraces = procRef.entry.Substring(1, procRef.entry.Length - 2);

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

                    if (Pkb.UsesProcedure(procNameWithoutBraces, varNameWithoutBraces))
                    {
                        usesReturn.List1.Add(new ProcRef(procNameWithoutBraces));
                        usesReturn.List2.Add(new VarRef(varNameWithoutBraces));
                    }
                }
                else
                {
                    throw new SuchThatException($"#Invalid VarRef type: expected 'Ident', 'Placeholder' or 'BracesIdent' for {varRef.entry}");
                }
            }
            else if (procRefType == typeof(Placeholder))
            {
                throw new SuchThatException($"#Invalid ProcRef type: expected 'Ident' or 'BracesIdent' for {procRef.entry}");
            }
            else
            {
                throw new SuchThatException($"#Invalid ProcRef type: expected 'Ident' or 'BracesIdent' for {procRef.entry}");
            }

            return(usesReturn);
        }