Control.h 9 KB
Newer Older
con's avatar
con committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// 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
// AUTHORS OR COPYRIGHT HOLDERS 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.

#ifndef CPLUSPLUS_CONTROL_H
#define CPLUSPLUS_CONTROL_H

#include "CPlusPlusForwardDeclarations.h"
25
#include "ASTfwd.h"
26
#include "Names.h"
Roberto Raggi's avatar
Roberto Raggi committed
27
28

namespace CPlusPlus {
con's avatar
con committed
29

30
31
32
33
34
35
36
class CPLUSPLUS_EXPORT TopLevelDeclarationProcessor
{
public:
    virtual ~TopLevelDeclarationProcessor() {}
    virtual bool processDeclaration(DeclarationAST *ast) = 0;
};

con's avatar
con committed
37
38
39
40
41
42
43
44
45
class CPLUSPLUS_EXPORT Control
{
public:
    Control();
    ~Control();

    TranslationUnit *translationUnit() const;
    TranslationUnit *switchTranslationUnit(TranslationUnit *unit);

46
47
48
    TopLevelDeclarationProcessor *topLevelDeclarationProcessor() const;
    void setTopLevelDeclarationProcessor(TopLevelDeclarationProcessor *processor);

con's avatar
con committed
49
50
51
    DiagnosticClient *diagnosticClient() const;
    void setDiagnosticClient(DiagnosticClient *diagnosticClient);

52
53
54
    /// Returns the canonical anonymous name id
    const AnonymousNameId *anonymousNameId(unsigned classTokenIndex);

con's avatar
con committed
55
    /// Returns the canonical template name id.
Roberto Raggi's avatar
Roberto Raggi committed
56
    const TemplateNameId *templateNameId(const Identifier *id,
57
                                         bool isSpecialization,
Roberto Raggi's avatar
Roberto Raggi committed
58
59
                                         const FullySpecifiedType *const args = 0,
                                         unsigned argc = 0);
con's avatar
con committed
60
61

    /// Returns the canonical destructor name id.
62
    const DestructorNameId *destructorNameId(const Name *name);
con's avatar
con committed
63
64

    /// Returns the canonical operator name id.
65
    const OperatorNameId *operatorNameId(OperatorNameId::Kind operatorId);
con's avatar
con committed
66
67

    /// Returns the canonical conversion name id.
Roberto Raggi's avatar
Roberto Raggi committed
68
    const ConversionNameId *conversionNameId(const FullySpecifiedType &type);
con's avatar
con committed
69
70

    /// Returns the canonical qualified name id.
71
    const QualifiedNameId *qualifiedNameId(const Name *base, const Name *name);
con's avatar
con committed
72

Roberto Raggi's avatar
Roberto Raggi committed
73
74
75
    const SelectorNameId *selectorNameId(const Name *const *names,
                                         unsigned nameCount,
                                         bool hasArguments);
76

con's avatar
con committed
77
78
79
80
81
82
83
84
85
86
    /// Returns a Type object of type VoidType.
    VoidType *voidType();

    /// Returns a Type object of type IntegerType.
    IntegerType *integerType(int integerId);

    /// Returns a Type object of type FloatType.
    FloatType *floatType(int floatId);

    /// Returns a Type object of type PointertoMemberType.
Roberto Raggi's avatar
Roberto Raggi committed
87
    PointerToMemberType *pointerToMemberType(const Name *memberName,
88
                                             const FullySpecifiedType &elementType);
con's avatar
con committed
89
90

    /// Returns a Type object of type PointerType.
91
    PointerType *pointerType(const FullySpecifiedType &elementType);
con's avatar
con committed
92
93

    /// Returns a Type object of type ReferenceType.
94
    ReferenceType *referenceType(const FullySpecifiedType &elementType, bool rvalueRef);
con's avatar
con committed
95
96

    /// Retruns a Type object of type ArrayType.
97
    ArrayType *arrayType(const FullySpecifiedType &elementType, unsigned size = 0);
con's avatar
con committed
98
99

    /// Returns a Type object of type NamedType.
Roberto Raggi's avatar
Roberto Raggi committed
100
    NamedType *namedType(const Name *name);
con's avatar
con committed
101
102

