From 0ad1e8efbd7e4b467d93568136e7beafe1e23fb5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 8 Aug 2015 17:45:16 +0300 Subject: Add plugin parameters *-specialdump=filename for dump only this file AST tree. --- src/command.h | 3 +++ src/parsers/decl/function_decl.cpp | 17 +++++++++++++++++ src/plugin.cpp | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/src/command.h b/src/command.h index 7fb7386..1ba0e2b 100644 --- a/src/command.h +++ b/src/command.h @@ -23,6 +23,8 @@ #define checkCommand(val) ((command & Command::val) == Command::val) #define disableCommand(val) command = static_cast(static_cast( \ command | Command::val) ^ static_cast(Command::val)) +#define enableCommand(val) command = static_cast(static_cast( \ + command | Command::val)) enum Command : int { @@ -38,5 +40,6 @@ enum Command : int }; extern Command command; +extern std::string dumpFile; #endif // COMMAND_H diff --git a/src/parsers/decl/function_decl.cpp b/src/parsers/decl/function_decl.cpp index f8a5579..3bd774d 100644 --- a/src/parsers/decl/function_decl.cpp +++ b/src/parsers/decl/function_decl.cpp @@ -19,6 +19,8 @@ #include "includes/parserincludes.h" +#include "command.h" + parserDefine(FunctionDecl); #include "parsers/base/decl.h" @@ -35,6 +37,15 @@ void parseFunctionDeclNode(FunctionDeclNode *node) fillLocation(node); fillDeclLabel(node); + bool spoofCommand(false); + Command oldCommand = command; + if (!node->parent && !dumpFile.empty() && node->file == dumpFile) + { + spoofCommand = true; + enableCommand(Dump); + Log::log("start dump\n"); + } + Log::dump(node); fillDeclAutoGenerated(node); @@ -79,6 +90,12 @@ void parseFunctionDeclNode(FunctionDeclNode *node) node, DECL_FUNCTION_SPECIFIC_OPTIMIZATION(node->gccNode), "optiomisations"); + + if (spoofCommand) + { + command = oldCommand; + Log::log("end dump\n"); + } } } diff --git a/src/plugin.cpp b/src/plugin.cpp index a4f7b66..27b6d18 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -39,6 +39,7 @@ struct Node; Command command = Command::DetectNullPointers; std::map foundNodesMap; std::map updateNodesMap; +std::string dumpFile; // copy/paste from plugin.h look like again guard header issue. extern void register_attribute (const struct attribute_spec *attr); @@ -139,6 +140,10 @@ int plugin_init (struct plugin_name_args *plugin_info, return 0; } } + if (!strcmp (argv[f].key, "specialdump")) + { + dumpFile = argv[f].value; + } } register_callback(plugin_info->base_name, -- cgit v1.2.3-60-g2f50