-unsigned assignadjust (type* lhst, struct expent* rhs)
-/* Adjust the type of the right hand expression so that it can be assigned to
- * the type on the left hand side. This function is used for assignment and
- * for converting parameters in a function call. It returns the code generator
- * flags for the operation. The type string of the right hand side will be
- * set to the type of the left hand side.
- */
-{
- /* Get the type of the right hand side */
- type* rhst = rhs->e_tptr;
-
- /* After calling this function, rhs will have the type of the lhs */
- rhs->e_tptr = lhst;
-
- /* First, do some type checking */
- if (IsVoid (lhst) || IsVoid (rhst)) {
- /* If one of the sides are of type void, output a more apropriate
- * error message.
- */
- Error (ERR_ILLEGAL_TYPE);
- } else if (IsInt (lhst)) {
- if (IsPtr (rhst)) {
- /* Pointer -> int conversion */
- Warning (WARN_PTR_TO_INT_CONV);
- } else if (!IsInt (rhst)) {
- Error (ERR_INCOMPATIBLE_TYPES);
- } else {
- /* Adjust the int types. To avoid manipulation of TOS mark lhs
- * as const.
- */
- unsigned flags = TypeOf (rhst);
- if (rhs->e_flags & E_MCONST) {
- flags |= CF_CONST;
- }
- return g_typeadjust (TypeOf (lhst) | CF_CONST, flags);
- }
- } else if (IsPtr (lhst)) {
- if (IsPtr (rhst)) {
- /* Pointer to pointer assignment is valid, if:
- * - both point to the same types, or
- * - the rhs pointer is a void pointer, or
- * - the lhs pointer is a void pointer.
- */
- type* left = Indirect (lhst);
- type* right = Indirect (rhst);
- if (!EqualTypes (left, right) && *left != T_VOID && *right != T_VOID) {
- Error (ERR_INCOMPATIBLE_POINTERS);
- }
- } else if (IsInt (rhst)) {
- /* Int to pointer assignment is valid only for constant zero */
- if ((rhs->e_flags & E_MCONST) == 0 || rhs->e_const != 0) {
- Warning (WARN_INT_TO_PTR_CONV);
- }
- } else if (IsFuncPtr (lhst) && IsFunc(rhst)) {
- /* Assignment of function to function pointer is allowed, provided
- * that both functions have the same parameter list.
- */
- if (!EqualTypes(Indirect (lhst), rhst)) {
- Error (ERR_INCOMPATIBLE_TYPES);
- }
- } else {
- Error (ERR_INCOMPATIBLE_TYPES);
- }
- } else {
- Error (ERR_INCOMPATIBLE_TYPES);
- }
-
- /* Return an int value in all cases where the operands are not both ints */
- return CF_INT;
-}
-
-
-
-void DefineData (struct expent* lval)