Extend copyright to 2018.
[kdbg.git] / kdbg / typetable.h
blob03c6995abba405be21fe818d7c2d6bd0a2f62a15
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 <QString>
8 #include <QRegExp>
9 #include <QStringList>
10 #include <map>
12 class KConfigGroup;
14 /**
15 * The maximum number of sub-expressions that may appear in a single struct
16 * value.
18 const int typeInfoMaxExpr = 5;
21 struct TypeInfo
23 TypeInfo(const QString& displayString);
24 ~TypeInfo();
26 /**
27 * The number of sub-expressions that need to be evaluated to get the
28 * struct value.
30 int m_numExprs;
31 /**
32 * This array contains the various parts which glue together the
33 * sub-expressions. The entries in this array are the parts that appear
34 * between the percent signs '%' of the display expression; hence,
35 * there is one part more than there are sub-expressions.
37 QString m_displayString[typeInfoMaxExpr+1];
38 /**
39 * This is a list of partial expressions. Each contains one or more \%s,
40 * which will be replaced by the parent expression. The results are
41 * substituted for the percent signs in m_displayString.
43 QString m_exprStrings[typeInfoMaxExpr];
44 /**
45 * This is a list of guard expressions. Each contains one or more \%s,
46 * which will be replaced by the parent expression, or is empty. If the
47 * evaluation of the resulting expression returns an error, the
48 * corresponding expression from m_exprStrings is not evaluated. (This
49 * is used to guard function calls.)
51 QString m_guardStrings[typeInfoMaxExpr];
52 /**
53 * This is the type name including template arguments that contain a
54 * pattern: A single '*' as template parameter matches one template
55 * argument, except that a '*' as the last template parameter matches
56 * all remaining template argument.
58 QString m_templatePattern;
59 /**
60 * Returns a pointer to a TypeInfo that identifies wchar_t
62 static TypeInfo* wchartType() { return &m_wchartType; }
63 /**
64 * Gets a pointer to a TypeInfo that means: "I don't know the type"
66 static TypeInfo* unknownType() { return &m_unknownType; }
68 protected:
69 static TypeInfo m_wchartType;
70 static TypeInfo m_unknownType;
73 class TypeTable
75 public:
76 TypeTable();
77 ~TypeTable();
79 typedef std::map<QString,TypeInfo> TypeInfoMap;
80 typedef std::map<QString,const TypeInfo*> TypeInfoRefMap;
82 /**
83 * Load all known type libraries.
85 static void initTypeLibraries();
87 /**
88 * Copy type infos to the specified dictionary.
90 void copyTypes(TypeInfoRefMap& dict);
92 /**
93 * Returns the template types
95 const TypeInfoMap& templates() const { return m_templates; }
97 /**
98 * Does the file name match this library?
100 bool matchFileName(const QString& fileName) const {
101 return m_shlibNameRE.indexIn(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.constData(); }
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(const KConfigGroup& cf, const QString& type);
121 TypeInfoMap m_typeDict;
122 TypeInfoRefMap m_aliasDict;
123 TypeInfoMap m_templates;
124 QString m_displayName;
125 QRegExp m_shlibNameRE;
126 QStringList m_enabledBuiltins;
127 QByteArray 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 const TypeInfo* lookup(QString type);
159 * Adds a new alias for a type name.
161 void registerAlias(const QString& name, const 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 TypeTable::TypeInfoRefMap m_types;
180 TypeTable::TypeInfoRefMap m_aliasDict;
181 struct TemplateInfo {
182 QStringList templateArgs;
183 const 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::TypeInfoMap::value_type& tt);
189 static QStringList splitTemplateArgs(const QString& t);
190 bool m_parseQt2QStrings;
191 bool m_QCharIsShort;
192 QByteArray m_printQStringDataCmd;