Convert parseSharedLibs() from QStrList to QStringList.
[kdbg.git] / kdbg / typetable.h
blob1f1d77dd95a8a8fed9bc1ef11bc3e6b728299673
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>
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 one or more \%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 one or more \%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 * This is the type name including template arguments that contain a
55 * pattern: A single '*' as template parameter matches one template
56 * argument, except that a '*' as the last template parameter matches
57 * all remaining template argument.
59 QString m_templatePattern;
60 /**
61 * Returns a pointer to a TypeInfo that identifies wchar_t
63 static TypeInfo* wchartType() { return &m_wchartType; }
64 /**
65 * Gets a pointer to a TypeInfo that means: "I don't know the type"
67 static TypeInfo* unknownType() { return &m_unknownType; }
69 protected:
70 static TypeInfo m_wchartType;
71 static TypeInfo m_unknownType;
74 class TypeTable
76 public:
77 TypeTable();
78 ~TypeTable();
80 typedef std::map<QString,TypeInfo*> TypeMap;
82 /**
83 * Load all known type libraries.
85 static void initTypeLibraries();
87 /**
88 * Copy type infos to the specified dictionary.
90 void copyTypes(QDict<TypeInfo>& dict);
92 /**
93 * Returns the template types
95 const TypeMap& templates() const { return m_templates; }
97 /**
98 * Does the file name match this library?
100 bool matchFileName(const char* fileName) {
101 return m_shlibNameRE.match(fileName) >= 0;
105 * Is the specified builtin feature enabled in this type library?
107 bool isEnabledBuiltin(const QString& feature) const;
110 * Returns the command to print the QString data.
112 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
114 protected:
116 * Loads the structure type information from the configuration files.
118 static void loadTypeTables();
119 void loadFromFile(const QString& fileName);
120 void readType(KConfigBase& cf, const QString& type);
121 QDict<TypeInfo> m_typeDict;
122 QDict<TypeInfo> m_aliasDict;
123 TypeMap m_templates;
124 QString m_displayName;
125 QRegExp m_shlibNameRE;
126 QStringList m_enabledBuiltins;
127 char* m_printQStringDataCmd;
132 * This table keeps only references to the global type table. It is set up
133 * once per program.
135 class ProgramTypeTable
137 public:
138 ProgramTypeTable();
139 ~ProgramTypeTable();
142 * Load types belonging to the specified libraries.
144 void loadLibTypes(const QStringList& libs);
147 * Load types belonging to the specified type table
149 void loadTypeTable(TypeTable* table);
152 * Lookup a structure type.
154 * If the type is unknown, 0 is returned.
156 TypeInfo* lookup(QString type);
159 * Adds a new alias for a type name.
161 void registerAlias(const QString& name, TypeInfo* type);
164 * Tells whether we use built-in support to understand QStrings.
166 bool parseQt2QStrings() const { return m_parseQt2QStrings; }
169 * Tells whether QChar are defined like in Qt3.
171 bool qCharIsShort() const { return m_QCharIsShort; }
174 * Returns the command to print the QString data.
176 const char* printQStringDataCmd() const { return m_printQStringDataCmd; }
178 protected:
179 QDict<TypeInfo> m_types;
180 QDict<TypeInfo> m_aliasDict;
181 struct TemplateInfo {
182 QStringList templateArgs;
183 TypeInfo* type;
185 typedef std::multimap<QString, TemplateInfo> TemplateMap;
186 TemplateMap m_templates; //!< one or more template patterns per template name
187 static TemplateMap::value_type
188 template2Info(const TypeTable::TypeMap::value_type& tt);
189 static QStringList splitTemplateArgs(const QString& t);
190 bool m_parseQt2QStrings;
191 bool m_QCharIsShort;
192 const char* m_printQStringDataCmd;