Jelajahi Sumber

Fixed issue with accessing decls before using namespace added. Using namespace must now exist (maybe to heavy?)

Mark Sibly 9 tahun lalu
induk
melakukan
a41e96af34
4 mengubah file dengan 31 tambahan dan 11 penghapusan
  1. 15 1
      src/mx2cc/builder.monkey2
  2. 6 0
      src/mx2cc/decl.monkey2
  3. 9 8
      src/mx2cc/filescope.monkey2
  4. 1 2
      src/mx2cc/mx2.monkey2

+ 15 - 1
src/mx2cc/builder.monkey2

@@ -275,6 +275,19 @@ Class BuilderInstance
 			
 			semantingModule=module
 			
+			For Local fscope:=Eachin module.fileScopes
+			
+				PNode.semanting.Push( fscope.fdecl )
+				
+				Try
+					fscope.SemantUsings()
+				catch ex:SemantEx
+				End
+				
+				PNode.semanting.Pop()
+				
+			Next
+			
 			For Local fscope:=Eachin module.fileScopes
 			
 				If opts.verbose>0 Print "Semanting "+fscope.fdecl.path
@@ -435,7 +448,7 @@ Class BuilderInstance
 		
 	End
 	
-	Method GetNamespace:NamespaceScope( path:String )
+	Method GetNamespace:NamespaceScope( path:String,mustExist:Bool=False )
 	
 		Local nmspace:=rootNamespace,i0:=0
 		
@@ -448,6 +461,7 @@ Class BuilderInstance
 			
 			Local ntype:=TCast<NamespaceType>( nmspace.GetType( id ) )
 			If Not ntype
+				If mustExist New SemantEx( "Namespace '"+path+"' not found" )
 				ntype=New NamespaceType( id,nmspace )
 				nmspace.Insert( id,ntype )
 			Endif

+ 6 - 0
src/mx2cc/decl.monkey2

@@ -119,6 +119,12 @@ Class FileDecl Extends Decl
 	Field globals:=New Stack<VarValue>
 	Field functions:=New Stack<FuncValue>
 	
+	Method New()
+		srcfile=Self
+		srcpos=1 Shl 12
+		endpos=1 Shl 12
+	End
+	
 	Method ToString:String() Override
 		Return "~q"+path+"~q"
 	End

+ 9 - 8
src/mx2cc/filescope.monkey2

@@ -24,7 +24,7 @@ Class FileScope Extends Scope
 		outer=nmspace
 		
 		For Local member:=Eachin fdecl.members
-
+		
 			Local node:=member.ToNode( Self )
 			
 			If member.IsExtension
@@ -66,10 +66,8 @@ Class FileScope Extends Scope
 		Next
 	End
 	
-	Method Semant()
+	Method SemantUsings()
 	
-'		Print "Semating:"+fdecl.path
-
 		If nmspace<>Builder.monkeyNamespace
 			UsingAll( Builder.monkeyNamespace )
 		Endif
@@ -82,20 +80,23 @@ Class FileScope Extends Scope
 			Endif
 		
 			If use.EndsWith( ".." )
-				Local nmspace:=Builder.GetNamespace( use.Slice( 0,-2 ) )
+				Local nmspace:=Builder.GetNamespace( use.Slice( 0,-2 ),True )
 				UsingAll( nmspace )
 				Continue
 			Endif
 		
 			If use.EndsWith( ".*" )
-				Local nmspace:=Builder.GetNamespace( use.Slice( 0,-2 ) )
+				Local nmspace:=Builder.GetNamespace( use.Slice( 0,-2 ),True )
 				UsingInner( nmspace )
 				Continue
 			Endif
 			
-			Local nmspace:=Builder.GetNamespace( use )
+			Local nmspace:=Builder.GetNamespace( use,True )
 			If nmspace UsingNamespace( nmspace )
 		Next
+	End
+
+	Method Semant()
 	
 		For Local node:=Eachin toSemant
 			Try			
@@ -125,7 +126,7 @@ Class FileScope Extends Scope
 	End
 	
 	Method FindType:Type( ident:String ) Override
-	
+
 		'Search in namespace hierarchy
 		'
 		Local type:=Super.FindType( ident )

+ 1 - 2
src/mx2cc/mx2.monkey2

@@ -39,10 +39,9 @@ Namespace mx2
 
 Using std
 Using std.stringio
-Using std.chartype
 Using std.filesystem
 Using std.collections
-Using lib.c
+Using libc
 
 ' Messy, but to update version:
 '