Skip to content

Commit

Permalink
mangling: change const type parameter mangling; and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrm committed Nov 10, 2018
1 parent dbfbac0 commit 44d3712
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/compiler/symb-mangling.bas
Original file line number Diff line number Diff line change
Expand Up @@ -452,49 +452,19 @@ sub symbMangleType _
dtype = typeJoin( dtype and (not FB_DATATYPE_INVALID), FB_DATATYPE_STRUCT )
end if

'' const array?
if( typeIsConst( dtype ) ) then
if( (options and FB_MANGLEOPT_KEEPTOPCONST) <> 0 ) then
mangled += "K"
symbMangleType( mangled, dtype, subtype )

hAbbrevAdd( dtype, subtype )
exit sub
end if
end if

'' reference?
if( typeIsRef( dtype ) ) then
'' const?
if( typeIsConst( dtype ) ) then
mangled += "RK"
else
mangled + = "R"
end if

symbMangleType( mangled, typeUnsetIsRef( dtype ), subtype )

hAbbrevAdd( dtype, subtype )
exit sub
end if

'' pointer? (must be checked/emitted before CONST)
if( typeIsPtr( dtype ) ) then
'' const?
if( typeIsConstAt( dtype, 1 ) ) then
mangled += "PK"
else
mangled += "P"
end if
mangled += "R"

symbMangleType( mangled, typeDeref( dtype ), subtype )
symbMangleType( mangled, typeUnsetIsRef( dtype ), subtype, FB_MANGLEOPT_KEEPTOPCONST )

hAbbrevAdd( dtype, subtype )
exit sub
end if

'' const?
if( typeGetConstMask( dtype ) ) then
if( typeIsConst( dtype ) ) then

'' The type has some CONST bits. For C++ mangling we remove the
'' toplevel one and recursively mangle the rest of the type.
''
Expand All @@ -503,12 +473,27 @@ sub symbMangleType _
'' difference. It's not allowed to have overloads that differ
'' only in BYVAL CONSTness. The CONST only matters if it's a
'' pointer or BYREF type.

if( (options and FB_MANGLEOPT_KEEPTOPCONST) <> 0 ) then
mangled += "K"
end if

symbMangleType( mangled, typeUnsetIsConst( dtype ), subtype )

hAbbrevAdd( dtype, subtype )
exit sub
end if

'' pointer?
if( typeIsPtr( dtype ) ) then
mangled += "P"

symbMangleType( mangled, typeDeref( dtype ), subtype, FB_MANGLEOPT_KEEPTOPCONST )

hAbbrevAdd( dtype, subtype )
exit sub
end if

''
'' Plain type without reference/pointer/const bits
''
Expand Down
94 changes: 94 additions & 0 deletions tests/cpp/cpp-mangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,98 @@ namespace cpp_mangle
return a;
}

/* byval const, pointer, reference */

double cpp_byval_const_double( const double a )
{
return a;
}

double cpp_byval_double_ptr( double* a )
{
return *a;
}

double cpp_byval_const_double_ptr( double const* a )
{
return *a;
}

double cpp_byval_double_const_ptr( double *const a )
{
return *a;
}

double cpp_byval_const_double_const_ptr( double const* const a )
{
return *a;
}

double cpp_byval_double_ptr_ptr( double** a )
{
return **a;
}

double cpp_byval_const_double_ptr_ptr( double const** a )
{
return **a;
}

double cpp_byval_double_const_ptr_ptr( double* const* a )
{
return **a;
}

double cpp_byval_double_ptr_const_ptr( double** const a )
{
return **a;
}

/* byval const, pointer, reference */

double cpp_byref_const_double( double const& a )
{
return a;
}

double cpp_byref_double_ptr( double* &a )
{
return *a;
}

double cpp_byref_const_double_ptr( double const*& a )
{
return *a;
}

double cpp_byref_double_const_ptr( double* const& a )
{
return *a;
}

double cpp_byref_const_double_const_ptr( double const* const& a )
{
return *a;
}

double cpp_byref_double_ptr_ptr( double**& a )
{
return **a;
}

