File tree Expand file tree Collapse file tree 9 files changed +39
-6
lines changed Expand file tree Collapse file tree 9 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -65,3 +65,13 @@ DefineFinder::getFinalIdentifier(const clang::Token &token) const {
65
65
// TODO: token is another definition. Find the original value
66
66
return nullptr ;
67
67
}
68
+
69
+ void DefineFinder::MacroUndefined (const clang::Token &MacroNameTok,
70
+ const clang::MacroDefinition &MD) {
71
+ clang::SourceManager &sm = compiler.getSourceManager ();
72
+ if (sm.isWrittenInMainFile (MacroNameTok.getLocation ()) &&
73
+ !MD.getMacroInfo ()->isFunctionLike ()) {
74
+ std::string macroName = MacroNameTok.getIdentifierInfo ()->getName ();
75
+ ir.removeDefine (macroName);
76
+ }
77
+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ class DefineFinder : public clang::PPCallbacks {
12
12
void MacroDefined (const clang::Token &MacroNameTok,
13
13
const clang::MacroDirective *MD) override ;
14
14
15
+ void MacroUndefined (const clang::Token &MacroNameTok,
16
+ const clang::MacroDefinition &MD) override ;
17
+
15
18
private:
16
19
IR &ir;
17
20
const clang::CompilerInstance &compiler;
Original file line number Diff line number Diff line change 1
1
#include " Define.h"
2
2
3
3
Define::Define (std::string name) : name(std::move(name)) {}
4
+
5
+ std::string Define::getName () { return name; }
Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ class Define {
7
7
public:
8
8
explicit Define (std::string name);
9
9
10
+ std::string getName ();
11
+
10
12
protected:
11
- const std::string name;
13
+ std::string name;
12
14
};
13
15
14
16
#endif // SCALA_NATIVE_BINDGEN_DEFINE_H
Original file line number Diff line number Diff line change @@ -247,3 +247,13 @@ bool IR::existsFunctionWithName(std::string functionName) {
247
247
}
248
248
return false ;
249
249
}
250
+
251
+ void IR::removeDefine (const std::string &name) {
252
+ for (auto it = literalDefines.begin (), end = literalDefines.end ();
253
+ it != end; ++it) {
254
+ if ((*it).getName () == name) {
255
+ literalDefines.erase (it);
256
+ return ;
257
+ }
258
+ }
259
+ }
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ class IR {
46
46
47
47
void generate (const std::string &excludePrefix);
48
48
49
+ void removeDefine (const std::string &name);
50
+
49
51
private:
50
52
/* *
51
53
* Generates type defs for enums, structs and unions
Original file line number Diff line number Diff line change 4
4
#include " Define.h"
5
5
#include < llvm/Support/raw_ostream.h>
6
6
7
- class LiteralDefine : Define {
7
+ class LiteralDefine : public Define {
8
8
public:
9
9
LiteralDefine (std::string name, std::string literal);
10
10
Original file line number Diff line number Diff line change @@ -10,11 +10,15 @@ extern int a;
10
10
#define MY_A a // unsupported
11
11
12
12
#ifdef NOT_DEFINED
13
- #define SHOULD_NOT_BE_DEFINED 0
13
+ #define SHOULD_NOT_BE_DEFINED "Because NOT_DEFINED is not defined"
14
14
#endif
15
15
16
+ #define DEFINED_ONLY_IN_HEADER "Defined only inside the header file"
17
+
16
18
#if INT == 0
17
- #define SHOULD_NOT_BE_DEFINED 1
19
+ #define SHOULD_NOT_BE_DEFINED "Because INT is 42"
18
20
#else
19
- #define SHOULD_BE_DEFINED 2
21
+ #define SHOULD_BE_DEFINED "Because INT is not equal to 0"
20
22
#endif
23
+
24
+ #undef DEFINED_ONLY_IN_HEADER
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ object DefineDefines {
7
7
val STRING : native.CString = c " Hello, World! "
8
8
val INT = 42
9
9
val FLOAT = 5.6
10
- val SHOULD_BE_DEFINED = 2
10
+ val SHOULD_BE_DEFINED : native. CString = c " Because INT is not equal to 0 "
11
11
}
You can’t perform that action at this time.
0 commit comments