C++: Basic support for C++11 user-defined literals

1. Extends lexer so digit or string can be followed by underscore '_' and
   alphanumeric defining literal.

2. Extends parser so it accepts operator"" _abc(...) user-defined literal
   definition.

3. Adds Token::Flags.userDefinedLiteral bool flag field representing if token
   carries user-defined literal.

4. Adds C++11 auto tests case with: 12_km, 0.5_Pa, 'c'_X, "abd"_L, u"xyz"_M

5. All optional suffix scanning methods now return boolean if the suffix was
   found.

6. Adds C++ Lexer tests for user-defined literals with C++11 feature enabled.

This change however does not make QtCreator understand user-defined literal
semantics, e.g. properly resolve type when applying custom literal operator.

Change-Id: I30e62f025ec9fb11c39261985ea4d772b1a80949
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Adam Strzelecki
2014-11-02 14:42:23 +01:00
committed by Nikolai Kosjar
parent 5699991a2f
commit 425811291d
7 changed files with 115 additions and 22 deletions

View File

@@ -1274,6 +1274,14 @@ bool Parser::parseOperator(OperatorAST *&node) // ### FIXME
} else if (LA() == T_LBRACKET && LA(2) == T_RBRACKET) {
ast->op_token = ast->open_token = consumeToken();
ast->close_token = consumeToken();
} else if (_languageFeatures.cxx11Enabled &&
LA() == T_STRING_LITERAL && LA(2) == T_IDENTIFIER &&
!tok().f.userDefinedLiteral && tok().string->size() == 0 &&
tok(2).identifier->size() > 1 && tok(2).identifier->chars()[0] == '_') {
// C++11 user-defined literal operator, e.g.:
// int operator"" _abc123(const char *str, size_t size) { ... }
ast->op_token = consumeToken();
consumeToken(); // consume literal operator identifier
} else {
return false;
}