Files
qt-creator/src/libs/cplusplus/PreprocessorClient.h

123 lines
4.1 KiB
C
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
2008-12-02 15:08:31 +01:00
#ifndef PREPROCESSORCLIENT_H
#define PREPROCESSORCLIENT_H
2008-12-02 12:01:29 +01:00
#include <cplusplus/CPlusPlusForwardDeclarations.h>
#include <QStringList>
#include <QVector>
2008-12-08 12:59:33 +01:00
QT_BEGIN_NAMESPACE
class QByteArray;
QT_END_NAMESPACE
2008-12-02 12:01:29 +01:00
namespace CPlusPlus {
2008-12-02 12:01:29 +01:00
class ByteArrayRef;
class Macro;
class CPLUSPLUS_EXPORT MacroArgumentReference
{
unsigned _bytesOffset;
unsigned _bytesLength;
unsigned _utf16charsOffset;
unsigned _utf16charsLength;
public:
explicit MacroArgumentReference(unsigned bytesOffset = 0, unsigned bytesLength = 0,
unsigned utf16charsOffset = 0, unsigned utf16charsLength = 0)
: _bytesOffset(bytesOffset)
, _bytesLength(bytesLength)
, _utf16charsOffset(utf16charsOffset)
, _utf16charsLength(utf16charsLength)
{ }
unsigned bytesOffset() const
{ return _bytesOffset; }
unsigned bytesLength() const
{ return _bytesLength; }
unsigned utf16charsOffset() const
{ return _utf16charsOffset; }
unsigned utf16charsLength() const
{ return _utf16charsLength; }
};
2008-12-08 12:59:33 +01:00
class CPLUSPLUS_EXPORT Client
2008-12-02 12:01:29 +01:00
{
Client(const Client &other);
void operator=(const Client &other);
public:
enum IncludeType {
IncludeLocal,
IncludeGlobal,
IncludeNext
2008-12-02 12:01:29 +01:00
};
public:
Client();
virtual ~Client() = 0;
2008-12-02 12:01:29 +01:00
2008-12-08 12:59:33 +01:00
virtual void macroAdded(const Macro &macro) = 0;
virtual void passedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset,
unsigned line, const Macro &macro) = 0;
virtual void failedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset,
const ByteArrayRef &name) = 0;
2008-12-02 12:01:29 +01:00
virtual void notifyMacroReference(unsigned bytesOffset, unsigned utf16charsOffset,
unsigned line, const Macro &macro) = 0;
C++: Core changes in preprocessing Summary of most relevant items: - Preprocessor output format change. No more gen true/false. Instead a more intuitive and natural expansion (like from a real compiler) is performed directly corresponding to the macro invocation. Notice that information about the generated tokens is not lost, because it's now embedded in the expansion section header (in terms of lines and columns as explained in the code). In addition the location on where the macro expansion happens is also documented for future use. - Fix line control directives and associated token line numbers. This was not detected in tests cases because some of them were actually wrong: Within expansions the line information was being considered as originally computed in the macro definition, while the desired and expected for Creator's reporting mechanism (just like regular compilers) is the line from the expanded version of the tokens. - Do not allow for eager expansion. This was previously being done inside define directives. However, it's not allowed and might lead to incorrect results, since the argument substitution should only happen upon the macro invocation (and following nested ones). At least GCC and clang are consistent with that. See test case tst_Preprocessor:dont_eagerly_expand for a detailed explanation. - Revive the 'expanded' token flag. This is used to mark every token that originates from a macro expansion. Notice, however, that expanded tokens are not necessarily generated tokens (although every generated token is a expanded token). Expanded tokens that are not generated are those which are still considered by our code model features, since they are visible on the editor. The translation unit is smart enough to calculate line/column position for such tokens based on the information from the expansion section header. - How expansions are tracked has also changed. Now, we simply add two surrounding marker tokens to each "top-level" expansion sequence. There is an enumeration that control expansion states. Also, no "previous" token is kept around. - Preprocessor client methods suffered a change in signature so they now receive the line number of the action in question as a paramater. Previously such line could be retrieved by the client implementation by accessing the environment line. However, this is not reliable because we try to avoid synchronization of the output/environment lines in order to avoid unnecessary output, while expanding macros or handling preprocessor directives. - Although macros are not expanded during define directives (as mentioned above) the preprocessor client is now "notified" when it sees a macro. This is to allow usage tracking. - Other small stuff. This is all in one patch because the fixes are a consequence of the change in preprocessing control. Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-06-20 15:22:02 +02:00
virtual void startExpandingMacro(unsigned bytesOffset, unsigned utf16charsOffset,
unsigned line, const Macro &macro,
const QVector<MacroArgumentReference> &actuals
= QVector<MacroArgumentReference>()) = 0;
virtual void stopExpandingMacro(unsigned bytesOffset, const Macro &macro) = 0; // TODO: ?!
/// Mark the given macro name as the include guard for the current file.
virtual void markAsIncludeGuard(const QByteArray &macroName) = 0;
/// Start skipping from the given utf16charsOffset.
virtual void startSkippingBlocks(unsigned utf16charsOffset) = 0;
virtual void stopSkippingBlocks(unsigned utf16charsOffset) = 0;
virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType mode,
const QStringList &initialIncludes = QStringList()) = 0;
static inline bool isInjectedFile(const QString &fileName)
{
return fileName.startsWith(QLatin1Char('<')) && fileName.endsWith(QLatin1Char('>'));
}
2008-12-02 12:01:29 +01:00
};
} // namespace CPlusPlus
2008-12-02 12:01:29 +01:00
#endif // PREPROCESSORCLIENT_H