Introduce a new object type that represents value trees of the parse results.
[kdbg.git] / kdbg / exprwnd.h
blob2a81f01a714580efdbe064aee683fbb4f4eed946
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #ifndef EXPRWND_H
7 #define EXPRWND_H
9 #include "ktreeview.h"
10 #include <qlineedit.h>
11 #include <qptrlist.h>
12 #include <qstrlist.h>
14 class ProgramTypeTable;
15 class TypeInfo;
17 /* a variable's value is the tree of sub-variables */
19 class VarTree : public KTreeViewItem
21 public:
22 enum VarKind { VKsimple, VKpointer, VKstruct, VKarray,
23 VKdummy /* used to update only children */
25 VarKind m_varKind;
26 enum NameKind { NKplain, NKstatic, NKtype,
27 NKaddress /* a dereferenced pointer */
29 NameKind m_nameKind;
30 QString m_value;
31 bool m_valueChanged;
32 TypeInfo* m_type; /* type of struct */
33 int m_exprIndex; /* used in struct value update */
34 bool m_exprIndexUseGuard; /* ditto; if guard expr should be used */
35 QString m_partialValue; /* while struct value update is in progress */
37 VarTree(const QString& name, NameKind kind);
38 virtual ~VarTree();
39 public:
40 void paintValue(QPainter* painter);
41 int valueWidth();
42 QString computeExpr() const;
43 bool isToplevelExpr() const;
44 /** is this element an ancestor of (or equal to) child? */
45 bool isAncestorEq(const VarTree* child) const;
46 /** update the value; return if repaint is necessary */
47 bool updateValue(const QString& newValue);
48 /** find out the type of this value using the child values */
49 void inferTypesOfChildren(ProgramTypeTable& typeTable);
50 /** get the type from base class part */
51 TypeInfo* inferTypeFromBaseClass();
52 /** returns whether the pointer is a wchar_t */
53 bool isWcharT() const;
55 VarTree* firstChild() const { return static_cast<VarTree*>(getChild()); }
56 VarTree* nextSibling() const { return static_cast<VarTree*>(getSibling()); }
59 /**
60 * Represents the value tree that is parsed by the debugger drivers.
62 struct ExprValue
64 QString m_name;
65 QString m_value;
66 VarTree::VarKind m_varKind;
67 VarTree::NameKind m_nameKind;
68 ExprValue* m_child; /* the first child expression */
69 ExprValue* m_next; /* the next sibling expression */
70 bool m_initiallyExpanded;
72 ExprValue(const QString& name, VarTree::NameKind kind);
73 ~ExprValue();
75 void appendChild(ExprValue* newChild);
76 uint childCount() const;
80 class ExprWnd;
82 class ValueEdit : public QLineEdit
84 Q_OBJECT
85 public:
86 ValueEdit(ExprWnd* parent);
87 ~ValueEdit();
89 void terminate(bool commit);
90 int m_row;
91 bool m_finished;
92 protected:
93 void keyPressEvent(QKeyEvent *e);
94 void focusOutEvent(QFocusEvent* ev);
95 void paintEvent(QPaintEvent* e);
96 public slots:
97 void slotSelectionChanged();
98 signals:
99 void done(int, const QString&);
103 class ExprWnd : public KTreeView
105 Q_OBJECT
106 public:
107 ExprWnd(QWidget* parent, const char* name);
108 ~ExprWnd();
110 /** fills the list with the expressions at the topmost level */
111 void exprList(QStrList& exprs);
112 /** appends a copy of expr to the end of the tree at the topmost level;
113 * returns a pointer to the inserted top-level item */
114 VarTree* insertExpr(ExprValue* expr, ProgramTypeTable& typeTable);
115 /** updates an existing expression */
116 void updateExpr(ExprValue* expr, ProgramTypeTable& typeTable);
117 void updateExpr(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
118 /** updates the value and repaints it for a single item (not the children) */
119 void updateSingleExpr(VarTree* display, ExprValue* newValues);
120 /** updates only the value of the node */
121 void updateStructValue(VarTree* display);
122 /** get a top-level expression by name */
123 VarTree* topLevelExprByName(const char* name);
124 /** return a member of the struct that pointer \a v refers to */
125 static VarTree* ptrMemberByName(VarTree* v, const QString& name);
126 /** return a member of the struct \a v */
127 static VarTree* memberByName(VarTree* v, const QString& name);
128 /** removes an expression; must be on the topmost level*/
129 void removeExpr(VarTree* item);
130 /** clears the list of pointers needing updates */
131 void clearPendingUpdates();
132 /** returns a pointer to update (or 0) and removes it from the list */
133 VarTree* nextUpdatePtr();
134 VarTree* nextUpdateType();
135 VarTree* nextUpdateStruct();
136 void editValue(int row, const QString& text);
137 /** tells whether the a value is currently edited */
138 bool isEditing() const;
140 VarTree* firstChild() const { return static_cast<VarTree*>(itemAt(0)); }
141 VarTree* selectedItem() const { return static_cast<VarTree*>(getCurrentItem()); }
143 protected:
144 bool updateExprRec(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
145 void replaceChildren(VarTree* display, ExprValue* newValues);
146 virtual void paintCell(QPainter* painter, int row, int col);
147 virtual int cellWidth(int col) const;
148 void updateValuesWidth();
149 static bool getMaxValueWidth(KTreeViewItem* item, void* user);
150 void collectUnknownTypes(VarTree* item);
151 static bool collectUnknownTypes(KTreeViewItem* item, void* user);
152 static QString formatWCharPointer(QString value);
153 int maxValueWidth;
154 QPixmap m_pixPointer;
156 QList<VarTree> m_updatePtrs; /* dereferenced pointers that need update */
157 QList<VarTree> m_updateType; /* structs whose type must be determined */
158 QList<VarTree> m_updateStruct; /* structs whose nested value needs update */
160 ValueEdit m_edit;
162 /** remove items that are in the subTree from the list */
163 void unhookSubtree(VarTree* subTree);
164 static void unhookSubtree(QList<VarTree>& list, VarTree* subTree);
166 protected slots:
167 void slotExpandOrCollapse(int);
169 signals:
170 void removingItem(VarTree*);
171 void editValueCommitted(int, const QString&);
174 #endif // EXPRWND_H