From dd9ee0ae37bb7bb0f3fdfad211d9a86f1d5d04ee Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 2 Aug 2004 16:37:00 +0000 Subject: [PATCH] New function PtrConversion git-svn-id: svn://svn.cc65.org/cc65/trunk@3168 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/datatype.c | 17 +++++++++++++++++ src/cc65/datatype.h | 6 ++++++ src/cc65/typeconv.c | 18 ++---------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 979e3e138..f4a30a8e6 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -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; + } +} + + + diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index cf7849042..284506aa8 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -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 */ diff --git a/src/cc65/typeconv.c b/src/cc65/typeconv.c index cf3c9a3ef..f93d34023 100644 --- a/src/cc65/typeconv.c +++ b/src/cc65/typeconv.c @@ -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); -- 2.39.5