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.
10 #include <qstringlist.h>
17 * The maximum number of sub-expressions that may appear in a single struct
20 const int typeInfoMaxExpr
= 5;
25 TypeInfo(const QString
& displayString
);
29 * The number of sub-expressions that need to be evaluated to get the
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];
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
];
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
];
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
;
62 * Returns a pointer to a TypeInfo that identifies wchar_t
64 static TypeInfo
* wchartType() { return &m_wchartType
; }
66 * Gets a pointer to a TypeInfo that means: "I don't know the type"
68 static TypeInfo
* unknownType() { return &m_unknownType
; }
71 static TypeInfo m_wchartType
;
72 static TypeInfo m_unknownType
;
81 typedef std::map
<QString
,TypeInfo
*> TypeMap
;
84 * Load all known type libraries.
86 static void initTypeLibraries();
89 * Copy type infos to the specified dictionary.
91 void copyTypes(QDict
<TypeInfo
>& dict
);
94 * Returns the template types
96 const TypeMap
& templates() const { return m_templates
; }
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
; }
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
;
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
136 class 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
; }
180 QDict
<TypeInfo
> m_types
;
181 QDict
<TypeInfo
> m_aliasDict
;
182 struct TemplateInfo
{
183 QStringList templateArgs
;
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
;
193 const char* m_printQStringDataCmd
;