@@ -20,7 +20,7 @@ public static void Main(string[] args)
2020 Console . Title = "CodeGenFix" ;
2121
2222 // get interop file
23- string filePath = Path . Combine ( Path . Combine ( Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) , ".." , ".." , ".." , ".." , ".." ) , "memflow.NET" , "memflow.NET" ) , "memflowInterop.cs" ) ;
23+ string filePath = Path . Combine ( Path . Combine ( Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) , ".." , ".." , ".." , ".." , ".." , ".." ) , "memflow.NET" , "memflow.NET" ) , "memflowInterop.cs" ) ;
2424 if ( args . Length == 1 )
2525 filePath = args [ 0 ] ;
2626 Console . WriteLine ( $ "Trying to parse '{ filePath } '") ;
@@ -67,10 +67,10 @@ public static void Main(string[] args)
6767 // NativeTypeName and NativeTypeNameAttribute get inserted by ClangSharp but have to be manually defined
6868 case "CS0246" :
6969 // find all usings directives
70- var Usings = parsedNodes . Where ( x => x . Kind ( ) == SyntaxKind . UsingDirective ) ;
70+ var Usings = parsedNodes . Where ( x => x . IsKind ( SyntaxKind . UsingDirective ) ) ;
7171
7272 // find namespace line
73- var NameSpace = parsedNodes . First ( x => x . Kind ( ) == SyntaxKind . NamespaceDeclaration ) ;
73+ var NameSpace = parsedNodes . First ( x => x . IsKind ( SyntaxKind . NamespaceDeclaration ) ) ;
7474 int line = NameSpace . GetLocation ( ) . GetLineSpan ( ) . StartLinePosition . Line + 2 ;
7575
7676 if ( errMsg . Contains ( "NativeTypeNameAttribute" ) || errMsg . Contains ( "NativeTypeName" ) )
@@ -106,6 +106,7 @@ public static void Main(string[] args)
106106
107107 // Invalid expression term 'character'
108108 // Clangsharp breaks some regular '=' operators and generates '.operator=' directives
109+ // Clangsharp gets thrown off on some defined fields
109110 case "CS1001" :
110111 case "CS1002" :
111112 case "CS1513" :
@@ -116,6 +117,25 @@ public static void Main(string[] args)
116117 case "CS1525" :
117118 if ( errLine . Contains ( ".operator=" ) )
118119 newSrcTextLines [ errLineNo ] = errLine . Replace ( ".operator=" , "=" ) ;
120+ else if ( errLine . Contains ( ";" ) && ( errLine . Contains ( "PhysicalAddress_INVALID" ) || errLine . Contains ( "Page_INVALID" ) ) )
121+ {
122+ if ( errLine . Contains ( "PhysicalAddress_INVALID" ) )
123+ {
124+ // insert PhysicalAddress_INVALID definition
125+ List < string > def = File . ReadAllLines ( Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) , "SourceDefinitions" , "PhysicalAddress_INVALID.cx" ) ) . ToList ( ) ;
126+ newSrcTextLines [ errLineNo ] = def [ 0 ] ;
127+ newSrcTextLines . InsertRange ( errLineNo + 1 , def [ 1 ..] ) ;
128+ goto Recompile ;
129+ }
130+ else
131+ {
132+ // insert Page_INVALID definition
133+ List < string > def = File . ReadAllLines ( Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) , "SourceDefinitions" , "Page_INVALID.cx" ) ) . ToList ( ) ;
134+ newSrcTextLines [ errLineNo ] = def [ 0 ] ;
135+ newSrcTextLines . InsertRange ( errLineNo + 1 , def [ 1 ..] ) ;
136+ goto Recompile ;
137+ }
138+ }
119139 else
120140 goto ThrowError ;
121141 break ;
@@ -194,7 +214,7 @@ public static void Main(string[] args)
194214 continue ;
195215 FixStructs :
196216 // replace lazy typed structs with explicit ones
197- var Structs = parsedNodes . Where ( x => x . Kind ( ) == SyntaxKind . StructDeclaration ) ;
217+ var Structs = parsedNodes . Where ( x => x . IsKind ( SyntaxKind . StructDeclaration ) ) ;
198218
199219 // ProcessInfo
200220 if ( Structs . Any ( x => x . ToString ( ) . Contains ( "struct ProcessInfo" ) ) )
@@ -224,36 +244,36 @@ public static void Main(string[] args)
224244 CppCompilation parsedHeader = CppParser . ParseFile ( Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) , "SourceDefinitions" , "memflow.h" ) ) ;
225245
226246 // enums
227- var Enums = parsedNodes . Where ( x => x . Kind ( ) == SyntaxKind . EnumDeclaration ) ;
247+ var Enums = parsedNodes . Where ( x => x . IsKind ( SyntaxKind . EnumDeclaration ) ) ;
228248 foreach ( CppEnum cDef in parsedHeader . Enums )
229249 {
230250 if ( cDef . TypeKind == CppTypeKind . Enum && cDef . Comment != null )
231251 {
232252 // find C# definition
233- SyntaxNode ? csDef = Enums . FirstOrDefault ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . Kind ( ) == SyntaxKind . IdentifierToken ) . Text . Equals ( cDef . Name , StringComparison . OrdinalIgnoreCase ) ) ;
253+ SyntaxNode ? csDef = Enums . FirstOrDefault ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . IsKind ( SyntaxKind . IdentifierToken ) ) . Text . Equals ( cDef . Name , StringComparison . OrdinalIgnoreCase ) ) ;
234254 InsertCppComment ( csDef , cDef . Comment , ref lineIndex , ref newSrcTextLines ) ;
235255 }
236256 }
237257
238258 // structs
239- Structs = parsedNodes . Where ( x => x . Kind ( ) == SyntaxKind . StructDeclaration ) ;
259+ Structs = parsedNodes . Where ( x => x . IsKind ( SyntaxKind . StructDeclaration ) ) ;
240260 foreach ( CppClass cDef in parsedHeader . Classes )
241261 {
242262 if ( cDef . TypeKind == CppTypeKind . StructOrClass && cDef . Comment != null )
243263 {
244264 // find C# definition
245- SyntaxNode ? csDef = Structs . FirstOrDefault ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . Kind ( ) == SyntaxKind . IdentifierToken ) . Text . Equals ( cDef . Name , StringComparison . OrdinalIgnoreCase ) ) ;
265+ SyntaxNode ? csDef = Structs . FirstOrDefault ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . IsKind ( SyntaxKind . IdentifierToken ) ) . Text . Equals ( cDef . Name , StringComparison . OrdinalIgnoreCase ) ) ;
246266 InsertCppComment ( csDef , cDef . Comment , ref lineIndex , ref newSrcTextLines ) ;
247267 }
248268 }
249269
250270 // functions
251- var Classes = parsedNodes . Where ( x => x . Kind ( ) == SyntaxKind . ClassDeclaration ) ;
252- var Functions = Classes . First ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . Kind ( ) == SyntaxKind . IdentifierToken ) . Text . Equals ( "Methods" , StringComparison . OrdinalIgnoreCase ) ) . ChildNodes ( ) ;
271+ var Classes = parsedNodes . Where ( x => x . IsKind ( SyntaxKind . ClassDeclaration ) ) ;
272+ var Functions = Classes . First ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . IsKind ( SyntaxKind . IdentifierToken ) ) . Text . Equals ( "Methods" , StringComparison . OrdinalIgnoreCase ) ) . ChildNodes ( ) ;
253273 foreach ( CppFunction cDef in parsedHeader . Functions )
254274 {
255275 // find C# field definition in Methods struct
256- SyntaxNode ? csDef = Functions . FirstOrDefault ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . Kind ( ) == SyntaxKind . IdentifierToken ) . Text . Equals ( cDef . Name , StringComparison . OrdinalIgnoreCase ) ) ;
276+ SyntaxNode ? csDef = Functions . FirstOrDefault ( x => x . ChildTokens ( ) . FirstOrDefault ( y => y . IsKind ( SyntaxKind . IdentifierToken ) ) . Text . Equals ( cDef . Name , StringComparison . OrdinalIgnoreCase ) ) ;
257277 InsertCppComment ( csDef , cDef . Comment , ref lineIndex , ref newSrcTextLines , 2 ) ;
258278 }
259279
0 commit comments