Skip to content

Commit

Permalink
Rewrite function properties functions to operate on the properties_t
Browse files Browse the repository at this point in the history
This makes function_properties_ref_t not const, in order to work
around cxx - I'm assuming google/autocxx#799
/ dtolnay/cxx#850
  • Loading branch information
faho committed Apr 11, 2023
1 parent 5b404b2 commit 2251cda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
36 changes: 12 additions & 24 deletions src/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,37 +165,25 @@ function_properties_ref_t function_get_props(const wcstring &name) {
return function_set.acquire()->get_props(name);
}

wcstring function_get_definition_file(const wcstring &name, parser_t &parser) {
auto props = function_get_props_autoload(name, parser);
if (!props || !props->definition_file) return L"";
return *props->definition_file;
wcstring function_get_definition_file(const function_properties_t &props) {
return props.definition_file ? *props.definition_file : L"";
}

wcstring function_get_copy_definition_file(const wcstring &name, parser_t &parser) {
auto props = function_get_props_autoload(name, parser);
if (!props || !props->copy_definition_file) return L"";
return *props->copy_definition_file;
wcstring function_get_copy_definition_file(const function_properties_t &props) {
return props.copy_definition_file ? *props.copy_definition_file : L"";
}
bool function_is_copy(const wcstring &name, parser_t &parser) {
auto props = function_get_props_autoload(name, parser);
if (!props) return false;
return props->is_copy;
bool function_is_copy(const function_properties_t &props) {
return props.is_copy;
}
int function_get_definition_lineno(const wcstring &name, parser_t &parser) {
auto props = function_get_props_autoload(name, parser);
if (!props) return 0;
return props->definition_lineno();
int function_get_definition_lineno(const function_properties_t &props) {
return props.definition_lineno();
}
int function_get_copy_definition_lineno(const wcstring &name, parser_t &parser) {
auto props = function_get_props_autoload(name, parser);
if (!props) return 0;
return props->copy_definition_lineno;
int function_get_copy_definition_lineno(const function_properties_t &props) {
return props.copy_definition_lineno;
}

wcstring function_get_annotated_definition(const wcstring &name, parser_t &parser) {
auto props = function_get_props_autoload(name, parser);
if (!props) return L"";
return props->annotated_definition(name);
wcstring function_get_annotated_definition(const function_properties_t &props, const wcstring &name) {
return props.annotated_definition(name);
}

function_properties_ref_t function_get_props_autoload(const wcstring &name, parser_t &parser) {
Expand Down
16 changes: 9 additions & 7 deletions src/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ struct function_properties_t {
wcstring annotated_definition(const wcstring &name) const;
};

using function_properties_ref_t = std::shared_ptr<const function_properties_t>;
// FIXME: Morally, this is const, but cxx doesn't get it
using function_properties_ref_t = std::shared_ptr<function_properties_t>;

/// Add a function. This may mutate \p props to set is_autoload.
void function_add(wcstring name, std::shared_ptr<function_properties_t> props);
Expand All @@ -78,12 +79,13 @@ void function_remove(const wcstring &name);
/// \return the properties for a function, or nullptr if none. This does not trigger autoloading.
function_properties_ref_t function_get_props(const wcstring &name);

wcstring function_get_definition_file(const wcstring &name, parser_t &parser);
wcstring function_get_copy_definition_file(const wcstring &name, parser_t &parser);
bool function_is_copy(const wcstring &name, parser_t &parser);
int function_get_definition_lineno(const wcstring &name, parser_t &parser);
int function_get_copy_definition_lineno(const wcstring &name, parser_t &parser);
wcstring function_get_annotated_definition(const wcstring &name, parser_t &parser);
/// Guff to work around cxx not getting function_properties_t.
wcstring function_get_definition_file(const function_properties_t &props);
wcstring function_get_copy_definition_file(const function_properties_t &props);
bool function_is_copy(const function_properties_t &props);
int function_get_definition_lineno(const function_properties_t &props);
int function_get_copy_definition_lineno(const function_properties_t &props);
wcstring function_get_annotated_definition(const function_properties_t &props, const wcstring &name);

/// \return the properties for a function, or nullptr if none, perhaps triggering autoloading.
function_properties_ref_t function_get_props_autoload(const wcstring &name, parser_t &parser);
Expand Down

0 comments on commit 2251cda

Please sign in to comment.