• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

abstractexpressionvisitor.h

00001 /* 
00002    Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
00003    Copyright 2009 Hamish Rodda <rodda@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KDEVPLATFORM_ABSTRACTEXPRESSIONVISITOR_H
00021 #define KDEVPLATFORM_ABSTRACTEXPRESSIONVISITOR_H
00022 
00023 #include "abstractcontextbuilder.h"
00024 #include "../types/abstracttype.h"
00025 #include "../declaration.h"
00026 #include "../ducontext.h"
00027 
00028 namespace KDevelop
00029 {
00030 
00031 template<typename T, typename NameT, typename TokenType, typename LanguageSpecificExpressionVisitorBase>
00032 class AbstractExpressionVisitor : public LanguageSpecificExpressionVisitorBase
00033 {
00034   public:
00035     AbstractExpressionVisitor()
00036     {
00037     }
00038 
00039     struct Instance {
00040       Instance() : isInstance(false) {
00041       }
00042       Instance( bool is ) : isInstance(is) {
00043       }
00044       Instance( DeclarationPointer decl ) : isInstance(true), declaration(decl) {
00045       }
00046       Instance( Declaration* decl ) : isInstance(true), declaration(DeclarationPointer(decl)) {
00047       }
00048       inline operator bool() const {
00049         return isInstance;
00050       }
00051 
00052       bool isInstance;
00053       DeclarationPointer declaration; //May contain the declaration of the instance, but only when isInstance is true. May also contain type-declaration, which signalizes that this is an instance of that type.
00054     };
00055 
00056     void parse( T* ast )
00057     {
00058       m_lastType = 0;
00059       m_lastInstance = Instance();
00060       DUContext* context = LanguageSpecificExpressionVisitorBase::contextFromNode(ast);
00061       Q_ASSERT(context);
00062       m_topContext = context->topContext();
00063       LanguageSpecificExpressionVisitorBase::startVisiting(ast);
00064       m_topContext = 0;
00065       flushUse();
00066     }
00067 
00068     const KDevelop::AbstractType::Ptr lastType() const
00069     {
00070       return m_lastType;
00071     }
00072 
00073     const Instance lastInstance() const
00074     {
00075       return m_lastInstance;
00076     }
00077 
00078   protected:
00079     KDevelop::AbstractType::Ptr lastType()
00080     {
00081       return m_lastType;
00082     }
00083 
00084     Instance lastInstance()
00085     {
00086       return m_lastInstance;
00087     }
00088 
00110     virtual void expressionType( T* node, const AbstractType::Ptr& type, Instance instance ) {
00111       Q_UNUSED(node) Q_UNUSED(type) Q_UNUSED(instance)
00112     }
00113 
00115     virtual void usingDeclaration( T* node, TokenType start_token, TokenType end_token, const KDevelop::DeclarationPointer& decl ) {
00116       Q_UNUSED(node) Q_UNUSED(start_token) Q_UNUSED(end_token) Q_UNUSED(decl)
00117     }
00118 
00125     virtual void problem( T* node, const QString& str )
00126     {
00127 #ifdef DUMP_PROBLEMS
00128       kDebug() << "Problem:" << str;
00129 #endif
00130     }
00131 
00132     void flushUse() {
00133       if( m_currentUse.isValid )
00134         usingDeclaration( m_currentUse.node, m_currentUse.start_token, m_currentUse.end_token, m_currentUse.declaration );
00135       m_currentUse.isValid = false;
00136     }
00137 
00138     struct CurrentUse {
00139       CurrentUse() : isValid(false), start_token(0), end_token(0) {
00140       }
00141       bool isValid;
00142       T* node;
00143       TokenType start_token, end_token;
00144       KDevelop::DeclarationPointer declaration;
00145     } m_currentUse; //This is used to temporarily delay the calling of usingDeclaration.
00146 
00147     KDevelop::TopDUContext* topContext() const
00148     {
00149       return m_topContext;
00150     }
00151 
00152   private:
00153     KDevelop::AbstractType::Ptr m_lastType;
00154     Instance m_lastInstance; //Contains whether the last evaluation resulted in an instance, and maybe the instance-declaration
00155 
00156     const KDevelop::TopDUContext* m_source;
00157 
00158     //Whenever a list of declarations is queried, it is stored here. Especially in visitName(...) and findMember(...)
00159     QList<KDevelop::DeclarationPointer> m_lastDeclarations;
00160 
00161     KDevelop::DUContext* m_currentContext;
00162     KDevelop::TopDUContext* m_topContext;
00163 };
00164 
00165 }
00166 
00167 #endif // KDEVPLATFORM_ABSTRACTEXPRESSIONVISITOR_H

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal