Sfoglia il codice sorgente

Keep global track of imported modules, so we don't inadvertently load the same module twice.

woollybah 11 anni fa
parent
commit
802d1e1fcc
2 ha cambiato i file con 17 aggiunte e 1 eliminazioni
  1. 8 1
      decl.bmx
  2. 9 0
      iparser.bmx

+ 8 - 1
decl.bmx

@@ -565,6 +565,7 @@ Type TScopeDecl Extends TDecl
 	End Method
 	End Method
 
 
 	Method FindType:TType( ident$,args:TType[] )
 	Method FindType:TType( ident$,args:TType[] )
+'DebugLog Self.ident + "::FindType::" + ident
 		Local decl:Object=(GetDecl( ident ))
 		Local decl:Object=(GetDecl( ident ))
 		If decl Then
 		If decl Then
 			Local ty:TType=TType(decl)
 			Local ty:TType=TType(decl)
@@ -623,7 +624,7 @@ End Rem
 	
 	
 	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False )
 	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False )
 'DebugLog "FindFuncDecl : " + ident
 'DebugLog "FindFuncDecl : " + ident
-'If ident = "_IsRootPath" Then DebugStop
+'If ident = "OpenStream" Then DebugStop
 		'Local funcs:TFuncDeclList=TFuncDeclList( FindDecl( ident ) )
 		'Local funcs:TFuncDeclList=TFuncDeclList( FindDecl( ident ) )
 		Local f:TDecl = TDecl(findDecl(ident))
 		Local f:TDecl = TDecl(findDecl(ident))
 		If Not f Then Return Null
 		If Not f Then Return Null
@@ -1685,6 +1686,8 @@ Type TAppDecl Extends TScopeDecl
 
 
 	Field imported:TMap=New TMap'<TModuleDecl>			'maps modpath->mdecl
 	Field imported:TMap=New TMap'<TModuleDecl>			'maps modpath->mdecl
 	
 	
+	Field globalImports:TMap = New TMap
+	
 	Field mainModule:TModuleDecl
 	Field mainModule:TModuleDecl
 	Field mainFunc:TFuncDecl	
 	Field mainFunc:TFuncDecl	
 		
 		
@@ -1723,6 +1726,10 @@ Type TAppDecl Extends TScopeDecl
 		EndIf
 		EndIf
 	End Method
 	End Method
 	
 	
+	Method IsImported:Int(modpath:String)
+		Return globalImports.Contains(modpath)
+	End Method
+	
 	Method GetDecl:Object( ident$ )
 	Method GetDecl:Object( ident$ )
 		Local obj:Object = Super.GetDecl(ident)
 		Local obj:Object = Super.GetDecl(ident)
 		If Not obj Then
 		If Not obj Then

+ 9 - 0
iparser.bmx

@@ -38,6 +38,13 @@ Type TIParser
 'DebugStop	
 'DebugStop	
 		Const STATE_CLASS:Int = 1
 		Const STATE_CLASS:Int = 1
 		
 		
+		
+		' already imported??
+		If _appInstance.IsImported(modpath)
+			' add import to the scope (so we can find decls in it later)
+			pmod.imported.Insert(modpath, _appInstance.globalImports.ValueForKey(modpath))
+			Return False
+		End If
 	
 	
 		Local _mod:TModuleDecl = New TModuleDecl.Create(modpath, "bb" + modpath, path, attrs)
 		Local _mod:TModuleDecl = New TModuleDecl.Create(modpath, "bb" + modpath, path, attrs)
 		Select modpath
 		Select modpath
@@ -66,6 +73,8 @@ Type TIParser
 		Else
 		Else
 			pmod.imported.Insert(modpath, _mod)
 			pmod.imported.Insert(modpath, _mod)
 		End If
 		End If
+
+		_appInstance.globalImports.Insert(modpath, _mod)
 		
 		
 		Local ipath:String
 		Local ipath:String