Convert TypeTable::loadFromFile() to modern types.
[kdbg.git] / kdbg / typetable.h
blob6edc8142308035b726c01222fc0b213763713ebe
1 /*
2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
5 */
7 #include <qdict.h>
8 #include <qstring.h>
9 #include <qregexp.h>
10 #include <qstringlist.h>
11 #include <qstrlist.h>
13 class KConfigBase;
15 /**
16 * The maximum number of sub-expressions that may appear in a single struct
17 * value.
19 const int typeInfoMaxExpr = 5;
22 struct TypeInfo
24 TypeInfo(const QString& displayString);
25 ~TypeInfo();
27 /**
28 * The number of sub-expressions that need to be evaluated to get the
29 * struct value.
31 int m_numExprs;
32 /**
33 * This array contains the various parts which glue together the
34 * sub-expressions. The entries in this array are the parts that appear
35 * between the percent signs '%' of the display expression; hence,
36 * there is one part more than there are sub-expressions.
38 QString m_displayString[typeInfoMaxExpr+1];
39 /**
40 * This is a list of partial expressions. Each contains exactly one \%s,
41 * which will be replaced by the parent expression. The results are
42 * substituted for the percent signs in m_displayString.
44 QString m_exprStrings[typeInfoMaxExpr];
45 /**
46 * This is a list of guard expressions. Each contains exactly one \%s,
47 * which will be replaced by the parent expression, or is empty. If the
48 * evaluation of the resulting expression returns an error, the
49 * corresponding expression from m_exprStrings is not evaluated. (This
50 * is used to guard function calls.)
52 QString m_guardStrings[typeInfoMaxExpr];
53 /**
54 * Returns a pointer to a TypeInfo that identifies wchar_t
56 static TypeInfo* wchartType() { return &m_wchartType; }
57 /**
58 * Gets a pointer to a TypeInfo that means: "I don't know the type"
60 static TypeInfo* unknownType() { return &m_unknownType; }
62 protected:
63 static TypeInfo m_wchartType;
64 static TypeInfo m_unknownType;
67 class TypeTable
69 public:
70 TypeTable();
71 ~TypeTable();
73 /**
74 * Load all known type libraries.
76 static void initTypeLibraries();
78 /**
79 * Copy type infos to the specified dictionary.
81 void copyTypes(QDict<TypeInfo>& dict);
83 /**
84 * Does the file name match this library?
86 bool matchFileName(const char* fileName) {
87 return m_shlibNameRE.match(fileName) >= 0;
90 /**
91 * Is the specified builtin feature enabled in this type library?
93 bool isEnabledBuiltin(const QString& feature) const;
95 /**
96 * Returns the command to print the QString data.
98 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
100 protected:
102 * Loads the structure type information from the configuration files.
104 static void loadTypeTables();
105 void loadFromFile(const QString& fileName);
106 void readType(KConfigBase& cf, const QString& type);
107 QDict<TypeInfo> m_typeDict;
108 QDict<TypeInfo> m_aliasDict;
109 QString m_displayName;
110 QRegExp m_shlibNameRE;
111 QStringList m_enabledBuiltins;
112 char* m_printQStringDataCmd;
117 * This table keeps only references to the global type table. It is set up
118 * once per program.
120 class ProgramTypeTable
122 public:
123 ProgramTypeTable();
124 ~ProgramTypeTable();
127 * Load types belonging to the specified libraries.
129 void loadLibTypes(const QStrList& libs);
132 * Load types belonging to the specified type table
134 void loadTypeTable(TypeTable* table);
137 * Clears that types and starts over (e.g. for a new program).
139 void clear();
142 * Lookup a structure type.
144 * If the type is unknown, 0 is returned.
146 TypeInfo* lookup(const QString& type);
149 * Adds a new alias for a type name.
151 void registerAlias(const QString& name, TypeInfo* type);
154 * Tells whether we use built-in support to understand QStrings.
156 bool parseQt2QStrings() const { return m_parseQt2QStrings; }
159 * Tells whether QChar are defined like in Qt3.
161 bool qCharIsShort() const { return m_QCharIsShort; }
164 * Returns the command to print the QString data.
166 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
168 protected:
169 QDict<TypeInfo> m_types;
170 QDict<TypeInfo> m_aliasDict;
171 bool m_parseQt2QStrings;
172 bool m_QCharIsShort;
173 const char* m_printQStringDataCmd;