14 #define LEX_FLAGS (LEXCHECK_NOWHITESPC
or _
46 errReportEx( errnum,
"expanding: " + *symbGetName( s ) )
52 if (pp.skipping = FALSE)
then
53 if (s->def.flags
and FB_DEFINE_FLAGS_NOGCC)
then
54 if( env.clopt.backend = FB_BACKEND_GCC )
then
66 byval s
as FBSYMBOL
ptr _
69 dim as FB_DEFPARAM
ptr param =
any, nextparam =
any
70 dim as FB_DEFTOK
ptr dt =
any
71 dim as FBTOKEN t =
any
73 dim as integer prntcnt =
any, num =
any, reached_vararg =
any, is_variadic =
any
74 dim as zstring ptr argtext =
any
92 param = symbGetDefineHeadParam( s )
93 if( param <> NULL )
then
100 reached_vararg = FALSE
103 is_variadic = ((s->def.flags
and FB_DEFINE_FLAGS_VARIADIC) <> 0)
113 nextparam = symbGetDefParamNext( param )
116 if( nextparam = NULL )
then
117 reached_vararg = is_variadic
127 select case as const t.id
136 if( prntcnt = 0 )
then
146 if( prntcnt = 1 )
then
147 if( reached_vararg = FALSE )
then
152 case FB_TK_EOL, FB_TK_EOF
159 if( argtb <> NULL )
then
160 if( t.dtype <> FB_DATATYPE_WCHAR )
then
169 with( argtb->
tb(num) )
171 if( .
text.
data )
then
173 if( (.
text.
data[0][0] = CHAR_SPACE)
or _
174 (.
text.
data[0][
len( *.
text.
data )-1] = CHAR_SPACE) )
then
182 if( prntcnt = 0 )
then
189 if( (symbGetDefParamNext( nextparam ) <> NULL)
or (
not is_variadic) )
then
194 assert( num < (symbGetDefineParams( s ) - 1) )
199 loop while( num < (symbGetDefineParams( s ) - 1) )
206 if( nextparam = NULL )
then
222 dt = symbGetDefineHeadToken( s )
224 select case as const( symbGetDefTokType( dt ) )
226 case FB_DEFTOK_TYPE_PARAM
227 assert( symbGetDefTokParamNum( dt ) <= num )
228 argtext = argtb->
tb( symbGetDefTokParamNum( dt ) ).
text.
data
231 if( argtext <> NULL )
then
236 case FB_DEFTOK_TYPE_PARAMSTR
237 assert( symbGetDefTokParamNum( dt ) <= num )
238 argtext = argtb->
tb( symbGetDefTokParamNum( dt ) ).
text.
data
241 if( argtext <> NULL )
then
252 case FB_DEFTOK_TYPE_TEX
253 text += *symbGetDefTokText( dt )
256 case FB_DEFTOK_TYPE_TEXW
257 text +=
str( *symbGetDefTokTextW( dt ) )
261 dt = symbGetDefTokNext( dt )
273 if( lex.ctx->deflen = 0 )
then
279 function =
len(
text )
286 byval s
as FBSYMBOL
ptr _
289 static as string text
290 dim as integer lgt =
any
295 if( symbGetDefineParams( s ) > 0 )
then
306 if( symbGetDefineCallback( s ) <> NULL )
then
308 if(
bit( symbGetDefineFlags( s ), 0 ) = 0 )
then
309 text =
"$" + QUOTE + symbGetDefineCallback( s )( ) + QUOTE
311 text = symbGetDefineCallback( s )( )
314 if( lex.ctx->deflen = 0 )
then
326 if( symbGetDefineIsArgless( s ) )
then
342 if( symbGetType( s ) <> FB_DATATYPE_WCHAR )
then
343 if( lex.ctx->deflen = 0 )
then
344 DZstrAssign( lex.ctx->deftext, symbGetDefineText( s ) )
347 *symbGetDefineText( s ) + *lex.ctx->defptr )
351 if( lex.ctx->deflen = 0 )
then
352 DZstrAssignW( lex.ctx->deftext, symbGetDefineTextW( s ) )
355 str( *symbGetDefineTextW( s ) ) + *lex.ctx->defptr )
359 lgt = symbGetLen( s )
365 lex.ctx->defptr = lex.ctx->deftext.
data
366 lex.ctx->deflen += lgt
369 lex.ctx->currchar =
cuint( INVALID )
377 byval s
as FBSYMBOL
ptr _
380 dim as FB_DEFPARAM
ptr param =
any, nextparam =
any
381 dim as FB_DEFTOK
ptr dt =
any
382 dim as FBTOKEN t =
any
384 dim as integer prntcnt =
any, lgt =
any, num =
any, reached_vararg =
any, is_variadic =
any
385 dim as wstring ptr argtext =
any
386 static as DWSTRING
text
403 param = symbGetDefineHeadParam( s )
404 if( param <> NULL )
then
411 reached_vararg = FALSE
414 is_variadic = ((s->def.flags
and FB_DEFINE_FLAGS_VARIADIC) <> 0)
424 nextparam = symbGetDefParamNext( param )
427 if( nextparam = NULL )
then
428 reached_vararg = is_variadic
438 select case as const t.id
447 if( prntcnt = 0 )
then
457 if( prntcnt = 1 )
then
458 if( reached_vararg = FALSE )
then
464 case FB_TK_EOL, FB_TK_EOF
471 if( argtb <> NULL )
then
472 if( t.dtype <> FB_DATATYPE_WCHAR )
then
481 with( argtb->
tb(num) )
483 if( .
textw.
data )
then
485 if( (.
textw.
data[0][0] = CHAR_SPACE)
or _
486 (.
textw.
data[0][
len( *.
textw.
data )-1] = CHAR_SPACE) )
then
494 if( prntcnt = 0 )
then
501 if( (symbGetDefParamNext( nextparam ) <> NULL)
or (
not is_variadic) )
then
506 assert( num < (symbGetDefineParams( s ) - 1) )
511 loop while( num < (symbGetDefineParams( s ) - 1) )
518 if( nextparam = NULL )
then
535 dt = symbGetDefineHeadToken( s )
537 select case as const( symbGetDefTokType( dt ) )
539 case FB_DEFTOK_TYPE_PARAM
540 assert( symbGetDefTokParamNum( dt ) <= num )
541 argtext = argtb->
tb( symbGetDefTokParamNum( dt ) ).
textw.
data
544 if( argtext <> NULL )
then
549 case FB_DEFTOK_TYPE_PARAMSTR
550 assert( symbGetDefTokParamNum( dt ) <= num )
551 argtext = argtb->
tb( symbGetDefTokParamNum( dt ) ).
textw.
data
554 if( argtext <> NULL )
then
562 case FB_DEFTOK_TYPE_TEX
566 case FB_DEFTOK_TYPE_TEXW
571 dt = symbGetDefTokNext( dt )
583 if( lex.ctx->deflen = 0 )
then
589 function =
len( *
text.
data )
596 byval s
as FBSYMBOL
ptr _
599 static as DWSTRING
text
600 dim as integer lgt =
any
605 if( symbGetDefineParams( s ) > 0 )
then
616 if( symbGetDefineCallback( s ) <> NULL )
then
618 if(
bit( symbGetDefineFlags( s ), 0 ) = 0 )
then
624 if( lex.ctx->deflen = 0 )
then
630 lgt =
len( *
text.
data )
635 if( symbGetDefineIsArgless( s ) )
then
651 if( symbGetType( s ) <> FB_DATATYPE_WCHAR )
then
652 if( lex.ctx->deflen = 0 )
then
653 DWstrAssignA( lex.ctx->deftextw, symbGetDefineText( s ) )
656 wstr( *symbGetDefineText( s ) ) + *lex.ctx->defptrw )
660 if( lex.ctx->deflen = 0 )
then
661 DWstrAssign( lex.ctx->deftextw, symbGetDefineTextW( s ) )
664 *symbGetDefineTextW( s ) + *lex.ctx->defptrw )
668 lgt = symbGetLen( s )
674 lex.ctx->defptrw = lex.ctx->deftextw.
data
675 lex.ctx->deflen += lgt
684 byval s
as FBSYMBOL
ptr _
688 if( s = lex.ctx->currmacro )
then
696 if( lex.ctx->currmacro = NULL )
then
697 lex.ctx->currmacro = s
700 if( env.inf.
format = FBFILE_FORMAT_ASCII )
then
707 lex.ctx->currchar =
cuint( INVALID )
714 byval tokhead
as FB_DEFTOK
ptr,
_
715 byval toktail
as FB_DEFTOK
ptr _
719 do while( toktail <> NULL )
721 if( symbGetDefTokType( toktail ) <> FB_DEFTOK_TYPE_TEX )
then
725 select case as const (*symbGetDefTokText( toktail ))[0]
727 case CHAR_SPACE, CHAR_TAB, CHAR_LF
735 if( toktail = NULL )
then
746 byval args
as integer,
_
747 byval paramhead
as FB_DEFPARAM
ptr,
_
748 byval ismultiline
as integer _
751 static as zstring * FB_MAXNAMELEN+1 arg
752 dim as FB_DEFPARAM
ptr param =
any
753 dim as FB_DEFTOK
ptr toktail = NULL, tokhead = NULL
754 dim as integer addquotes =
any, nestedcnt = 0
761 if( ismultiline )
then
768 if( ismultiline = FALSE )
then
773 if( tokhead <> NULL )
then
783 case FB_TK_COMMENT, FB_TK_REM
784 if( ismultiline = FALSE )
then
792 case FB_TK_EOL, FB_TK_EOF
801 (
not LEXCHECK_NOWHITESPC) )
810 if( ismultiline )
then
815 case FB_TK_PP_ENDMACRO
816 if( ismultiline )
then
818 if( nestedcnt = 0 )
then
839 case CHAR_SPACE, CHAR_TAB
842 if( tokhead <> NULL )
then
856 case FB_TKCLASS_STRLITERAL
859 if( env.inf.
format = FBFILE_FORMAT_ASCII )
then
861 if( tokhead = NULL )
then
870 if( tokhead = NULL )
then
880 case FB_TKCLASS_IDENTIFIER, FB_TKCLASS_KEYWORD, FB_TKCLASS_QUIRKWD
882 if( tokhead = NULL )
then
889 param =
hashLookup( @symb.def.paramhash, arg )
892 if( param <> NULL )
then
893 if( addquotes = FALSE )
then
894 symbSetDefTokType( toktail, FB_DEFTOK_TYPE_PARAM )
896 symbSetDefTokType( toktail, FB_DEFTOK_TYPE_PARAMSTR )
899 symbSetDefTokParamNum( toktail, symbGetDefParamNum( param ) )
917 if( tokhead = NULL )
then
935 byval sym
as FBSYMBOL
ptr,
_
936 byval defname
as zstring ptr,
_
937 byval isargless
as integer,
_
938 byval ismultiline
as integer _
941 dim as zstring ptr text =
any
942 dim as wstring ptr textw =
any
944 if( env.inf.
format = FBFILE_FORMAT_ASCII )
then
949 if( sym <> NULL )
then
950 if( (symbGetDefineParams( sym ) > 0)
or _
951 (symbGetType( sym ) <> FB_DATATYPE_CHAR) )
then
953 elseif( (*symbGetDefineText( sym ) <> *
text) )
then
966 if( sym <> NULL )
then
967 if( (symbGetDefineParams( sym ) > 0)
or _
968 (symbGetType( sym ) <> FB_DATATYPE_WCHAR) )
then
970 elseif( (*symbGetDefineTextW( sym ) <> *
textw) )
then
1006 sub ppDefine(
byval ismultiline
as integer )
1007 static as zstring * FB_MAXNAMELEN+1 defname
1008 dim as integer params =
any, isargless =
any, flags =
any, is_variadic =
any
1009 dim as FB_DEFPARAM
ptr paramhead =
any, lastparam =
any
1010 dim as FBSYMBOL
ptr sym =
any
1011 dim as FBSYMCHAIN
ptr chain_ =
any
1012 dim as FBSYMBOL
ptr base_parent =
any
1013 dim as FB_DEFTOK
ptr tokhead =
any
1018 chain_ =
cIdentifier( base_parent, FB_IDOPT_ISDECL
or FB_IDOPT_DEFAULT )
1021 if( ismultiline )
then
1022 flags
and=
not LEXCHECK_NOWHITESPC
1028 errReport( FB_ERRMSG_EXPECTEDIDENTIFIER )
1034 errReport( FB_ERRMSG_CANTINCLUDEPERIODS )
1037 if( chain_ <> NULL )
then
1039 if( symbIsDefine( sym ) = FALSE )
then
1063 case FB_TKCLASS_IDENTIFIER, FB_TKCLASS_KEYWORD, FB_TKCLASS_QUIRKWD
1067 errReport( FB_ERRMSG_EXPECTEDIDENTIFIER )
1072 if( lastparam = NULL )
then
1079 if( params >= FB_MAXDEFINEARGS )
then
1086 if( paramhead = NULL )
then
1087 paramhead = lastparam
1111 lexSkipToken( LEX_FLAGS
and (
not LEXCHECK_NOWHITESPC) )
1114 if( ismultiline = FALSE )
then
1123 if( params = 0 )
then
1130 if( sym <> NULL )
then
1136 FB_DEFINE_FLAGS_VARIADIC,
_
1137 FB_DEFINE_FLAGS_NONE ) )