Mark Sibly před 9 roky
rodič
revize
f3c3941561

+ 45 - 24
src/c2mx2/c2mx2.monkey2

@@ -22,6 +22,7 @@ Only tested on Windows.
 
 Using libc..
 Using std..
+
 Using libclang..
 
 Global tab:String
@@ -284,6 +285,7 @@ Function SetFile( file:String )
 	If file=CurrentFile Return
 	CurrentFile=file
 	buf.Push( "~n'***** File: "+CurrentFile+" *****~n" )
+	Print "Processing:"+file
 End
 
 Function VisitMembers:CXChildVisitResult( cursor:CXCursor,parent:CXCursor,client_data:CXClientData )
@@ -442,35 +444,53 @@ End
 
 Function Main()
 
-	ChangeDir( AppDir() )
+	Local path:=RequestFile( "Select c2mx2.json file...","Json files:json" )
+	If Not path 
+		Print "No path selected"
+		Return
+	Endif
 	
-	While GetFileType( "bin" )<>FileType.Directory Or GetFileType( "modules" )<>FileType.Directory
-
-		If IsRootDir( CurrentDir() )
-			Print "Error initializing c2mx2 - can't find working dir!"
-			libc.exit_( 1 )
-		Endif
-		
-		ChangeDir( ExtractDir( CurrentDir() ) )
-	Wend
+	Local config:=JsonObject.Load( path )
+	If Not config
+		Notify( "c2mx2","Failed to load JSON object from "+path,True )
+		Return
+	Endif
 
-	Local config:=JsonObject.Load( "src/c2mx2/chipmunk_c2mx2.json" )
+	If Not config.Contains( "inputFile" )
+		Notify( "c2mx2","No inputFile specified",True )
+		Return
+	Endif
+	
+	If Not config.Contains( "outputFile" )
+		Notify( "c2mx2","No outputFile specified",True )
+		Return
+	Endif
 
+	If Not config.Contains( "clangArgs" )
+		Notify( "c2mx2","No clangArgs specified",True )
+		Return
+	Endif
+	
 	'change to working dir
+	ChangeDir( ExtractDir( path ) )
+	
 	If config.Contains( "workingDir" ) 
 		ChangeDir( config.GetString( "workingDir" ) )
 	Endif
 	
+	'input file
+	Local input:=config.GetString( "inputFile" )
+	
+	'outfile file
+	Local output:=config.GetString( "outputFile" )
+
 	'clang args
 	Local cargs:=config.GetArray( "clangArgs" )
-	Local args:=New const_char_t Ptr[ cargs.Length]
+	Local args:=New const_char_t Ptr[cargs.Length]
 	For Local i:=0 Until args.Length
 		args[i]=ToCString( cargs[i].ToString() )
 	Next
 
-	'input file
-	Local file:=config.GetString( "inputFile" )
-
 	'include/exclude files
 	If config.Contains( "includeFiles" )
 		IncludeFiles=New StringMap<Bool>
@@ -492,14 +512,16 @@ Function Main()
 	'start clang	
 	Local index:=clang_createIndex( 1,1 )
 	
-	Local tu:=clang_createTranslationUnitFromSourceFile( index,file,2,args.Data,0,Null )
+	Local tu:=clang_createTranslationUnitFromSourceFile( index,input,args.Length,args.Data,0,Null )
 	Assert( tu,"Failed to create translation unit from source file" )
 	
 	'emit header
-	Local header:=config.GetArray( "header" )
-	For Local line:=Eachin header
-		buf.Push( line.ToString() )
-	Next
+	If config.Contains( "header" )
+		Local header:=config.GetArray( "header" )
+		For Local line:=Eachin header
+			buf.Push( line.ToString() )
+		Next
+	Endif
 	
 	'Let's GO!
 	InitKeywords()
@@ -526,11 +548,10 @@ Function Main()
 	Endif
 
 	'emit output	
