浏览代码

Improved support for importing files.

woollybah 11 年之前
父节点
当前提交
b780201683
共有 4 个文件被更改,包括 53 次插入29 次删除
  1. 10 22
      config.bmx
  2. 39 3
      ctranslator.bmx
  3. 1 1
      iparser.bmx
  4. 3 3
      parser.bmx

+ 10 - 22
config.bmx

@@ -203,10 +203,17 @@ Function FilePath:String(path:String)
 End Function
 
 Function BuildHeaderName:String(path:String)
-	path = StripDir(path)
-
 	If opt_buildtype = BUILDTYPE_MODULE Then
-		path = opt_modulename + "." + path
+		path = opt_modulename + "." + StripDir(path)
+	Else
+		Local dir:String = ExtractDir(path).ToLower().Replace("/.bmx","")
+		dir = dir[dir.findLast("/") + 1..]
+		If dir.EndsWith(".mod") Then
+			dir = dir.Replace(".mod", "")
+		End If
+		dir = dir.Replace(".", "_").Replace("-", "_")
+		Local file:String = StripDir(path).ToLower()
+		path = dir + "_" + file
 	End If
 	
 	Return path
@@ -217,10 +224,6 @@ Function MungModuleName:String(ident:String)
 	Return mung.Replace(".", "_").Replace("-", "_")
 End Function
 
-Function MungImportFromFile:String(file:String)
-	Return "_bb_" + file
-End Function
-
 Rem
 bbdoc: Get the header file name from a given module ident, optionally with include path.
 End Rem
@@ -237,21 +240,6 @@ Function ModuleHeaderFromIdent:String(ident:String, includePath:Int = False)
 	Return file
 End Function
 
-Function FileHeaderFromFile:String(filepath:String, includePath:Int = False)
-
-	Local name:String = StripAll(filepath)
-	Local dir:String = ExtractDir(filePath)
-
-	Local file:String = name + ".bmx" + FileMung(opt_apptype) + ".h"
-
-	If includePath Then
-		'Local parent:String = dir[dir.FindLast("/") + 1..]
-		'file = parent + "/.bmx/" + file
-	End If
-
-	Return file
-End Function
-
 Function HeaderFile:String(path:String, mung:String)
 	Local fileDir:String = FilePath(path)
 	Local file:String = StripDir(path)

+ 39 - 3
ctranslator.bmx

@@ -2304,7 +2304,7 @@ End Rem
 				Emit "#include <" + ModuleHeaderFromIdent(moduleDecl.ident, True) + ">"
 			Else
 				' maybe a file import...
-				Emit "#include ~q" + FileHeaderFromFile(moduleDecl.filepath) + "~q"
+				Emit "#include ~q" + FileHeaderFromFile(moduleDecl, False) + "~q"
 			End If
 '			DebugLog moduleDecl.filepath
 		End If
@@ -2317,7 +2317,7 @@ End Rem
 				Emit MungModuleName(moduleDecl.ident) + "();"
 			Else
 				' maybe a file import...
-				Emit MungImportFromFile(moduleDecl.ident) + "();"
+				Emit MungImportFromFile(moduleDecl) + "();"
 			End If
 		End If
 	End Method
@@ -2649,6 +2649,34 @@ End Rem
 		
 	End Method
 
+	Method FileHeaderFromFile:String(mdecl:TModuleDecl, includePath:Int = False)
+	
+		Local name:String = StripAll(mdecl.filepath)
+		Local dir:String = ExtractDir(mdecl.filePath)
+	
+		Local file:String = name + ".bmx" + FileMung(opt_apptype And (Not mdecl.declImported)) + ".h"
+
+		If mdecl.relPath Then
+			Local dir:String = ExtractDir(mdecl.relPath)
+			If dir Then
+				file = "../" + dir + "/.bmx/" + file
+			End If
+		End If
+	
+		Return file
+	End Method
+
+	Method MungImportFromFile:String(mdecl:TModuleDecl)
+		Local dir:String = ExtractDir(mdecl.filepath).ToLower()
+		dir = dir[dir.findLast("/") + 1..]
+		If dir.EndsWith(".mod") Then
+			dir = dir.Replace(".mod", "")
+		End If
+		dir = dir.Replace(".", "_").Replace("-", "_")
+		Local file:String = StripDir(mdecl.filepath).ToLower()
+		Return "_bb_" + dir + "_" + StripExt(file)
+	End Method
+
 	Method TransInterface(app:TAppDecl)
 
 		SetOutput("interface")
@@ -2668,7 +2696,14 @@ End Rem
 					Emit "import " + mdecl.ident
 					processed.Insert(mdecl.ident, "")
 				Else If Not opt_ismain And mdecl.filepath.EndsWith(".bmx") And app.mainModule<>mdecl
-					Emit "import " + Enquote(StripDir(mdecl.filepath))
+					Local file:String = StripDir(mdecl.filepath)
+					If mdecl.relPath Then
+						Local dir:String = ExtractDir(mdecl.relPath)
+						If dir Then
+							file = dir + "/" + file
+						End If
+					End If
+					Emit "import " + Enquote(file)
 				End If
 			End If
 		Next
@@ -2739,3 +2774,4 @@ End Rem
 	End Method
 	
 End Type
+

+ 1 - 1
iparser.bmx

@@ -170,7 +170,7 @@ DebugLog "FILE NOT FOUND : " + ipath
 							modpath = modpath.ToLower().Replace(".", "_").Replace("-", "_")
 						Else
 							' todo file imports for apps
-							internalErr
+							'internalErr
 						End If
 
 

+ 3 - 3
parser.bmx

@@ -2141,8 +2141,8 @@ End Rem
 				modpath = opt_modulename + "_" + StripExt(filepath)
 				modpath = modpath.ToLower().Replace(".", "_").Replace("-", "_")
 			Else
-				' todo file imports for apps
-				internalErr
+				modpath = StripExt(filepath)
+				modpath = modpath.ToLower().Replace(".", "_").Replace("-", "_")
 			End If
 
 			' try to import interface
@@ -2258,7 +2258,7 @@ End Rem
 				End If
 				dir = dir.Replace(".", "_").Replace("-", "_")
 				Local file:String = StripDir(opt_filepath).ToLower()
-				app.munged = "bb_" + dir + "_" + StripExt(file)
+				app.munged = "_bb_" + dir + "_" + StripExt(file)
 			End If
 		End If
 		app.munged = app.munged.Replace(".", "_").Replace("-", "_")