Replies: 3 comments 2 replies
-
This seems weird since in theory the visitor does not touch the AST. Which language are you targeting ?Envoyé de mon iPhoneLe 18 oct. 2022 à 08:44, Julien ***@***.***> a écrit :
I have a program that does multiple analyses on the same AST, one analysis per thread. The analysis is done with a Visitor. For now, each thread parses the program input, transforms it as an AST, and runs its visitor. However, this is very time-consuming to parse the same program multiple times.
I tried to parse the program once and have the threads to use the visitors, but it does not seem multiple visitors can share the same tree (especially concurrently).
One alternative would be to parse the program, build the AST and make a copy of the AST that is later analyzed.
Any recommendations on how to proceed?
Is there any way to safely process the same AST by different threads?
Is there a way to make a copy (e.g. deep copy) of an AST?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Can you share your visitor's code ? It could be touching the parse tree without knowing... |
Beta Was this translation helpful? Give feedback.
1 reply
-
Actually you are not targeting Python but Java i.e. your parser parses Python code but runs in Java…I suspect you’re changing the parse tree in the piece of code that you cannot share…Envoyé de mon iPhoneLe 19 oct. 2022 à 01:11, Julien ***@***.***> a écrit :
Unfortunately, I cannot share everything.
The visitor executes rules for each node.
So we have functions in the visitor that analyze each node like the code below. The transformStmtToTryStatement converts the Antlr AST into our own representation.
@OverRide
public List<Violation> visitTry_stmt(PythonParser.Try_stmtContext ctx) {
Optional<TryStatement> tryStatementOptional = transformStmtToTryStatement(ctx, root);
tryStatementOptional.ifPresent(this::executeRule);
return visitChildren(ctx);
}
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a program that does multiple analyses on the same AST, one analysis per thread. The analysis is done with a Visitor. For now, each thread parses the program input, transforms it as an AST, and runs its visitor. However, this is very time-consuming to parse the same program multiple times.
I tried to parse the program once and have the threads to use the visitors, but it does not seem multiple visitors can share the same tree (especially concurrently).
One alternative would be to parse the program, build the AST and make a copy of the AST that is later analyzed.
Any recommendations on how to proceed?
Beta Was this translation helpful? Give feedback.
All reactions