xaizek / zograscope (License: AGPLv3 only) (since 2018-12-07)
Mainly a syntax-aware diff that also provides a number of additional tools.
Commit 3ab93155d6aa13f4fecd6568e6a1ddd9ba4bf980

Add call node meta-type (extends zs-find a bit)
This way call expressions can be located in the code base.
Author: xaizek
Author date (UTC): 2019-07-03 16:04
Committer name: xaizek
Committer date (UTC): 2019-07-03 16:04
Parent(s): a27ac9e01a29de610f54c1fea11ac5fb905173e1
Signing key: 99DC5E4DB05F6BE2
Tree: 9c03a7c31cdb15aafa3e4db30fb7d34b863b15ae
File Lines added Lines deleted
src/c/C11Language.cpp 3 0
src/make/MakeLanguage.cpp 3 0
src/mtypes.cpp 2 0
src/mtypes.hpp 1 0
src/srcml/cxx/SrcmlCxxLanguage.cpp 3 0
src/tooling/Finder.cpp 2 0
tests/tooling/Matcher.cpp 27 0
tools/find/find.cpp 1 0
File src/c/C11Language.cpp changed (mode: 100644) (index 72d0af9..7a81c65)
... ... C11Language::classify(SType stype) const
338 338 case C11SType::FunctionDefinition: case C11SType::FunctionDefinition:
339 339 return MType::Function; return MType::Function;
340 340
341 case C11SType::CallExpr:
342 return MType::Call;
343
341 344 case C11SType::Parameter: case C11SType::Parameter:
342 345 return MType::Parameter; return MType::Parameter;
343 346
File src/make/MakeLanguage.cpp changed (mode: 100644) (index ce19e98..96c12d1)
... ... MakeLanguage::classify(SType stype) const
195 195 case MakeSType::Comment: case MakeSType::Comment:
196 196 return MType::Comment; return MType::Comment;
197 197
198 case MakeSType::CallExpr:
199 return MType::Call;
200
198 201 case MakeSType::Directive: case MakeSType::Directive:
199 202 case MakeSType::Include: case MakeSType::Include:
200 203 return MType::Directive; return MType::Directive;
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/srcml/cxx/SrcmlCxxLanguage.cpp changed (mode: 100644) (index 5203628..0359524)
... ... SrcmlCxxLanguage::classify(SType stype) const
552 552 case SrcmlCxxSType::Destructor: case SrcmlCxxSType::Destructor:
553 553 return MType::Function; return MType::Function;
554 554
555 case SrcmlCxxSType::Call:
556 return MType::Call;
557
555 558 case SrcmlCxxSType::Parameter: case SrcmlCxxSType::Parameter:
556 559 return MType::Parameter; return MType::Parameter;
557 560
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
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/zograscope

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/zograscope

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master