mirror of
https://github.com/cc65/cc65.git
synced 2024-11-18 00:07:21 +00:00
New function PtrConversion
git-svn-id: svn://svn.cc65.org/cc65/trunk@3168 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
3b8b9704bc
commit
dd9ee0ae37
@ -797,3 +797,20 @@ type* IntPromotion (type* T)
|
||||
|
||||
|
||||
|
||||
type* PtrConversion (type* T)
|
||||
/* If the type is a function, convert it to pointer to function. If the
|
||||
* expression is an array, convert it to pointer to first element. Otherwise
|
||||
* return T.
|
||||
*/
|
||||
{
|
||||
if (IsTypeFunc (T)) {
|
||||
return PointerTo (T);
|
||||
} else if (IsTypeArray (T)) {
|
||||
return ArrayToPtr (T);
|
||||
} else {
|
||||
return T;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -496,6 +496,12 @@ type* IntPromotion (type* T);
|
||||
* string may be T if there is no need to change it.
|
||||
*/
|
||||
|
||||
type* PtrConversion (type* T);
|
||||
/* If the type is a function, convert it to pointer to function. If the
|
||||
* expression is an array, convert it to pointer to first element. Otherwise
|
||||
* return T.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of datatype.h */
|
||||
|
@ -55,20 +55,6 @@
|
||||
|
||||
|
||||
|
||||
static void DoPtrConversions (ExprDesc* Expr)
|
||||
/* If the expression is a function, convert it to pointer to function.
|
||||
* If the expression is an array, convert it to pointer to first element.
|
||||
*/
|
||||
{
|
||||
if (IsTypeFunc (Expr->Type)) {
|
||||
Expr->Type = PointerTo (Expr->Type);
|
||||
} else if (IsTypeArray (Expr->Type)) {
|
||||
Expr->Type = ArrayToPtr (Expr->Type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void DoConversion (ExprDesc* Expr, const type* NewType)
|
||||
/* Emit code to convert the given expression to a new type. */
|
||||
{
|
||||
@ -185,7 +171,7 @@ void TypeConversion (ExprDesc* Expr, type* NewType)
|
||||
/* Get the type of the right hand side. Treat function types as
|
||||
* pointer-to-function
|
||||
*/
|
||||
DoPtrConversions (Expr);
|
||||
Expr->Type = PtrConversion (Expr->Type);
|
||||
|
||||
/* First, do some type checking */
|
||||
if (IsTypeVoid (NewType) || IsTypeVoid (Expr->Type)) {
|
||||
@ -293,7 +279,7 @@ void TypeCast (ExprDesc* Expr)
|
||||
hie10 (Expr);
|
||||
|
||||
/* Convert functions and arrays to "pointer to" object */
|
||||
DoPtrConversions (Expr);
|
||||
Expr->Type = PtrConversion (Expr->Type);
|
||||
|
||||
/* Convert the value. */
|
||||
DoConversion (Expr, NewType);
|
||||
|
Loading…
Reference in New Issue
Block a user