Macro.h 4.95 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
con's avatar
con committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*
  Copyright 2005 Roberto Raggi <roberto@kdevelop.org>

  Permission to use, copy, modify, distribute, and sell this software and its
  documentation for any purpose is hereby granted without fee, provided that
  the above copyright notice appear in all copies and that both that
  copyright notice and this permission notice appear in supporting
  documentation.

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

Roberto Raggi's avatar
Roberto Raggi committed
49 50
#ifndef CPLUSPLUS_PP_MACRO_H
#define CPLUSPLUS_PP_MACRO_H
con's avatar
con committed
51

52 53
#include "PPToken.h"

Roberto Raggi's avatar
Roberto Raggi committed
54 55
#include <CPlusPlusForwardDeclarations.h>

56 57 58
#include <QByteArray>
#include <QVector>
#include <QString>
con's avatar
con committed
59

60
namespace CPlusPlus {
con's avatar
con committed
61

62 63
class Environment;

Roberto Raggi's avatar
Roberto Raggi committed
64 65
class CPLUSPLUS_EXPORT Macro
{
66 67
    typedef Internal::PPToken PPToken;

Roberto Raggi's avatar
Roberto Raggi committed
68
public:
69
    Macro();
Roberto Raggi's avatar
Roberto Raggi committed
70

71 72
    QByteArray name() const
    { return _name; }
con's avatar
con committed
73

74 75
    void setName(const QByteArray &name)
    { _name = name; }
con's avatar
con committed
76

77 78 79 80 81
    const QByteArray definitionText() const
    { return _definitionText; }

    const QVector<PPToken> &definitionTokens() const
    { return _definitionTokens; }
82

83 84
    void setDefinition(const QByteArray &definitionText, const QVector<PPToken> &definitionTokens)
    { _definitionText = definitionText; _definitionTokens = definitionTokens; }
85

86
    const QVector<QByteArray> &formals() const
87 88 89 90 91
    { return _formals; }

    void addFormal(const QByteArray &formal)
    { _formals.append(formal); }

92
    QString fileName() const
93 94
    { return _fileName; }

95
    void setFileName(const QString &fileName)
96 97
    { _fileName = fileName; }

98 99 100 101 102 103
    unsigned fileRevision() const
    { return _fileRevision; }

    void setFileRevision(unsigned fileRevision)
    { _fileRevision = fileRevision; }

104 105 106 107 108 109
    unsigned line() const
    { return _line; }

    void setLine(unsigned line)
    { _line = line; }

110 111 112 113 114 115 116 117 118 119 120 121
    unsigned offset() const
    { return _offset; }

    void setOffset(unsigned offset)
    { _offset = offset; }

    unsigned length() const
    { return _length; }

    void setLength(unsigned length)
    { _length = length; }

122
    bool isHidden() const
123
    { return f._hidden; }
124 125

    void setHidden(bool isHidden)
126
    { f._hidden = isHidden; }
127 128

    bool isFunctionLike() const
129
    { return f._functionLike; }
130 131

    void setFunctionLike(bool isFunctionLike)
132
    { f._functionLike = isFunctionLike; }
133 134

    bool isVariadic() const
135
    { return f._variadic; }
136 137

    void setVariadic(bool isVariadic)
138
    { f._variadic = isVariadic; }
Roberto Raggi's avatar
Roberto Raggi committed
139

140
    QString toString() const;
141
    QString toStringWithLineBreaks() const;
142

143 144
private:
    friend class Environment;
145 146 147 148
    Macro *_next;
    unsigned _hashcode;

private:
149 150
    QString decoratedName() const;

151 152 153 154 155 156 157
    struct Flags
    {
        unsigned _hidden: 1;
        unsigned _functionLike: 1;
        unsigned _variadic: 1;
    };

158
    QByteArray _name;
159 160
    QByteArray _definitionText;
    QVector<PPToken> _definitionTokens;
161
    QVector<QByteArray> _formals;
162
    QString _fileName;
163
    unsigned _fileRevision;
164
    unsigned _line;
165 166
    unsigned _offset;
    unsigned _length;
167 168 169 170

    union
    {
        unsigned _state;
171
        Flags f;
172
    };
Roberto Raggi's avatar
Roberto Raggi committed
173
};
con's avatar
con committed
174

175
} // namespace CPlusPlus
con's avatar
con committed
176

Roberto Raggi's avatar
Roberto Raggi committed
177
#endif // CPLUSPLUS_PP_MACRO_H