Skip to content

Commit 6a1ceb8

Browse files
authored
Merge pull request #426 from skyfish4tb/master
Preprocess the target macro based on the macro parameter list.
2 parents 49d8ccb + 60d7787 commit 6a1ceb8

File tree

6 files changed

+985
-19
lines changed

6 files changed

+985
-19
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: 212 additions & 1 deletion
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
@@ -1321,6 +1329,45 @@ function hStr2long( byref txt as string, byref value as long ) as integer
13211329
return (*s = CHAR_NULL)
13221330
end function
13231331

1332+
function hWStr2long( byref txt as wstring, byref value as long ) as integer
1333+
'' could we not use VALINT() or some variation from rtlib?
1334+
1335+
const CHAR_ZERO = asc("0")
1336+
1337+
dim nvalue as long = 0
1338+
dim nsign as long = 1
1339+
1340+
if( len( txt ) = 0 ) then
1341+
return FALSE
1342+
end if
1343+
1344+
dim s as WSTRING_CHAR ptr = strptr(txt)
1345+
1346+
if( s = NULL orelse *s = CHAR_NULL ) then
1347+
return FALSE
1348+
end if
1349+
1350+
if( *s = CHAR_MINUS ) then
1351+
nsign = -1
1352+
s += 1
1353+
end if
1354+
1355+
if( *s = CHAR_NULL ) then
1356+
return FALSE
1357+
end if
1358+
1359+
while( hIsCharNumeric(*s) )
1360+
nvalue *= 10
1361+
nvalue += (*s - CHAR_ZERO)
1362+
s += 1
1363+
wend
1364+
1365+
value = nvalue * nsign
1366+
1367+
'' return TRUE if we read the entire string
1368+
return (*s = CHAR_NULL)
1369+
end function
1370+
13241371
'':::::
13251372
sub hSplitStr(byref txt as string, byref del as string, res() as string)
13261373

@@ -1424,7 +1471,7 @@ end function
14241471
'':::::
14251472
function hStr2Args( byval txt as const zstring ptr, res() as string ) as integer
14261473

1427-
'' !!!TODO!!! add the wstring version
1474+
'' add the string version
14281475

14291476
dim as integer t = 0
14301477
dim as const ubyte ptr s = cast(const ubyte ptr, txt)
@@ -1585,3 +1632,167 @@ function hStr2Args( byval txt as const zstring ptr, res() as string ) as integer
15851632
function = t
15861633

