| 1 |
//===- MacroWalker.hh - Get macro structures according to location *- C++ -*-===// |
| 2 |
// |
| 3 |
// This project is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
/// \file |
| 10 |
/// Helper functions and methods to handle macros. |
| 11 |
// |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
/* Author: Giuliano Belinassi */ |
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <clang/Tooling/Tooling.h> |
| 19 |
|
| 20 |
using namespace clang; |
| 21 |
|
| 22 |
class MacroWalker |
| 23 |
{ |
| 24 |
public: |
| 25 |
MacroWalker(Preprocessor &p) |
| 26 |
: PProcessor(p) |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
/** The object which holds the macro arguments is the MacroInfo. Get the |
| 31 |
MacroInfo being extra careful to not pick the last definition, since |
| 32 |
macros can be redefined. */ |
| 33 |
MacroInfo *Get_Macro_Info(MacroDefinitionRecord *record); |
| 34 |
MacroInfo *Get_Macro_Info(MacroExpansion *macroexp); |
| 35 |
MacroInfo *Get_Macro_Info(const IdentifierInfo *id, const SourceLocation &loc); |
| 36 |
|
| 37 |
MacroDirective* Get_Macro_Directive(MacroDefinitionRecord *record); |
| 38 |
|
| 39 |
/** Check if macro is a builtin-macro. */ |
| 40 |
bool Is_Builtin_Macro(MacroInfo *info); |
| 41 |
|
| 42 |
/** Check if IdentifierInfo `tok` is actually an argument of the macro info. */ |
| 43 |
static bool Is_Identifier_Macro_Argument(MacroInfo *info, const IdentifierInfo *tok); |
| 44 |
static bool Is_Identifier_Macro_Argument(MacroInfo *info, StringRef tok_str); |
| 45 |
|
| 46 |
private: |
| 47 |
Preprocessor &PProcessor; |
| 48 |
}; |