59 #include "SystemInterpreter.hpp"
62 #define check_TE debug_encoding
81 const char *name =
"<NULL>";
87 if (currentContext ==
OREF_NULL) name =
"<NULL activation>";
91 package = currentContext->getPackage();
92 if (package ==
OREF_NULL) name =
"<NULL package>";
96 if (packageName ==
OREF_NULL) name =
"<NULL packageName>";
100 if (name ==
OREF_NULL) name =
"<NULL name>";
105 printf(
"%s checkTE package=%p %s %zu\n", method, package, name,
line);
106 printf(
"%s checkTE this=%p text=%p encoding=%p for '%s'\n", method,
this, this->
text, this->
encoding, this->
getStringData());
107 if (this->
text !=
OREF_NULL && this->
text !=
this) printf(
"%s checkTE CHECK_TEXT\n", method);
117 this->
checkTE(
"RexxString::RexxString");
126 const char *name =
"<NULL>";
132 if (currentContext ==
OREF_NULL) name =
"<NULL activation>";
136 package = currentContext->getPackage();
137 if (package ==
OREF_NULL) name =
"<NULL package>";
141 if (packageName ==
OREF_NULL) name =
"<NULL packageName>";
145 if (name ==
OREF_NULL) name =
"<NULL name>";
150 printf(
"RexxString::RexxString(restoreType %u) checkTE package=%p %s %zu\n", restoreType, package, name,
line);
151 printf(
"RexxString::RexxString(restoreType %u) checkTE this=%p text=%p encoding=%p for '%s'\n", restoreType,
this, this->
text, this->
encoding, this->
getStringData());
152 if (this->
text !=
OREF_NULL && this->
text !=
this) printf(
"RexxString::RexxString checkTE CHECK_TEXT\n");
267 const char *strEqual =
" ";
268 const char *strDifferent =
"DIFFERENT";
269 printf(
"RexxString::liveGeneral (1) %s string=%p text=%p encoding=%p %s\n", strEqual,
this, this->
getText(), this->
getEncoding(), this->
getStringData());
270 bool breakpoint =
false;
271 if ((text1 !=
OREF_NULL) && (text1 !=
this))
275 if (breakpoint) printf(
"RexxString::liveGeneral BREAKPOINT\n");
287 bool different = (text1 != text2) || (encoding1 != encoding2) || (stringData1 != stringData2);
288 printf(
"RexxString::liveGeneral (2) %s string=%p text=%p encoding=%p %s\n", different ? strDifferent : strEqual,
this, this->
getText(), this->
getEncoding(), this->
getStringData());
506 result = std::numeric_limits<double>::signaling_NaN();
511 result = std::numeric_limits<double>::quiet_NaN();
622 if (bufl <= this->
getLength() - startPos)
765 const char *firstStart;
766 const char *secondStart;
794 if (alternativeOperator !=
OREF_NULL && alternativeOperatorResultPtr != NULL)
802 bool alternativeResult = other->
messageSend(alternativeOperator, args, 1, 0, result,
false);
819 return firstNum->
comp(secondNum);
833 while (firstLen > 0 && (*firstStart ==
ch_BLANK || *firstStart ==
ch_TAB))
839 while (secondLen > 0 && (*secondStart ==
ch_BLANK || *secondStart ==
ch_TAB))
845 if (firstLen >= secondLen)
851 result = memcmp(firstStart, secondStart, secondLen);
853 if ((result == 0) && (firstLen != secondLen))
856 firstStart = firstStart + secondLen;
857 while (firstLen-- > secondLen)
861 unsigned char current = *firstStart++;
874 result = memcmp(firstStart, secondStart, firstLen);
879 secondStart = secondStart + firstLen;
880 while (secondLen-- > firstLen)
884 unsigned char current = *secondStart++;
912 if (alternativeOperator !=
OREF_NULL && alternativeOperatorResultPtr != NULL)
920 bool alternativeResult = otherObj->
messageSend(alternativeOperator, args, 1, 0, result,
false);
941 if ((result == 0) && (this->
getLength() > otherLen))
983 bool alternativeResult = right_term->
messageSend(OREF_PLUS_RIGHT, args, 1, 0, result,
false);
989 return numstr->
plus(right_term);
1008 bool alternativeResult = this->
messageSend(OREF_SUBTRACT_LEFT,
OREF_NULL, 0, 0, result,
false);
1016 bool alternativeResult = right_term->
messageSend(OREF_SUBTRACT_RIGHT, args, 1, 0, result,
false);
1022 return numstr->
minus(right_term);
1042 bool alternativeResult = right_term->
messageSend(OREF_MULTIPLY_RIGHT, args, 1, 0, result,
false);
1047 return numstr->
multiply(right_term);
1067 bool alternativeResult = right_term->
messageSend(OREF_DIVIDE_RIGHT, args, 1, 0, result,
false);
1072 return numstr->
divide(right_term);
1092 bool alternativeResult = right_term->
messageSend(OREF_INTDIV_RIGHT, args, 1, 0, result,
false);
1117 bool alternativeResult = right_term->
messageSend(OREF_REMAINDER_RIGHT, args, 1, 0, result,
false);
1142 bool alternativeResult = right_term->
messageSend(OREF_POWER_RIGHT, args, 1, 0, result,
false);
1147 return numstr->
power(right_term);
1164 return numstr->
abs();
1181 return numstr->
Sign();
1199 return numstr->
Max(arguments, argCount, named_argCount);
1217 return numstr->
Min(arguments, argCount, named_argCount);
1234 return numstr->
trunc(decimals);
1252 return numstr->
floor();
1288 return numstr->
round();
1306 return numstr->
formatRexx(Integers, Decimals, MathExp, ExpTrigger);
1359 bool alternativeResult = other->
messageSend(OREF_STRICT_EQUAL_RIGHT, args, 1, 0, result,
false);
1386 bool alternativeResult = other->
messageSend(OREF_STRICT_BACKSLASH_EQUAL_RIGHT, args, 1, 0, result,
false);
1407 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1423 wholenumber_t result = this->
comp(other, OREF_BACKSLASH_EQUAL_RIGHT, &alternativeResult);
1424 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1440 wholenumber_t result = this->
comp(other, OREF_GREATERTHAN_RIGHT, &alternativeResult);
1441 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1457 wholenumber_t result = this->
comp(other, OREF_LESSTHAN_RIGHT, &alternativeResult);
1458 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1474 wholenumber_t result = this->
comp(other, OREF_GREATERTHAN_EQUAL_RIGHT, &alternativeResult);
1475 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1491 wholenumber_t result = this->
comp(other, OREF_LESSTHAN_EQUAL_RIGHT, &alternativeResult);
1492 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1509 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1526 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1543 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1560 if (alternativeResult !=
OREF_NULL)
return alternativeResult;
1621 bool alternativeResult = otherObj->
messageSend(OREF_CONCATENATE_RIGHT, args, 1, 0, result,
false);
1666 blen2 = strlen(other);
1672 memcpy(result->
getWritableData() + blen2, this->getStringData(), blen1);
1686 blen2 = strlen(other);
1717 bool alternativeResult = otherObj->
messageSend(OREF_BLANK_RIGHT, args, 1, 0, result,
false);
1812 if (testString->
getChar(0) ==
'0')
1818 else if (testString->
getChar(0) ==
'1')
1849 const char *endData;
1854 while (data < endData)
1856 if (*data != toupper(*data))
1881 const char *endData;
1887 while (data < endData)
1889 *outdata = toupper(*data);
1908 const unsigned char *Current;
1959 bool needTranslation;
1962 needTranslation =
false;
1966 if (*data != tolower(*data))
1968 needTranslation =
true;
1973 if (needTranslation)
1983 *outdata = tolower(*data);
2021 if (rangeLength == 0)
2026 return lower(startPos, rangeLength);
2055 if (rangeLength == 0)
2060 return upper(startPos, rangeLength);
2083 for (
size_t i = 0; i < _length; i++)
2085 *data = tolower(*data);
2112 for (
size_t i = 0; i < _length; i++)
2114 *data = toupper(*data);
2219 bool alternativeResult = other->
messageSend(OREF_AND_RIGHT, args, 1, 0, result,
false);
2250 bool alternativeResult = other->
messageSend(OREF_OR_RIGHT, args, 1, 0, result,
false);
2279 bool alternativeResult = other->
messageSend(OREF_XOR_RIGHT, args, 1, 0, result,
false);
2289 if (!thisTruthValue)
2332 const char *digitPtr;
2339 for (; digitsLeft != 0 && (*digitPtr ==
ch_BLANK || *digitPtr ==
ch_TAB); ++digitPtr, --digitsLeft) ;
2341 if (digitsLeft != 0)
2347 for (++digitPtr, --digitsLeft;
2348 digitsLeft != 0 && (*digitPtr ==
ch_BLANK || *digitPtr ==
ch_TAB);
2349 ++digitPtr, --digitsLeft) ;
2351 if (digitsLeft == 0)
2359 for (; digitsLeft != 0 && *digitPtr >=
ch_ZERO && *digitPtr <=
ch_NINE;
2360 ++digitPtr, --digitsLeft) ;
2363 if ( digitsLeft != 0 && *digitPtr ==
ch_PERIOD)
2367 for (; digitsLeft != 0 && *digitPtr ==
ch_ZERO; ++digitPtr, --digitsLeft) ;
2371 for (; digitsLeft != 0 && (*digitPtr ==
ch_BLANK || *digitPtr ==
ch_TAB); ++digitPtr, --digitsLeft) ;
2375 if (digitsLeft == 0)
2395 this->
checkTE(
"RexxString::evaluate 1st");
2402 printf(
"RexxString::evaluate fix the text of %p text=%p encoding=%p\n",
this, this->
text, this->
encoding);
2412 printf(
"RexxString::evaluate fix the encoding of %p text=%p encoding=%p\n",
this, this->
text, this->
encoding);
2422 printf(
"RexxString::evaluate 1st evaluation for %p '%s'\n",
this, this->
getStringData());
2432 const char *packageEncodingName =
"<NULL>";
2436 bool messageUnderstood = package->messageSend(OREF_SETENCODING,
OREF_NULL, 0, 0, result,
false);
2441 const char *packageName =
"<NULL>";
2442 messageUnderstood = package->messageSend(OREF_NAME,
OREF_NULL, 0, 0, result,
false);
2445 packageName = ((
RexxString *)result)->getStringData();
2447 messageUnderstood = packageEncoding->messageSend(OREF_NAME,
OREF_NULL, 0, 0, result,
false);
2450 packageEncodingName = ((
RexxString *)result)->getStringData();
2452 printf(
"RexxString::evaluate the package %p %s has an encoding %p %s\n", package, packageName, packageEncoding, packageEncodingName);
2460 printf(
"RexxString::evaluate not ASCII for '%s'\n", this->
getStringData());
2464 messageUnderstood = packageEncoding->messageSend(OREF_ISBYTE,
OREF_NULL, 0, 0, result,
false);
2471 args[0] = packageEncoding;
2472 bool messageUnderstood = this->
messageSend(OREF_SETENCODING, args, 1, 0, result,
false);
2482 printf(
"RexxString::evaluate text=%p for '%s'\n", this->
text, this->
getStringData());
2491 printf(
"RexxString::evaluate condition this->encoding (%p) == OREF_NULL && packageEncoding (%p) != OREF_NULL\n", this->
encoding, packageEncoding);
2497 printf(
"RexxString::evaluate setEncoding %p %s on value=%p for '%s'\n", packageEncoding, packageEncodingName, value, this->
getStringData());
2502 args[0] = packageEncoding;
2503 bool messageUnderstood = value->
messageSend(OREF_SETENCODING, args, 1, 0, result,
false);
2514 this->
checkTE(
"RexxString::evaluate 2nd");
2592 size_t size2 =
sizeof(
RexxString) - (
sizeof(
char) * 3) + blength;
2600 newObj->
putChar(blength,
'\0');
2602 newObj->
put(0,
string, blength);
2608 newObj->
checkTE(
"RexxString::newString");
2629 size_t size2 =
sizeof(
RexxString) - (
sizeof(
char) * 3) + blength;
2636 newObj->
putChar(blength,
'\0');
2642 newObj->
checkTE(
"RexxString::rawString");
2672 size_t size2 =
sizeof(
RexxString) - (
sizeof(
char) * 3) + blength;
2681 const char *indata = string;
2682 const char *endData = indata + blength;
2683 while (indata < endData)
2685 *outdata = toupper(*indata);
2692 newObj->
putChar(blength,
'\0');
2698 newObj->
checkTE(
"RexxString::newUpperString");
2739 snprintf(buffer,
sizeof buffer,
"%.*g", (
int)precision, number);
2740 size_t len = strlen(buffer);
2742 if (buffer[len - 1] ==
'.')
2796 string->hasUninit();
2799 string->sendMessage(OREF_INIT, init_args, argCount, named_argCount);
void reportException(wholenumber_t error)
RexxInteger * new_integer(wholenumber_t v)
RexxNumberString * new_numberstring(const char *s, stringsize_t l)
RexxNumberString * new_numberstringFromDouble(double n)
RexxObject *(RexxObject::* PCPPM)()
RexxString * stringArgument(RexxObject *object, RexxString *kind, size_t position)
RexxString * REQUEST_STRING(RexxObject *object)
bool isPolymorphicString(RexxObject *o)
bool isString(RexxObject *o)
bool hasRexxTextArguments(RexxObject **arguments, size_t argcount, size_t named_argcount)
size_t optionalLengthArgument(RexxObject *o, size_t d, size_t p)
size_t optionalPositionArgument(RexxObject *o, size_t d, size_t p)
#define TheNumberStringClass
void requiredArgument(RexxObject *object, RexxString *kind, size_t position)
#define Error_Logical_value_method
#define Error_No_result_object_message
#define Error_Incorrect_method_nostring
#define Error_Incorrect_method_string_nonumber
#define Error_Conversion_operator
#define memory_mark(oref)
RexxObject * new_object(size_t s)
#define flatten_reference(oref, envel)
#define CLASS_CREATE(name, id, className)
#define memory_mark_general(oref)
#define setUpFlatten(type)
RexxString * raw_string(stringsize_t l)
RexxString * new_string(const char *s, stringsize_t l)
static RexxActivity *volatile currentActivity
static wholenumber_t minVal(wholenumber_t n1, wholenumber_t n2)
void traceIntermediate(RexxObject *v, int p)
RexxActivation * getCurrentRexxFrame()
RexxClass * getOwningClass()
static void processNewArgs(RexxObject **, size_t, RexxObject ***, size_t *, size_t, RexxObject **, RexxObject **)
RexxBehaviour * getInstanceBehaviour()
void append(const char *newData, size_t stringLen)
void push(RexxObject *value)
void setString(RexxString *string)
RexxString * getStringrep()
RexxObject * getValue(RexxActivation *)
void setBehaviour(RexxBehaviour *b)
void setHasNoReferences()
RexxBehaviour * behaviour
wholenumber_t comp(RexxObject *, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
RexxNumberString * multiply(RexxObject *)
RexxNumberString * minus(RexxObject *)
RexxNumberString * Max(RexxObject **, size_t, size_t)
bool unsignedNumberValue(uwholenumber_t &result, size_t precision)
RexxString * stringValue()
RexxString * formatRexx(RexxObject *, RexxObject *, RexxObject *, RexxObject *)
RexxInteger * integerValue(size_t)
RexxNumberString * Min(RexxObject **, size_t, size_t)
void setString(RexxString *)
RexxNumberString * integerDivide(RexxObject *)
bool numberValue(wholenumber_t &result, size_t precision)
RexxObject * trunc(RexxObject *)
RexxNumberString * power(RexxObject *)
RexxNumberString * remainder(RexxObject *)
RexxNumberString * plus(RexxObject *)
RexxNumberString * divide(RexxObject *)
bool doubleValue(double &result)
virtual wholenumber_t compareTo(RexxObject *)
RexxNumberString * numberString()
RexxString * stringValue()
void sendMessage(RexxString *, RexxArray *, RexxDirectory *, ProtectedObject &)
bool messageSend(RexxString *, RexxObject **, size_t, size_t, ProtectedObject &, bool processUnknown=true, bool dynamicTarget=true)
RexxString * requestString()
RexxClass * classObject()
RexxObject * makeArrayRexx()
RexxString * stringValue()
bool numberValue(wholenumber_t &result, size_t precision)
RexxInteger * isLessOrEqual(RexxObject *)
RexxInteger * isLessThan(RexxObject *)
RexxString * concatRexx(RexxObject *)
static void createInstance()
RexxInteger * strictEqual(RexxObject *)
RexxInteger * caselessEquals(RexxString *other)
static RexxString * newProxy(const char *)
void checkTE(const char *method)
RexxObject * trunc(RexxInteger *decimals)
RexxObject * xorOp(RexxObject *)
RexxObject * operatorNot(RexxObject *)
RexxObject * Min(RexxObject **args, size_t argCount, size_t named_argCount)
bool primitiveCaselessIsEqual(RexxObject *)
RexxObject * getEncoding()
RexxInteger * strictGreaterThan(RexxObject *)
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
RexxString * upperRexx(RexxInteger *, RexxInteger *)
HashCode getObjectHashCode()
RexxInteger * notEqual(RexxObject *)
RexxInteger * strictLessOrEqual(RexxObject *)
RexxNumberString * createNumberString()
RexxObject * lengthRexx()
RexxNumberString * fastNumberString()
RexxObject * format(RexxObject *Integers, RexxObject *Decimals, RexxObject *MathExp, RexxObject *ExpTrigger)
bool doubleValue(double &result)
void liveGeneral(int reason)
RexxString * makeString()
const char * getStringData()
RexxObject * integerDivide(RexxObject *right)
void setNumberString(RexxObject *)
RexxObject * remainder(RexxObject *right)
RexxObject * Max(RexxObject **args, size_t argCount, size_t named_argCount)
RexxInteger * integerValue(size_t precision)
RexxString * concatBlank(RexxObject *)
RexxNumberString * numberString()
void setEncoding(RexxObject *e)
static RexxString * newString(const char *, size_t l)
RexxInteger * compareToRexx(RexxString *other, RexxInteger *start_, RexxInteger *len_)
void setIsASCIIChecked(bool value=true)
RexxObject * getRealValue(RexxActivation *)
bool primitiveIsEqual(RexxObject *)
RexxObject * plus(RexxObject *right)
RexxInteger * strictLessThan(RexxObject *)
RexxInteger * strictGreaterOrEqual(RexxObject *)
void setIsASCII(bool value=true)
RexxString * extract(size_t offset, size_t sublength)
void flatten(RexxEnvelope *envelope)
size_t copyData(size_t, char *, size_t)
RexxInteger * equal(RexxObject *)
RexxObject * multiply(RexxObject *right)
RexxString * concatWithCstring(const char *)
static RexxClass * classInstance
virtual bool logicalValue(logical_t &)
RexxObject * andOp(RexxObject *)
bool isEqual(RexxObject *)
wholenumber_t comp(RexxObject *, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
virtual HashCode getHashValue()
RexxString * concat(RexxString *)
RexxString * concatWith(RexxString *, char)
char putChar(size_t p, char c)
void setText(RexxObject *t)
RexxObject * getValue(RexxActivation *)
RexxString * stringTrace()
RexxString * concatToCstring(const char *)
wholenumber_t compareTo(RexxObject *)
RexxNumberString * NumberString
bool strCompare(const char *s)
void copyToRxstring(RXSTRING &r)
RexxInteger * isASCIIRexx()
RexxInteger * isGreaterOrEqual(RexxObject *)
RexxObject * orOp(RexxObject *)
RexxString * newRexx(RexxObject **, size_t, size_t)
RexxObject * divide(RexxObject *right)
RexxObject * unflatten(RexxEnvelope *)
static RexxString * rawString(size_t l)
RexxInteger * equals(RexxString *other)
void put(size_t s, const void *b, size_t l)
RexxInteger * isGreaterThan(RexxObject *)
wholenumber_t strictComp(RexxObject *, RexxString *alternativeOperator=NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
RexxObject * power(RexxObject *right)
RexxString * lowerRexx(RexxInteger *, RexxInteger *)
bool unsignedNumberValue(uwholenumber_t &result, size_t precision)
static PCPPM operatorMethods[]
RexxString * primitiveMakeString()
virtual RexxObject * dynamicTarget(RexxObject **arguments, size_t count, size_t named_count)
RexxInteger * strictNotEqual(RexxObject *)
static RexxString * newUpperString(const char *, stringsize_t l)
RexxObject * minus(RexxObject *right)
void copyIntoTail(RexxCompoundTail *buffer)
virtual RexxObject * unflatten(RexxEnvelope *)
static bool checkIsASCII(const char *s, size_t length)
static int caselessCompare(const char *, const char *, size_t)
static RexxArray * makearray(const char *start, size_t length, RexxString *separator)
static void * allocateResultMemory(size_t)