2
0
Эх сурвалжийг харах

Added new Export keyword. Fixes #348.
Export attribute prevents any mangling of a function name, specifically for dll exports.

woollybah 7 жил өмнө
parent
commit
721fe463f2
6 өөрчлөгдсөн 40 нэмэгдсэн , 2 устгасан
  1. 4 0
      ctranslator.bmx
  2. 12 0
      decl.bmx
  3. 3 0
      iparser.bmx
  4. 11 0
      parser.bmx
  5. 1 1
      toker.bmx
  6. 9 1
      translator.bmx

+ 4 - 0
ctranslator.bmx

@@ -4928,6 +4928,10 @@ End Rem
 		If funcDecl.attrs & DECL_API_STDCALL Then
 		If funcDecl.attrs & DECL_API_STDCALL Then
 			func :+ "W"
 			func :+ "W"
 		End If
 		End If
+		
+		If funcDecl.attrs & DECL_EXPORT Then
+			func :+ "E"
+		End If
 
 
 		func :+ "="
 		func :+ "="
 
 

+ 12 - 0
decl.bmx

@@ -39,6 +39,7 @@ Const DECL_INITONLY:Int=     $1000000
 
 
 Const DECL_NODEBUG:Int=      $2000000
 Const DECL_NODEBUG:Int=      $2000000
 Const DECL_PROTECTED:Int=    $4000000
 Const DECL_PROTECTED:Int=    $4000000
+Const DECL_EXPORT:Int=       $8000000
 
 
 Const DECL_API_CDECL:Int=   $00000000
 Const DECL_API_CDECL:Int=   $00000000
 Const DECL_API_STDCALL:Int= $10000000
 Const DECL_API_STDCALL:Int= $10000000
@@ -1800,6 +1801,7 @@ Type TFuncDecl Extends TBlockDecl
 	
 	
 	Field mangled:String
 	Field mangled:String
 	Field noMangle:Int
 	Field noMangle:Int
+	Field exported:Int
 	
 	
 	Field equalsBuiltIn:Int = -1
 	Field equalsBuiltIn:Int = -1
 	
 	
@@ -1838,6 +1840,7 @@ Type TFuncDecl Extends TBlockDecl
 		t.metadata = metadata
 		t.metadata = metadata
 		t.mangled = mangled
 		t.mangled = mangled
 		t.noMangle = noMangle
 		t.noMangle = noMangle
+		t.exported = exported
 		t.blockType = blockType
 		t.blockType = blockType
 		Return  t
 		Return  t
 	End Method
 	End Method
@@ -2046,6 +2049,15 @@ Type TFuncDecl Extends TBlockDecl
 						End If
 						End If
 					End If
 					End If
 				End If
 				End If
+				If exported Then
+					If decl<>Self Then
+						If decl.argDecls.Length = 0 Then
+							Err "You cannot apply Export to the function, as another function with no arguments exists."
+						Else If decl.exported Then
+							Err "Another function is already declared with Export."
+						End If
+					End If
+				End If
 			Next
 			Next
 		End If
 		End If
 		
 		

+ 3 - 0
iparser.bmx

@@ -1012,6 +1012,9 @@ Type TIParser
 				Case Asc("R")
 				Case Asc("R")
 					attrs:| DECL_PROTECTED
 					attrs:| DECL_PROTECTED
 					parsed = True
 					parsed = True
+				Case Asc("E")
+					attrs:| DECL_EXPORT
+					parsed = True
 			End Select
 			End Select
 		Next
 		Next
 
 

+ 11 - 0
parser.bmx

@@ -2672,6 +2672,7 @@ End Rem
 		Local meth:Int = attrs & FUNC_METHOD
 		Local meth:Int = attrs & FUNC_METHOD
 		Local meta:TMetadata
 		Local meta:TMetadata
 		Local noMangle:Int
 		Local noMangle:Int
+		Local exported:Int
 
 
 		Local classDecl:TClassDecl = TClassDecl(parent)
 		Local classDecl:TClassDecl = TClassDecl(parent)
 
 
