New function PtrConversion
git-svn-id: svn://svn.cc65.org/cc65/trunk@3168 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -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.
|
* 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 */
|
/* 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)
|
static void DoConversion (ExprDesc* Expr, const type* NewType)
|
||||||
/* Emit code to convert the given expression to a new type. */
|
/* 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
|
/* Get the type of the right hand side. Treat function types as
|
||||||
* pointer-to-function
|
* pointer-to-function
|
||||||
*/
|
*/
|
||||||
DoPtrConversions (Expr);
|
Expr->Type = PtrConversion (Expr->Type);
|
||||||
|
|
||||||
/* First, do some type checking */
|
/* First, do some type checking */
|
||||||
if (IsTypeVoid (NewType) || IsTypeVoid (Expr->Type)) {
|
if (IsTypeVoid (NewType) || IsTypeVoid (Expr->Type)) {
|
||||||
@@ -293,7 +279,7 @@ void TypeCast (ExprDesc* Expr)
|
|||||||
hie10 (Expr);
|
hie10 (Expr);
|
||||||
|
|
||||||
/* Convert functions and arrays to "pointer to" object */
|
/* Convert functions and arrays to "pointer to" object */
|
||||||
DoPtrConversions (Expr);
|
Expr->Type = PtrConversion (Expr->Type);
|
||||||
|
|
||||||
/* Convert the value. */
|
/* Convert the value. */
|
||||||
DoConversion (Expr, NewType);
|
DoConversion (Expr, NewType);
|
||||||
|
|||||||
Reference in New Issue
Block a user