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

Improve handling of enum class declarations
Author: xaizek
Author date (UTC): 2020-03-30 16:46
Committer name: xaizek
Committer date (UTC): 2020-03-30 16:46
Parent(s): 59b2fbc26df34ff1695242beb54fcc7984ff7ff2
Signing key: 99DC5E4DB05F6BE2
Tree: 5fd372c88c72fb50376e315be8e1b2287d00e8bd
File Lines added Lines deleted
src/srcml/cxx/SrcmlCxxLanguage.cpp 15 0
tests/srcml/cxx/srcml-cxx-parser.cpp 10 0
File src/srcml/cxx/SrcmlCxxLanguage.cpp changed (mode: 100644) (index 408d866..bfc0e5a)
... ... static void postProcessIfStmt(PNode *node, TreeBuilder &tb,
36 36 const std::string &contents); const std::string &contents);
37 37 static void postProcessBlock(PNode *node, TreeBuilder &tb, static void postProcessBlock(PNode *node, TreeBuilder &tb,
38 38 const std::string &contents); const std::string &contents);
39 static void postProcessEnumDecl(PNode *node, TreeBuilder &tb,
40 const std::string &contents);
39 41 static void postProcessEnum(PNode *node, TreeBuilder &tb, static void postProcessEnum(PNode *node, TreeBuilder &tb,
40 42 const std::string &contents); const std::string &contents);
41 43 static void postProcessEnumClass(PNode *node, TreeBuilder &tb, static void postProcessEnumClass(PNode *node, TreeBuilder &tb,
 
... ... postProcessTree(PNode *node, TreeBuilder &tb, const std::string &contents)
221 223 postProcessBlock(node, tb, contents); postProcessBlock(node, tb, contents);
222 224 } }
223 225
226 if (node->stype == +SrcmlCxxSType::EnumDecl) {
227 postProcessEnumDecl(node, tb, contents);
228 }
229
224 230 if (node->stype == +SrcmlCxxSType::Enum) { if (node->stype == +SrcmlCxxSType::Enum) {
225 231 postProcessEnum(node, tb, contents); postProcessEnum(node, tb, contents);
226 232 postProcessEnumClass(node, tb, contents); postProcessEnumClass(node, tb, contents);
 
... ... postProcessBlock(PNode *node, TreeBuilder &tb, const std::string &contents)
362 368 node->children.assign({ stmts }); node->children.assign({ stmts });
363 369 } }
364 370
371 // Rewrites enumeration class declaration nodes to be more diff-friendly. This
372 // breaks "enum\s+class" into two separate keyword tokens.
373 static void
374 postProcessEnumDecl(PNode *node, TreeBuilder &tb, const std::string &contents)
375 {
376 // Processing here is the same.
377 postProcessEnumClass(node, tb, contents);
378 }
379
365 380 // Rewrites enumeration nodes to be more diff-friendly. This turns ",\s*}" into // Rewrites enumeration nodes to be more diff-friendly. This turns ",\s*}" into
366 381 // two separate tokens. // two separate tokens.
367 382 static void static void
File tests/srcml/cxx/srcml-cxx-parser.cpp changed (mode: 100644) (index 1b63674..d3902ef)
... ... TEST_CASE("Enum classes are properly handled", "[.srcml][srcml-cxx][parser]")
415 415 CHECK(findNode(tree, makePred(Type::Other, ",")) != nullptr); CHECK(findNode(tree, makePred(Type::Other, ",")) != nullptr);
416 416 CHECK(findNode(tree, makePred(Type::RightBrackets, "}")) != nullptr); CHECK(findNode(tree, makePred(Type::RightBrackets, "}")) != nullptr);
417 417 CHECK(findNode(tree, makePred(Type::Other, ";")) != nullptr); CHECK(findNode(tree, makePred(Type::Other, ";")) != nullptr);
418
419 tree = parseCxx("enum class SType : std::uint8_t;");
420 CHECK(findNode(tree, makePred(Type::Keywords, "enum")) != nullptr);
421 CHECK(findNode(tree, makePred(Type::Keywords, "class")) != nullptr);
422 CHECK(findNode(tree, makePred(Type::Identifiers, "SType")) != nullptr);
423 CHECK(findNode(tree, makePred(Type::Other, ":")) != nullptr);
424 CHECK(findNode(tree, makePred(Type::UserTypes, "std")) != nullptr);
425 CHECK(findNode(tree, makePred(Type::Virtual, "::")) != nullptr);
426 CHECK(findNode(tree, makePred(Type::UserTypes, "uint8_t")) != nullptr);
427 CHECK(findNode(tree, makePred(Type::Other, ";")) != nullptr);
418 428 } }
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