-
Notifications
You must be signed in to change notification settings - Fork 362
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
SymbolTable support #1401
Comments
Hello @guwirth, I started to look into this user story by comparing of sonar-java and sonar-cxx. The sonar-java's implementation of sonar-cxx relies on SSLR only, not only for checks but also e.g. for highlighting. SSLR produces a tree of E.g. symbols in java's * Traversing of our As far as I know sonar-cxx is designed to be used with external analyzers, rather than implement own rules (#1410). But I really don't known how we could implement a good highlighting or correct symbol table without AST. There is an open source implementation of C/C++ AST made by EclipseCDT. There are examples how to use it in stand-alone projects. So maybe we should use them as a first step? |
Hallo @guwirth, @ivangalkin, I was also looking into this improvement and used the implementation from the python plugin as template. By the way, introducing another AST model will be a breaking change if the current will be replaced because the current supports C++/CLI and CUDA kernel declaration. I did not plan to share the sources in this state but the last comment forced me to do it now. The last 2 commits has the partial implementation of a SymbolTable. // @Test
public void global_variable_reference() {
CxxSymbol a = lookup(rootTree, "global1");
assertThat(a.writeUsages()).extracting(AstNode::getTokenLine).contains(15, 87);
}
// @Test
public void class_variable() {
AstNode classMotorController = rootTree.getFirstDescendant(CxxGrammarImpl.classSpecifier);
assertThat(symbolTable.symbols(classMotorController)).hasSize(12);
CxxSymbol classVariableA = lookup(classMotorController, "speed");
assertThat(classVariableA.writeUsages()).extracting(AstNode::getTokenLine).containsOnly(19,27,50,66);
assertThat(classVariableA.readUsages()).extracting(AstNode::getTokenLine).containsOnly(90,66,55);
} |
Hello @Bertk, thank you for the information. Regarding the EclipseCDT: I searched for the CUDA / C++CLI support and at least according to the screenshots they are properly highlighted. By the way, which kind of support does sonar-cxx provide? I took a brief look at your commit Bertk@78643d3 . All I can say is that it is very complex and the main reason IMHO is a lack of proper parsing/AST: In order to implement a single (and pretty basic functionality) you had to re-invent a big part of lexical/semantic analysis ( |
Hello All, I was very interested in this feature and was able to implement the functionality with Eclipse CDT. Please take a look at #1479. The pull request contains implementation details and the first evaluation. Please review. Thank you |
As an user I like to get symbol highlighting support within a file. Double clicking a symbol all corresponding symbols should also be highlighted.
Sample could be: https://github.com/SonarSource/sonar-java/blob/d35941d6b78031c22a63b875226a4f0ea49cd967/java-frontend/src/main/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitor.java
The text was updated successfully, but these errors were encountered: