-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathppmacrocallback.h
More file actions
101 lines (79 loc) · 2.46 KB
/
ppmacrocallback.h
File metadata and controls
101 lines (79 loc) · 2.46 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
94
95
96
97
98
99
100
101
#ifndef CC_PARSER_PPMACROCALLBACK_H
#define CC_PARSER_PPMACROCALLBACK_H
#include <clang/Lex/PPCallbacks.h>
#include <clang/Lex/Preprocessor.h>
#include <clang/AST/ASTContext.h>
#include <model/cppastnode.h>
#include <model/cppastnode-odb.hxx>
#include <model/cppmacro.h>
#include <model/cppmacro-odb.hxx>
#include <model/cppmacroexpansion.h>
#include <model/cppmacroexpansion-odb.hxx>
#include <parser/parsercontext.h>
#include <util/logutil.h>
#include "entitycache.h"
namespace cc
{
namespace parser
{
class PPMacroCallback : public clang::PPCallbacks
{
public:
PPMacroCallback(
ParserContext& ctx_,
clang::ASTContext& astContext_,
EntityCache& entityCache_,
clang::Preprocessor& pp_);
~PPMacroCallback();
/*virtual void MacroExpands(
const clang::Token& macroNameTok_,
const clang::MacroDefinition& md_,
clang::SourceRange range_,
const clang::MacroArgs* args_) override;*/
virtual void MacroDefined(
const clang::Token& macroNameTok_,
const clang::MacroDirective* md_) override;
virtual void MacroUndefined(
const clang::Token& macroNameTok_,
const clang::MacroDefinition& md_,
const clang::MacroDirective* undef_) override;
private:
/**
* This function creates an AST Node for a macro.
*/
model::CppAstNodePtr createMacroAstNode(
const clang::Token& macroNameTok_,
const clang::MacroInfo* mi_);
/**
* This function tells that a macro is a built-in macro.
*/
bool isBuiltInMacro(const clang::MacroInfo* mi_) const;
/**
* This function returns a unique identifier of the macro.
*
* TODO: In Clang there is a function named generateUSRForMacro(), but we're
* not using that in this implementation. That function gets a
* MacroDefinitionRecord as parameter, but here we have a MacroInfo.
*/
std::string getUSR(const clang::MacroInfo *MI);
/**
* This function add fill the file location of the AST node.
*/
void addFileLoc(
model::CppAstNodePtr& astNode,
const clang::SourceLocation& start,
const clang::SourceLocation& end);
ParserContext& _ctx;
clang::Preprocessor& _pp;
const std::string _cppSourceType;
clang::SourceManager& _clangSrcMgr;
FileLocUtil _fileLocUtil;
bool _disabled = false;
EntityCache& _entityCache;
std::vector<model::CppAstNodePtr> _astNodes;
std::vector<model::CppMacroPtr> _macros;
std::vector<model::CppMacroExpansionPtr> _macrosExpansion;
};
} // parser
} // cc
#endif // CC_PARSER_PPMACROCALLBACK_H