diff options
| author | Christian Kandeler <christian.kandeler@qt.io> | 2024-06-05 17:32:36 +0200 |
|---|---|---|
| committer | Christian Kandeler <christian.kandeler@qt.io> | 2024-06-13 13:03:08 +0000 |
| commit | ccae4fc93c3bdddc37e8cf68d9f0923fb64c1e7c (patch) | |
| tree | 68bba62b519cb0499435f700e613137375b9b1f9 /src/libs/cplusplus/pp-engine.cpp | |
| parent | d49934604b2ffe5cbfc979f5a5905931ea33bbe7 (diff) | |
CppEditor: Consider #pragma once when inserting includes
Fixes: QTCREATORBUG-30808
Change-Id: Ib9f2ed1e428abfaa608b9dc42bc09dd2d403ee56
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/libs/cplusplus/pp-engine.cpp')
| -rw-r--r-- | src/libs/cplusplus/pp-engine.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 74ca1ceb516..a1343e54713 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -1626,10 +1626,10 @@ void Preprocessor::handlePreprocessorDirective(PPToken *tk) static const QByteArray ppInclude("include"); static const QByteArray ppIncludeNext("include_next"); static const QByteArray ppImport("import"); + static const QByteArray ppPragma("pragma"); //### TODO: // line // error - // pragma if (tk->is(T_IDENTIFIER)) { const ByteArrayRef directive = tk->asByteArrayRef(); @@ -1640,6 +1640,8 @@ void Preprocessor::handlePreprocessorDirective(PPToken *tk) handleIfDefDirective(true, tk); } else if (directive == ppEndIf) { handleEndIfDirective(tk, poundToken); + } else if (directive == ppPragma) { + handlePragmaDirective(tk); } else { m_state.updateIncludeGuardState(State::IncludeGuardStateHint_OtherToken); @@ -1866,6 +1868,23 @@ void Preprocessor::handleDefineDirective(PPToken *tk) m_client->macroAdded(macro); } +void Preprocessor::handlePragmaDirective(PPToken *tk) +{ + Pragma pragma; + pragma.line = tk->lineno; + lex(tk); // consume "pragma" token + + while (isContinuationToken(*tk)) { + if (!consumeComments(tk)) + return; + pragma.tokens << tk->asByteArrayRef().toByteArray(); + lex(tk); + } + + if (m_client) + m_client->pragmaAdded(pragma); +} + QByteArray Preprocessor::expand(PPToken *tk, PPToken *lastConditionToken) { unsigned line = tk->lineno; |
