Skip to content

Commit

Permalink
upb: implement Dart public imports
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 625175731
  • Loading branch information
ericsalo authored and copybara-github committed Apr 16, 2024
1 parent 4515006 commit 92ec5d9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions upb/reflection/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions upb/reflection/file_def.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions upb/reflection/file_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92ec5d9

Please sign in to comment.