Skip to content

Commit b86ed4e

Browse files
committed
fbc: internal: refactor src/compiler/symb-define.bas
- factor out common code from hMacro_EvalZ(), hMacro_EvalW(), hDefQuerySymZ_cb() - add hArgInsertArgA() - insert argument from zstring - add hArgInsertArgW() - insert argument from wstring - add hArgAppendLFCHAR() - append EOL character to inserted argument
1 parent 80665c2 commit b86ed4e

File tree

1 file changed

+57
-102
lines changed

1 file changed

+57
-102
lines changed

src/compiler/symb-define.bas

Lines changed: 57 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,55 @@ end function
319319

320320
#define hIsTokenEndOfStream() ((lexGetToken() = FB_TK_EOL) orelse (lexGetToken() = FB_TK_EOF))
321321

322+
private sub hArgAppendLFCHAR( )
323+
'' Add an end of expression marker so that the parser
324+
'' doesn't read past the end of the expression text
325+
'' by appending an LFCHAR to the end of the expression
326+
'' It would be better to use the explicit EOF character,
327+
'' but we can't appened an extra NUL character to a zstring
328+
329+
'' ascii
330+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
331+
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
332+
lex.ctx->defptr = lex.ctx->deftext.data
333+
lex.ctx->deflen += len( LFCHAR )
334+
'' unicode
335+
else
336+
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
337+
lex.ctx->defptrw = lex.ctx->deftextw.data
338+
lex.ctx->deflen += len( LFCHAR )
339+
end if
340+
end sub
341+
342+
private sub hArgInsertArgA( byval arg as zstring ptr )
343+
'' ascii
344+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
345+
DZstrAssign( lex.ctx->deftext, *arg )
346+
lex.ctx->defptr = lex.ctx->deftext.data
347+
lex.ctx->deflen += len( *arg )
348+
'' unicode
349+
else
350+
DWstrAssignA( lex.ctx->deftextw, *arg )
351+
lex.ctx->defptrw = lex.ctx->deftextw.data
352+
lex.ctx->deflen += len( *arg )
353+
end if
354+
end sub
355+
356+
private sub hArgInsertArgW( byval arg as wstring ptr )
357+
'' ascii
358+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
359+
DZstrAssignW( lex.ctx->deftext, *arg )
360+
lex.ctx->defptr = lex.ctx->deftext.data
361+
lex.ctx->deflen += len( *arg )
362+
'' unicode
363+
else
364+
DWstrAssign( lex.ctx->deftextw, *arg )
365+
lex.ctx->defptrw = lex.ctx->deftextw.data
366+
lex.ctx->deflen += len( *arg )
367+
end if
368+
end sub
369+
370+
322371
private function hMacro_EvalZ( byval arg as zstring ptr, byval errnum as integer ptr ) as string
323372

