-
Notifications
You must be signed in to change notification settings - Fork 1
feat: adjust output to pipetester requirements #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c43e400
a88e218
12f3f69
8ea8843
fa3818e
f56004f
dfd3ffa
d0c8378
316ed06
9eefbf5
e52f768
1c6957e
ee132ce
83e0a82
d08c4c7
402f11e
eb817a6
4332b84
f4c80bd
a1fdca3
fa21f49
c679599
008c6eb
3b8cb6c
4bbcd5d
aa5fa9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| from ats.ast import nodes | ||
| from ats.ast.nodes import ProcedureNode | ||
| from ats.pkb.design_extractor import extract | ||
| from ats.pkb.utils import process_relation | ||
| from ats.pkb.utils import map_result, process_relation | ||
|
|
||
|
|
||
| def process_follows(query, context, relation): | ||
|
|
@@ -102,6 +100,8 @@ def resolve_node(param): | |
| if isinstance(param, int): | ||
| return context["statements"][param] | ||
| else: | ||
| if param == relation["parameters"][0]: | ||
| return context["procedures"][param[1:-1]] | ||
| return param[1:-1] | ||
|
|
||
| return process_relation( | ||
|
|
@@ -119,6 +119,8 @@ def resolve_node(param): | |
| if isinstance(param, int): | ||
| return context["statements"][param] | ||
| else: | ||
| if param == relation["parameters"][0]: | ||
| return context["procedures"][param[1:-1]] | ||
|
Comment on lines
+122
to
+123
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To tez moze byc stmt.... https://github.com/wvffle/ATS-project-simple/blob/master/ats/pql/pql.py#L25-26 |
||
| return param[1:-1] | ||
|
|
||
| return process_relation( | ||
|
|
@@ -168,9 +170,26 @@ def relation_cb(node_a, node_b): | |
| ) | ||
|
|
||
|
|
||
| def evaluate_query(node: nodes.ProgramNode, query): | ||
| context = extract(node) | ||
| def evaluate_query(query, context): | ||
| all_results = set() | ||
|
|
||
| # if ( | ||
| # len(query["conditions"]["attributes"]) > 0 | ||
| # or len(query["conditions"]["patterns"]) > 0 | ||
| # ): | ||
| # raise ValueError("Attribute and pattern conditions are not supported yet") | ||
|
|
||
| if query["searching_variable"] != "BOOLEAN": | ||
| if len(query["conditions"]["relations"]) == 0: | ||
| all_results = set( | ||
| map( | ||
| map_result, | ||
| context["statements_by_type"][ | ||
| query["variables"][query["searching_variable"]] | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| for i, relation in enumerate(query["conditions"]["relations"]): | ||
| results = all_results if i == 0 else set() | ||
| if relation["relation"] == "Follows": | ||
|
|
@@ -206,18 +225,6 @@ def evaluate_query(node: nodes.ProgramNode, query): | |
| if results != all_results: | ||
| all_results = all_results.intersection(results) | ||
|
|
||
| # assign a1; | ||
| # while w1, w2; | ||
| # Select a1 such that Parent(w1, a1) and Parent(w2, w1) with w2.stmt# = 5 | ||
| for i, condition in enumerate(query["conditions"]["attributes"]): | ||
| results = all_results if i == 0 else set() | ||
|
|
||
| if results != all_results: | ||
| all_results = all_results.intersection(results) | ||
|
|
||
| for i, condition in enumerate(query["conditions"]["patterns"]): | ||
| ... | ||
|
|
||
| if query["searching_variable"] == "BOOLEAN": | ||
| return len(all_results) > 0 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| import sys | ||
| from threading import Timer | ||
|
|
||
| from ats.ast.nodes import ProcedureNode, ProgramNode, StmtLstNode, StmtNode | ||
| from ats.parser.parser import parse | ||
| from ats.pkb.design_extractor import extract | ||
| from ats.pkb.query_evaluator import evaluate_query | ||
| from ats.pql.pql import parse_query | ||
|
|
||
| if __name__ == "__main__": | ||
| sys.stdout.reconfigure(encoding="utf-8") | ||
| sys.stdout.reconfigure(encoding="utf-8") # nie powinno być ibm852? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to zmiencie? |
||
| if "--print-test-tree" in sys.argv: | ||
| tree = parse( | ||
| """ | ||
|
|
@@ -45,17 +47,39 @@ | |
| Select BOOLEAN such that Calls(_, _) | ||
| """ | ||
| ) | ||
| context = extract(tree) | ||
| print(evaluate_query(queries[0], context)) | ||
|
|
||
| print(evaluate_query(tree, queries[0])) | ||
| elif len(sys.argv) > 0: # pragma no cover | ||
|
|
||
| def no_time_left(): | ||
| print("\nPreparationTimeout") | ||
| exit(1) | ||
|
|
||
| elif len(sys.argv) > 0: | ||
| with open(sys.argv[-1]) as f: | ||
| code = f.read() | ||
| tree = parse(code) | ||
| # TODO: Extract design patterns here! | ||
| context = extract(tree) | ||
| print("Ready") | ||
| while True: | ||
| try: | ||
| t = Timer(60, no_time_left) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kiedy to ma sprawdzac?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aż nie ma zapytań |
||
| t.start() | ||
| query = input() + "\n" + input() | ||
| t.cancel() | ||
|
|
||
| queries = parse_query(query) | ||
| result = evaluate_query(queries[0], context) | ||
|
|
||
| if isinstance(result, bool): | ||
| print("true" if result else "false") | ||
| continue | ||
|
|
||
| if len(result) == 0: | ||
| print("none") | ||
| continue | ||
|
|
||
| query = input() + "\n" + input() | ||
| print(", ".join(str(part) for part in result)) | ||
|
|
||
| # TODO: use PQL and PKB | ||
| print("8") | ||
| except Exception as e: | ||
| print("# " + e.args[0].replace("\n", " ")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| procedure test { | ||
| a = b; | ||
| while a { | ||
| a = c + d + g; | ||
| if e then { | ||
| b = a + e; | ||
| } | ||
| else { | ||
| c = f + c; | ||
| } | ||
| } | ||
| b = 10; | ||
| while a { | ||
| c = a + b; | ||
| f = c; | ||
| } | ||
| } | ||
| procedure test2 { | ||
| a = b + c; | ||
| while d { | ||
| if e then { | ||
| call test; | ||
| } | ||
| else { | ||
| a = f; | ||
| } | ||
| } | ||
| i = j; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ale wiecie ze to moze byc rowniez stmt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/wvffle/ATS-project-simple/blob/master/ats/pql/pql.py#L27-L28