File indexing completed on 2024-05-12 15:37:53

0001 #ifndef DEBUGDOCUMENT_H
0002 #define DEBUGDOCUMENT_H
0003 
0004 #include <QHash>
0005 #include <QObject>
0006 #include <QVector>
0007 #include <QStringList>
0008 
0009 #include "misc/shared.h"
0010 
0011 namespace KJS
0012 {
0013 class Interpreter;
0014 }
0015 
0016 namespace KTextEditor
0017 {
0018 class Document;
0019 class View;
0020 class Editor;
0021 }
0022 
0023 namespace KJSDebugger
0024 {
0025 
0026 class DebugDocument : public QObject, public khtml::Shared<DebugDocument>
0027 {
0028     Q_OBJECT
0029 public:
0030     typedef SharedPtr<DebugDocument> Ptr;
0031 
0032     DebugDocument(KJS::Interpreter *interp, const QString &url,
0033                   int sourceId, int baseLine, const QString &source);
0034     ~DebugDocument();
0035 
0036     QString name() const;
0037     QString url() const;
0038     int     sid() const;
0039 
0040     KTextEditor::Document *viewerDocument();
0041     KTextEditor::View     *viewerView();
0042 
0043     // Marks the document as being discarded for reload, so that new data should be set here.
0044     void markReload();
0045     bool isMarkedReload() const;
0046 
0047     void reloaded(int sourceId, const QString &source);
0048 
0049     void setBreakpoint(int lineNumber);
0050     void removeBreakpoint(int lineNumber);
0051     bool hasBreakpoint(int lineNumber);
0052 
0053     // We keep track of whether documents have functions, since we can't discard
0054     // eval contexts that do
0055     bool hasFunctions();
0056     void setHasFunctions();
0057 
0058     KJS::Interpreter *interpreter();
0059 
0060     int baseLine() const;
0061     int length()   const;
0062 
0063 Q_SIGNALS:
0064     void documentDestroyed(KJSDebugger::DebugDocument *);
0065 private:
0066     QString m_url;
0067     QString m_name;
0068     KJS::Interpreter *m_interpreter;
0069 
0070     bool m_hasFunctions;
0071 
0072     // This is set to true when we are rebuilding the document.
0073     // in that case, the UI might get undesired mark add/remove events,
0074     // and update the breakpoint set accordingly --- such as removing all of them
0075     // on clear.
0076     bool m_rebuilding;
0077 
0078     bool m_reload;
0079 
0080     int m_firstLine;
0081     int m_sourceId;
0082     QStringList m_sourceLines;
0083     QString     m_md5; // empty if invalid/not computed.
0084 
0085     void rebuildViewerDocument();
0086     void setupViewerDocument();
0087 
0088     // We store breakpoints differently for scopes with URL
0089     // and without it. Those that have it are stored globally,
0090     // so that breakpoints persist across multiple visits of the
0091     // document. For eval scopes, we store them based on the MD5
0092     // of the source code.
0093     static QHash<QString, QVector<int> > *s_perUrlBreakPoints;
0094     static QHash<QString, QVector<int> > *s_perHashBreakPoints;
0095 
0096     QVector<int> &breakpoints();
0097 
0098     KTextEditor::Document *m_kteDoc;
0099     KTextEditor::View     *m_kteView;
0100     static KTextEditor::Editor *s_kate;
0101     static KTextEditor::Editor *kate();
0102 };
0103 
0104 }
0105 
0106 #endif