Use QFileInfo to get the file's name instead of parsing the path manually.
[kdbg.git] / kdbg / typetable.h
blobfc689980bcc4209579a69ab0f325a18be50978a9
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 <map>
12 #include <qstrlist.h>
14 class KConfigBase;
16 /**
17 * The maximum number of sub-expressions that may appear in a single struct
18 * value.
20 const int typeInfoMaxExpr = 5;
23 struct TypeInfo
25 TypeInfo(const QString& displayString);
26 ~TypeInfo();
28 /**
29 * The number of sub-expressions that need to be evaluated to get the
30 * struct value.
32 int m_numExprs;
33 /**
34 * This array contains the various parts which glue together the
35 * sub-expressions. The entries in this array are the parts that appear
36 * between the percent signs '%' of the display expression; hence,
37 * there is one part more than there are sub-expressions.
39 QString m_displayString[typeInfoMaxExpr+1];
40 /**
41 * This is a list of partial expressions. Each contains one or more \%s,
42 * which will be replaced by the parent expression. The results are
43 * substituted for the percent signs in m_displayString.
45 QString m_exprStrings[typeInfoMaxExpr];
46 /**
47 * This is a list of guard expressions. Each contains one or more \%s,
48 * which will be replaced by the parent expression, or is empty. If the
49 * evaluation of the resulting expression returns an error, the
50 * corresponding expression from m_exprStrings is not evaluated. (This
51 * is used to guard function calls.)
53 QString m_guardStrings[typeInfoMaxExpr];
54 /**
55 * This is the type name including template arguments that contain a
56 * pattern: A single '*' as template parameter matches one template
57 * argument, except that a '*' as the last template parameter matches
58 * all remaining template argument.
60 QString m_templatePattern;
61 /**
62 * Returns a pointer to a TypeInfo that identifies wchar_t
64 static TypeInfo* wchartType() { return &m_wchartType; }
65 /**
66 * Gets a pointer to a TypeInfo that means: "I don't know the type"
68 static TypeInfo* unknownType() { return &m_unknownType; }
70 protected:
71 static TypeInfo m_wchartType;
72 static TypeInfo m_unknownType;
75 class TypeTable
77 public:
78 TypeTable();
79 ~TypeTable();
81 typedef std::map<QString,TypeInfo*> TypeMap;
83 /**
84 * Load all known type libraries.
86 static void initTypeLibraries();
88 /**
89 * Copy type infos to the specified dictionary.
91 void copyTypes(QDict<TypeInfo>& dict);
93 /**
94 * Returns the template types
96 const TypeMap& templates() const { return m_templates; }
98 /**
99 * Does the file name match this library?
101 bool matchFileName(const char* fileName) {
102 return m_shlibNameRE.match(fileName) >= 0;
106 * Is the specified builtin feature enabled in this type library?
108 bool isEnabledBuiltin(const QString& feature) const;
111 * Returns the command to print the QString data.
113 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
115 protected:
117 * Loads the structure type information from the configuration files.
119 static void loadTypeTables();
120 void loadFromFile(const QString& fileName);
121 void readType(KConfigBase& cf, const QString& type);
122 QDict<TypeInfo> m_typeDict;
123 QDict<TypeInfo> m_aliasDict;
124 TypeMap m_templates;
125 QString m_displayName;
126 QRegExp m_shlibNameRE;
127 QStringList m_enabledBuiltins;
128 char* m_printQStringDataCmd;
133 * This table keeps only references to the global type table. It is set up
134 * once per program.
136 class ProgramTypeTable
138 public:
139 ProgramTypeTable();
140 ~ProgramTypeTable();
143 * Load types belonging to the specified libraries.
145 void loadLibTypes(const QStrList& libs);
148 * Load types belonging to the specified type table
150 void loadTypeTable(TypeTable* table);
153 * Lookup a structure type.
155 * If the type is unknown, 0 is returned.
157 TypeInfo* lookup(QString type);
160 * Adds a new alias for a type name.
162 void registerAlias(const QString& name, TypeInfo* type);
165 * Tells whether we use built-in support to understand QStrings.
167 bool parseQt2QStrings() const { return m_parseQt2QStrings; }
170 * Tells whether QChar are defined like in Qt3.
172 bool qCharIsShort() const { return m_QCharIsShort; }
175 * Returns the command to print the QString data.
177 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
179 protected:
180 QDict<TypeInfo> m_types;
181 QDict<TypeInfo> m_aliasDict;
182 struct TemplateInfo {
183 QStringList templateArgs;
184 TypeInfo* type;
186 typedef std::multimap<QString, TemplateInfo> TemplateMap;
187 TemplateMap m_templates; //!< one or more template patterns per template name
188 static TemplateMap::value_type
189 template2Info(const TypeTable::TypeMap::value_type& tt);
190 static QStringList splitTemplateArgs(const QString& t);
191 bool m_parseQt2QStrings;
192 bool m_QCharIsShort;
193 const char* m_printQStringDataCmd;