#includeusing namespace clang; void retrieveFunctionsInNamespace(DeclContext* ns) { for (auto decl : ns->decls()) { if (auto funcDecl = dyn_cast (decl)) { // Do something with function declaration } } }
class MyClass { public: int myVar1; float myVar2; }; void retrieveMembersOfClass(DeclContext* cl) { if (auto classDecl = dyn_castThis example defines a class and uses DeclContext to retrieve all member variables declared in it. It uses the dynamic cast to check if the given context is a class and then uses the `fields` function to retrieve all member variable declarations. Package library: Standard Library(cl)) { for (auto field : classDecl->fields()) { // Do something with member variable declaration } } }