-
Notifications
You must be signed in to change notification settings - Fork 108
Support for C# static analysis #584
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?
Conversation
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.
The plugin generally works fine, however, there is much space for improvement. We should run some tests on larger projects to find critical errors.
| bool CsharpParser::acceptProjectBuildPath(const std::vector<std::string>& path_) | ||
| { | ||
| return path_.size() >= 2 && fs::is_directory(path_[0]) && fs::is_directory(path_[1]); | ||
| } |
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.
The parser requires the source code root directory and the build directory to work properly. Right now the solution is to have a fix order of input parameters (the source root first and the build directory second). This is a very inflexible solution, especially if we want to use multiple language plugins at the same time.
| add_custom_target(dotnetaddref2 | ||
| COMMAND dotnet add reference ${CMAKE_SOURCE_DIR}/lib/csharp/thrift_netstd/Thrift/Thrift.csproj | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen-netstd/" | ||
| ) | ||
|
|
||
| add_dependencies(dotnetaddref2 dotnetaddref dotnetaddclasslib dotnetbuildservice) |
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.
Maybe this reference can be written in csproj file permanently.
| std::string& return_, | ||
| const core::AstNodeId& astNodeId_) | ||
| { | ||
| LOG(info) << "getSourceText"; |
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.
All unnecessary debug comments should be deleted.
| namespace bp = boost::process; | ||
| namespace pt = boost::property_tree; | ||
|
|
||
| int CsharpServiceHandler::_thriftServerPort = 9091; |
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.
Let us make sure that the port is free and if it's not, search for a free one.
| private ulong createIdentifier(CsharpAstNode astNode){ | ||
| string[] properties = | ||
| { | ||
| astNode.AstValue,":", | ||
| astNode.AstType.ToString(),":", | ||
| astNode.EntityHash.ToString(),":", | ||
| astNode.RawKind.ToString(),":", | ||
| astNode.Path,":", | ||
| astNode.Location_range_start_line.ToString(),":", | ||
| astNode.Location_range_start_column.ToString(),":", | ||
| astNode.Location_range_end_line.ToString(),":", | ||
| astNode.Location_range_end_column.ToString() | ||
| }; | ||
|
|
||
| string res = string.Concat(properties); | ||
|
|
||
| //WriteLine(res); | ||
| return fnvHash(res); | ||
| } | ||
|
|
||
| private ulong fnvHash(string data_) | ||
| { | ||
| ulong hash = 14695981039346656037; | ||
|
|
||
| int len = data_.Length; | ||
| for (int i = 0; i < len; ++i) | ||
| { | ||
| hash ^= data_[i]; | ||
| hash *= 1099511628211; | ||
| } | ||
|
|
||
| return hash; | ||
| } |
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.
Helper functions like these might be placed in a separate file / class.
| { | ||
| private static readonly ILogger Logger = LoggingHelper.CreateLogger<CSharpQueryServer>(); | ||
| private static readonly TConfiguration Configuration = new TConfiguration(); | ||
| private static int port = 9091; |
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.
Although I rewrote this part to not clash with the cpp service, and to work with multiple parsed C# projects, port numbering should really be given some thought. The plugin should look for the next free port if the current one is taken.
lib/csharp/thrift_netstd/Benchmarks/Thrift.Benchmarks/CompactProtocolBenchmarks.cs
Outdated
Show resolved
Hide resolved
…irectories and a separate build path. Also corrected the parsing command to be able to run CodeCompass_parser from anywhere.
# Conflicts: # .github/workflows/ci.yml # .gitignore # docker/runtime/Dockerfile # docker/web/Dockerfile
…SP.NET SDK instead of obsolete NuGet addition.
…Make build system.
…ixes in the build system of the C# plugin.
The official support for C# static analysis. Uses the Roslyn Semantic API to parse source code.
This plugin has been made by @Borisz42 as his TDK thesis. Thanks Dávid for your work!