upb: implement Dart public imports

PiperOrigin-RevId: 625324587
pull/16518/head
Eric Salo 7 months ago committed by Copybara-Service
parent 9ca7354815
commit bb3e50e15e
  1. 4
      upb/reflection/def.hpp
  2. 11
      upb/reflection/file_def.c
  3. 3
      upb/reflection/file_def.h

@ -515,6 +515,10 @@ class FileDefPtr {
return FieldDefPtr(upb_FileDef_TopLevelExtension(ptr_, index));
}
bool resolves(const char* path) const {
return upb_FileDef_Resolves(ptr_, path);
}
explicit operator bool() const { return ptr_ != nullptr; }
friend bool operator==(FileDefPtr lhs, FileDefPtr rhs) {

@ -170,6 +170,17 @@ const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable(
return f->ext_layouts[i];
}
// Note: Import cycles are not allowed so this will terminate.
bool upb_FileDef_Resolves(const upb_FileDef* f, const char* path) {
if (!strcmp(f->name, path)) return true;
for (int i = 0; i < upb_FileDef_PublicDependencyCount(f); i++) {
const upb_FileDef* dep = upb_FileDef_PublicDependency(f, i);
if (upb_FileDef_Resolves(dep, path)) return true;
}
return false;
}
static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) {
char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx));
if (!ret) _upb_DefBuilder_OomErr(ctx);

@ -51,6 +51,9 @@ int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f);
const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i);
int upb_FileDef_WeakDependencyCount(const upb_FileDef* f);
// Returns whether |symbol| is transitively included by |f|
bool upb_FileDef_Resolves(const upb_FileDef* f, const char* symbol);
#ifdef __cplusplus
} /* extern "C" */
#endif

Loading…
Cancel
Save