tools/porting/src/semantic.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2001-2004 Roberto Raggi
       
     4 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     5 ** All rights reserved.
       
     6 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     7 **
       
     8 ** This file is part of the qt3to4 porting application of the Qt Toolkit.
       
     9 **
       
    10 ** $QT_BEGIN_LICENSE:LGPL$
       
    11 ** No Commercial Usage
       
    12 ** This file contains pre-release code and may not be distributed.
       
    13 ** You may use this file in accordance with the terms and conditions
       
    14 ** contained in the Technology Preview License Agreement accompanying
       
    15 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    30 ** Nokia at qt-info@nokia.com.
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 **
       
    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