15871634
end function
1635+
1636+
'':::::
1637+
function hWStr2Args( byval txt as const wstring ptr, res() as DWSTRING ) as integer
1638+
1639+
dim as integer t = 0
1640+
dim as const WSTRING_CHAR ptr s = cast(const WSTRING_CHAR ptr, txt)
1641+
1642+
dim as integer prntcnt = 0
1643+
dim as uinteger c = CHAR_NULL
1644+
dim as integer max_t = 10
1645+
1646+
if( txt = NULl ) then
1647+
return 0
1648+
end if
1649+
1650+
#define PeekChar() cast( uinteger, s[0] )
1651+
#define SkipChar() s += 1
1652+
#define ReadChar(c) DWstrConcatAssign( res(t-1), wchr(c) ) : s += 1
1653+
1654+
redim res( 0 to max_t-1 ) as DWSTRING
1655+
1656+
do
1657+
c = PeekChar()
1658+
if (c = CHAR_TAB) or (c = CHAR_SPACE) then
1659+
SkipChar()
1660+
else
1661+
exit do
1662+
end if
1663+
loop
1664+
1665+
'' no arguments?
1666+
if( c = CHAR_NULL ) then
1667+
return 0
1668+
end if
1669+
1670+
'' ok, there's at least one argument
1671+
t += 1
1672+
1673+
'' scan for arguments
1674+
do
1675+
c = PeekChar()
1676+
select case c
1677+
case CHAR_NULL
1678+
exit do
1679+
1680+
case CHAR_LPRNT
1681+
prntcnt += 1
1682+
1683+
case CHAR_RPRNT
1684+
if( prntcnt > 0 ) then
1685+
prntcnt -= 1
1686+
end if
1687+
1688+
case CHAR_COMMA
1689+
if( prntcnt = 0 ) then
1690+
t += 1
1691+
if( t > max_t ) then
1692+
max_t += 10
1693+
redim preserve res( 0 to max_t - 1 )
1694+
end if
1695+
SkipChar()
1696+
continue do
1697+
end if
1698+
1699+
case CHAR_QUOTE, CHAR_EXCL, CHAR_DOLAR
1700+
dim as integer escaped = env.opt.escapestr
1701+
if( c <> CHAR_QUOTE ) then
1702+
escaped = ( c = CHAR_EXCL )
1703+
1704+
'' '!' | '$'
1705+
ReadChar(c)
1706+
c = PeekChar()
1707+
if( c <> CHAR_QUOTE ) then
1708+
continue do
1709+
end if
1710+
1711+
end if
1712+
1713+
'' '"'
1714+
ReadChar(c)
1715+
1716+
do
1717+
c = PeekChar()
1718+
if( c = CHAR_NULL ) then
1719+
exit do
1720+
end if
1721+
1722+
'' '"' | '\\' | any other string char
1723+
ReadChar(c)
1724+
if( c = CHAR_QUOTE ) then
1725+
1726+
c = PeekChar()
1727+
if( c <> CHAR_QUOTE ) then
1728+
exit do
1729+
end if
1730+
1731+
'' '"'
1732+
ReadChar(c)
1733+
1734+
elseif( c = CHAR_RSLASH ) then
1735+
1736+
c = PeekChar()
1737+
select case c
1738+
case CHAR_QUOTE, CHAR_RSLASH
1739+
'' '"' | '\\'
1740+
ReadChar(c)
1741+
end select
1742+
1743+
end if
1744+
loop
1745+
continue do
1746+
1747+
case CHAR_SLASH
1748+
1749+
'' '/'
1750+
ReadChar(c)
1751+
1752+
c = PeekChar()
1753+
if( c <> CHAR_APOST ) then
1754+
continue do
1755+
end if
1756+
1757+
'' '''
1758+
ReadChar(c)
1759+
1760+
do
1761+
c = PeekChar()
1762+
if( c = CHAR_NULL ) then
1763+
exit do
1764+
end if
1765+
1766+
'' ''' | any other comment char
1767+
ReadChar(c)
1768+
1769+
if( c = CHAR_APOST ) then
1770+
c = PeekChar()
1771+
if( c = CHAR_SLASH ) then
1772+
'' '/'
1773+
ReadChar(c)
1774+
exit do
1775+
end if
1776+
end if
1777+
1778+
loop
1779+
continue do
1780+
1781+
case CHAR_APOST
1782+
while( c <> CHAR_NULL )
1783+
'' ''' or any comment char to end of line
1784+
ReadChar(c)
1785+
c = PeekChar()
1786+
wend
1787+
exit do
1788+
1789+
end select
1790+
1791+
'' any other char not handled above
1792+
ReadChar(c)
1793+
1794+
loop
1795+
1796+
function = t
1797+
1798+
end function

src/compiler/hlp-str.bi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef __HELP_STR_BI__
22
#define __HELP_STR_BI__
3+
#include once "dstr.bi"
34

45
declare sub ZstrAssign _
56
( _
@@ -138,12 +139,16 @@ declare function hIsValidHexDigit( byval ch as integer ) as integer
138139

139140
declare function hStr2long( byref txt as string, byref value as long ) as integer
140141

142+
declare function hWStr2long( byref txt as wstring, byref value as long ) as integer
143+
141144
declare sub hSplitStr(byref txt as string, byref del as string, res() as string)
142145

143146
declare function hStr2Tok(byval txt as const zstring ptr, res() as string) as integer
144147

145148
declare function hStr2Args(byval txt as const zstring ptr, res() as string) as integer
146149

150+
declare function hWStr2Args( byval txt as const wstring ptr, res() as DWSTRING ) as integer
151+
147152
'':::::
148153
#define ZstrAllocate(chars) xallocate( chars + 1 )
149154

0 commit comments

Comments
 (0)