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 |
} |
} |