Skip to content

Commit 46c2f30

Browse files
committed
Make #print typeof() differentiate between Zstring and Zstring * 1
This should make it more accurate. dim pz as zstring ptr #print typeof(*pz) gave "ZSTRING * 1" previously, which may be a bit confusing, considering that a ZSTRING PTR doesn't have a length encoded in the type. It's not like a ZSTRING * N variable... now this would just print "ZSTRING".
1 parent e859301 commit 46c2f30

23 files changed

+200
-88
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version 1.05.0
1212
- 1.04.0 regression: Under -gen gcc -asm att, support for gcc-style inline asm was broken
1313
- ld was warning about unsupported linker options on OS X
1414
- BYREF fixed-length strings (e.g. BYREF myParameter AS ZSTRING * 10) now trigger a compiler error since they are unsupported
15+
- #print typeof() output now differentiates between ZSTRING and ZSTRING * N (ZSTRING without size is produced by dereferencing a ZSTRING PTR, or BYREF AS ZSTRING)
1516

1617

1718
Version 1.04.0

src/compiler/ast-misc.bas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,14 +1214,16 @@ sub astSetType _
12141214

12151215
end sub
12161216

1217-
function astSizeOf( byval n as ASTNODE ptr ) as longint
1217+
function astSizeOf( byval n as ASTNODE ptr, byref is_fixlenstr as integer ) as longint
1218+
is_fixlenstr = FALSE
12181219
function = symbCalcLen( n->dtype, n->subtype )
12191220

12201221
'' If it's a STRING * N, we must get the real length from the
12211222
'' associated symbol, since the N isn't encoded in the dtype/subtype.
12221223
select case( typeGetDtAndPtrOnly( n->dtype ) )
12231224
case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR, FB_DATATYPE_FIXSTR
12241225
if( n->sym ) then
1226+
is_fixlenstr = TRUE
12251227
function = symbGetLen( n->sym )
12261228
end if
12271229
end select

src/compiler/ast.bi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ declare sub astSetType _
12951295
byval subtype as FBSYMBOL ptr _
12961296
)
12971297

1298-
declare function astSizeOf( byval n as ASTNODE ptr ) as longint
1298+
declare function astSizeOf( byval n as ASTNODE ptr, byref is_fixlenstr as integer = FALSE ) as longint
12991299
declare function astIsAccessToLocal( byval expr as ASTNODE ptr ) as integer
13001300
declare function astIsRelationalBop( byval n as ASTNODE ptr ) as integer
13011301

src/compiler/parser-decl-const.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private sub hGetType( byref dtype as integer, byref subtype as FBSYMBOL ptr )
1212
if( lexGetToken( ) = FB_TK_AS ) then
1313
lexSkipToken( )
1414

15-
if( cSymbolType( dtype, subtype, 0 ) = FALSE ) then
15+
if( cSymbolType( dtype, subtype ) = FALSE ) then
1616
errReport( FB_ERRMSG_EXPECTEDIDENTIFIER )
1717
dtype = FB_DATATYPE_INTEGER
1818
subtype = NULL

src/compiler/parser-decl-proc-params.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private function hParamDecl _
396396
options or= FB_SYMBTYPEOPT_ISBYREF
397397
end if
398398

399-
if( cSymbolType( dtype, subtype, 0, options ) = FALSE ) then
399+
if( cSymbolType( dtype, subtype, , , options ) = FALSE ) then
400400
hParamError( proc, id )
401401
'' error recovery: fake type
402402
dtype = FB_DATATYPE_INTEGER

src/compiler/parser-decl-symbtype.bas

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ function cTypeOrExpression _
149149
byval tk as integer, _
150150
byref dtype as integer, _
151151
byref subtype as FBSYMBOL ptr, _
152-
byref lgt as longint _
152+
byref lgt as longint, _
153+
byref is_fixlenstr as integer _
153154
) as ASTNODE ptr
154155

155156
dim as ASTNODE ptr expr = any
@@ -211,7 +212,7 @@ function cTypeOrExpression _
211212

212213
if( maybe_type ) then
213214
'' Parse as type
214-
if( cSymbolType( dtype, subtype, lgt, FB_SYMBTYPEOPT_NONE ) ) then
215+
if( cSymbolType( dtype, subtype, lgt, is_fixlenstr, FB_SYMBTYPEOPT_NONE ) ) then
215216
'' Successful -- it's a type, not an expression
216217
ambigioussizeof.maybeWarn( tk, TRUE )
217218
return NULL
@@ -235,13 +236,14 @@ sub cTypeOf _
235236
( _
236237
byref dtype as integer, _
237238
byref subtype as FBSYMBOL ptr, _
238-
byref lgt as longint _
239+
byref lgt as longint, _
240+
byref is_fixlenstr as integer _
239241
)
240242

241243
dim as ASTNODE ptr expr = any
242244

243245
'' Type or an Expression
244-
expr = cTypeOrExpression( FB_TK_TYPEOF, dtype, subtype, lgt )
246+
expr = cTypeOrExpression( FB_TK_TYPEOF, dtype, subtype, lgt, is_fixlenstr )
245247

