[insight-vmi] r1983 committed - Added intermediate class FunctionFilter in between TypeFilter and...

0 views
Skip to first unread message

insig...@googlecode.com

unread,
Jun 21, 2013, 8:50:56 AM6/21/13
to insight-v...@googlegroups.com
Revision: 1983
Author: chrsc...@googlemail.com
Date: Fri Jun 21 05:50:44 2013
Log: Added intermediate class FunctionFilter in between TypeFilter and
VariableFilter. This allows us to match types based on their originating
source file, especially functions.

http://code.google.com/p/insight-vmi/source/detail?r=1983

Modified:
/trunk/libinsight/include/insight/typefilter.h
/trunk/libinsight/typefilter.cpp

=======================================
--- /trunk/libinsight/include/insight/typefilter.h Tue Feb 12 09:35:31 2013
+++ /trunk/libinsight/include/insight/typefilter.h Fri Jun 21 05:50:44 2013
@@ -461,10 +461,117 @@
};


+/**
+ * This class manages the filter options for a Function object.
+ */
+class FunctionFilter: public TypeFilter
+{
+public:
+ /**
+ * Constructor
+ * @param symFiles list of files the symbols in SymFactory were parsed
from
+ */
+ FunctionFilter(const QStringList& symFiles = QStringList())
+ : _symFileRegEx(0), _symFiles(symFiles) {}
+
+ /**
+ * Copy constructor
+ * @param from initialize from this object
+ */
+ FunctionFilter(const FunctionFilter& from);
+
+ /**
+ * Destructor
+ */
+ virtual ~FunctionFilter();
+
+ /**
+ * Assignment operator
+ */
+ FunctionFilter& operator=(const FunctionFilter& src);
+
+ /**
+ * Comparison operator
+ * @param other compare to
+ */
+ inline bool operator==(const FunctionFilter& other) const
+ {
+ return TypeFilter::operator ==(other) && _symFile ==
other._symFile;
+ }
+
+ /**
+ * Comparison operator
+ * @param other compare to
+ */
+ inline bool operator!=(const FunctionFilter& other) const
+ {
+ return !operator==(other);
+ }
+
+ /**
+ * \copydoc GenericFilter::clear()
+ */
+ virtual void clear();
+
+ /**
+ * @copydoc TypeFilter::matchType()
+ */
+ bool matchType(const BaseType* type) const;
+
+ /**
+ * \copydoc GenericFilter::parseOption()
+ */
+ virtual bool parseOption(const QString& key, const QString& value,
+ const KeyValueStore *keyVals = 0);
+
+ /**
+ * Returns the symbol file name or pattern.
+ */
+ inline const QString& symFileName() const { return _symFile; }
+
+ /**
+ * Sets the symbol file name or pattern this filter matches on.
+ * @param name file name or pattern (depending on \a syntax)
+ * @param syntax the pattern syntax used in \a name
+ * \sa symFileName(), symFileNameSyntax()
+ */
+ void setSymFileName(const QString& name,
+ Filter::PatternSyntax syntax = Filter::psAuto);
+
+ /**
+ * Returns the pattern syntax used for the symbol file name.
+ * \sa setSymFileName()
+ */
+ Filter::PatternSyntax symFileNameSyntax() const;
+
+ /**
+ * \copydoc GenericFilter::toString()
+ */
+ virtual QString toString(const ColorPalette* col = 0) const;
+
+ /**
+ * Returns a key-value list of parameters this filter can parse. The
key
+ * is the name of the parameter, the value holds a short description
of the
+ * parameter and its values.
+ * @return key-value list of parameters this filter parses
+ * \sa parseOption()
+ */
+ static const KeyValueStore& supportedFilters();
+
+protected:
+ bool matchSymFileName(const QString& name) const;
+
+private:
+ QRegExp* _symFileRegEx;
+ QString _symFile;
+ const QStringList& _symFiles;
+};
+
+
/**
* This class manages the filter options for a Variable object.
*/
-class VariableFilter: public TypeFilter
+class VariableFilter: public FunctionFilter
{
public:
/**
@@ -472,7 +579,7 @@
* @param symFiles list of files the symbols in SymFactory were parsed
from
*/
VariableFilter(const QStringList& symFiles = QStringList())
- : _varRegEx(0), _symFileRegEx(0), _symFiles(symFiles) {}
+ : FunctionFilter(symFiles), _varRegEx(0) {}

/**
* Copy constructor
@@ -497,7 +604,7 @@
inline bool operator==(const VariableFilter& other) const
{
// Do NOT compare the _varRegEx pointer
- return TypeFilter::operator ==(other);
+ return FunctionFilter::operator ==(other);
}

/**
@@ -548,26 +655,6 @@
*/
Filter::PatternSyntax varNameSyntax() const;

- /**
- * Returns the symbol file name or pattern.
- */
- inline const QString& symFileName() const { return _symFile; }
-
- /**
- * Sets the symbol file name or pattern this filter matches on.
- * @param name file name or pattern (depending on \a syntax)
- * @param syntax the pattern syntax used in \a name
- * \sa symFileName(), symFileNameSyntax()
- */
- void setSymFileName(const QString& name,
- Filter::PatternSyntax syntax = Filter::psAuto);
-
- /**
- * Returns the pattern syntax used for the symbol file name.
- * \sa setSymFileName()
- */
- Filter::PatternSyntax symFileNameSyntax() const;
-
/**
* \copydoc GenericFilter::toString()
*/
@@ -584,14 +671,10 @@

protected:
bool matchVarName(const QString& name) const;
- bool matchSymFileName(const QString& name) const;

private:
QString _varName;
QRegExp* _varRegEx;
- QRegExp* _symFileRegEx;
- QString _symFile;
- const QStringList& _symFiles;
};