324373
'' the expression should have already been handled in hLoadMacro|hLoadMacroW
@@ -345,36 +394,8 @@ private function hMacro_EvalZ( byval arg as zstring ptr, byval errnum as integer
345394
'' prevent cExpression from writing to .pp.bas file
346395
lex.ctx->reclevel += 1
347396

348-
'' ascii
349-
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
350-
DZstrAssign( lex.ctx->deftext, *arg )
351-
lex.ctx->defptr = lex.ctx->deftext.data
352-
lex.ctx->deflen += len( *arg )
353-
354-
'' Add an end of expression marker so that the parser
355-
'' doesn't read past the end of the expression text
356-
'' by appending an LFCHAR to the end of the expression
357-
'' It would be better to use the explicit EOF character,
358-
'' but we can't appened an extra NUL character to a zstring
359-
360-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
361-
lex.ctx->defptr = lex.ctx->deftext.data
362-
lex.ctx->deflen += len( LFCHAR )
363-
364-
'' unicode
365-
else
366-
DWstrAssignA( lex.ctx->deftextw, *arg )
367-
lex.ctx->defptrw = lex.ctx->deftextw.data
368-
lex.ctx->deflen += len( *arg )
369-
370-
'' Add an end of expression marker so that the parser
371-
'' (see above)
372-
373-
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
374-
lex.ctx->defptrw = lex.ctx->deftextw.data
375-
lex.ctx->deflen += len( LFCHAR )
376-
377-
end if
397+
hArgInsertArgA( arg )
398+
hArgAppendLFCHAR()
378399

379400
dim expr as ASTNODE ptr = cExpression( )
380401
var errmsg = FB_ERRMSG_OK
@@ -449,36 +470,8 @@ private function hMacro_EvalW( byval arg as wstring ptr, byval errnum as integer
449470
'' prevent cExpression from writing to .pp.bas file
450471
lex.ctx->reclevel += 1
451472

452-
'' ascii
453-
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
454-
DZstrAssignW( lex.ctx->deftext, *arg )
455-
lex.ctx->defptr = lex.ctx->deftext.data
456-
lex.ctx->deflen += len( *arg )
457-
458-
'' Add an end of expression marker so that the parser
459-
'' doesn't read past the end of the expression text
460-
'' by appending an LFCHAR to the end of the expression
461-
'' It would be better to use the explicit EOF character,
462-
'' but we can't appened an extra NUL character to a zstring
463-
464-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
465-
lex.ctx->defptr = lex.ctx->deftext.data
466-
lex.ctx->deflen += len( LFCHAR )
467-
468-
''unicode
469-
else
470-
DWstrAssign( lex.ctx->deftextw, *arg )
471-
lex.ctx->defptrw = lex.ctx->deftextw.data
472-
lex.ctx->deflen += len( *arg )
473-
474-
'' Add an end of expression marker so that the parser
475-
'' (see above)
476-
477-
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
478-
lex.ctx->defptrw = lex.ctx->deftextw.data
479-
lex.ctx->deflen += len( LFCHAR )
480-
481-
end if
473+
hArgInsertArgW( arg )
474+
hArgAppendLFCHAR()
482475

483476
dim expr as ASTNODE ptr = cExpression( )
484477
var errmsg = FB_ERRMSG_OK
@@ -1071,27 +1064,8 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum
10711064
'' prevent cExpression from writing to .pp.bas file
10721065
lex.ctx->reclevel += 1
10731066

1074-
'' ascii
1075-
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
1076-
DZstrAssign( lex.ctx->deftext, *sexpr )
1077-
lex.ctx->defptr = lex.ctx->deftext.data
1078-
lex.ctx->deflen += len( *sexpr )
1079-
1080-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
1081-
lex.ctx->defptr = lex.ctx->deftext.data
1082-
lex.ctx->deflen += len( LFCHAR )
1083-
1084-
'' unicode
1085-
else
1086-
DWstrAssignA( lex.ctx->deftextw, *sexpr )
1087-
lex.ctx->defptrw = lex.ctx->deftextw.data
1088-
lex.ctx->deflen += len( *sexpr )
1089-
1090-
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
1091-
lex.ctx->defptrw = lex.ctx->deftextw.data
1092-
lex.ctx->deflen += len( LFCHAR )
1093-
1094-
end if
1067+
hArgInsertArgA( sexpr )
1068+
hArgAppendLFCHAR()
10951069

10961070
'' if filtervalue is zero then set the default methods to use for
10971071
'' look-up depending on what we are looking for
@@ -1181,27 +1155,8 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum
11811155
'' reset the current lexer context and refresh the text to parse.
11821156
lexInit( FALSE, TRUE )
11831157

1184-
'' ascii
1185-
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
1186-
DZstrAssign( lex.ctx->deftext, *sexpr )
1187-
lex.ctx->defptr = lex.ctx->deftext.data
1188-
lex.ctx->deflen += len( *sexpr )
1189-
1190-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
1191-
lex.ctx->defptr = lex.ctx->deftext.data
1192-
lex.ctx->deflen += len( LFCHAR )
1193-
1194-
'' unicode
1195-
else
1196-
DWstrAssignA( lex.ctx->deftextw, *sexpr )
1197-
lex.ctx->defptrw = lex.ctx->deftextw.data
1198-
lex.ctx->deflen += len( *sexpr )
1199-
1200-
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
1201-
lex.ctx->defptrw = lex.ctx->deftextw.data
1202-
lex.ctx->deflen += len( LFCHAR )
1203-
1204-
end if
1158+
hArgInsertArgA( sexpr )
1159+
hArgAppendLFCHAR()
12051160
end if
12061161

12071162
end if

0 commit comments

Comments
 (0)