double cpp_byref_const_double_ptr_ptr( double const**& a )
{
return **a;
}

double cpp_byref_double_const_ptr_ptr( double* const*& a )
{
return **a;
}

double cpp_byref_double_ptr_const_ptr( double** const& a )
{
return **a;
}

}
54 changes: 54 additions & 0 deletions tests/cpp/fbc-mangle.bas
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ namespace cpp_mangle
declare function cpp_byref_ulonglongint( byref a as unsigned longint ) as unsigned longint
declare function cpp_byref_slonglongint( byref a as longint ) as longint

declare function cpp_byval_const_double( byval a as const double ) as double
declare function cpp_byval_double_ptr( byval a as double ptr ) as double
declare function cpp_byval_const_double_ptr( byval a as const double ptr ) as double
declare function cpp_byval_double_const_ptr( byval a as double const ptr ) as double
declare function cpp_byval_const_double_const_ptr( byval a as const double const ptr ) as double
declare function cpp_byval_double_ptr_ptr( byval a as double ptr ptr ) as double
declare function cpp_byval_const_double_ptr_ptr( byval a as const double ptr ptr ) as double
declare function cpp_byval_double_const_ptr_ptr( byval a as double const ptr ptr ) as double
declare function cpp_byval_double_ptr_const_ptr( byval a as double ptr const ptr ) as double

declare function cpp_byref_const_double( byref a as const double ) as double
declare function cpp_byref_double_ptr( byref a as double ptr ) as double
declare function cpp_byref_const_double_ptr( byref a as const double ptr ) as double
declare function cpp_byref_double_const_ptr( byref a as double const ptr ) as double
declare function cpp_byref_const_double_const_ptr( byref a as const double const ptr ) as double
declare function cpp_byref_double_ptr_ptr( byref a as double ptr ptr ) as double
declare function cpp_byref_const_double_ptr_ptr( byref a as const double ptr ptr ) as double
declare function cpp_byref_double_const_ptr_ptr( byref a as double const ptr ptr ) as double
declare function cpp_byref_double_ptr_const_ptr( byref a as double ptr const ptr ) as double

end namespace

end extern
Expand Down Expand Up @@ -209,3 +229,37 @@ scope
ASSERT( cpp_byref_slonglongint(sll) = &h7fffffffffffffff )

end scope

scope
'' [const] pointers and references

dim d as double = 1
dim dp as double ptr = @d
dim dpp as double ptr ptr = @dp

ASSERT( cpp_byval_double( d ) = d )
ASSERT( cpp_byval_const_double( d ) = d )
ASSERT( cpp_byval_double_ptr( dp ) = d )
ASSERT( cpp_byval_const_double_ptr( dp ) = d )
ASSERT( cpp_byval_double_const_ptr( dp ) = d )
ASSERT( cpp_byval_const_double_const_ptr( dp ) = d )

ASSERT( cpp_byval_double_ptr_ptr( dpp ) = d )
ASSERT( cpp_byval_const_double_ptr_ptr( dpp ) = d )
ASSERT( cpp_byval_double_const_ptr_ptr( dpp ) = d )
ASSERT( cpp_byval_double_ptr_const_ptr( dpp ) = d )

ASSERT( cpp_byref_double( d ) = d )
ASSERT( cpp_byref_const_double( d ) = d )
ASSERT( cpp_byref_double_ptr( dp ) = d )
ASSERT( cpp_byref_const_double_ptr( dp ) = d )
ASSERT( cpp_byref_double_const_ptr( dp ) = d )
ASSERT( cpp_byref_const_double_const_ptr( dp ) = d )

ASSERT( cpp_byref_double_ptr_ptr( dpp ) = d )
ASSERT( cpp_byref_const_double_ptr_ptr( dpp ) = d )
ASSERT( cpp_byref_double_const_ptr_ptr( dpp ) = d )
ASSERT( cpp_byref_double_ptr_const_ptr( dpp ) = d )


end scope

0 comments on commit 44d3712

Please sign in to comment.