Selaa lähdekoodia

Fixed global/local decl assignment. Fixes #440.

woollybah 6 vuotta sitten
vanhempi
commit
7c677c6775
2 muutettua tiedostoa jossa 33 lisäystä ja 21 poistoa
  1. 14 10
      decl.bmx
  2. 19 11
      parser.bmx

+ 14 - 10
decl.bmx

@@ -316,18 +316,20 @@ Type TDecl
 				If TGlobalDecl( Self )
 				If TGlobalDecl( Self )
 					' FIXME
 					' FIXME
 					If AppScope() Then
 					If AppScope() Then
+						If TGlobalDecl( Self ).mscope Then
+							AppScope()._semanted.AddLast Self
+						End If
 						AppScope().semantedGlobals.AddLast TGlobalDecl( Self )
 						AppScope().semantedGlobals.AddLast TGlobalDecl( Self )
 					End If
 					End If
-				EndIf
-				
-				If TModuleDecl( scope )
-					' FIXME
-					Local app:TAppDecl = AppScope()
-					If app Then
-						app._semanted.AddLast Self
-					End If
-				EndIf
-			
+				Else
+					If TModuleDecl( scope )
+						' FIXME
+						Local app:TAppDecl = AppScope()
+						If app Then
+							app._semanted.AddLast Self
+						End If
+					EndIf
+				End If
 			EndIf
 			EndIf
 			
 			
 			If TValDecl(Self) And TValDecl(Self).deferInit Then
 			If TValDecl(Self) And TValDecl(Self).deferInit Then
@@ -713,6 +715,7 @@ Type TGlobalDecl Extends TVarDecl
 
 
 	Field inited:Int
 	Field inited:Int
 	Field funcGlobal:Int
 	Field funcGlobal:Int
+	Field mscope:TScopeDecl
 	
 	
 	Method Create:TGlobalDecl( ident$,ty:TType,init:TExpr,attrs:Int=0,funcGlobal:Int=False )
 	Method Create:TGlobalDecl( ident$,ty:TType,init:TExpr,attrs:Int=0,funcGlobal:Int=False )
 		Self.deferInit = True
 		Self.deferInit = True
@@ -728,6 +731,7 @@ Type TGlobalDecl Extends TVarDecl
 		Local g:TGlobalDecl = New TGlobalDecl.Create( ident,declTy,declInit,attrs,funcGlobal )
 		Local g:TGlobalDecl = New TGlobalDecl.Create( ident,declTy,declInit,attrs,funcGlobal )
 		g.ty = ty
 		g.ty = ty
 		g.init = init
 		g.init = init
+		g.mscope = mscope
 		Return g
 		Return g
 	End Method
 	End Method
 	
 	

+ 19 - 11
parser.bmx

@@ -2229,8 +2229,10 @@ End Rem
 			Select _toke
 			Select _toke
 				Case "~n"
 				Case "~n"
 					NextToke
 					NextToke
-				Case "const","global"
+				Case "const"
 					mdecl.InsertDecls ParseDecls( _toke,attrs )
 					mdecl.InsertDecls ParseDecls( _toke,attrs )
+				Case "global"
+					ParseDeclStmts(True, attrs, mdecl)
 				Case "struct"
 				Case "struct"
 					mdecl.InsertDecl ParseClassDecl( _toke,attrs | CLASS_STRUCT )
 					mdecl.InsertDecl ParseClassDecl( _toke,attrs | CLASS_STRUCT )
 				Case "type"
 				Case "type"
@@ -2521,22 +2523,33 @@ End Rem
 		Forever
 		Forever
 	End Method
 	End Method
 
 
-	Method ParseDeclStmts()
-
+	Method ParseDeclStmts(initOnly:Int = False, attrs:Int = 0, mdecl:TModuleDecl  = Null)
 		Local toke$=_toke
 		Local toke$=_toke
 		NextToke
 		NextToke
 		Repeat
 		Repeat
-			Local decl:TDecl=ParseDecl( toke,0 )
+			Local decl:TDecl=ParseDecl( toke,attrs )
 			_block.AddStmt New TDeclStmt.Create( decl )
 			_block.AddStmt New TDeclStmt.Create( decl )
 			
 			
 			' reset the decl scope, adding decl to the block decl list.
 			' reset the decl scope, adding decl to the block decl list.
 			' this improves scope visibilty - for decls such as embedded functions
 			' this improves scope visibilty - for decls such as embedded functions
 			If TConstDecl(decl) Or TGlobalDecl(decl) Then
 			If TConstDecl(decl) Or TGlobalDecl(decl) Then
+
+				If mdecl Then
+					mdecl.InsertDecl decl
+				End If
+
 				decl.scope = Null
 				decl.scope = Null
 				_block.InsertDecl(decl)
 				_block.InsertDecl(decl)
+				
 				If TGlobalDecl(decl) Then
 				If TGlobalDecl(decl) Then
-					TGlobalDecl(decl).funcGlobal = True
+					If initOnly Then
+						decl.attrs :| DECL_INITONLY
+						TGlobalDecl(decl).mscope = _module
+					Else
+						TGlobalDecl(decl).funcGlobal = True
+					End If
 				End If
 				End If
+
 			End If
 			End If
 			
 			
 		Until Not CParse(",")
 		Until Not CParse(",")
@@ -3775,12 +3788,7 @@ End Rem
 			Case "const"
 			Case "const"
 				_module.InsertDecls ParseDecls( _toke,attrs )
 				_module.InsertDecls ParseDecls( _toke,attrs )
 			Case "global"
 			Case "global"
-				Local list:TList = ParseDecls( _toke,attrs )
-				_module.InsertDecls list
-				For Local gdecl:TGlobalDecl = EachIn list
-					gdecl.attrs :| DECL_INITONLY
-					_block.AddStmt New TDeclStmt.Create( gdecl )
-				Next
+				ParseDeclStmts(True, attrs, _module)
 			Case "struct"
 			Case "struct"
 				_module.InsertDecl ParseClassDecl( _toke,attrs | CLASS_STRUCT )
 				_module.InsertDecl ParseClassDecl( _toke,attrs | CLASS_STRUCT )
 			Case "type"
 			Case "type"