    /// Creates a new Declaration symbol.
Roberto Raggi's avatar
Roberto Raggi committed
103
    Declaration *newDeclaration(unsigned sourceLocation, const Name *name);
con's avatar
con committed
104

105
106
107
    /// Creates a new EnumeratorDeclaration symbol.
    EnumeratorDeclaration *newEnumeratorDeclaration(unsigned sourceLocation, const Name *name);

con's avatar
con committed
108
    /// Creates a new Argument symbol.
Roberto Raggi's avatar
Roberto Raggi committed
109
    Argument *newArgument(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
110

Roberto Raggi's avatar
Roberto Raggi committed
111
112
113
    /// Creates a new Argument symbol.
    TypenameArgument *newTypenameArgument(unsigned sourceLocation, const Name *name = 0);

con's avatar
con committed
114
    /// Creates a new Function symbol.
Roberto Raggi's avatar
Roberto Raggi committed
115
    Function *newFunction(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
116
117

    /// Creates a new Namespace symbol.
Roberto Raggi's avatar
Roberto Raggi committed
118
    Namespace *newNamespace(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
119

120
121
122
    /// Creates a new Template symbol.
    Template *newTemplate(unsigned sourceLocation, const Name *name = 0);

123
124
125
    /// Creates a new Namespace symbol.
    NamespaceAlias *newNamespaceAlias(unsigned sourceLocation, const Name *name = 0);

con's avatar
con committed
126
    /// Creates a new BaseClass symbol.
Roberto Raggi's avatar
Roberto Raggi committed
127
    BaseClass *newBaseClass(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
128
129

    /// Creates a new Class symbol.
Roberto Raggi's avatar
Roberto Raggi committed
130
    Class *newClass(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
131
132

    /// Creates a new Enum symbol.
Roberto Raggi's avatar
Roberto Raggi committed
133
    Enum *newEnum(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
134
135
136
137
138

    /// Creates a new Block symbol.
    Block *newBlock(unsigned sourceLocation);

    /// Creates a new UsingNamespaceDirective symbol.
Roberto Raggi's avatar
Roberto Raggi committed
139
    UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
140
141

    /// Creates a new UsingDeclaration symbol.
Roberto Raggi's avatar
Roberto Raggi committed
142
    UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, const Name *name = 0);
con's avatar
con committed
143

144
    /// Creates a new ForwardClassDeclaration symbol.
Roberto Raggi's avatar
Roberto Raggi committed
145
    ForwardClassDeclaration *newForwardClassDeclaration(unsigned sourceLocation, const Name *name = 0);
146

147
148
149
    /// Creates a new QtPropertyDeclaration symbol.
    QtPropertyDeclaration *newQtPropertyDeclaration(unsigned sourceLocation, const Name *name = 0);

150
151
152
    /// Creates a new QtEnum symbol.
    QtEnum *newQtEnum(unsigned sourceLocation, const Name *name = 0);

Roberto Raggi's avatar
Roberto Raggi committed
153
154
    ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name);
    ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name);
155

156
    /// Creates a new Objective-C class symbol.
Roberto Raggi's avatar
Roberto Raggi committed
157
    ObjCClass *newObjCClass(unsigned sourceLocation, const Name *name = 0);
158
159

    /// Creates a new Objective-C class forward declaration symbol.
Roberto Raggi's avatar
Roberto Raggi committed
160
    ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name = 0);
161
162

    /// Creates a new Objective-C protocol symbol.
Roberto Raggi's avatar
Roberto Raggi committed
163
    ObjCProtocol *newObjCProtocol(unsigned sourceLocation, const Name *name = 0);
164
165

    /// Creates a new Objective-C protocol forward declaration symbol.
Roberto Raggi's avatar
Roberto Raggi committed
166
    ObjCForwardProtocolDeclaration *newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name = 0);
167

168
    /// Creates a new Objective-C method symbol.
Roberto Raggi's avatar
Roberto Raggi committed
169
    ObjCMethod *newObjCMethod(unsigned sourceLocation, const Name *name = 0);
170

171
    /// Creates a new Objective-C @property declaration symbol.
Roberto Raggi's avatar
Roberto Raggi committed
172
    ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name);
173

Erik Verbruggen's avatar
Erik Verbruggen committed
174
    const Identifier *deprecatedId() const;
175
    const Identifier *unavailableId() const;
176
    // Objective-C specific context keywords.
Roberto Raggi's avatar
Roberto Raggi committed
177
178
179
180
181
182
183
184
    const Identifier *objcGetterId() const;
    const Identifier *objcSetterId() const;
    const Identifier *objcReadwriteId() const;
    const Identifier *objcReadonlyId() const;
    const Identifier *objcAssignId() const;
    const Identifier *objcRetainId() const;
    const Identifier *objcCopyId() const;
    const Identifier *objcNonatomicId() const;
185
186
187
    // C++11 context keywords
    const Identifier *cpp11Override() const;
    const Identifier *cpp11Final() const;
Roberto Raggi's avatar
Roberto Raggi committed
188

189
190
    const OperatorNameId *findOperatorNameId(OperatorNameId::Kind operatorId) const;

Roberto Raggi's avatar
Roberto Raggi committed
191
    const Identifier *findIdentifier(const char *chars, unsigned size) const;
192
193
    const Identifier *identifier(const char *chars, unsigned size);
    const Identifier *identifier(const char *chars);
con's avatar
con committed
194

195
    typedef const Identifier *const *IdentifierIterator;
196
197
    typedef const StringLiteral *const *StringLiteralIterator;
    typedef const NumericLiteral *const *NumericLiteralIterator;
198
199
200
201

    IdentifierIterator firstIdentifier() const;
    IdentifierIterator lastIdentifier() const;

202
203
204
205
206
207
    StringLiteralIterator firstStringLiteral() const;
    StringLiteralIterator lastStringLiteral() const;

    NumericLiteralIterator firstNumericLiteral() const;
    NumericLiteralIterator lastNumericLiteral() const;

208
209
    const StringLiteral *stringLiteral(const char *chars, unsigned size);
    const StringLiteral *stringLiteral(const char *chars);
con's avatar
con committed
210

211
212
    const NumericLiteral *numericLiteral(const char *chars, unsigned size);
    const NumericLiteral *numericLiteral(const char *chars);
con's avatar
con committed
213

214
215
    Symbol **firstSymbol() const;
    Symbol **lastSymbol() const;
216
    unsigned symbolCount() const;
217

218
    bool hasSymbol(Symbol *symbol) const;
219
    void addSymbol(Symbol *symbol);
220

221
222
    void squeeze();

con's avatar
con committed
223
224
225
226
227
228
private:
    class Data;
    friend class Data;
    Data *d;
};

229
} // namespace CPlusPlus
Roberto Raggi's avatar
Roberto Raggi committed
230

con's avatar
con committed
231
232

#endif // CPLUSPLUS_CONTROL_H