=======================================
--- /trunk/libinsight/typefilter.cpp Fri Feb 15 10:58:10 2013
+++ /trunk/libinsight/typefilter.cpp Fri Jun 21 05:50:44 2013
@@ -745,18 +745,170 @@



//------------------------------------------------------------------------------
-// VariableFilter
+// FunctionFilter

//------------------------------------------------------------------------------

static const QStringList emptyList;

+FunctionFilter::FunctionFilter(const FunctionFilter &from)
+ : TypeFilter(from), _symFileRegEx(0), _symFiles(emptyList)
+{
+ if (from._symFileRegEx)
+ _symFileRegEx = new QRegExp(*from._symFileRegEx);
+}
+
+
+FunctionFilter::~FunctionFilter()
+{
+ if (_symFileRegEx)
+ delete _symFileRegEx;
+}
+
+
+void FunctionFilter::setSymFileName(const QString &name,
Filter::PatternSyntax syntax)
+{
+ _filters &= ~ftSymFileAll;
+ QRegExp rx;
+ syntax = setNamePattern(name, _symFile, rx, syntax, "[-_.a-zA-Z0-9]*");
+
+ switch (syntax) {
+ case psAuto: break;
+ case psAny: _filters |= ftSymFileAny; break;
+ case psLiteral: _filters |= ftSymFileLiteral; break;
+ case psRegExp: _filters |= ftSymFileRegEx; break;
+ case psWildcard: _filters |= ftSymFileWildcard; break;
+ }
+
+ if (_symFileRegEx)
+ delete _symFileRegEx;
+ if (syntax & (psRegExp|psWildcard))
+ _symFileRegEx = new QRegExp(rx);
+ else
+ _symFileRegEx = 0;
+}
+
+
+Filter::PatternSyntax FunctionFilter::symFileNameSyntax() const
+{
+ if (filterActive(ftSymFileAny))
+ return psAny;
+ else if (filterActive(ftSymFileRegEx))
+ return psRegExp;
+ else if (filterActive(ftSymFileWildcard))
+ return psWildcard;
+ else
+ return psLiteral;
+}
+
+
+void FunctionFilter::clear()
+{
+ TypeFilter::clear();
+ if (_symFileRegEx) {
+ delete _symFileRegEx;
+ _symFileRegEx = 0;
+ }
+ _symFile.clear();
+}
+
+
+bool FunctionFilter::matchType(const BaseType *type) const
+{
+ if (!type)
+ return false;
+
+ if (filterActive(ftSymFileAll) &&
+ !matchSymFileName(type->origFileName()))
+ return false;
+
+ return TypeFilter::matchType(type);
+}
+
+
+bool FunctionFilter::matchSymFileName(const QString &name) const
+{
+ if (filterActive(ftSymFileLiteral) &&
+ _symFile.compare(name, Qt::CaseInsensitive) != 0)
+ return false;
+ else {
+ QMutexLocker lock(&_regExLock);
+ if (filterActive(ftSymFileWildcard) &&
+ !_symFileRegEx->exactMatch(name))
+ return false;
+ else if (filterActive(ftSymFileRegEx) &&
+ _symFileRegEx->indexIn(name) < 0)
+ return false;
+ }
+
+ return true;
+}
+
+
+bool FunctionFilter::parseOption(const QString &key, const QString &value,
+ const KeyValueStore* keyVals)
+{
+ if (QString(xml::filename).startsWith(key))
+ setSymFileName(value, givenSyntax(keyVals));
+ else
+ return TypeFilter::parseOption(key, value, keyVals);
+
+ return true;
+}
+
+
+QString FunctionFilter::toString(const ColorPalette *col) const
+{
+ QString s(TypeFilter::toString(col));
+
+ if (filterActive(ftSymFileAny)) {
+ s += QString("%0 %1\n")
+ .arg(Console::colorize("Sym. file:", ctColHead, col))
+ .arg(Console::colorize(QString("(%1)").arg(xml::any),
+ ctSrcFile, col));
+ }
+ else if (filterActive(ftSymFileLiteral)) {
+ s += QString("%0 %1\n")
+ .arg(Console::colorize("Sym. file:", ctColHead, col))
+ .arg(Console::colorize(_symFile, ctSrcFile, col));
+ }
+ else if (filterActive(ftSymFileRegEx)) {
+ s += QString("%0 %2\n")
+ .arg(Console::colorize("Sym. file (%1):", ctColHead, col))
+ .arg(xml::regex)
+ .arg(Console::colorize(_symFile, ctSrcFile, col));
+ }
+ else if (filterActive(ftSymFileWildcard)) {
+ s += QString("%0 %2\n")
+ .arg(Console::colorize("Sym. file (%1):", ctColHead, col))
+ .arg(xml::wildcard)
+ .arg(Console::colorize(_symFile, ctSrcFile, col));
+ }
+
+ return s;
+}
+
+
+const KeyValueStore &FunctionFilter::supportedFilters()
+{
+ static KeyValueStore funcFilters;
+ if (funcFilters.isEmpty()) {
+ funcFilters = TypeFilter::supportedFilters();
+ funcFilters[xml::filename] = "Match symbol file the symbol belongs
to, "
+ "e.g. \"vmlinux\" or \"*/snd.ko\".";
+ }
+ return funcFilters;
+}
+
+
+//------------------------------------------------------------------------------
+// VariableFilter
+//------------------------------------------------------------------------------
+
VariableFilter::VariableFilter(const VariableFilter& from)
- : TypeFilter(from), _varRegEx(0), _symFileRegEx(0),
_symFiles(emptyList)
+ : FunctionFilter(from), _varRegEx(0)
{
if (from._varRegEx)
_varRegEx = new QRegExp(*from._varRegEx);
- if (from._symFileRegEx)
- _symFileRegEx = new QRegExp(*from._symFileRegEx);
}


