Преглед изворни кода

Finally added build errors for #import file not found.

Mark Sibly пре 7 година
родитељ
комит
a907a21274
4 измењених фајлова са 67 додато и 44 уклоњено
  1. 35 23
      src/mx2cc/builder.monkey2
  2. 6 0
      src/mx2cc/errors.monkey2
  3. 21 0
      src/mx2cc/parser.monkey2
  4. 5 21
      src/mx2cc/test.monkey2

+ 35 - 23
src/mx2cc/builder.monkey2

@@ -219,13 +219,28 @@ Class BuilderInstance
 '			fdecl.rfile=module.cfileDir+"r_"+ident+".cpp"
 
 			module.fileDecls.Push( fdecl )
-
-			For Local imp:=Eachin fdecl.imports
 			
-				ImportFile( imp )
+			BuildEx.srcpath=fdecl.path
+			BuildEx.srcpos=-1
+			
+			For Local imp:=0 Until fdecl.imports.Length
 				
+				Local path:=fdecl.imports[imp]
+				
+				Local i:=path.FindLast( "[" )
+				If i<>-1 And path.EndsWith( "]" )
+					BuildEx.srcpos=Int( path.Slice( i+1,-1 ) )
+					path=path.Slice( 0,i )
+					fdecl.imports[imp]=path
+				Else
+					BuildEx.srcpos=-1
+				Endif
+				
+				ImportFile( path )
 			Next
 			
+			BuildEx.srcpath=""
+			
 			currentDir=cd
 			
 		Forever
@@ -594,8 +609,8 @@ Class BuilderInstance
 		Type.TypeInfoClass.Semant()
 	End
 	
-	Method ImportFile:Void( path:String )
-	
+	Method ImportFile( path:String )
+		
 		If path.StartsWith( "<" ) And path.EndsWith( ">" )
 			ImportSystemFile( path.Slice( 1,-1 ) )
 		Else
@@ -744,34 +759,31 @@ Class BuilderInstance
 		
 		Local qpath:="~q"+path+"~q"
 		
-		Select ext
-		Case ".framework"
+		If ext=".framework"
 			
 			If product.toolchain="gcc"
 				If GetFileType( path )<>FileType.Directory
-					New BuildEx( "Framework "+qpath+" not found" )
-					Return
+					New BuildEx( "Framework not found "+qpath )
 				Endif
+				
+				Return
 			Endif
 			
-		Default
-			Select GetFileType( path )
-			Case FileType.Directory
+		Else If GetFileType( path )=FileType.Directory
 			
-				product.ASSET_FILES.Push( path )
-				Return
-				
-			Case FileType.None
+			product.ASSET_FILES.Push( path )
+			Return
 			
-'				New BuildEx( "File "+qpath+" not found" )
-'				Return
-				
-			End
-		End
+		Else If GetFileType( path )<>FileType.File
+			
+			New BuildEx( "File not found "+qpath )
+			Return
+		
+		Endif
 		
 		Select ext
 		Case ".mx2",".monkey2"
-		
+			
 			MX2_SRCS.Push( path )
 			
 		Case ".h",".hh",".hxx",".hpp"
@@ -786,7 +798,7 @@ Class BuilderInstance
 		
 		Case ".java"
 			
-			If opts.target="android"
+			If opts.target="android" 
 				product.JAVA_FILES.Push( path )
 			Endif
 			

+ 6 - 0
src/mx2cc/errors.monkey2

@@ -63,6 +63,9 @@ Class SemantEx Extends ErrorEx
 End
 
 Class BuildEx Extends ErrorEx
+
+	Global srcpath:String	
+	Global srcpos:Int
 	
 	Method New( msg:String )
 		Super.New( msg )
@@ -71,6 +74,9 @@ Class BuildEx Extends ErrorEx
 	End
 	
 	Method ToString:String() Override
+		
+		If srcpath Return srcpath+" ["+(srcpos Shr 12)+"] : Error : "+msg
+			
 		Return "Build error: "+msg
 	End
 

+ 21 - 0
src/mx2cc/parser.monkey2

@@ -2112,6 +2112,7 @@ Class Parser
 	Field _docs:=New StringStack
 	Field _doccing:Bool
 	Field _imports:=New StringStack
+	Field _reflects:=New StringStack
 	
 	Method IsBool:Bool( v:String )
 		Return v="true" Or v="false"
@@ -2290,9 +2291,29 @@ Class Parser
 						If Not ExtractExt( path ) path+=".monkey2"
 						
 					Endif
+						
+					path+="["+SrcPos+"]"
+						
+					'Print "path="+path
 					
 					_imports.Push( path )
+				Endif
+				
+			Case "reflect"
+				
+				If _cc.Top=1
+					
+					p.Bump()
+					
+					Local path:=p.ParseIdent()
+					
+					While p.CParse( "." )
+						path+="."+p.ParseIdent()
+					Wend
+					
+					p.ParseEol()
 					
+					_reflects.Push( path )
 				Endif
 				
 			Case "print"

+ 5 - 21
src/mx2cc/test.monkey2

@@ -1,28 +1,12 @@
 
-Interface I
-End
-
-Interface J
-End
-
-Class A
-End
-
-Class B
-End
+#Reflect mojo.app
+#Reflect mojo.graphics
 
-Class C Implements I
-End
-
-Class D Implements J
-End
-
-Class E<X,Y> Where X Implements I Or Y Implements J
-End
+#Import "where.monkey2"
 
 Function Main()
-	
-	Local test:=New E<A,D>
+
+	Print "Hello World"
 	
 End