-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstExternals.hpp
More file actions
31 lines (28 loc) · 988 Bytes
/
AstExternals.hpp
File metadata and controls
31 lines (28 loc) · 988 Bytes
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
#include "AstVisitor.hpp"
#include <map>
class AstExternals : public AstVisitorTransform {
public:
std::map<std::string, Expression*> *externals;
AstExternals(std::map<std::string, Expression*> *externals) : externals(externals) {}
StructDecl* visitStructDecl(StructDecl *decl) {
// Remove external struct
if (decl->name.compare("external") == 0) {
return NULL;
} else {
return AstVisitorTransform::visitStructDecl(decl);
}
}
Expression* visitFieldReference(FieldReference *ref) {
if (ref->expr->nodeType == ReferenceNode) {
Reference *ref2 = static_cast<Reference*>(ref->expr);
if (ref2->name.compare("external") == 0) {
// Check map for expression
if (externals->count(ref->field) > 0) {
delete ref;
return (*externals)[ref->field];
}
}
}
return ref;
}
};