Skip to content

Conversation

@intjftw
Copy link
Collaborator

@intjftw intjftw commented Oct 4, 2022

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!

@intjftw intjftw requested review from bruntib and mcserep October 4, 2022 15:20
@intjftw intjftw changed the title C# plugin Support for C# static analysis Oct 4, 2022
@intjftw intjftw added Kind: Enhancement 🌟 Plugin: C# Issues related to the parsing and presentation of C# projects. labels Oct 4, 2022
Copy link
Collaborator Author

@intjftw intjftw left a 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.

Comment on lines 31 to 34
bool CsharpParser::acceptProjectBuildPath(const std::vector<std::string>& path_)
{
return path_.size() >= 2 && fs::is_directory(path_[0]) && fs::is_directory(path_[1]);
}
Copy link
Collaborator Author

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.

Comment on lines 26 to 31
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)
Copy link
Collaborator Author

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";
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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.

Comment on lines +27 to +59
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;
}
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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.

@mcserep mcserep added this to the Release Gershwin milestone Jan 8, 2023
intjftw added 2 commits March 29, 2023 14:58
…irectories and a separate build path. Also corrected the parsing command to be able to run CodeCompass_parser from anywhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kind: Enhancement 🌟 Plugin: C# Issues related to the parsing and presentation of C# projects.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants