Skip to content

Commit

Permalink
Use integer types for enums in JSON (Fixes iovisor#2615)
Browse files Browse the repository at this point in the history
The JSON generated for enums wasn't being handled, and caused
exceptions. Since the enum values aren't needed (and would've been
useless without the associated numerical values, anyway), just use the
matching integer type instead.
  • Loading branch information
alexer authored and yonghong-song committed Dec 1, 2019
1 parent feadea6 commit 556d9ec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
17 changes: 1 addition & 16 deletions src/cc/json_map_decl_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class BMapDeclVisitor : public clang::RecursiveASTVisitor<BMapDeclVisitor> {
bool VisitTypedefType(const clang::TypedefType *T);
bool VisitTagType(const clang::TagType *T);
bool VisitPointerType(const clang::PointerType *T);
bool VisitEnumConstantDecl(clang::EnumConstantDecl *D);
bool VisitEnumDecl(clang::EnumDecl *D);
bool VisitAttr(clang::Attr *A);

Expand Down Expand Up @@ -93,22 +92,8 @@ bool BMapDeclVisitor::VisitFieldDecl(FieldDecl *D) {
return true;
}

bool BMapDeclVisitor::VisitEnumConstantDecl(EnumConstantDecl *D) {
result_ += "\"";
result_ += D->getName();
result_ += "\",";
return false;
}

bool BMapDeclVisitor::VisitEnumDecl(EnumDecl *D) {
result_ += "[\"";
result_ += D->getName();
result_ += "\", [";
for (auto it = D->enumerator_begin(); it != D->enumerator_end(); ++it) {
TraverseDecl(*it);
}
result_.erase(result_.end() - 1);
result_ += "], \"enum\"]";
TraverseType(D->getIntegerType());
return false;
}

Expand Down
1 change: 1 addition & 0 deletions tests/python/test_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ def test_enumerations(self):
BPF_HASH(drops, struct a);
"""
b = BPF(text=text)
t = b['drops']

def test_int128_types(self):
text = """
Expand Down

0 comments on commit 556d9ec

Please sign in to comment.