-	Local output:=config.GetString( "outputFile" )
-	If output
-		SaveString( buf.Join( "~n" ),output )
+	If SaveString( buf.Join( "~n" ),output )
+		Notify( "c2mx2","Finished generating '"+output+"'!" )
 	Else
-		Print buf.Join( "~n" )
+		Notify( "c2mx2","Failed to generat output file",true )
 	Endif
 
 End

+ 0 - 23
src/c2mx2/chipmunk_c2mx2.json

@@ -1,23 +0,0 @@
-{
-	"workingDir":"modules/chipmunk",
-	
-	"inputFile":"Chipmunk7/include/chipmunk/chipmunk.h",
-	
-	"outputFile":"chipmunk_extern.monkey2",
-	
-	"excludeFiles":[
-	],
-
-	"clangArgs":[
-		"-Xclang",
-		"-IChipmunk7/include"
-	],
-	
-	"header":[
-		"Namespace chipmunk",
-		"#Import \"<libc>\"",
-		"#Import \"Chipmunk7/include/*.h\"",
-		"#Import \"<chipmunk/chipmunk.h>\"",
-		"Extern"
-	]
-}

+ 6 - 2
src/c2mx2/libclang_c2mx2.json

@@ -1,6 +1,4 @@
 {
-	"workingDir":"src/c2mx2",
-	
 	"inputFile":"LLVM/include/clang-c/Index.h",
 	
 	"outputFile":"libclang_extern_new.monkey2",
@@ -13,12 +11,18 @@
 	"anonEnumType":"Int",
 	
 	"header":[
+		"",
+		"'***** Auto generated by c2mx2! *****",
+		"",
 		"Namespace libclang",
+		"",
 		"#Import \"<libc>\"",
+		"",
 		"#Import \"LLVM/bin/libclang.dll\"",
 		"#Import \"LLVM/lib/libclang.lib\"",
 		"#Import \"LLVM/include/*.h\"",
 		"#Import \"<clang-c/Index.h>\"",
+		"",
 		"Extern"
 	],
 	

+ 7 - 1
src/c2mx2/libclang_extern.monkey2

@@ -1,9 +1,15 @@
+
+'***** Auto generated by c2mx2! *****
+
 Namespace libclang
+
 #Import "<libc>"
+
 #Import "LLVM/bin/libclang.dll"
 #Import "LLVM/lib/libclang.lib"
 #Import "LLVM/include/*.h"
 #Import "<clang-c/Index.h>"
+
 Extern
 
 '***** File: LLVM/include\clang-c/CXErrorCode.h *****
@@ -1150,4 +1156,4 @@ Struct CXTranslationUnitImpl
 End
 Struct CXVirtualFileOverlayImpl
 End
-Public
+Public

+ 6 - 0
src/c2mx2/libclang_extern_new.monkey2

@@ -1,9 +1,15 @@
+
+'***** Auto generated by c2mx2! *****
+
 Namespace libclang
+
 #Import "<libc>"
+
 #Import "LLVM/bin/libclang.dll"
 #Import "LLVM/lib/libclang.lib"
 #Import "LLVM/include/*.h"
 #Import "<clang-c/Index.h>"
+
 Extern
 
 '***** File: LLVM/include\clang-c/CXErrorCode.h *****

+ 0 - 30
src/c2mx2/sdl2_c2mx2.json

@@ -1,30 +0,0 @@
-
-{
-	"inputFile":"SDL/include/SDL.h",
-	
-	"outputFile":"sdl2.monkey2",
-	
-	"excludeFiles":[
-		"SDL_atomic.h",
-		"SDL_stdinc.h",
-		"SDL_assert.h",
-		"SDL_platform.h"
-	],
-
-	"clangArgs":[
-		"-Xclang",
-		"-ISDL/include"
-	],
-	
-	"anonEnumType":"Uint32",
-	
-	"header":[
-		"Namespace sdl2",
-		"Import \"<libc>\"",
-		"Alias size_t:int"
-	],
-	
-	"footer":[
-	]
-}
-