Skip to content

Commit 0c95451

Browse files
committed
Output correct file format version if version is 4
1 parent 6ed086e commit 0c95451

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

tools/cgcollector2/src/CallGraphCollectionAction.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* https://github.com/tudasc/metacg/LICENSE.txt
55
*/
66

7-
87
#include "CallGraphCollectionAction.h"
98
#include "CallGraphNodeGenerator.h"
9+
#include "MCGBaseInfo.h"
1010
#include "Plugin.h"
1111
#include "SharedDefs.h"
1212
#include "metadata/Internal/ASTNodeMetadata.h"
@@ -32,8 +32,8 @@ void CallGraphCollectorConsumer::HandleTranslationUnit(clang::ASTContext& Contex
3232
mcgm.resetManager();
3333
mcgm.addToManagedGraphs("newGraph", std::make_unique<metacg::Callgraph>());
3434
auto callgraph = mcgm.getCallgraph();
35-
CallGraphNodeGenerator graphGenerator(callgraph, captureCtorsDtors, captureNewDeleteCalls, captureImplicits, inferCtorsDtors,
36-
standalone, level);
35+
CallGraphNodeGenerator graphGenerator(callgraph, captureCtorsDtors, captureNewDeleteCalls, captureImplicits,
36+
inferCtorsDtors, standalone, level);
3737

3838
graphGenerator.TraverseDecl(Context.getTranslationUnitDecl());
3939

@@ -63,25 +63,29 @@ void CallGraphCollectorConsumer::HandleTranslationUnit(clang::ASTContext& Contex
6363

6464
std::unique_ptr<metacg::io::MCGWriter> mcgWriter;
6565

66-
switch (mcgVersion){
67-
case 1: SPDLOG_WARN("This tool can not generate output files in the V1 format, using V2 instead");
68-
__attribute__ ((fallthrough));
66+
switch (mcgVersion) {
67+
case 1:
68+
SPDLOG_WARN("This tool can not generate output files in the V1 format, using V2 instead");
69+
__attribute__((fallthrough));
6970
case 2:
70-
mcgWriter = std::make_unique<metacg::io::VersionTwoMCGWriter>(metacg::getVersionTwoFileInfo({std::string("CGCollector2"), MetaCG_VERSION_MAJOR,
71-
MetaCG_VERSION_MINOR, MetaCG_GIT_SHA}));
71+
mcgWriter = std::make_unique<metacg::io::VersionTwoMCGWriter>(metacg::MCGFileInfo(
72+
{2, 0},
73+
{std::string("CGCollector2"), MetaCG_VERSION_MAJOR, MetaCG_VERSION_MINOR, MetaCG_GIT_SHA}));
7274
break;
73-
case 3: SPDLOG_WARN("V3 format was removed and is currently not supported, using V4 instead");
74-
__attribute__ ((fallthrough));
75-
case 4: mcgWriter = std::make_unique<metacg::io::VersionFourMCGWriter>(metacg::getVersionTwoFileInfo({std::string("CGCollector2"), MetaCG_VERSION_MAJOR,
76-
MetaCG_VERSION_MINOR, MetaCG_GIT_SHA}));
75+
case 3:
76+
SPDLOG_WARN("V3 format was removed and is currently not supported, using V4 instead");
77+
__attribute__((fallthrough));
78+
case 4:
79+
mcgWriter = std::make_unique<metacg::io::VersionFourMCGWriter>(metacg::MCGFileInfo(
80+
{4, 0},
81+
{std::string("CGCollector2"), MetaCG_VERSION_MAJOR, MetaCG_VERSION_MINOR, MetaCG_GIT_SHA}));
7782
break;
7883
default:
7984
assert(false && "The selected output format is not recognized");
80-
SPDLOG_WARN("The selected output format {} is not recognized. Using default format (V2) instead",mcgVersion);
85+
SPDLOG_WARN("The selected output format {} is not recognized. Using default format (V2) instead", mcgVersion);
8186
mcgWriter = std::make_unique<metacg::io::VersionTwoMCGWriter>();
8287
}
8388

84-
8589
metacg::io::JsonSink js;
8690
mcgWriter->write(callgraph, js);
8791
auto& sm = Context.getSourceManager();

0 commit comments

Comments
 (0)