forked from Ericsson/CodeCompass
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcppparser.h
More file actions
93 lines (74 loc) · 2.72 KB
/
cppparser.h
File metadata and controls
93 lines (74 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef CC_PARSER_CXXPARSER_H
#define CC_PARSER_CXXPARSER_H
#include <map>
#include <unordered_set>
#include <vector>
#include <clang/Tooling/JSONCompilationDatabase.h>
#include <clang/Tooling/Tooling.h>
#include <model/buildaction.h>
#include <parser/abstractparser.h>
#include <parser/parsercontext.h>
namespace cc
{
namespace parser
{
class CppParser : public AbstractParser
{
public:
CppParser(ParserContext& ctx_);
virtual ~CppParser();
virtual std::vector<std::string> getDependentParsers() const override;
virtual bool parse() override;
private:
/**
* This function gets the input-output pairs from the compile command.
*
* If the compile command comtains C/C++ source file(s) and the output is set
* by -o flag then the output file will be mapped to these source files.
* Otherwise if no -o flag given but -c is given then the output files will
* have the same name as the source file but with .o extension. If no -c and
* -o provided then the output file name will be a.out. If the compile
* command contains no source files then the function returns an empty map.
*/
std::map<std::string, std::string> extractInputOutputs(
const clang::tooling::CompileCommand& command_) const;
model::BuildActionPtr addBuildAction(
const clang::tooling::CompileCommand& command_);
void addCompileCommand(
const clang::tooling::CompileCommand& command_,
model::BuildActionPtr buildAction_,
bool error_ = false);
bool isParsed(const clang::tooling::CompileCommand& command_);
bool isSourceFile(const std::string& file_) const;
bool isNonSourceFlag(const std::string& arg_) const;
bool parseByJson(const std::string& jsonFile_, std::size_t threadNum_);
int worker(const clang::tooling::CompileCommand& command_);
/**
* A single build command's cc::util::JobQueueThreadPool job.
*/
struct ParseJob
{
/**
* The build command itself. This is given to CppParser::worker.
*/
std::reference_wrapper<const clang::tooling::CompileCommand> command;
/**
* The # of the build command in the compilation command database.
*/
std::size_t index;
ParseJob(const clang::tooling::CompileCommand& command, std::size_t index)
: command(command), index(index)
{}
ParseJob(const ParseJob&) = default;
};
// SymbolClusterer should NOT be ran if there isn't a single Link action
// amongst the parsed build actions, because it would resolve every reference
// to not be linked together, ultimately misleading the user.
bool linkCommandFound;
std::vector<clang::tooling::CompileCommand> _compileCommands;
std::size_t _index;
std::unordered_set<std::uint64_t> _parsedCommandHashes;
};
} // parser
} // cc
#endif // CC_PARSER_CXXPARSER_H