Skip to content

Commit 60d7787

Browse files
committed
fbc: github # 426: add __FB_ARG_LISTEXPAND__( macroname, macroargcount, args... )
- tests added - only emit NEWLINE if the expansion is multiple source lines - fix pointers to string characters to use sizeof(wstring) since it will vary depending on host platform - add __FB_ARG_LISTEXPAND__( macroname, macroargcount, args... ) - expands to one or more 'macroname( .... )' depending on the value of macroargcount and number of arguments in the args... list /' #macro m( arg... ) #print " "##arg #endmacro #print "1. MacroArgCount=0:" __FB_ARG_LISTEXPAND__( m, 0, Hello1, Hello2, Hello3, Hello4) #print "2. MacroArgCount>0:" __FB_ARG_LISTEXPAND__( m, 1, Hello1, Hello2, Hello3, Hello4) #print "3. MacroArgCount<0:" __FB_ARG_LISTEXPAND__( m, -1, Hello1, Hello2, Hello3, Hello4) '/ /' Compiler output: 1. MacroArgCount=0: Hello1, Hello2, Hello3, Hello4 2. MacroArgCount>0: Hello1 Hello2 Hello3 Hello4 3. MacroArgCount<0: Hello1, Hello2, Hello3, Hello4 Hello2, Hello3, Hello4 Hello3, Hello4 Hello4 '/
1 parent 392937e commit 60d7787

File tree

5 files changed

+602
-8
lines changed

5 files changed

+602
-8
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Version 1.20.0
6262
- fbc: intrinsic define __FB_OPTION_PROFILE__ to indicate if profiling is currently enabled for code generation
6363
- rtlib: ./fbc-int/profile.bi - extra features for working with the built-in profiler; ProfileSetFileName(), ProfileGetOptions(), ProfileSetOptions(). ProfileIgnore()
6464
- '-earraydims' command line option to enable array dimensions checking. Enabled by default with '-exx' command line option.
65+
- github #426: add __FB_ARG_LISTEXPAND__( macroname, macroargcount, args... ): expands to one or more 'macroname( .... )' depending on the value of macroargcount and number of arguments in the args... list (skyfish)
6566

6667
[fixed]
6768
- github #410: give consistent floating point comparisons results involving NaNs.

src/compiler/hlp-str.bas

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
#include once "fbint.bi"
88
#include once "dstr.bi"
99

10+
#if sizeof(wstring) = 4
11+
type WSTRING_CHAR as ulong
12+
#elseif sizeof(wstring) = 2
13+
type WSTRING_CHAR as ushort
14+
#else
15+
type WSTRING_CHAR as ubyte
16+
#endif
17+
1018
'':::::
1119
#macro ASSIGN_SETUP(dst, src, _type)
1220
dim as integer dst_len, src_len
@@ -1333,7 +1341,7 @@ function hWStr2long( byref txt as wstring, byref value as long ) as integer
13331341
return FALSE
13341342
end if
13351343

1336-
dim s as ushort ptr = strptr(txt)
1344+
dim s as WSTRING_CHAR ptr = strptr(txt)
13371345

13381346
if( s = NULL orelse *s = CHAR_NULL ) then
13391347
return FALSE
@@ -1628,10 +1636,9 @@ end function
16281636
'':::::
16291637
function hWStr2Args( byval txt as const wstring ptr, res() as DWSTRING ) as integer
16301638

1631-
'' add the wstring version
1632-
16331639
dim as integer t = 0
1634-
dim as const ushort ptr s = cast(const ushort ptr, txt)
1640+
dim as const WSTRING_CHAR ptr s = cast(const WSTRING_CHAR ptr, txt)
1641+
16351642
dim as integer prntcnt = 0
16361643
dim as uinteger c = CHAR_NULL
16371644
dim as integer max_t = 10

src/compiler/symb-define.bas

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,17 +747,23 @@ private function hDefArgListExpandZ_cb( byval argtb as LEXPP_ARGTB ptr, byval er
747747
numVarArgs = hStr2Args( argStr, varArgs() ) - 1
748748
if ArgCount < 0 then ' Is Negate ?
749749
for index = 0 to numVarArgs step -ArgCount
750+
if( index > 0 ) then
751+
res &= NEWLINE
752+
end if
750753
res &= *MacroNameStr & "("
751754
for index2 = index to numVarArgs
752755
res &= varArgs(index2)
753756
if index2 <> numVarArgs then
754757
res &= ","
755758
end if
756759
next
757-
res &= ")" & NEWLINE
760+
res &= ")"
758761
next
759762
else
760763
for index = 0 to numVarArgs step ArgCount
764+
if( index > 0 ) then
765+
res &= NEWLINE
766+
end if
761767
res &= *MacroNameStr & "("
762768
MaxVarArgs = iif(ArgCount>numVarArgs-index,numVarArgs,index+ArgCount-1)
763769
for index2 = index to MaxVarArgs
@@ -766,7 +772,7 @@ private function hDefArgListExpandZ_cb( byval argtb as LEXPP_ARGTB ptr, byval er
766772
res &= ","
767773
end if
768774
next
769-
res &= ")" & NEWLINE
775+
res &= ")"
770776
next
771777
end if
772778
end if
@@ -812,6 +818,9 @@ private function hDefArgListExpandW_cb( byval argtb as LEXPP_ARGTB ptr, byval er
812818
numVarArgs = hWStr2Args( argStr, varArgs() ) - 1
813819
if ArgCount < 0 then ' Is Negate ?
814820
for index = 0 to numVarArgs step -ArgCount
821+
if( index > 0 ) then
822+
DWstrConcatAssign(res, NEWLINE )
823+
end if
815824
DWstrConcatAssign(res, *MacroNameStr.data )
816825
DWstrConcatAssign(res, "(" )
817826
for index2 = index to numVarArgs
@@ -820,10 +829,13 @@ private function hDefArgListExpandW_cb( byval argtb as LEXPP_ARGTB ptr, byval er
820829
DWstrConcatAssign(res, "," )
821830
end if
822831
next
823-
DWstrConcatAssign(res, ")" & NEWLINE )
832+
DWstrConcatAssign(res, ")" )
824833
next
825834
else
826835
for index = 0 to numVarArgs step ArgCount
836+
if( index > 0 ) then
837+
DWstrConcatAssign(res, NEWLINE )
838+
end if
827839
DWstrConcatAssign(res, *MacroNameStr.data )
828840
DWstrConcatAssign(res, "(" )
829841
MaxVarArgs = iif(ArgCount>numVarArgs-index,numVarArgs,index+ArgCount-1)
@@ -833,7 +845,7 @@ private function hDefArgListExpandW_cb( byval argtb as LEXPP_ARGTB ptr, byval er
833845
DWstrConcatAssign(res, "," )
834846
end if
835847
next
836-
DWstrConcatAssign(res, ")" & NEWLINE )
848+
DWstrConcatAssign(res, ")" )
837849
next
838850
end if
839851
end if
31.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)