int gensub(int p1, int p2, int swapped) { int rp = PINT; gentext(); if (cgload2() || !swapped) cgswap(); if (!inttype(p1) && !inttype(p2) && p1 != p2) error("incompatible pointer types in binary '-'", NULL); if (ptr(p1) && !ptr(p2)) { if (needscale(p1)) { if ( (p1 & STCMASK) == STCPTR || (p1 & STCMASK) == UNIPTR ) cgscale2by(objsize(deref(p1), TVARIABLE, 1)); else cgscale2(); } rp = p1; } cgsub(); if (needscale(p1) && needscale(p2)) { if ( (p1 & STCMASK) == STCPTR || (p1 & STCMASK) == UNIPTR ) cgunscaleby(objsize(deref(p1), TVARIABLE, 1)); else cgunscale(); } return rp; }
int binoptype(int op, int p1, int p2) { binopchk(op, p1, p2); if (PLUS == op) { if (!inttype(p1)) return p1; if (!inttype(p2)) return p2; } else if (MINUS == op) { if (!inttype(p1)) { if (!inttype(p2)) return PINT; return p1; } } return PINT; }
static void binopchk(int op, int p1, int p2) { if (ASPLUS == op) op = PLUS; else if (ASMINUS == op) op = MINUS; if (inttype(p1) && inttype(p2)) return; else if (comptype(p1) || comptype(p2)) /* fail */; else if (PVOID == p1 || PVOID == p2) /* fail */; else if (PLUS == op && (inttype(p1) || inttype(p2))) return; else if (MINUS == op && (!inttype(p1) || inttype(p2))) return; else if ((EQUAL == op || NOTEQ == op || LESS == op || GREATER == op || LTEQ == op || GTEQ == op) && (p1 == p2 || (VOIDPTR == p1 && !inttype(p2)) || (VOIDPTR == p2 && !inttype(p1))) ) return; error("invalid operands to binary operator", NULL); }
//-------------------------------------------------------------------------- // Function: CompType::getMemberIntType ///\brief Returns the integer datatype of the specified member in this /// compound datatype. ///\param member_num - IN: Zero-based index of the member ///\return IntType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- IntType CompType::getMemberIntType( unsigned member_num ) const { try { IntType inttype(p_get_member_type(member_num)); return(inttype); } catch (DataTypeIException E) { throw DataTypeIException("CompType::getMemberIntType", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: AbstractDs::getIntType ///\brief Returns the integer datatype of this abstract dataset which /// can be a dataset or an attribute. ///\return IntType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- IntType AbstractDs::getIntType() const { // Gets the id of the datatype used by this dataset or attribute using // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type // depending on which object invokes getIntType. Then, create and // return the IntType object try { IntType inttype(p_get_type()); return(inttype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getIntType", E.getDetailMsg()); } catch (AttributeIException E) { throw DataTypeIException("Attribute::getIntType", E.getDetailMsg()); } }
TYPE *destSize(TYPE *tp1, TYPE *tp2, EXPRESSION **exp1, EXPRESSION **exp2, BOOLEAN minimizeInt, TYPE *atp) /* * compare two types and determine if they are compatible for purposes * of the current operation. Return an appropriate type. Also checks for * dangerous pointer conversions... */ { int isctp1, isctp2; if (tp1->type == bt_any) return tp1; if (tp2->type == bt_any) return tp2; if (isvoid(tp1) || isvoid(tp2)) { error(ERR_NOT_AN_ALLOWED_TYPE); return tp1; } if (isref(tp1)) tp1 = basetype(tp1)->btp; if (isref(tp2)) tp2 = basetype(tp2)->btp; tp1 = basetype(tp1); tp2 = basetype(tp2); isctp1 = isarithmetic(tp1); isctp2 = isarithmetic(tp2); /* if (isctp1 && isctp2 && tp1->type == tp2->type) return tp1 ; */ if (tp1->type >= bt_float || tp2->type >= bt_float) { int isim1 = tp1->type >= bt_float_imaginary && tp1->type <= bt_long_double_imaginary; int isim2 = tp2->type >= bt_float_imaginary && tp2->type <= bt_long_double_imaginary; if (isim1 && !isim2 && tp2->type < bt_float_imaginary) { TYPE *tp ; if (tp1->type == bt_long_double_imaginary || tp2->type == bt_long_double) tp = &stdlongdoublecomplex; else if (tp1->type == bt_double_imaginary || tp2->type == bt_double || tp1->type == bt_long_long || tp1->type == bt_unsigned_long_long) tp = &stddoublecomplex; else tp = &stdfloatcomplex; if (exp1) cast(tp, exp1); if (exp2) cast(tp, exp2); return tp; } else if (isim2 && !isim1 && tp1->type < bt_float_imaginary) { TYPE *tp ; if (tp2->type == bt_long_double_imaginary || tp1->type == bt_long_double) tp = &stdlongdoublecomplex; else if (tp2->type == bt_double_imaginary || tp1->type == bt_double || tp1->type == bt_long_long || tp1->type == bt_unsigned_long_long) tp = &stddoublecomplex; else tp = &stdfloatcomplex; if (exp1) cast(tp, exp1); if (exp2) cast(tp, exp2); return tp; } else if (tp1->type > tp2->type) { if (exp2) cast(tp1, exp2); } else if (tp1->type < tp2->type) { if (exp1) cast(tp2, exp1); } if (tp1->type == bt_long_double_complex && isctp2) return tp1; if (tp2->type == bt_long_double_complex && isctp1) return tp2; if (tp1->type == bt_long_double_imaginary && isim2) return tp1; if (tp2->type == bt_long_double_imaginary && isim1) return tp2; if (tp1->type == bt_long_double && isctp2) return tp1; if (tp2->type == bt_long_double && isctp1) return tp2; if (tp1->type == bt_double_complex && isctp2) return tp1; if (tp2->type == bt_double_complex && isctp1) return tp2; if (tp1->type == bt_double_imaginary && isim2) return tp1; if (tp2->type == bt_double_imaginary && isim1) return tp2; if (tp1->type == bt_double && isctp2) return tp1; if (tp2->type == bt_double && isctp1) return tp2; if (tp1->type == bt_float_complex && isctp2) return tp1; if (tp2->type == bt_float_complex && isctp1) return tp2; if (tp1->type == bt_float_imaginary && isim2) return tp1; if (tp2->type == bt_float_imaginary && isim1) return tp2; if (tp1->type == bt_float && isctp2) return tp1; if (tp2->type == bt_float && isctp1) return tp2; } if (isctp1 && isctp2) { TYPE *rv ; enum e_bt t1, t2; t1 = tp1->type; t2 = tp2->type; /* if (cparams.prm_cplusplus && (t1 == bt_enum || t2 == bt_enum)) { if (t1 == t2) { if (tp1->sp->mainsym == tp2->sp->mainsym) { return tp1; } genmismatcherror(ERR_ENUMMISMATCH, tp1, tp2); } } */ if (t1 == bt_enum) t1= bt_int; if (t2 == bt_enum) t2= bt_int; if (t1 == bt_wchar_t) t1 = bt_unsigned; if (t2 == bt_wchar_t) t2 = bt_unsigned; if (t1 < bt_int) t1= bt_int; if (t2 < bt_int) t2= bt_int; t1 = imax(t1, t2); rv = inttype(t1); if (rv->type != tp1->type && exp1) cast(rv, exp1); if (rv->type != tp2->type && exp2) cast(rv,exp2); return rv; } else { /* have a pointer or other exceptional case*/ if (tp1->type == bt_void && tp2->type == bt_void) return tp1; if (tp1->type <= bt_unsigned_long_long && ispointer(tp2)) { if (!ispointer(tp1)) cast(tp2, exp1); return tp2; } if (tp2->type <= bt_unsigned_long_long && ispointer(tp1)) { if (!ispointer(tp2)) cast(tp1, exp2); return tp1; } if (isstructured(tp1)) { return tp2; /* if (comparetypes(tp1, tp2, FALSE)) return tp1; if (cparams.prm_cplusplus) { cppcast(tp2, tp1, exp1, FALSE, ERR_CPPMISMATCH); } else error(ERR_ILL_STRUCTURE_OPERATION); return tp2; */ } if (isstructured(tp2)) { return tp1; /* if (comparetypes(tp1, tp2, FALSE)) return tp2; if (cparams.prm_cplusplus) { cppcast(tp1, tp2, exp1, FALSE, ERR_CPPMISMATCH); } else error(ERR_ILL_STRUCTURE_OPERATION); return tp1; */ } if (isfunction(tp1)) if (isfunction(tp2) || ispointer(tp2)) return tp1; if (isfunction(tp2)) if (isfunction(tp1) || ispointer(tp1)) return tp2; if (ispointer(tp1)) if (ispointer(tp2)) { /* if (tp1->type != tp2->type || !comparetypes(tp1->btp, tp2->btp, TRUE)) generror(ERR_SUSPICIOUS, 0, 0); */ return tp1; } } return tp1; }