Skip to content

Commit 267de90

Browse files
committed
Change names according to design document; make wasCreatedFromLiteral() private
1 parent 3375059 commit 267de90

File tree

6 files changed

+71
-64
lines changed

6 files changed

+71
-64
lines changed

icu4c/source/i18n/messageformat2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ UnicodeString& MessageFormatter::bidiIsolate(UMFBidiOption uDirOption,
477477
status = U_ZERO_ERROR;
478478
return randVal;
479479
} // There might be an implicit formatter
480-
const Formattable& toFormat = contained->getOperand();
480+
const Formattable& toFormat = contained->unwrap();
481481
// If it has an object type, there might be an implicit formatter for it...
482482
switch (toFormat.getType()) {
483483
case UFMT_OBJECT: {
@@ -1008,7 +1008,7 @@ bool MessageFormatter::operandToStringWithBadOptionError(MessageContext& context
10081008
const FunctionValue* val = iVal.getValue(status);
10091009
U_ASSERT(U_SUCCESS(status));
10101010

1011-
result = val->getOperand().getString(status);
1011+
result = val->unwrap().getString(status);
10121012
if (U_FAILURE(status)) {
10131013
status = U_ZERO_ERROR;
10141014
context.getErrors().setBadOption({}, status);

icu4c/source/i18n/messageformat2_evaluation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ using namespace data_model;
2929

3030
BaseValue::BaseValue(const Locale& loc, const UnicodeString& fb, const Formattable& source, bool wasCreatedFromLiteral)
3131
: locale(loc), fromLiteral(wasCreatedFromLiteral) {
32-
operand = source;
32+
innerValue = source;
3333
fallback += LEFT_CURLY_BRACE;
3434
fallback += fb;
3535
fallback += RIGHT_CURLY_BRACE;
36-
dir = U_MF_DIRECTIONALITY_UNKNOWN;
3736
}
3837

3938
/* static */ BaseValue* BaseValue::create(const Locale& locale,
@@ -47,13 +46,14 @@ BaseValue::BaseValue(const Locale& loc, const UnicodeString& fb, const Formattab
4746
extern UnicodeString formattableToString(const Locale&, const Formattable&, UErrorCode&);
4847

4948
UnicodeString BaseValue::formatToString(UErrorCode& errorCode) const {
50-
return formattableToString(locale, operand, errorCode);
49+
return formattableToString(locale, innerValue, errorCode);
5150
}
5251

5352
BaseValue& BaseValue::operator=(BaseValue&& other) noexcept {
54-
operand = std::move(other.operand);
53+
innerValue = std::move(other.innerValue);
5554
opts = std::move(other.opts);
5655
dir = other.dir;
56+
inputDir = other.inputDir;
5757
locale = other.locale;
5858
fallback = other.fallback;
5959
fromLiteral = other.fromLiteral;

icu4c/source/i18n/messageformat2_evaluation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace message2 {
164164
static VariableValue* create(const FunctionValue*, UErrorCode&);
165165
UBool wasCreatedFromLiteral() const override { return false; }
166166
UnicodeString formatToString(UErrorCode& status) const override { return underlyingValue->formatToString(status); }
167-
const Formattable& getOperand() const override { return underlyingValue->getOperand(); }
167+
const Formattable& unwrap() const override { return underlyingValue->unwrap(); }
168168
const FunctionOptions& getResolvedOptions() const override { return underlyingValue->getResolvedOptions(); }
169169
const Locale& getLocale() const override { return underlyingValue->getLocale(); }
170170
UMFDirectionality getDirection() const override { return underlyingValue->getDirection(); }

icu4c/source/i18n/messageformat2_function_registry.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ bool isDigitSizeOption(const UnicodeString& s) {
398398
CHECK_ERROR(status);
399399
for (int32_t i = 0; i < opts.optionsCount(); i++) {
400400
const ResolvedFunctionOption& opt = opts.options[i];
401-
if (isDigitSizeOption(opt.getName()) && !isInteger(opt.getValue().getOperand())) {
401+
if (isDigitSizeOption(opt.getName()) && !isInteger(opt.getValue().unwrap())) {
402402
status = U_MF_BAD_OPTION;
403403
return;
404404
}
@@ -673,7 +673,7 @@ int32_t StandardFunctions::Number::digitSizeOption(const FunctionOptions& opts,
673673
localStatus = U_ZERO_ERROR;
674674
}
675675
// Next try the operand
676-
val = getInt64Value(Locale("en-US"), opt->getOperand(), localStatus);
676+
val = getInt64Value(Locale("en-US"), opt->unwrap(), localStatus);
677677
if (U_SUCCESS(localStatus)) {
678678
return static_cast<int32_t>(val);
679679
}
@@ -738,7 +738,7 @@ StandardFunctions::NumberValue::NumberValue(const Number& parent,
738738

739739
locale = context.getLocale();
740740
opts = options.mergeOptions(arg.getResolvedOptions(), errorCode);
741-
operand = arg.getOperand();
741+
innerValue = arg.unwrap();
742742
functionName = UnicodeString(parent.isInteger ? "integer" : "number");
743743
inputDir = context.getDirection();
744744
dir = numberOutputDirectionalityFromUDir(inputDir, locale);
@@ -749,31 +749,31 @@ StandardFunctions::NumberValue::NumberValue(const Number& parent,
749749
int64_t integerValue = 0;
750750

751751
if (U_SUCCESS(errorCode)) {
752-
switch (operand.getType()) {
752+
switch (innerValue.getType()) {
753753
case UFMT_DOUBLE: {
754-
double d = operand.getDouble(errorCode);
754+
double d = innerValue.getDouble(errorCode);
755755
U_ASSERT(U_SUCCESS(errorCode));
756756
formattedNumber = realFormatter.formatDouble(d, errorCode);
757757
integerValue = static_cast<int64_t>(std::round(d));
758758
break;
759759
}
760760
case UFMT_LONG: {
761-
int32_t l = operand.getLong(errorCode);
761+
int32_t l = innerValue.getLong(errorCode);
762762
U_ASSERT(U_SUCCESS(errorCode));
763763
formattedNumber = realFormatter.formatInt(l, errorCode);
764764
integerValue = l;
765765
break;
766766
}
767767
case UFMT_INT64: {
768-
int64_t i = operand.getInt64(errorCode);
768+
int64_t i = innerValue.getInt64(errorCode);
769769
U_ASSERT(U_SUCCESS(errorCode));
770770
formattedNumber = realFormatter.formatInt(i, errorCode);
771771
integerValue = i;
772772
break;
773773
}
774774
case UFMT_STRING: {
775775
// Try to parse the string as a number
776-
const UnicodeString& s = operand.getString(errorCode);
776+
const UnicodeString& s = innerValue.getString(errorCode);
777777
U_ASSERT(U_SUCCESS(errorCode));
778778
double d = parseNumberLiteral(s, errorCode);
779779
if (U_FAILURE(errorCode))
@@ -797,7 +797,7 @@ StandardFunctions::NumberValue::NumberValue(const Number& parent,
797797

798798
// Need to set the integer value if invoked as :integer
799799
if (parent.isInteger) {
800-
operand = Formattable(integerValue);
800+
innerValue = Formattable(integerValue);
801801
}
802802
}
803803

@@ -1066,7 +1066,7 @@ StandardFunctions::DateTimeValue::DateTimeValue(DateTime::DateTimeType type,
10661066

10671067
locale = context.getLocale();
10681068
opts = options.mergeOptions(arg.getResolvedOptions(), errorCode);
1069-
operand = arg.getOperand();
1069+
innerValue = arg.unwrap();
10701070
switch (type) {
10711071
case DateTimeType::kDate:
10721072
functionName = functions::DATE;
@@ -1081,7 +1081,7 @@ StandardFunctions::DateTimeValue::DateTimeValue(DateTime::DateTimeType type,
10811081
inputDir = context.getDirection();
10821082
dir = numberOutputDirectionalityFromUDir(inputDir, locale);
10831083

1084-
const Formattable* source = &operand;
1084+
const Formattable* source = &innerValue;
10851085

10861086
LocalPointer<DateFormat> df;
10871087
Formattable opt;
@@ -1271,7 +1271,7 @@ StandardFunctions::DateTimeValue::DateTimeValue(DateTime::DateTimeType type,
12711271
}
12721272
df->adoptTimeZone(createTimeZone(dateInfo, errorCode));
12731273
df->format(dateInfo.date, result, 0, errorCode);
1274-
operand = message2::Formattable(std::move(dateInfo));
1274+
innerValue = message2::Formattable(std::move(dateInfo));
12751275
break;
12761276
}
12771277
case UFMT_DATE: {
@@ -1488,13 +1488,13 @@ StandardFunctions::StringValue::StringValue(const FunctionContext& context,
14881488
UErrorCode& status) {
14891489
CHECK_ERROR(status);
14901490
locale = context.getLocale();
1491-
operand = val.getOperand();
1491+
innerValue = val.unwrap();
14921492
functionName = UnicodeString("string");
14931493
inputDir = context.getDirection();
14941494
dir = stringOutputDirectionFromInput(inputDir);
14951495
// No options
14961496
// Convert to string
1497-
formattedString = formattableToString(context.getLocale(), operand, status);
1497+
formattedString = formattableToString(context.getLocale(), innerValue, status);
14981498
}
14991499

15001500
void StandardFunctions::StringValue::selectKeys(const UnicodeString* keys,
@@ -1601,7 +1601,7 @@ static void setFailsFromFunctionValue(const FunctionValue& optionValue,
16011601
bool& failsFormat,
16021602
bool& failsSelect,
16031603
UErrorCode& status) {
1604-
UnicodeString failsString = optionValue.getOperand().getString(status);
1604+
UnicodeString failsString = optionValue.unwrap().getString(status);
16051605
if (U_SUCCESS(status)) {
16061606
// 9i. If its value resolves to the string 'always', then
16071607
if (failsString == u"always") {
@@ -1655,7 +1655,7 @@ static void setFailsFromFunctionValue(const FunctionValue& optionValue,
16551655
// 5. If arg is the resolved value of an expression with a :test:function, :test:select, or :test:format annotation for which resolution has succeeded, then
16561656
if (isTestFunction(arg.getFunctionName())) {
16571657
// 5i. Let Input be the Input value of arg.
1658-
input = formattableToNumber(arg.getOperand(), status);
1658+
input = formattableToNumber(arg.unwrap(), status);
16591659
if (U_FAILURE(status)) {
16601660
status = U_MF_OPERAND_MISMATCH_ERROR;
16611661
return;
@@ -1664,7 +1664,7 @@ static void setFailsFromFunctionValue(const FunctionValue& optionValue,
16641664
// 5ii. Set DecimalPlaces to be DecimalPlaces value of arg.
16651665
const FunctionValue* decimalPlacesFunctionValue = opts.getFunctionOption(UnicodeString("decimalPlaces"), status);
16661666
if (U_SUCCESS(status)) {
1667-
decimalPlaces = formattableToNumber(decimalPlacesFunctionValue->getOperand(), status);
1667+
decimalPlaces = formattableToNumber(decimalPlacesFunctionValue->unwrap(), status);
16681668
if (U_FAILURE(status)) {
16691669
status = U_MF_OPERAND_MISMATCH_ERROR;
16701670
return;
@@ -1689,7 +1689,7 @@ static void setFailsFromFunctionValue(const FunctionValue& optionValue,
16891689
// (Done in previous step)
16901690
} else {
16911691
// 6. Else if arg is a numerical value or a string matching the number-literal production, then
1692-
input = formattableToNumber(arg.getOperand(), status);
1692+
input = formattableToNumber(arg.unwrap(), status);
16931693
if (U_FAILURE(status)) {
16941694
// 7. Else,
16951695
// 7i. Emit "bad-input" Resolution Error.
@@ -1704,7 +1704,7 @@ static void setFailsFromFunctionValue(const FunctionValue& optionValue,
17041704
if (U_SUCCESS(status)) {
17051705
// 8i. If its value resolves to a numerical integer value 0 or 1
17061706
// or their corresponding string representations '0' or '1', then
1707-
double decimalPlacesInput = formattableToNumber(decimalPlacesOpt->getOperand(), status);
1707+
double decimalPlacesInput = formattableToNumber(decimalPlacesOpt->unwrap(), status);
17081708
if (U_SUCCESS(status)) {
17091709
if (decimalPlacesInput == 0 || decimalPlacesInput == 1) {
17101710
// 8ia. Set DecimalPlaces to be the numerical value of the option.
@@ -1745,7 +1745,7 @@ StandardFunctions::TestFunctionValue::TestFunctionValue(const TestFunction& pare
17451745
failsFormat, failsSelect, input, status);
17461746
CHECK_ERROR(status);
17471747
opts = options.mergeOptions(arg.getResolvedOptions(), status);
1748-
operand = arg.getOperand();
1748+
innerValue = arg.unwrap();
17491749
canFormat = parent.canFormat;
17501750
canSelect = parent.canSelect;
17511751
functionName = UnicodeString(canFormat && canSelect ?

icu4c/source/i18n/unicode/messageformat2_function_registry.h

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ namespace message2 {
431431
* @internal ICU 78 technology preview
432432
* @deprecated This API is for technology preview only.
433433
*/
434-
virtual const Formattable& getOperand() const { return operand; }
434+
virtual const Formattable& unwrap() const { return innerValue; }
435435
/**
436436
* Returns a reference to the resolved options for this value.
437437
*
@@ -564,29 +564,16 @@ namespace message2 {
564564
* @deprecated This API is for technology preview only.
565565
*/
566566
virtual ~FunctionValue();
567-
// FIXME: Can this be made private?
568-
// Should only be overridden by BaseValue -- should not be overridden by other classes
569-
// True iff this option was represented in the syntax by a literal value.
570-
// This is necessary in order to implement the spec for the `select` option
571-
// of `:number` and `:integer`.
572-
/**
573-
* Returns true iff this FunctionValue was created directly or indirectly
574-
* from a literal.
575-
*
576-
* @returns A boolean.
577-
*
578-
* @internal ICU 78 technology preview
579-
* @deprecated This API is for technology preview only.
580-
*/
581-
virtual UBool wasCreatedFromLiteral() const { return false; }
582567
protected:
583568
/**
584-
* Operand used to construct this value.
569+
* Computed result of the function invocation that
570+
* returned this FunctionValue. This may simply be the
571+
* operand, or may be a value computed from the operand.
585572
*
586573
* @internal ICU 78 technology preview
587574
* @deprecated This API is for technology preview only.
588575
*/
589-
Formattable operand;
576+
Formattable innerValue;
590577
/**
591578
* Resolved options attached to this value.
592579
*
@@ -619,6 +606,8 @@ namespace message2 {
619606
Locale locale;
620607
/**
621608
* Directionality of formatted result.
609+
* Defaults to U_MF_DIRECTIONALITY_UNKNOWN if not set
610+
* by the subclass's constructor.
622611
*
623612
* @internal ICU 78 technology preview
624613
* @deprecated This API is for technology preview only.
@@ -633,6 +622,24 @@ namespace message2 {
633622
* @deprecated This API is for technology preview only.
634623
*/
635624
UMFBidiOption inputDir = U_MF_BIDI_OPTION_INHERIT;
625+
private:
626+
friend class FunctionOptions;
627+
628+
// Should only be overridden by BaseValue
629+
/**
630+
* Returns true iff this FunctionValue was created directly or indirectly
631+
* from a literal.
632+
* This method should not be overridden. It is overridden by an internal class
633+
* in the message formatter.
634+
* It is used to implement the MessageFormat specification for the `select`
635+
* option of `:number` and `:integer`.
636+
*
637+
* @returns A boolean.
638+
*
639+
* @internal ICU 78 technology preview
640+
* @deprecated This API is for technology preview only.
641+
*/
642+
virtual UBool wasCreatedFromLiteral() const { return false; }
636643
}; // class FunctionValue
637644

638645
} // namespace message2

0 commit comments

Comments
 (0)