| 1 |
// © 2024 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
|
| 4 |
#include "unicode/utypes.h" |
| 5 |
|
| 6 |
#ifndef U_HIDE_DEPRECATED_API |
| 7 |
|
| 8 |
#ifndef MESSAGEFORMAT_CHECKER_H |
| 9 |
#define MESSAGEFORMAT_CHECKER_H |
| 10 |
|
| 11 |
#if U_SHOW_CPLUSPLUS_API |
| 12 |
|
| 13 |
#if !UCONFIG_NO_NORMALIZATION |
| 14 |
|
| 15 |
#if !UCONFIG_NO_FORMATTING |
| 16 |
|
| 17 |
#if !UCONFIG_NO_MF2 |
| 18 |
|
| 19 |
#include "unicode/messageformat2_data_model.h" |
| 20 |
#include "messageformat2_errors.h" |
| 21 |
|
| 22 |
U_NAMESPACE_BEGIN |
| 23 |
|
| 24 |
namespace message2 { |
| 25 |
|
| 26 |
using namespace data_model; |
| 27 |
|
| 28 |
// Used for checking missing selector annotation errors |
| 29 |
// and duplicate declaration errors (specifically for |
| 30 |
// implicit declarations) |
| 31 |
class TypeEnvironment : public UMemory { |
| 32 |
public: |
| 33 |
// MessageFormat has a simple type system; |
| 34 |
// variables are in-scope and annotated; in-scope and unannotated; |
| 35 |
// or free (a free variable has no explicit declaration in the scope |
| 36 |
// of its use.) |
| 37 |
enum Type { |
| 38 |
Annotated, |
| 39 |
Unannotated, |
| 40 |
FreeVariable |
| 41 |
}; |
| 42 |
void extend(const VariableName&, Type, UErrorCode& status); |
| 43 |
Type get(const VariableName&) const; |
| 44 |
bool known(const VariableName&) const; |
| 45 |
TypeEnvironment(UErrorCode& status); |
| 46 |
|
| 47 |
virtual ~TypeEnvironment(); |
| 48 |
|
| 49 |
private: |
| 50 |
// Stores variables known to be annotated. |
| 51 |
LocalPointer<UVector> annotated; // Vector of `VariableName`s |
| 52 |
// Stores variables that are in-scope but unannotated. |
| 53 |
LocalPointer<UVector> unannotated; // Vector of `VariableName`s |
| 54 |
// Stores free variables that are used in the RHS of a declaration |
| 55 |
LocalPointer<UVector> freeVars; // Vector of `VariableNames`; tracks free variables |
| 56 |
// This can't just be "variables that don't appear in |
| 57 |
// `annotated` or `unannotated`", as a use introduces |
| 58 |
// an explicit declaration |
| 59 |
}; // class TypeEnvironment |
| 60 |
|
| 61 |
class MessageFormatter; |
| 62 |
|
| 63 |
// Checks a data model for semantic errors |
| 64 |
// (Errors are defined in https://github.com/unicode-org/message-format-wg/blob/main/spec/formatting.md ) |
| 65 |
class Checker { |
| 66 |
public: |
| 67 |
void check(UErrorCode&); |
| 68 |
Checker(const MFDataModel& d, StaticErrors& e, const MessageFormatter& mf) |
| 69 |
: dataModel(d), errors(e), context(mf) {} |
| 70 |
private: |
| 71 |
|
| 72 |
Key normalizeNFC(const Key&) const; |
| 73 |
|
| 74 |
void requireAnnotated(const TypeEnvironment&, const VariableName&, UErrorCode&); |
| 75 |
void addFreeVars(TypeEnvironment& t, const Operand&, UErrorCode&); |
| 76 |
void addFreeVars(TypeEnvironment& t, const Operator&, UErrorCode&); |
| 77 |
void addFreeVars(TypeEnvironment& t, const OptionMap&, UErrorCode&); |
| 78 |
void addFreeVars(TypeEnvironment& t, const Expression&, UErrorCode&); |
| 79 |
void checkDeclarations(TypeEnvironment&, UErrorCode&); |
| 80 |
void checkSelectors(const TypeEnvironment&, UErrorCode&); |
| 81 |
void checkVariants(UErrorCode&); |
| 82 |
void check(const OptionMap&); |
| 83 |
void check(const Operand&); |
| 84 |
void check(const Expression&); |
| 85 |
void check(const Pattern&); |
| 86 |
const MFDataModel& dataModel; |
| 87 |
StaticErrors& errors; |
| 88 |
|
| 89 |
// Used for NFC normalization |
| 90 |
const MessageFormatter& context; |
| 91 |
}; // class Checker |
| 92 |
|
| 93 |
} // namespace message2 |
| 94 |
|
| 95 |
U_NAMESPACE_END |
| 96 |
|
| 97 |
#endif /* #if !UCONFIG_NO_MF2 */ |
| 98 |
|
| 99 |
#endif /* #if !UCONFIG_NO_FORMATTING */ |
| 100 |
|
| 101 |
#endif /* #if !UCONFIG_NO_NORMALIZATION */ |
| 102 |
|
| 103 |
#endif /* U_SHOW_CPLUSPLUS_API */ |
| 104 |
|
| 105 |
#endif // MESSAGEFORMAT_CHECKER_H |
| 106 |
|
| 107 |
#endif // U_HIDE_DEPRECATED_API |
| 108 |
// eof |
| 109 |
|