Merge with 2.0.
[kdbg.git] / kdbg / typetable.h
blobdc05a5328311b72c13b2e40d5ab7792006a6b049
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include <qdict.h>
7 #include <qstring.h>
8 #include <qregexp.h>
9 #include <qstrlist.h>
11 class KConfigBase;
13 /**
14 * The maximum number of sub-expressions that may appear in a single struct
15 * value.
17 const int typeInfoMaxExpr = 5;
20 struct TypeInfo
22 TypeInfo(const QString& displayString);
23 ~TypeInfo();
25 /**
26 * The number of sub-expressions that need to be evaluated to get the
27 * struct value.
29 int m_numExprs;
30 /**
31 * This array contains the various parts which glue together the
32 * sub-expressions. The entries in this array are the parts that appear
33 * between the percent signs '%' of the display expression; hence,
34 * there is one part more than there are sub-expressions.
36 QString m_displayString[typeInfoMaxExpr+1];
37 /**
38 * This is a list of partial expressions. Each contains exactly one %s,
39 * which will be replaced by the parent expression. The results are
40 * substituted for the percent signs in m_displayString.
42 QString m_exprStrings[typeInfoMaxExpr];
43 /**
44 * This is a list of guard expressions. Each contains exactly one %s,
45 * which will be replaced by the parent expression, or is empty. If the
46 * evaluation of the resulting expression returns an error, the
47 * corresponding expression from m_exprStrings is not evaluated. (This
48 * is used to guard function calls.)
50 QString m_guardStrings[typeInfoMaxExpr];
51 /**
52 * Returns a pointer to a TypeInfo that identifies wchar_t
54 static TypeInfo* wchartType() { return &m_wchartType; }
55 /**
56 * Gets a pointer to a TypeInfo that means: "I don't know the type"
58 static TypeInfo* unknownType() { return &m_unknownType; }
60 protected:
61 static TypeInfo m_wchartType;
62 static TypeInfo m_unknownType;
65 class TypeTable
67 public:
68 TypeTable();
69 ~TypeTable();
71 /**
72 * Load all known type libraries.
74 static void initTypeLibraries();
76 /**
77 * Copy type infos to the specified dictionary.
79 void copyTypes(QDict<TypeInfo>& dict);
81 /**
82 * Does the file name match this library?
84 bool matchFileName(const char* fileName) {
85 return m_shlibNameRE.match(fileName) >= 0;
88 /**
89 * Is the specified builtin feature enabled in this type library?
91 bool isEnabledBuiltin(const char* feature);
93 /**
94 * Returns the command to print the QString data.
96 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
98 protected:
99 /**
100 * Loads the structure type information from the configuration files.
102 static void loadTypeTables();
103 void loadFromFile(const QString& fileName);
104 void readType(KConfigBase& cf, const char* type);
105 QDict<TypeInfo> m_typeDict;
106 QDict<TypeInfo> m_aliasDict;
107 QString m_displayName;
108 QRegExp m_shlibNameRE;
109 QStrList m_enabledBuiltins;
110 char* m_printQStringDataCmd;
115 * This table keeps only references to the global type table. It is set up
116 * once per program.
118 class ProgramTypeTable
120 public:
121 ProgramTypeTable();
122 ~ProgramTypeTable();
125 * Load types belonging to the specified libraries.
127 void loadLibTypes(const QStrList& libs);
130 * Load types belonging to the specified type table
132 void loadTypeTable(TypeTable* table);
135 * Clears that types and starts over (e.g. for a new program).
137 void clear();
140 * Lookup a structure type.
142 * A type is looked up in the following manner:
144 * - If the type is unknown, 0 is returned.
146 * - If the type is known and it belongs to a shared library and that
147 * shared library was loaded, the type is returned such that isNew()
148 * returns true.
150 * - Otherwise the type is returned such that isNew() returns true.
152 TypeInfo* lookup(const char* type);
155 * Adds a new alias for a type name.
157 void registerAlias(const QString& name, TypeInfo* type);
160 * Tells whether we use built-in support to understand QStrings.
162 bool parseQt2QStrings() const { return m_parseQt2QStrings; }
165 * Tells whether QChar are defined like in Qt3.
167 bool qCharIsShort() const { return m_QCharIsShort; }
170 * Returns the command to print the QString data.
172 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
174 protected:
175 QDict<TypeInfo> m_types;
176 QDict<TypeInfo> m_aliasDict;
177 bool m_parseQt2QStrings;
178 bool m_QCharIsShort;
179 const char* m_printQStringDataCmd;