@@ -14,63 +14,18 @@ partial class AstVisitor : CSharpSyntaxWalker
1414 private readonly CsharpDbContext DbContext ;
1515 private readonly SemanticModel Model ;
1616 private readonly SyntaxTree Tree ;
17+ private readonly AstVisitorHelper Helper ;
1718
1819 public bool FullyParsed = true ;
1920
2021 public AstVisitor ( CsharpDbContext context , SemanticModel model , SyntaxTree tree )
2122 {
2223 this . DbContext = context ;
2324 this . Model = model ;
24- this . Tree = tree ;
25- }
26-
27- private ulong createIdentifier ( CsharpAstNode astNode ) {
28- string [ ] properties =
29- {
30- astNode . AstValue , ":" ,
31- astNode . AstType . ToString ( ) , ":" ,
32- astNode . EntityHash . ToString ( ) , ":" ,
33- astNode . RawKind . ToString ( ) , ":" ,
34- astNode . Path , ":" ,
35- astNode . Location_range_start_line . ToString ( ) , ":" ,
36- astNode . Location_range_start_column . ToString ( ) , ":" ,
37- astNode . Location_range_end_line . ToString ( ) , ":" ,
38- astNode . Location_range_end_column . ToString ( )
39- } ;
40-
41- string res = string . Concat ( properties ) ;
42-
43- //WriteLine(res);
44- return fnvHash ( res ) ;
25+ this . Tree = tree ;
26+ this . Helper = new AstVisitorHelper ( ) ;
4527 }
4628
47- private ulong fnvHash ( string data_ )
48- {
49- ulong hash = 14695981039346656037 ;
50-
51- int len = data_ . Length ;
52- for ( int i = 0 ; i < len ; ++ i )
53- {
54- hash ^= data_ [ i ] ;
55- hash *= 1099511628211 ;
56- }
57-
58- return hash ;
59- }
60-
61- private ulong getAstNodeId ( SyntaxNode node ) {
62- CsharpAstNode astNode = new CsharpAstNode
63- {
64- AstValue = node . ToString ( ) ,
65- RawKind = node . Kind ( ) ,
66- EntityHash = node . GetHashCode ( ) ,
67- AstType = AstTypeEnum . Declaration
68- } ;
69- astNode . SetLocation ( node . SyntaxTree . GetLineSpan ( node . Span ) ) ;
70- var ret = createIdentifier ( astNode ) ;
71- return ret ;
72- }
73-
7429 private CsharpAstNode AstNode ( SyntaxNode node , AstSymbolTypeEnum type , AstTypeEnum astType )
7530 {
7631 Accessibility acc = Accessibility . NotApplicable ;
@@ -92,7 +47,7 @@ private CsharpAstNode AstNode(SyntaxNode node, AstSymbolTypeEnum type, AstTypeEn
9247 Accessibility = acc
9348 } ;
9449 astNode . SetLocation ( Tree . GetLineSpan ( node . Span ) ) ;
95- astNode . Id = createIdentifier ( astNode ) ;
50+ astNode . Id = Helper . createIdentifier ( astNode ) ;
9651
9752 if ( DbContext . CsharpAstNodes . Find ( astNode . Id ) == null )
9853 {
@@ -933,7 +888,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
933888 FullyParsed = false ;
934889 }
935890 var info = Model . GetTypeInfo ( node ) . ConvertedType ;
936- var declaratorNodeId = getAstNodeId ( declaration . GetSyntax ( ) ) ;
891+ var declaratorNodeId = Helper . getAstNodeId ( declaration . GetSyntax ( ) ) ;
937892 var astNode = AstNode ( node , AstSymbolTypeEnum . EtcEntity , AstTypeEnum . Usage ) ;
938893 CsharpEtcEntity invoc = new CsharpEtcEntity
939894 {
@@ -981,7 +936,7 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
981936 EtcEntityTypeEnum . ForeachExpr : EtcEntityTypeEnum . Invocation ;
982937 if ( node . Parent . Parent . Kind ( ) != SyntaxKind . InvocationExpression )
983938 {
984- var declaratorNodeId = getAstNodeId ( declaration . GetSyntax ( ) ) ;
939+ var declaratorNodeId = Helper . getAstNodeId ( declaration . GetSyntax ( ) ) ;
985940 var astNode = AstNode ( node , AstSymbolTypeEnum . EtcEntity , AstTypeEnum . Usage ) ;
986941 CsharpEtcEntity expr = new CsharpEtcEntity
987942 {
@@ -1004,4 +959,54 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
1004959
1005960 }
1006961 }
962+
963+ class AstVisitorHelper
964+ {
965+ public ulong createIdentifier ( CsharpAstNode astNode ) {
966+ string [ ] properties =
967+ {
968+ astNode . AstValue , ":" ,
969+ astNode . AstType . ToString ( ) , ":" ,
970+ astNode . EntityHash . ToString ( ) , ":" ,
971+ astNode . RawKind . ToString ( ) , ":" ,
972+ astNode . Path , ":" ,
973+ astNode . Location_range_start_line . ToString ( ) , ":" ,
974+ astNode . Location_range_start_column . ToString ( ) , ":" ,
975+ astNode . Location_range_end_line . ToString ( ) , ":" ,
976+ astNode . Location_range_end_column . ToString ( )
977+ } ;
978+
979+ string res = string . Concat ( properties ) ;
980+
981+ //WriteLine(res);
982+ return fnvHash ( res ) ;
983+ }
984+
985+ private ulong fnvHash ( string data_ )
986+ {
987+ ulong hash = 14695981039346656037 ;
988+
989+ int len = data_ . Length ;
990+ for ( int i = 0 ; i < len ; ++ i )
991+ {
992+ hash ^= data_ [ i ] ;
993+ hash *= 1099511628211 ;
994+ }
995+
996+ return hash ;
997+ }
998+
999+ public ulong getAstNodeId ( SyntaxNode node ) {
1000+ CsharpAstNode astNode = new CsharpAstNode
1001+ {
1002+ AstValue = node . ToString ( ) ,
1003+ RawKind = node . Kind ( ) ,
1004+ EntityHash = node . GetHashCode ( ) ,
1005+ AstType = AstTypeEnum . Declaration
1006+ } ;
1007+ astNode . SetLocation ( node . SyntaxTree . GetLineSpan ( node . Span ) ) ;
1008+ var ret = createIdentifier ( astNode ) ;
1009+ return ret ;
1010+ }
1011+ }
10071012}
0 commit comments