private static bool ValidateCallsAsterisk(string param1, string param2) { ProcRef procRef1 = new ProcRef(param1); ProcRef procRef2 = new ProcRef(param2); return(procRef1.IsGrammarCorrect() && procRef2.IsGrammarCorrect()); }
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); }
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); }
/// <summary> /// Executes correct method /// </summary> /// <param name="methodName">method which should be executed</param> /// <param name="param1">first param from query</param> /// <param name="param2">second param from query</param> /// <returns></returns> /// <returns></returns> 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}"); } }