diff options
author | Francois Ferrand <thetypz@gmail.com> | 2014-10-24 14:55:43 +0200 |
---|---|---|
committer | Francois Ferrand <thetypz@gmail.com> | 2016-03-08 17:24:22 +0000 |
commit | 41b232962a9222ddc594ef7d564041af0c476cb9 (patch) | |
tree | e38343360733bd601d388c08a9fb20ff43744023 /src/libs/3rdparty/cplusplus | |
parent | 90571432280a36f5e9ef5da468f832cf1d973f66 (diff) |
C++: fix trigraph parsing in macros.
Trigraphs must only be parsed before/during preprocessing. The preprocessor
will now replace trigraphs with their standard form, and re-lexing in
TranslationUnit will not try to parse any trigraph.
Also added a few missing trigraphs: ??=, ??', ??! and ??-.
Task-number: QTCREATORBUG-13253
Change-Id: I1723ed53b00090b878c22b83b7e963b647b65f72
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Lexer.cpp | 44 | ||||
-rw-r--r-- | src/libs/3rdparty/cplusplus/Lexer.h | 1 | ||||
-rw-r--r-- | src/libs/3rdparty/cplusplus/Token.h | 4 |
3 files changed, 47 insertions, 2 deletions
diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index db7cb9e0f8..68f87f126c 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -336,20 +336,62 @@ void Lexer::scan_helper(Token *tok) break; case '?': - if (_yychar == '?') { + if (_yychar == '?' && f._ppMode) { yyinp(); if (_yychar == '(') { yyinp(); tok->f.kind = T_LBRACKET; + tok->f.trigraph = true; } else if (_yychar == ')') { yyinp(); tok->f.kind = T_RBRACKET; + tok->f.trigraph = true; } else if (_yychar == '<') { yyinp(); tok->f.kind = T_LBRACE; + tok->f.trigraph = true; } else if (_yychar == '>') { yyinp(); tok->f.kind = T_RBRACE; + tok->f.trigraph = true; + } else if (_yychar == '=') { + yyinp(); + tok->f.trigraph = true; + if (_yychar == '?' && *(_currentChar + 1) == '?' && *(_currentChar + 2) == '=') { + yyinp(); + yyinp(); + yyinp(); + tok->f.kind = T_POUND_POUND; + } else { + tok->f.kind = T_POUND; + } + } else if (_yychar == '\'') { + yyinp(); + if (_yychar == '=') { + yyinp(); + tok->f.kind = T_CARET_EQUAL; + } else { + tok->f.kind = T_CARET; + } + tok->f.trigraph = true; + } else if (_yychar == '!') { + yyinp(); + if (_yychar == '=') { + yyinp(); + tok->f.kind = T_PIPE_EQUAL; + } else { + tok->f.kind = T_PIPE; + } + tok->f.trigraph = true; + } else if (_yychar == '-') { + yyinp(); + if (_yychar == '=') { + yyinp(); + tok->f.kind = T_TILDE_EQUAL; + } else { + tok->f.kind = T_TILDE; + } + tok->f.trigraph = true; } } else { tok->f.kind = T_QUESTION; diff --git a/src/libs/3rdparty/cplusplus/Lexer.h b/src/libs/3rdparty/cplusplus/Lexer.h index d47dcdf12a..8e862ea54c 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.h +++ b/src/libs/3rdparty/cplusplus/Lexer.h @@ -125,6 +125,7 @@ private: unsigned _scanKeywords: 1; unsigned _scanAngleStringLiteralTokens: 1; unsigned _ppMode: 1; + unsigned _ignoreTrigraph : 1; }; struct State { diff --git a/src/libs/3rdparty/cplusplus/Token.h b/src/libs/3rdparty/cplusplus/Token.h index 39a74031c9..afe732d493 100644 --- a/src/libs/3rdparty/cplusplus/Token.h +++ b/src/libs/3rdparty/cplusplus/Token.h @@ -371,8 +371,10 @@ public: // The token is C++11 user-defined literal such as: // 12_km, 0.5_Pa, 'c'_X, "abd"_L, u16"xyz"_M unsigned userDefinedLiteral : 1; + // Indicates the token is a trigraph + unsigned trigraph : 1; // Unused... - unsigned pad : 2; + unsigned pad : 1; // The token length in bytes and UTF16 chars. unsigned bytes : 16; unsigned utf16chars : 16; |