@@ -764,8 +916,6 @@
{
if (_varRegEx)
delete _varRegEx;
- if (_symFileRegEx)
- delete _symFileRegEx;
}


@@ -799,25 +949,6 @@
_varRegEx->indexIn(name) < 0)
return false;
}
-
- return true;
-}
-
-
-bool VariableFilter::matchSymFileName(const QString &name) const
-{
- if (filterActive(ftSymFileLiteral) &&
- _symFile.compare(name, Qt::CaseInsensitive) != 0)
- return false;
- else {
- QMutexLocker lock(&_regExLock);
- if (filterActive(ftSymFileWildcard) &&
- !_symFileRegEx->exactMatch(name))
- return false;
- else if (filterActive(ftSymFileRegEx) &&
- _symFileRegEx->indexIn(name) < 0)
- return false;
- }

return true;
}
@@ -830,27 +961,29 @@

if (filterActive(ftVarNameAll) && !matchVarName(var->name()))
return false;
- else if (filterActive(ftSymFileAll) &&
+
+ // Note: FunctionFilter::matchType() matches the type's origFileName()
+ // against the symFile. What we want here is to match
var-origFileName()
+ // against the symFile. So we do the check here ourself and delegate
the
+ // final decision to TypeFilter::matchType() below as opposed to
+ // FunctionFilter::matchType().
+ if (filterActive(ftSymFileAll) &&
!matchSymFileName(var->origFileName()))
return false;

+ // DON'T call FunctionFilter::matchType() here!
return TypeFilter::matchType(var->refType());
}


