summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-24 15:53:52 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-24 15:53:52 +0300
commit8520c503041946148e499faf6a6b65b2afc670bf (patch)
tree342870ea2f00de996b90c3bd26bcbb003777076f
parentc20a4844817573be1de5f355d4890e93db386e54 (diff)
downloadmplint-8520c503041946148e499faf6a6b65b2afc670bf.tar.gz
mplint-8520c503041946148e499faf6a6b65b2afc670bf.tar.bz2
mplint-8520c503041946148e499faf6a6b65b2afc670bf.tar.xz
mplint-8520c503041946148e499faf6a6b65b2afc670bf.zip
Add second rule for checking #include "debug.h"
-rw-r--r--src/lintmanager.cpp21
-rw-r--r--src/lintmanager.h5
-rw-r--r--src/rulebase.cpp15
-rw-r--r--src/rulebase.h8
-rw-r--r--src/rules/debug.cpp20
5 files changed, 65 insertions, 4 deletions
diff --git a/src/lintmanager.cpp b/src/lintmanager.cpp
index 3b49b0b..8acb622 100644
--- a/src/lintmanager.cpp
+++ b/src/lintmanager.cpp
@@ -48,11 +48,22 @@ void LintManager::addRule(RuleBase *const rule)
void LintManager::deleteRule(RuleBase *const rule)
{
- FOR_EACH (std::vector<RuleBase*>::iterator, it, mRules)
+ deleteFrom(rule, mRules);
+}
+
+void LintManager::deleteSelectedRule(RuleBase *const rule)
+{
+ deleteFrom(rule, mSelectedRules);
+}
+
+void LintManager::deleteFrom(RuleBase *const rule,
+ std::vector<RuleBase*> &rules)
+{
+ FOR_EACH (std::vector<RuleBase*>::iterator, it, rules)
{
if (*it == rule)
{
- mRules.erase(it);
+ rules.erase(it);
return;
}
}
@@ -109,9 +120,12 @@ void LintManager::applyRulesToFile()
const std::string &str = *itStr;
rule->setLine(line);
rule->parseLine(str);
+ if (!rule->getFlag())
+ break;
line ++;
}
- rule->end();
+ if (rule->getFlag())
+ rule->end();
}
}
@@ -145,6 +159,7 @@ void LintManager::selectRulesForFile()
{
// printf("set file %s, for rule %s\n",
// mFileName.c_str(), rule->getName().c_str());
+ rule->init();
rule->setFile(mFileName);
rule->start();
mSelectedRules.push_back(rule);
diff --git a/src/lintmanager.h b/src/lintmanager.h
index b504482..7992971 100644
--- a/src/lintmanager.h
+++ b/src/lintmanager.h
@@ -39,6 +39,8 @@ class LintManager final
void deleteRule(RuleBase *const rule);
+ void deleteSelectedRule(RuleBase *const rule);
+
protected:
void enumFiles(std::string path);
@@ -52,6 +54,9 @@ class LintManager final
void applyRulesToFile();
+ void deleteFrom(RuleBase *const rule,
+ std::vector<RuleBase*> &rules);
+
private:
std::vector<RuleBase*> mRules;
diff --git a/src/rulebase.cpp b/src/rulebase.cpp
index 1d08986..d6e428a 100644
--- a/src/rulebase.cpp
+++ b/src/rulebase.cpp
@@ -26,7 +26,9 @@
RuleBase::RuleBase() :
file(),
- line(-1)
+ ruleName(),
+ line(-1),
+ flag(true)
{
lint.addRule(this);
}
@@ -52,3 +54,14 @@ void RuleBase::deleteSelf()
{
lint.deleteRule(this);
}
+
+void RuleBase::terminateRule()
+{
+ lint.deleteSelectedRule(this);
+ flag = false;
+}
+
+void RuleBase::init()
+{
+ flag = true;
+}
diff --git a/src/rulebase.h b/src/rulebase.h
index d205b7d..1d237ee 100644
--- a/src/rulebase.h
+++ b/src/rulebase.h
@@ -34,6 +34,8 @@ class RuleBase
virtual ~RuleBase()
{ }
+ void init();
+
virtual void start()
{ }
@@ -61,6 +63,11 @@ class RuleBase
std::string getName() const A_WARN_UNUSED
{ return ruleName; }
+ bool getFlag() const A_WARN_UNUSED
+ { return flag; }
+
+ void terminateRule();
+
protected:
void print(const std::string &text) const;
@@ -75,6 +82,7 @@ class RuleBase
std::string file;
std::string ruleName;
int line;
+ bool flag;
};
#endif // RULEBASE_H
diff --git a/src/rules/debug.cpp b/src/rules/debug.cpp
index 880b60b..7edae01 100644
--- a/src/rules/debug.cpp
+++ b/src/rules/debug.cpp
@@ -39,3 +39,23 @@ parseLineRule(debugH)
"Probably need replace it to #include \"localconsts.h\"");
}
}
+
+
+registerRuleExt(debugCpp, "(.+)[.]cpp")
+
+startRule(debugCpp)
+{
+}
+
+endRule(debugCpp)
+{
+ print("Missing #include \"debug.h\". "
+ "It need for profiling and memory debugging.");
+}
+
+parseLineRule(debugCpp)
+{
+ trim(data);
+ if (data == "#include \"debug.h\"")
+ terminateRule();
+}