Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ nbproject/
## Build folders
build/
build_*/
Build/
Build_*/
install/
install_*/
69 changes: 69 additions & 0 deletions plugins/csharp/csharp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "db_model", "db_model", "{2E2F0E00-502D-A052-0019-82CFB9270E3D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "migrations", "migrations", "{D4C4D1C2-DE9C-AF20-17FD-0A3EB2BFD436}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "service", "service", "{226567F5-DD15-7888-5BF1-C4407778305A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "parser", "parser", "{BC34E35A-B109-A120-90EC-15530B70B9CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbModel", "db_model\DbModel.csproj", "{BADE2559-4F0F-21F6-067B-8EDF7DE9DFC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqliteMigrations", "migrations\sqliteMigrations\SqliteMigrations.csproj", "{2C9A9B86-A50E-C025-B4E0-195D2ACD4B54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PgsqlMigrations", "migrations\pgsqlMigrations\PgsqlMigrations.csproj", "{20C587AF-64DB-68B4-1F92-61681232D74B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src_csharp", "src_csharp", "{9BD6E17B-7A65-7B8B-5096-A508D0BE5AAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharpservice", "service\src_csharp\csharpservice.csproj", "{1AF03105-21A5-3508-A40F-365ADA9DFF92}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src_csharp", "src_csharp", "{37C60329-C8F7-3ACB-DE03-F714C9EE58C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpParser", "parser\src_csharp\CSharpParser.csproj", "{568E5C5A-2A3E-AEA2-1355-EC26E382DA2B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BADE2559-4F0F-21F6-067B-8EDF7DE9DFC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BADE2559-4F0F-21F6-067B-8EDF7DE9DFC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BADE2559-4F0F-21F6-067B-8EDF7DE9DFC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BADE2559-4F0F-21F6-067B-8EDF7DE9DFC1}.Release|Any CPU.Build.0 = Release|Any CPU
{2C9A9B86-A50E-C025-B4E0-195D2ACD4B54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C9A9B86-A50E-C025-B4E0-195D2ACD4B54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C9A9B86-A50E-C025-B4E0-195D2ACD4B54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C9A9B86-A50E-C025-B4E0-195D2ACD4B54}.Release|Any CPU.Build.0 = Release|Any CPU
{20C587AF-64DB-68B4-1F92-61681232D74B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20C587AF-64DB-68B4-1F92-61681232D74B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20C587AF-64DB-68B4-1F92-61681232D74B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20C587AF-64DB-68B4-1F92-61681232D74B}.Release|Any CPU.Build.0 = Release|Any CPU
{1AF03105-21A5-3508-A40F-365ADA9DFF92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AF03105-21A5-3508-A40F-365ADA9DFF92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AF03105-21A5-3508-A40F-365ADA9DFF92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AF03105-21A5-3508-A40F-365ADA9DFF92}.Release|Any CPU.Build.0 = Release|Any CPU
{568E5C5A-2A3E-AEA2-1355-EC26E382DA2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{568E5C5A-2A3E-AEA2-1355-EC26E382DA2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{568E5C5A-2A3E-AEA2-1355-EC26E382DA2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{568E5C5A-2A3E-AEA2-1355-EC26E382DA2B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BADE2559-4F0F-21F6-067B-8EDF7DE9DFC1} = {2E2F0E00-502D-A052-0019-82CFB9270E3D}
{2C9A9B86-A50E-C025-B4E0-195D2ACD4B54} = {D4C4D1C2-DE9C-AF20-17FD-0A3EB2BFD436}
{20C587AF-64DB-68B4-1F92-61681232D74B} = {D4C4D1C2-DE9C-AF20-17FD-0A3EB2BFD436}
{9BD6E17B-7A65-7B8B-5096-A508D0BE5AAA} = {226567F5-DD15-7888-5BF1-C4407778305A}
{1AF03105-21A5-3508-A40F-365ADA9DFF92} = {9BD6E17B-7A65-7B8B-5096-A508D0BE5AAA}
{37C60329-C8F7-3ACB-DE03-F714C9EE58C5} = {BC34E35A-B109-A120-90EC-15530B70B9CB}
{568E5C5A-2A3E-AEA2-1355-EC26E382DA2B} = {37C60329-C8F7-3ACB-DE03-F714C9EE58C5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17FCE6F1-24FA-4D94-8799-D869033FFB44}
EndGlobalSection
EndGlobal
3 changes: 0 additions & 3 deletions plugins/csharp/parser/src/csharpparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ bool CsharpParser::parse()

if (acceptProjectBuildPath(buildPath))
{
LOG(debug) << "C# parser parse path: " << paths[0];
LOG(debug) << "Parsed csharp project build path: " << buildPath;
success = success && parseProjectBuildPath(paths, buildPath);
}
else
Expand Down Expand Up @@ -108,7 +106,6 @@ bool CsharpParser::parseProjectBuildPath(

std::string line;
std::stringstream log_str(log.get());
//LOG(warning) << log_str.str();
int countFull = 0, countPart = 0;

while(std::getline(log_str, line, '\n'))
Expand Down
57 changes: 6 additions & 51 deletions plugins/csharp/parser/src_csharp/AstVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,18 @@ partial class AstVisitor : CSharpSyntaxWalker
private readonly CsharpDbContext DbContext;
private readonly SemanticModel Model;
private readonly SyntaxTree Tree;
private readonly AstVisitorHelper Helper;

public bool FullyParsed = true;

public AstVisitor(CsharpDbContext context, SemanticModel model, SyntaxTree tree)
{
this.DbContext = context;
this.Model = model;
this.Tree = tree;
}

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);
this.Tree = tree;
this.Helper = new AstVisitorHelper();
}

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;
}

private ulong getAstNodeId(SyntaxNode node){
CsharpAstNode astNode = new CsharpAstNode
{
AstValue = node.ToString(),
RawKind = node.Kind(),
EntityHash = node.GetHashCode(),
AstType = AstTypeEnum.Declaration
};
astNode.SetLocation(node.SyntaxTree.GetLineSpan(node.Span));
var ret = createIdentifier(astNode);
return ret;
}

private CsharpAstNode AstNode(SyntaxNode node, AstSymbolTypeEnum type, AstTypeEnum astType)
{
Accessibility acc = Accessibility.NotApplicable;
Expand All @@ -92,7 +47,7 @@ private CsharpAstNode AstNode(SyntaxNode node, AstSymbolTypeEnum type, AstTypeEn
Accessibility = acc
};
astNode.SetLocation(Tree.GetLineSpan(node.Span));
astNode.Id = createIdentifier(astNode);
astNode.Id = Helper.createIdentifier(astNode);

if (DbContext.CsharpAstNodes.Find(astNode.Id) == null)
{
Expand Down Expand Up @@ -933,7 +888,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
FullyParsed = false;
}
var info = Model.GetTypeInfo(node).ConvertedType;
var declaratorNodeId = getAstNodeId(declaration.GetSyntax());
var declaratorNodeId = Helper.getAstNodeId(declaration.GetSyntax());
var astNode = AstNode(node, AstSymbolTypeEnum.EtcEntity, AstTypeEnum.Usage);
CsharpEtcEntity invoc = new CsharpEtcEntity
{
Expand Down Expand Up @@ -981,7 +936,7 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
EtcEntityTypeEnum.ForeachExpr : EtcEntityTypeEnum.Invocation;
if (node.Parent.Parent.Kind() != SyntaxKind.InvocationExpression)
{
var declaratorNodeId = getAstNodeId(declaration.GetSyntax());
var declaratorNodeId = Helper.getAstNodeId(declaration.GetSyntax());
var astNode = AstNode(node, AstSymbolTypeEnum.EtcEntity, AstTypeEnum.Usage);
CsharpEtcEntity expr = new CsharpEtcEntity
{
Expand Down
61 changes: 61 additions & 0 deletions plugins/csharp/parser/src_csharp/AstVisitorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using CSharpParser.model;
using Microsoft.CodeAnalysis;

namespace CSharpParser
{
class AstVisitorHelper
{
public 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;
}

public ulong getAstNodeId(SyntaxNode node){
CsharpAstNode astNode = new CsharpAstNode
{
AstValue = node.ToString(),
RawKind = node.Kind(),
EntityHash = node.GetHashCode(),
AstType = AstTypeEnum.Declaration
};
astNode.SetLocation(node.SyntaxTree.GetLineSpan(node.Span));
var ret = createIdentifier(astNode);
return ret;
}
}
}
100 changes: 5 additions & 95 deletions plugins/csharp/parser/src_csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int Main(string[] args)
}*/

//Converting the connectionstring into entiy framwork style connectionstring
string csharpConnectionString = transformConnectionString();
string csharpConnectionString = ProgramHelper.transformConnectionString(_connectionString);

var options = new DbContextOptionsBuilder<CsharpDbContext>()
.UseNpgsql(csharpConnectionString)
Expand All @@ -95,17 +95,17 @@ static int Main(string[] args)
foreach (var p in _rootDir)
{
Console.WriteLine(p);
allFiles.AddRange(GetSourceFilesFromDir(p, ".cs"));
allFiles.AddRange(ProgramHelper.GetSourceFilesFromDir(p, ".cs"));
}

foreach (var f in allFiles)
{
WriteLine(f);
}
IEnumerable<string> assemblies = GetSourceFilesFromDir(_buildDir, ".dll");
IEnumerable<string> assemblies = ProgramHelper.GetSourceFilesFromDir(_buildDir, ".dll");
IEnumerable<string> assemblies_base = assemblies;
if (args.Length == 5)
assemblies_base = GetSourceFilesFromDir(_buildDirBase, ".dll");
assemblies_base = ProgramHelper.GetSourceFilesFromDir(_buildDirBase, ".dll");

List<SyntaxTree> trees = new List<SyntaxTree>();
foreach (string file in allFiles)
Expand Down Expand Up @@ -195,96 +195,6 @@ private static async Task<int> ParseTree(CsharpDbContext context,
return index;
});
return await ParsingTask;
}

public static IEnumerable<string> GetSourceFilesFromDir(string root, string extension)
{
IEnumerable<string> allFiles = new string[]{};
// Data structure to hold names of subfolders.
ArrayList dirs = new ArrayList();

if (!System.IO.Directory.Exists(root))
{
throw new ArgumentException();
}
dirs.Add(root);

while (dirs.Count > 0)
{
string currentDir = dirs[0].ToString();
dirs.RemoveAt(0);
string[] subDirs;
try
{
subDirs = System.IO.Directory.GetDirectories(currentDir);
}
catch (UnauthorizedAccessException e)
{
WriteLine(e.Message);
continue;
}
catch (System.IO.DirectoryNotFoundException e)
{
WriteLine(e.Message);
continue;
}

// Add the subdirectories for traversal.
dirs.AddRange(subDirs);

string[] files = null;
try
{
files = System.IO.Directory.GetFiles(currentDir);
}
catch (UnauthorizedAccessException e)
{
Console.WriteLine(e.Message);
continue;
}
catch (System.IO.DirectoryNotFoundException e)
{
Console.WriteLine(e.Message);
continue;
}

foreach (string file in files)
{
try
{
System.IO.FileInfo fi = new System.IO.FileInfo(file);
if (fi.Extension == extension) {
allFiles = allFiles.Append(file);
}
}
catch (System.IO.FileNotFoundException e)
{
// If file was deleted by a separate application
Console.WriteLine(e.Message);
}
}
}

return allFiles;
}

private static string transformConnectionString()
{
_connectionString = _connectionString.Substring(_connectionString.IndexOf(':')+1);
_connectionString = _connectionString.Replace("user", "username");
string [] properties = _connectionString.Split(';');
string csharpConnectionString = "";
for (int i = 0; i < properties.Length; ++i)
{
csharpConnectionString += properties[i].Substring(0,1).ToUpper()
+ properties[i].Substring(1);
if (i < properties.Length-1)
{
csharpConnectionString += ";";
}
}

return csharpConnectionString;
}
}
}
}
Loading
Loading