language/duchain
abstractexpressionvisitor.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
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;
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;
00155
00156 const KDevelop::TopDUContext* m_source;
00157
00158
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