| File src/mtypes.cpp changed (mode: 100644) (index b027f17..c447514) |
| ... |
... |
operator<<(std::ostream &os, MType mtype) |
| 29 |
29 |
case MType::Declaration: return (os << "Declaration"); |
case MType::Declaration: return (os << "Declaration"); |
| 30 |
30 |
case MType::Statement: return (os << "Statement"); |
case MType::Statement: return (os << "Statement"); |
| 31 |
31 |
case MType::Function: return (os << "Function"); |
case MType::Function: return (os << "Function"); |
|
32 |
|
case MType::Call: return (os << "Call"); |
| 32 |
33 |
case MType::Parameter: return (os << "Parameter"); |
case MType::Parameter: return (os << "Parameter"); |
| 33 |
34 |
case MType::Comment: return (os << "Comment"); |
case MType::Comment: return (os << "Comment"); |
| 34 |
35 |
case MType::Directive: return (os << "Directive"); |
case MType::Directive: return (os << "Directive"); |
| |
| ... |
... |
bool |
| 43 |
44 |
canNest(MType mtype) |
canNest(MType mtype) |
| 44 |
45 |
{ |
{ |
| 45 |
46 |
switch (mtype) { |
switch (mtype) { |
|
47 |
|
case MType::Call: |
| 46 |
48 |
case MType::Block: |
case MType::Block: |
| 47 |
49 |
return true; |
return true; |
| 48 |
50 |
case MType::Other: |
case MType::Other: |
| File src/mtypes.hpp changed (mode: 100644) (index 3fff56c..b15757e) |
| ... |
... |
enum class MType : std::uint8_t |
| 29 |
29 |
Declaration, // Any sort of declaration. |
Declaration, // Any sort of declaration. |
| 30 |
30 |
Statement, // Statement. |
Statement, // Statement. |
| 31 |
31 |
Function, // Functions (their definitions only). |
Function, // Functions (their definitions only). |
|
32 |
|
Call, // Function invocation. |
| 32 |
33 |
Parameter, // Parameter in declaration of a function. |
Parameter, // Parameter in declaration of a function. |
| 33 |
34 |
Comment, // Comments of any kind. |
Comment, // Comments of any kind. |
| 34 |
35 |
Directive, // Preprocessor-alike directives. |
Directive, // Preprocessor-alike directives. |
| File src/tooling/Finder.cpp changed (mode: 100644) (index a2965f4..87cac45) |
| ... |
... |
Finder::Finder(const CommonArgs &args, TimeReport &tr, bool countOnly) |
| 62 |
62 |
return MType::Statement; |
return MType::Statement; |
| 63 |
63 |
} else if (str == "func") { |
} else if (str == "func") { |
| 64 |
64 |
return MType::Function; |
return MType::Function; |
|
65 |
|
} else if (str == "call") { |
|
66 |
|
return MType::Call; |
| 65 |
67 |
} else if (str == "param") { |
} else if (str == "param") { |
| 66 |
68 |
return MType::Parameter; |
return MType::Parameter; |
| 67 |
69 |
} else if (str == "comm") { |
} else if (str == "comm") { |
| File tests/tooling/Matcher.cpp changed (mode: 100644) (index cf428f4..d213a68) |
| ... |
... |
TEST_CASE("Block matcher works", "[tooling][matcher][.srcml]") |
| 120 |
120 |
CHECK(nMatches == 4); |
CHECK(nMatches == 4); |
| 121 |
121 |
} |
} |
| 122 |
122 |
} |
} |
|
123 |
|
|
|
124 |
|
TEST_CASE("Call matcher works", "[tooling][matcher][.srcml]") |
|
125 |
|
{ |
|
126 |
|
Matcher matcher(MType::Call, nullptr); |
|
127 |
|
|
|
128 |
|
int nMatches = 0; |
|
129 |
|
|
|
130 |
|
auto matchHandler = [&](Node */*node*/) { |
|
131 |
|
++nMatches; |
|
132 |
|
}; |
|
133 |
|
|
|
134 |
|
SECTION("In Make") { |
|
135 |
|
Tree tree = parseMake("$(info $(addprefix bla,bla))"); |
|
136 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
137 |
|
CHECK(nMatches == 2); |
|
138 |
|
} |
|
139 |
|
SECTION("In C") { |
|
140 |
|
Tree tree = parseC("void f() { call1(nested()); call2(); }", true); |
|
141 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
142 |
|
CHECK(nMatches == 3); |
|
143 |
|
} |
|
144 |
|
SECTION("In C++") { |
|
145 |
|
Tree tree = parseCxx("void f() { call1(); call2(nested()); }"); |
|
146 |
|
CHECK(matcher.match(tree.getRoot(), *tree.getLanguage(), matchHandler)); |
|
147 |
|
CHECK(nMatches == 3); |
|
148 |
|
} |
|
149 |
|
} |
| File tools/find/find.cpp changed (mode: 100644) (index 90476c2..d22083e) |
| ... |
... |
Available matchers: |
| 37 |
37 |
decl Any sort of declaration |
decl Any sort of declaration |
| 38 |
38 |
stmt Statement |
stmt Statement |
| 39 |
39 |
func Functions (their definitions only) |
func Functions (their definitions only) |
|
40 |
|
call Function invocation |
| 40 |
41 |
param Parameter of a function |
param Parameter of a function |
| 41 |
42 |
comm Comments of any kind |
comm Comments of any kind |
| 42 |
43 |
dir Preprocessor-alike directives |
dir Preprocessor-alike directives |