void VariableFilter::clear()
{
- TypeFilter::clear();
+ FunctionFilter::clear();
if (_varRegEx) {
delete _varRegEx;
_varRegEx = 0;
}
_varName.clear();
- if (_symFileRegEx) {
- delete _symFileRegEx;
- _symFileRegEx = 0;
- }
- _symFile.clear();
}


@@ -888,47 +1021,11 @@
else
return psLiteral;
}
-
-
-void VariableFilter::setSymFileName(const QString &name,
Filter::PatternSyntax syntax)
-{
- _filters &= ~ftSymFileAll;
- QRegExp rx;
- syntax = setNamePattern(name, _symFile, rx, syntax, "[-_.a-zA-Z0-9]*");
-
- switch (syntax) {
- case psAuto: break;
- case psAny: _filters |= ftSymFileAny; break;
- case psLiteral: _filters |= ftSymFileLiteral; break;
- case psRegExp: _filters |= ftSymFileRegEx; break;
- case psWildcard: _filters |= ftSymFileWildcard; break;
- }
-
- if (_symFileRegEx)
- delete _symFileRegEx;
- if (syntax & (psRegExp|psWildcard))
- _symFileRegEx = new QRegExp(rx);
- else
- _symFileRegEx = 0;
-}
-
-
-Filter::PatternSyntax VariableFilter::symFileNameSyntax() const
-{
- if (filterActive(ftSymFileAny))
- return psAny;
- else if (filterActive(ftSymFileRegEx))
- return psRegExp;
- else if (filterActive(ftSymFileWildcard))
- return psWildcard;
- else
- return psLiteral;
-}


QString VariableFilter::toString(const ColorPalette *col) const
{
- QString s(TypeFilter::toString(col));
+ QString s(FunctionFilter::toString(col));

if (filterActive(ftVarNameAny)) {
s += QString("%0 %1\n")
@@ -957,16 +1054,12 @@
return s;
}

-
-static KeyValueStore varFilters;

const KeyValueStore &VariableFilter::supportedFilters()
{
+ static KeyValueStore varFilters;
if (varFilters.isEmpty()) {
- varFilters = TypeFilter::supportedFilters();
- varFilters[xml::variablename] = "Match variable name, either by a "
- "literal match, by a wildcard expression *glob*, or by a "
- "regular expression /re/.";
+ varFilters = FunctionFilter::supportedFilters();
varFilters[xml::filename] = "Match symbol file the variable
belongs to, "
"e.g. \"vmlinux\" or \"snd.ko\".";
}
@@ -979,10 +1072,8 @@
{
if (QString(xml::variablename).startsWith(key))
setVarName(value, givenSyntax(keyVals));
- else if (QString(xml::filename).startsWith(key))
- setSymFileName(value, givenSyntax(keyVals));
else
- return TypeFilter::parseOption(key, value, keyVals);
+ return FunctionFilter::parseOption(key, value, keyVals);

return true;
}
Reply all
Reply to author
Forward
0 new messages