@@ -2791,6 +2792,15 @@ End Rem
 			End If
 			End If
 		End If
 		End If
 		
 		
+		If CParse("export") Then
+			attrs :| DECL_EXPORT
+			If attrs & FUNC_METHOD Then
+				Err "Only functions can specify Export"
+			Else
+				exported = True
+			End If
+		End If
+		
 		attrs :| ParseCallConvention(attrs & DECL_API_STDCALL)
 		attrs :| ParseCallConvention(attrs & DECL_API_STDCALL)
 		
 		
 		If CParse( "nodebug" ) Then
 		If CParse( "nodebug" ) Then
@@ -2809,6 +2819,7 @@ End Rem
 				funcDecl=New TFuncDecl.CreateF( id,ty,args,attrs )
 				funcDecl=New TFuncDecl.CreateF( id,ty,args,attrs )
 			'End If
 			'End If
 			funcDecl.noMangle = noMangle
 			funcDecl.noMangle = noMangle
+			funcDecl.exported = exported
 		End If
 		End If
 		If meta Then
 		If meta Then
 			funcDecl.metadata = meta
 			funcDecl.metadata = meta

+ 1 - 1
toker.bmx

@@ -49,7 +49,7 @@ Type TToker
 		"and,or,shl,shr,sar,end,if,then,else,elseif,endif,while,wend,repeat,until,forever,for,to,step," + ..
 		"and,or,shl,shr,sar,end,if,then,else,elseif,endif,while,wend,repeat,until,forever,for,to,step," + ..
 		"next,return,alias,rem,endrem,throw,assert,try,catch,finally,nodebug,incbin,endselect,endmethod," + ..
 		"next,return,alias,rem,endrem,throw,assert,try,catch,finally,nodebug,incbin,endselect,endmethod," + ..
 		"endfunction,endtype,endextern,endtry,endwhile,pi,release,defdata,readdata,restoredata,interface," + ..
 		"endfunction,endtype,endextern,endtry,endwhile,pi,release,defdata,readdata,restoredata,interface," + ..
-		"endinterface,implements,size_t,uint,ulong,struct,endstruct,operator,where,readonly"
+		"endinterface,implements,size_t,uint,ulong,struct,endstruct,operator,where,readonly,export"
 	Global _keywords:TMap
 	Global _keywords:TMap
 
 
 	Field _path$
 	Field _path$

+ 9 - 1
translator.bmx

@@ -493,6 +493,10 @@ Type TTranslator
 '				munged=decl.ModuleScope().munged+"_"+id
 '				munged=decl.ModuleScope().munged+"_"+id
 '			EndIf
 '			EndIf
 '		Case "cpp"
 '		Case "cpp"
+		If Not munged And TFuncDecl(decl) And TFuncDecl(decl).exported Then
+			munged = id
+		Else
+
 			If TModuleDecl( decl.scope )
 			If TModuleDecl( decl.scope )
 				munged=decl.ModuleScope().munged+"_"+id
 				munged=decl.ModuleScope().munged+"_"+id
 				
 				
@@ -506,7 +510,7 @@ Type TTranslator
 			If TModuleDecl( decl )
 			If TModuleDecl( decl )
 				munged=decl.ModuleScope().munged+"_"+id
 				munged=decl.ModuleScope().munged+"_"+id
 			EndIf
 			EndIf
-
+		End If
 '		End Select
 '		End Select
 'DebugStop
 'DebugStop
 
 
@@ -542,6 +546,10 @@ Type TTranslator
 
 
 		'add an increasing number to identifier if already used  
 		'add an increasing number to identifier if already used  
 		If mungScope.Contains( munged )
 		If mungScope.Contains( munged )
+			If TFuncDecl(decl) And TFuncDecl(decl).exported Then
+				Err "Cannot export duplicate identifiers : " + decl.ident 
+			End If
+		
 			Local i:Int=1
 			Local i:Int=1
 			Repeat
 			Repeat
 				i:+1
 				i:+1