Skip to content

Commit

Permalink
fbc: nested types - anonymous inner types
Browse files Browse the repository at this point in the history
- don't allow named types|unions inside an anonymous type|union

   type T1
     a as integer
     union           '' anoymous inner union
       b as integer
       type NAMED1   '' do not allow named type
     end union
   end type

- move changelog.txt message to avoid conflicts
  • Loading branch information
jayrm committed Oct 9, 2022
1 parent d8e6f21 commit 28d771f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Version 1.10.0
- makefile: 'DISABLE_GAS64_DEBUG=1' makefile configuration option to disable debugging comments in gas64 asm files
- gfxlib2: add FB.GET_SCANLINE_SIZE to fbgfx.bi and ScreenControl() to get current internal scan line size multiplier
- gfxlib2: SCREENCONTROL: add getters for GL parameters - new GET_GL_* constants in fbgfx.bi
- fbc: allow a TYPE or UNION to be declared inside another TYPE or UNION to allow declaration of inner named types. Support c++ name mangling parameters of inner types.
- Name mangling for c++ 'char' through BYTE/UBYTE parameters using the form "[unsigned] byte alias "char". Data type size is still 8 byte signed/unsigned from fbc side, but will mangled as 'char'; neither signed nor unsigned for the c++ side.
- Support 'SOURCE_DATE_EPOCH' environment variable for controlling the instrinsic __DATE__, __DATE_ISO__, __TIME__ macros. This in turn controls __FB_BUILD_DATE__ and __FB_BUILD_DATE_ISO__ macros when building the compiler. Report error message on malformed values.
- fbc: allow a TYPE or UNION to be declared inside another TYPE or UNION to allow declaration of inner named types. Support c++ name mangling parameters of inner types.

[fixed]
- gas64: missing restoring of use of one virtual register on sqr for float (SARG)
Expand Down
13 changes: 10 additions & 3 deletions src/compiler/parser-decl-struct.bas
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,18 @@ decl_inner:
case FB_TK_AS
hTypeElementDecl( FB_TK_DIM, s, attrib )

'' Otherwise TYPE|UNION starts an inner declaration
'' Otherwise TYPE|UNION maybe starts an inner declaration
case else
'' Inside an anonymous type|union? Don't allow named types
if( symbIsStruct( s ) andalso symbGetUDTIsAnon( s ) ) then
hTypeElementDecl( FB_TK_DIM, s, attrib )

'' allow named UNION|TYPE to be nested in another UNION|TYPE
hBeginNesting( s )
cTypeDecl( attrib )
else
hBeginNesting( s )
cTypeDecl( attrib )

end if

end select

Expand Down
4 changes: 4 additions & 0 deletions tests/syntax/r/dos/type-decl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
2 errors for field members as parent type
type-decl.bas(9) error 24: Invalid data types in 'member1 as T1'
type-decl.bas(10) error 24: Invalid data types, found 'member2' in 'as T1 member2'
---
2 errors for named type/union in an anonymous type/union
type-decl.bas(24) error 17: Syntax error, found 'NAMED1' in 'type NAMED1'
type-decl.bas(31) error 17: Syntax error, found 'NAMED2' in 'union NAMED2'
4 changes: 4 additions & 0 deletions tests/syntax/r/linux-x86/type-decl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
2 errors for field members as parent type
type-decl.bas(9) error 24: Invalid data types in 'member1 as T1'
type-decl.bas(10) error 24: Invalid data types, found 'member2' in 'as T1 member2'
---
2 errors for named type/union in an anonymous type/union
type-decl.bas(24) error 17: Syntax error, found 'NAMED1' in 'type NAMED1'
type-decl.bas(31) error 17: Syntax error, found 'NAMED2' in 'union NAMED2'
4 changes: 4 additions & 0 deletions tests/syntax/r/linux-x86_64/type-decl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
2 errors for field members as parent type
type-decl.bas(9) error 24: Invalid data types in 'member1 as T1'
type-decl.bas(10) error 24: Invalid data types, found 'member2' in 'as T1 member2'
---
2 errors for named type/union in an anonymous type/union
type-decl.bas(24) error 17: Syntax error, found 'NAMED1' in 'type NAMED1'
type-decl.bas(31) error 17: Syntax error, found 'NAMED2' in 'union NAMED2'
4 changes: 4 additions & 0 deletions tests/syntax/r/win32/type-decl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
2 errors for field members as parent type
type-decl.bas(9) error 24: Invalid data types in 'member1 as T1'
type-decl.bas(10) error 24: Invalid data types, found 'member2' in 'as T1 member2'
---
2 errors for named type/union in an anonymous type/union
type-decl.bas(24) error 17: Syntax error, found 'NAMED1' in 'type NAMED1'
type-decl.bas(31) error 17: Syntax error, found 'NAMED2' in 'union NAMED2'
4 changes: 4 additions & 0 deletions tests/syntax/r/win64/type-decl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
2 errors for field members as parent type
type-decl.bas(9) error 24: Invalid data types in 'member1 as T1'
type-decl.bas(10) error 24: Invalid data types, found 'member2' in 'as T1 member2'
---
2 errors for named type/union in an anonymous type/union
type-decl.bas(24) error 17: Syntax error, found 'NAMED1' in 'type NAMED1'
type-decl.bas(31) error 17: Syntax error, found 'NAMED2' in 'union NAMED2'
21 changes: 21 additions & 0 deletions tests/syntax/type-decl.bas
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@ namespace n1
end type
end type
end namespace

'' ------------------------------------
#print "---"
#print "2 errors for named type/union in an anonymous type/union"

namespace n2
type T1
a as integer
union
b as integer
type NAMED1
end union
end type
union U1
a as integer
type
b as integer
union NAMED2
end type
end union
end namespace

0 comments on commit 28d771f

Please sign in to comment.