Bug 1501928 - Part 2: Remove MUST_MATCH_TOKEN_FUNC* macros. r=Waldo

This commit is contained in:
Tooru Fujisawa 2018-11-02 15:51:05 +09:00
Родитель da0a033384
Коммит f59014cf0f
2 изменённых файлов: 25 добавлений и 15 удалений

Просмотреть файл

@ -86,15 +86,6 @@ using BindingNameVector = Vector<BindingName, 6>;
} \
JS_END_MACRO
#define MUST_MATCH_TOKEN_FUNC_MOD_OR(func, modifier, errorNumber, failureValue) \
MUST_MATCH_TOKEN_INTERNAL((func)(token), modifier, error(errorNumber), failureValue)
#define MUST_MATCH_TOKEN_FUNC_OR(func, errorNumber, failureValue) \
MUST_MATCH_TOKEN_FUNC_MOD_OR(func, TokenStream::None, errorNumber, failureValue)
#define MUST_MATCH_TOKEN_FUNC(func, errorNumber) \
MUST_MATCH_TOKEN_FUNC_OR(func, errorNumber, null())
#define MUST_MATCH_TOKEN_MOD_WITH_REPORT_OR(tt, modifier, errorReport, failureValue) \
MUST_MATCH_TOKEN_INTERNAL(token == tt, modifier, errorReport, failureValue)
@ -708,15 +699,16 @@ GeneralParser<ParseHandler, Unit>::asFinalParser() const
}
template <class ParseHandler, typename Unit>
template <typename ConditionT>
bool
GeneralParser<ParseHandler, Unit>::mustMatchToken(TokenKind expected, Modifier modifier,
unsigned errorNumber)
GeneralParser<ParseHandler, Unit>::mustMatchTokenInternal(ConditionT condition, Modifier modifier,
unsigned errorNumber)
{
TokenKind actual;
if (!tokenStream.getToken(&actual, modifier)) {
return false;
}
if (actual != expected) {
if (!condition(actual)) {
error(errorNumber);
return false;
}
@ -5699,7 +5691,9 @@ Parser<FullParseHandler, Unit>::namedImportsOrNamespaceImport(TokenKind tt,
return false;
}
MUST_MATCH_TOKEN_FUNC_OR(TokenKindIsPossibleIdentifierName, JSMSG_NO_BINDING_NAME, false);
if (!mustMatchToken(TokenKindIsPossibleIdentifierName, JSMSG_NO_BINDING_NAME)) {
return false;
}
NameNodeType importName = newName(context->names().star);
if (!importName) {
@ -6321,7 +6315,9 @@ GeneralParser<ParseHandler, Unit>::exportClause(uint32_t begin)
return null();
}
if (foundAs) {
MUST_MATCH_TOKEN_FUNC(TokenKindIsPossibleIdentifierName, JSMSG_NO_EXPORT_NAME);
if (!mustMatchToken(TokenKindIsPossibleIdentifierName, JSMSG_NO_EXPORT_NAME)) {
return null();
}
}
NameNodeType exportName = newName(anyChars.currentName());

Просмотреть файл

@ -929,11 +929,25 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE)
*/
ListNodeType parse();
private:
template<typename ConditionT>
MOZ_MUST_USE bool mustMatchTokenInternal(ConditionT condition, Modifier modifier,
unsigned errorNumber);
public:
MOZ_MUST_USE bool mustMatchToken(TokenKind expected, Modifier modifier, unsigned errorNumber) {
return mustMatchTokenInternal([expected](TokenKind actual) { return actual == expected; },
modifier, errorNumber);
}
MOZ_MUST_USE bool mustMatchToken(TokenKind excpected, unsigned errorNumber) {
return mustMatchToken(excpected, TokenStream::None, errorNumber);
}
MOZ_MUST_USE bool mustMatchToken(TokenKind expected, Modifier modifier, unsigned errorNumber);
template<typename ConditionT>
MOZ_MUST_USE bool mustMatchToken(ConditionT condition, unsigned errorNumber) {
return mustMatchTokenInternal(condition, TokenStream::None, errorNumber);
}
/* Report the given error at the current offset. */
void error(unsigned errorNumber, ...);