1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2001-2004 Roberto Raggi
|
---|
4 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
5 | ** All rights reserved.
|
---|
6 | ** Contact: Nokia Corporation ([email protected])
|
---|
7 | **
|
---|
8 | ** This file is part of the qt3to4 porting application of the Qt Toolkit.
|
---|
9 | **
|
---|
10 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
11 | ** Commercial Usage
|
---|
12 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
13 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
14 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
15 | ** a written agreement between you and Nokia.
|
---|
16 | **
|
---|
17 | ** GNU Lesser General Public License Usage
|
---|
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
19 | ** General Public License version 2.1 as published by the Free Software
|
---|
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
21 | ** packaging of this file. Please review the following information to
|
---|
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
24 | **
|
---|
25 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
26 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
28 | **
|
---|
29 | ** GNU General Public License Usage
|
---|
30 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
31 | ** General Public License version 3.0 as published by the Free Software
|
---|
32 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
33 | ** packaging of this file. Please review the following information to
|
---|
34 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
35 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
36 | **
|
---|
37 | ** If you have questions regarding the use of this file, please contact
|
---|
38 | ** Nokia at [email protected].
|
---|
39 | ** $QT_END_LICENSE$
|
---|
40 | **
|
---|
41 | ****************************************************************************/
|
---|
42 |
|
---|
43 | #ifndef SEMANTIC_H
|
---|
44 | #define SEMANTIC_H
|
---|
45 |
|
---|
46 | #include "treewalker.h"
|
---|
47 | #include "codemodel.h"
|
---|
48 | #include "tokenstreamadapter.h"
|
---|
49 |
|
---|
50 | #include <QObject>
|
---|
51 | #include <QStack>
|
---|
52 | #include <QList>
|
---|
53 | #include <QByteArray>
|
---|
54 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | class Semantic: public QObject, public TreeWalker
|
---|
58 | {
|
---|
59 | Q_OBJECT
|
---|
60 | public:
|
---|
61 | Semantic(CodeModel::NamespaceScope *globalScope,
|
---|
62 | TokenStreamAdapter::TokenStream *tokenStream,
|
---|
63 | TypedPool<CodeModel::Item> *storage);
|
---|
64 |
|
---|
65 | void parseAST(TranslationUnitAST *node);
|
---|
66 | signals:
|
---|
67 | void error(const QByteArray &message);
|
---|
68 | void warning(const QByteArray &message);
|
---|
69 | protected:
|
---|
70 | virtual void parseNamespace(NamespaceAST *);
|
---|
71 | virtual void parseClassSpecifier(ClassSpecifierAST *);
|
---|
72 | virtual void parseElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST *node);
|
---|
73 | virtual void parseSimpleDeclaration(SimpleDeclarationAST *);
|
---|
74 | virtual void parseDeclaration(AST *funSpec, AST *storageSpec, TypeSpecifierAST *typeSpec, InitDeclaratorAST *decl);
|
---|
75 | virtual void parseFunctionDeclaration(AST *funSpec, AST *storageSpec, TypeSpecifierAST *typeSpec, InitDeclaratorAST *decl);
|
---|
76 | virtual void parseFunctionArguments(const DeclaratorAST *declarator, CodeModel::FunctionMember *method);
|
---|
77 | virtual void parseFunctionDefinition(FunctionDefinitionAST *);
|
---|
78 | virtual void parseStatementList(StatementListAST *);
|
---|
79 | virtual void parseBaseClause(BaseClauseAST *baseClause, CodeModel::ClassScope * klass);
|
---|
80 | virtual void parseLinkageSpecification(LinkageSpecificationAST *);
|
---|
81 | virtual void parseUsing(UsingAST *);
|
---|
82 | virtual void parseUsingDirective(UsingDirectiveAST *);
|
---|
83 | virtual void parseExpression(AbstractExpressionAST*);
|
---|
84 | virtual void parseExpressionStatement(ExpressionStatementAST *node);
|
---|
85 | virtual void parseClassMemberAccess(ClassMemberAccessAST *node);
|
---|
86 | virtual void parseNameUse(NameAST*);
|
---|
87 | virtual void parseEnumSpecifier(EnumSpecifierAST *);
|
---|
88 | virtual void parseTypedef(TypedefAST *);
|
---|
89 | virtual void parseTypeSpecifier(TypeSpecifierAST *);
|
---|
90 |
|
---|
91 | QList<CodeModel::Member *> nameLookup(CodeModel::Scope *baseScope, const NameAST* name);
|
---|
92 | QList<CodeModel::Member *> unqualifiedNameLookup(CodeModel::Scope *baseScope, const NameAST* name);
|
---|
93 | QList<CodeModel::Member *> qualifiedNameLookup(CodeModel::Scope *baseScope, const NameAST* name);
|
---|
94 | QList<CodeModel::Member *> lookupNameInScope(CodeModel::Scope *scope, const NameAST* name);
|
---|
95 |
|
---|
96 | CodeModel::TypeMember *typeLookup(CodeModel::Scope *baseScope, const NameAST* name);
|
---|
97 | CodeModel::FunctionMember *functionLookup(CodeModel::Scope *baseScope, const DeclaratorAST *functionDeclarator);
|
---|
98 | CodeModel::Scope *scopeLookup(CodeModel::Scope *baseScope, const NameAST* name);
|
---|
99 | CodeModel::FunctionMember *selectFunction(QList<CodeModel::Member*> candidatateList, const DeclaratorAST *functionDeclarator);
|
---|
100 |
|
---|
101 | QByteArray typeOfDeclaration(TypeSpecifierAST *typeSpec, DeclaratorAST *declarator);
|
---|
102 | QList<QByteArray> scopeOfName(NameAST *id, const QList<QByteArray> &scope);
|
---|
103 | QList<QByteArray> scopeOfDeclarator(DeclaratorAST *d, const QList<QByteArray> &scope);
|
---|
104 | QByteArray declaratorToString(DeclaratorAST* declarator, const QByteArray& scope = QByteArray(), bool skipPtrOp = false);
|
---|
105 | QByteArray typeSpecToString(TypeSpecifierAST* typeSpec);
|
---|
106 |
|
---|
107 | QByteArray textOf(const AST *node) const;
|
---|
108 | void createNameUse(CodeModel::Member *member, NameAST *name);
|
---|
109 | void addNameUse(AST *node, CodeModel::NameUse *nameUse);
|
---|
110 | CodeModel::NameUse *findNameUse(AST *node);
|
---|
111 | TokenEngine::TokenRef tokenRefFromAST(AST *node);
|
---|
112 | private:
|
---|
113 | TokenStreamAdapter::TokenStream *m_tokenStream;
|
---|
114 | TypedPool<CodeModel::Item> *m_storage;
|
---|
115 | CodeModel::Member::Access m_currentAccess;
|
---|
116 | bool m_inSlots;
|
---|
117 | bool m_inSignals;
|
---|
118 | bool m_inStorageSpec;
|
---|
119 | bool m_inTypedef;
|
---|
120 |
|
---|
121 | QMap<int, CodeModel::NameUse *> m_nameUses;
|
---|
122 | QStack<CodeModel::Scope *> currentScope;
|
---|
123 | CodeModel::TypeMember *m_sharedUnknownMember;
|
---|
124 | private:
|
---|
125 | Semantic(const Semantic &source);
|
---|
126 | void operator = (const Semantic &source);
|
---|
127 | };
|
---|
128 |
|
---|
129 | QT_END_NAMESPACE
|
---|
130 |
|
---|
131 | #endif // SEMANTIC_H
|
---|