246248
'' Was it a type?
247249
if( expr = NULL ) then
@@ -252,7 +254,7 @@ sub cTypeOf _
252254

253255
dtype = astGetFullType( expr )
254256
subtype = astGetSubtype( expr )
255-
lgt = astSizeOf( expr )
257+
lgt = astSizeOf( expr, is_fixlenstr )
256258

257259
astDelTree( expr )
258260
end sub
@@ -306,16 +308,18 @@ function cSymbolType _
306308
byref dtype as integer, _
307309
byref subtype as FBSYMBOL ptr, _
308310
byref lgt as longint, _
311+
byref is_fixlenstr as integer, _
309312
byval options as FB_SYMBTYPEOPT _
310313
) as integer
311314

312315
dim as integer isunsigned = any, isfunction = any
313316

314317
function = FALSE
315318

316-
lgt = 0
317319
dtype = FB_DATATYPE_INVALID
318320
subtype = NULL
321+
lgt = 0
322+
is_fixlenstr = FALSE
319323

320324
dim as integer is_const = FALSE
321325
dim as integer ptr_cnt = 0
@@ -332,7 +336,7 @@ function cSymbolType _
332336
end if
333337

334338
'' datatype
335-
cTypeOf( dtype, subtype, lgt )
339+
cTypeOf( dtype, subtype, lgt, is_fixlenstr )
336340

337341
'' ')'
338342
if( hMatch( CHAR_RPRNT ) = FALSE ) then
@@ -520,6 +524,7 @@ function cSymbolType _
520524
dtype = symbGetFullType( sym )
521525
subtype = symbGetSubtype( sym )
522526
lgt = symbGetLen( sym )
527+
is_fixlenstr = symbGetIsFixLenStr( sym )
523528
ptr_cnt += typeGetPtrCnt( dtype )
524529
exit do, do
525530
end select
@@ -576,6 +581,7 @@ function cSymbolType _
576581

577582
'' expr
578583
lgt = cConstIntExpr( cEqInParensOnlyExpr( ) )
584+
is_fixlenstr = TRUE
579585

580586
select case as const typeGet( dtype )
581587
case FB_DATATYPE_STRING

src/compiler/parser-decl-typedef.bas

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ private function hReadType _
5454
( _
5555
byref dtype as integer, _
5656
byref subtype as FBSYMBOL ptr, _
57-
byref lgt as longint _
57+
byref lgt as longint, _
58+
byref is_fixlenstr as integer _
5859
) as zstring ptr
5960

6061
static as zstring * FB_MAXNAMELEN+1 tname
6162

62-
if( cSymbolType( dtype, subtype, lgt, FB_SYMBTYPEOPT_ALLOWFORWARD ) ) then
63+
if( cSymbolType( dtype, subtype, lgt, is_fixlenstr, FB_SYMBTYPEOPT_ALLOWFORWARD ) ) then
6364
return NULL
6465
end if
6566

@@ -95,7 +96,8 @@ private sub hAddForwardRef _
9596
byval pfwdname as zstring ptr, _
9697
byref dtype as integer, _
9798
byref subtype as FBSYMBOL ptr, _
98-
byref lgt as longint _
99+
byref lgt as longint, _
100+
byref is_fixlenstr as integer _
99101
)
100102

101103
dim as integer ptrcount = typeGetPtrCnt( dtype )
@@ -115,6 +117,7 @@ private sub hAddForwardRef _
115117

116118
subtype = NULL
117119
lgt = 0
120+
is_fixlenstr = FALSE
118121
else
119122

120123
'' The typeJoin()'s will remove the PTR's off the typedef's type, but we
@@ -167,16 +170,21 @@ private sub hAddTypedef _
167170
byval pfwdname as zstring ptr, _
168171
byval dtype as integer, _
169172
byval subtype as FBSYMBOL ptr, _
170-
byval lgt as longint _
173+
byval lgt as longint, _
174+
byval is_fixlenstr as integer _
171175
)
172176

173177
'' Forward ref? Note: may update dtype & co
174178
if( pfwdname <> NULL ) then
175-
hAddForwardRef( pid, pfwdname, dtype, subtype, lgt )
179+
hAddForwardRef( pid, pfwdname, dtype, subtype, lgt, is_fixlenstr )
176180
end if
177181

178182
dim as FBSYMBOL ptr typedef = symbAddTypedef( pid, dtype, subtype, lgt )
179-
if( typedef = NULL ) then
183+
if( typedef ) then
184+
if( is_fixlenstr ) then
185+
symbSetIsFixLenStr( typedef )
186+
end if
187+
else
180188
'' check if the dup definition is different
181189
dim as integer isdup = TRUE
182190
dim as FBSYMBOL ptr sym = any
@@ -235,35 +243,28 @@ end function
235243

236244
'' MultipleTypedef = TYPE AS SymbolType symbol (',' symbol)*
237245
sub cTypedefMultDecl( )
238-
dim as zstring ptr pfwdname = any, pid = any
239-
dim as integer dtype = any
240-
dim as longint lgt = any
241-
dim as FBSYMBOL ptr subtype = any
242-
243246
if( cCompStmtIsAllowed( FB_CMPSTMT_MASK_DECL or FB_CMPSTMT_MASK_CODE ) = FALSE ) then
244247
hSkipStmt( )
245248
exit sub
246249
end if
247250

248-
'' AS
249-
lexSkipToken( )
251+
'' AS
252+
lexSkipToken( )
250253

251-
'' SymtolType
252-
pfwdname = hReadType( dtype, subtype, lgt )
254+
'' SymtolType
255+
dim as integer dtype, is_fixlenstr
256+
dim as longint lgt
257+
dim as FBSYMBOL ptr subtype
258+
var pfwdname = hReadType( dtype, subtype, lgt, is_fixlenstr )
253259

254-
do
255-
'' Parse the ID
256-
pid = hReadId( )
257-
258-
hAddTypedef( pid, pfwdname, dtype, subtype, lgt )
260+
do
261+
'' Parse the ID
262+
var pid = hReadId( )
259263

260-
'' ','?
261-
if( lexGetToken( ) <> CHAR_COMMA ) then
262-
exit do
263-
end if
264+
hAddTypedef( pid, pfwdname, dtype, subtype, lgt, is_fixlenstr )
264265

265-
lexSkipToken( )
266-
loop
266+
'' ','?
267+
loop while( hMatch( CHAR_COMMA ) )
267268
end sub
268269

269270
'' SingleTypedef = TYPE symbol AS SymbolType (',' symbol AS SymbolType)*
@@ -275,32 +276,26 @@ sub cTypedefSingleDecl( byval pid as zstring ptr )
275276
exit sub
276277
end if
277278

278-
dim as zstring ptr pfwdname = any
279-
dim as integer dtype = any
280-
dim as longint lgt = any
281-
dim as FBSYMBOL ptr subtype = any
282-
283-
do
284-
'' AS?
285-
if( lexGetToken( ) <> FB_TK_AS ) then
286-
errReport( FB_ERRMSG_SYNTAXERROR )
287-
else
288-
lexSkipToken( )
289-
end if
290-
291-
'' SymtolType
292-
pfwdname = hReadType( dtype, subtype, lgt )
279+
do
280+
'' AS?
281+
if( hMatch( FB_TK_AS ) = FALSE ) then
282+
errReport( FB_ERRMSG_SYNTAXERROR )
283+
end if
293284

294-
hAddTypedef( pid, pfwdname, dtype, subtype, lgt )
285+
'' SymtolType
286+
dim as integer dtype, is_fixlenstr
287+
dim as longint lgt
288+
dim as FBSYMBOL ptr subtype
289+
var pfwdname = hReadType( dtype, subtype, lgt, is_fixlenstr )
295290

296-
'' ','?
297-
if( lexGetToken( ) <> CHAR_COMMA ) then
298-
exit do
299-
end if
291+
hAddTypedef( pid, pfwdname, dtype, subtype, lgt, is_fixlenstr )
300292

301-
lexSkipToken( )
293+
'' ','?
294+
if( hMatch( CHAR_COMMA ) = FALSE ) then
295+
exit do
296+
end if
302297

303-
'' Parse the next ID
304-
pid = hReadId( )
305-
loop
298+
'' Parse the next ID
299+
pid = hReadId( )
300+
loop
306301
end sub

src/compiler/parser-decl-var.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sub hSymbolType _
4848
end if
4949

5050
'' parse the symbol type (INTEGER, STRING, etc...)
51-
if( cSymbolType( dtype, subtype, lgt, options ) = FALSE ) then
51+
if( cSymbolType( dtype, subtype, lgt, , options ) = FALSE ) then
5252
errReport( FB_ERRMSG_EXPECTEDIDENTIFIER )
5353
'' error recovery: fake a type
5454
dtype = FB_DATATYPE_INTEGER

src/compiler/parser-expr-binary.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function cIsExpression _
376376
'' SymbolType
377377
dim as integer dtype = any
378378
dim as FBSYMBOL ptr subtype = any
379-
if( cSymbolType( dtype, subtype, 0 ) = FALSE ) then
379+
if( cSymbolType( dtype, subtype ) = FALSE ) then
380380
return NULL
381381
end if
382382

src/compiler/parser-expr-unary.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private function hCast( byval options as AST_CONVOPT ) as ASTNODE ptr
300300
lexSkipToken( )
301301

302302
'' DataType
303-
if( cSymbolType( dtype, subtype, 0 ) = FALSE ) then
303+
if( cSymbolType( dtype, subtype ) = FALSE ) then
304304
errReport( FB_ERRMSG_SYNTAXERROR )
305305
'' error recovery: skip until ',', create a fake type
306306
hSkipUntil( CHAR_COMMA )

0 commit comments

Comments
 (0)