Skip to content

Commit

Permalink
Merge pull request #2353 from hzeller/feature-20250216-explicit-linkage
Browse files Browse the repository at this point in the history
Be a bit more explicit with internal and external linkage.
  • Loading branch information
hzeller authored Feb 17, 2025
2 parents d515916 + 7f0bc2e commit 005007b
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 80 deletions.
2 changes: 2 additions & 0 deletions verible/common/analysis/matcher/inner-match-handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "verible/common/analysis/matcher/inner-match-handlers.h"

#include <vector>

#include "verible/common/analysis/matcher/bound-symbol-manager.h"
Expand Down
15 changes: 8 additions & 7 deletions verible/common/formatting/align.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ struct AlignmentCell {
using AlignmentRow = VectorTree<AlignmentCell>;
using AlignmentMatrix = std::vector<AlignmentRow>;

std::ostream &operator<<(std::ostream &stream, const AlignmentCell &cell) {
static std::ostream &operator<<(std::ostream &stream,
const AlignmentCell &cell) {
if (!cell.tokens.empty()) {
// See UnwrappedLine::AsCode for similar printing.
stream << absl::StrJoin(cell.tokens, " ",
Expand Down Expand Up @@ -480,8 +481,8 @@ static std::pair<std::string, char> GetColumnDataCellLabel(
return {label.str(), node.Value().properties.flush_left ? '<' : '>'};
}

std::ostream &operator<<(std::ostream &stream,
const VectorTree<AggregateColumnData> &tree) {
static std::ostream &operator<<(std::ostream &stream,
const VectorTree<AggregateColumnData> &tree) {
ColumnsTreeFormatter<AggregateColumnData>(
stream, tree, GetColumnDataCellLabel<AggregateColumnData>);
return stream;
Expand All @@ -493,8 +494,8 @@ std::ostream &operator<<(std::ostream &stream, const ColumnPositionTree &tree) {
return stream;
}

std::ostream &operator<<(std::ostream &stream,
const VectorTree<AlignmentCell> &tree) {
static std::ostream &operator<<(std::ostream &stream,
const VectorTree<AlignmentCell> &tree) {
ColumnsTreeFormatter<AlignmentCell>(
stream, tree,
[](const VectorTree<AlignmentCell> &node)
Expand All @@ -515,8 +516,8 @@ std::ostream &operator<<(std::ostream &stream,
return stream;
}

std::ostream &operator<<(std::ostream &stream,
const VectorTree<AlignedColumnConfiguration> &tree) {
static std::ostream &operator<<(
std::ostream &stream, const VectorTree<AlignedColumnConfiguration> &tree) {
ColumnsTreeFormatter<AlignedColumnConfiguration>(
stream, tree, [](const VectorTree<AlignedColumnConfiguration> &node) {
const auto &cell = node.Value();
Expand Down
2 changes: 1 addition & 1 deletion verible/common/lsp/dummy-ls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ using verible::lsp::JsonRpcDispatcher;
using verible::lsp::MessageStreamSplitter;

// The "initialize" method requests server capabilities.
InitializeResult InitializeServer(const nlohmann::json &params) {
static InitializeResult InitializeServer(const nlohmann::json &params) {
// Ignore passed client capabilities from params right now,
// just announce what we do.
InitializeResult result;
Expand Down
13 changes: 7 additions & 6 deletions verible/common/lsp/jcxxgen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ABSL_FLAG(std::string, json_header, "\"nlohmann/json.hpp\"",
"Include path to json.hpp including brackets <> or quotes \"\" "
"around.");

namespace {
// Interface. Currently private, but could be moved to a header if needed.
struct Location {
const char *filename;
Expand Down Expand Up @@ -89,13 +90,11 @@ struct ObjectType {

using ObjectTypeVector = std::vector<ObjectType *>;

static bool contains(const std::string &s, char c) {
return absl::StrContains(s, c);
}
bool contains(const std::string &s, char c) { return absl::StrContains(s, c); }

// Returns if successful.
static bool ParseObjectTypesFromFile(const std::string &filename,
ObjectTypeVector *parsed_out) {
bool ParseObjectTypesFromFile(const std::string &filename,
ObjectTypeVector *parsed_out) {
static const RE2 emptyline_or_comment_re("^[ \t]*(#.*)?");
static const RE2 toplevel_object_re("^([a-zA-Z0-9_]+):");

Expand Down Expand Up @@ -150,7 +149,7 @@ static bool ParseObjectTypesFromFile(const std::string &filename,
}

// Validate types and return if successful.
static bool ValidateTypes(ObjectTypeVector *object_types) {
bool ValidateTypes(ObjectTypeVector *object_types) {
absl::flat_hash_map<std::string, ObjectType *> typeByName;

for (auto &obj : *object_types) {
Expand Down Expand Up @@ -357,6 +356,7 @@ void GenerateCode(const std::string &filename,
fprintf(out, "} // %s\n", gen_namespace.c_str());
}
}
} // namespace

int main(int argc, char *argv[]) {
const auto usage =
Expand Down Expand Up @@ -386,4 +386,5 @@ int main(int argc, char *argv[]) {

GenerateCode(schema_filename, absl::GetFlag(FLAGS_json_header),
absl::GetFlag(FLAGS_class_namespace), *objects, out);
fclose(out);
}
4 changes: 2 additions & 2 deletions verible/common/lsp/lsp-file-utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
namespace verible {
namespace lsp {

std::string PathPrefix(const std::string &path) {
static std::string PathPrefix(const std::string &path) {
#ifdef _WIN32
return absl::StrCat("y:/", path);
#else
return absl::StrCat("/", path);
#endif
}

std::string URIPrefix(const std::string &path) {
static std::string URIPrefix(const std::string &path) {
#ifdef _WIN32
return absl::StrCat("file:///y%3a/", path);
#else
Expand Down
16 changes: 2 additions & 14 deletions verible/common/strings/diff_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <initializer_list>
#include <ostream>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>

Expand All @@ -29,7 +28,7 @@

namespace diff {
// Print functions copied from external_libs/editscript_test.cc
std::ostream &operator<<(std::ostream &out, Operation operation) {
static std::ostream &operator<<(std::ostream &out, Operation operation) {
switch (operation) {
case Operation::EQUALS:
return (out << "EQUALS");
Expand All @@ -41,22 +40,11 @@ std::ostream &operator<<(std::ostream &out, Operation operation) {
return out;
}

std::ostream &operator<<(std::ostream &out, const diff::Edit &edit) {
static std::ostream &operator<<(std::ostream &out, const diff::Edit &edit) {
out << "{" << edit.operation << ",[" << edit.start << "," << edit.end << ")}";
return out;
}

std::ostream &operator<<(std::ostream &out, const Edits &edits) {
out << "Edits{";
std::string outer_delim;
for (auto &edit : edits) {
out << outer_delim << edit;
outer_delim = ",";
}
out << "};";
return out;
}

} // namespace diff

namespace verible {
Expand Down
2 changes: 1 addition & 1 deletion verible/common/text/text-structure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static bool TokenLocationLess(const TokenInfo &token,

// Makes an iterator-writable copy of items_view without using const_cast.
template <class V>
std::vector<typename V::iterator> CopyWriteableIterators(
static std::vector<typename V::iterator> CopyWriteableIterators(
V &items, const std::vector<typename V::const_iterator> &items_view) {
// precondition: items_view's iterators all point into items array.
// postcondition: results's iterators point to the same items as items_view.
Expand Down
6 changes: 3 additions & 3 deletions verible/common/text/text-structure_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ TEST(FilterTokensTest, EmptyTokens) {
}

// Create a one-token token stream and syntax tree.
void OneTokenTextStructureView(TextStructureView *view) {
static void OneTokenTextStructureView(TextStructureView *view) {
TokenInfo token(1, view->Contents());
view->MutableTokenStream().push_back(token);
view->MutableTokenStreamView().push_back(view->TokenStream().begin());
view->MutableSyntaxTree() = Leaf(token);
}

// Create a two-token token stream, no syntax tree.
void MultiTokenTextStructureViewNoTree(TextStructureView *view) {
static void MultiTokenTextStructureViewNoTree(TextStructureView *view) {
const auto contents = view->Contents();
CHECK_GE(contents.length(), 5);
auto &stream = view->MutableTokenStream();
Expand Down Expand Up @@ -467,7 +467,7 @@ TEST_F(TextStructureViewPublicTest, ExpandSubtreesEmpty) {
}

// Splits a single token into a syntax tree node with two leaves.
void FakeParseToken(TextStructureView *data, int offset, int node_tag) {
static void FakeParseToken(TextStructureView *data, int offset, int node_tag) {
TokenSequence &tokens = data->MutableTokenStream();
tokens.push_back(TokenInfo(11, data->Contents().substr(0, offset)));
tokens.push_back(TokenInfo(12, data->Contents().substr(offset)));
Expand Down
2 changes: 1 addition & 1 deletion verible/verilog/CST/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::vector<verible::TreeSearchMatch> FindAllProgramDeclarations(
return SearchSyntaxTree(root, NodekProgramDeclaration());
}

bool IsModuleOrInterfaceOrProgramDeclaration(
static bool IsModuleOrInterfaceOrProgramDeclaration(
const SyntaxTreeNode &declaration) {
return declaration.MatchesTagAnyOf({NodeEnum::kModuleDeclaration,
NodeEnum::kInterfaceDeclaration,
Expand Down
14 changes: 7 additions & 7 deletions verible/verilog/CST/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const SyntaxTreeNode *GetAssertionStatementAssertClause(
NodeEnum::kAssertionClause);
}

const SyntaxTreeNode *GetAssertionClauseStatementBody(
static const SyntaxTreeNode *GetAssertionClauseStatementBody(
const Symbol &assertion_clause) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(assertion_clause), NodeEnum::kAssertionClause));
Expand All @@ -154,7 +154,7 @@ const SyntaxTreeNode *GetAssumeStatementAssumeClause(
NodeEnum::kAssumeClause);
}

const SyntaxTreeNode *GetAssumeClauseStatementBody(
static const SyntaxTreeNode *GetAssumeClauseStatementBody(
const Symbol &assume_clause) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(assume_clause), NodeEnum::kAssumeClause));
Expand Down Expand Up @@ -197,7 +197,7 @@ const SyntaxTreeNode *GetAssertPropertyStatementAssertClause(
NodeEnum::kAssertPropertyClause);
}

const SyntaxTreeNode *GetAssertPropertyStatementBody(
static const SyntaxTreeNode *GetAssertPropertyStatementBody(
const Symbol &assert_clause) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(assert_clause), NodeEnum::kAssertPropertyClause));
Expand Down Expand Up @@ -225,7 +225,7 @@ const SyntaxTreeNode *GetAssumePropertyStatementAssumeClause(
NodeEnum::kAssumePropertyClause);
}

const SyntaxTreeNode *GetAssumePropertyStatementBody(
static const SyntaxTreeNode *GetAssumePropertyStatementBody(
const Symbol &assume_clause) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(assume_clause), NodeEnum::kAssumePropertyClause));
Expand Down Expand Up @@ -253,7 +253,7 @@ const SyntaxTreeNode *GetExpectPropertyStatementExpectClause(
NodeEnum::kExpectPropertyClause);
}

const SyntaxTreeNode *GetExpectPropertyStatementBody(
static const SyntaxTreeNode *GetExpectPropertyStatementBody(
const Symbol &expect_clause) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(expect_clause), NodeEnum::kExpectPropertyClause));
Expand All @@ -274,7 +274,7 @@ const SyntaxTreeNode *GetExpectPropertyStatementElseClause(
NodeEnum::kElseClause);
}

const SyntaxTreeNode *GetCoverPropertyStatementBody(
static const SyntaxTreeNode *GetCoverPropertyStatementBody(
const Symbol &cover_property) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(cover_property), NodeEnum::kCoverPropertyStatement));
Expand All @@ -283,7 +283,7 @@ const SyntaxTreeNode *GetCoverPropertyStatementBody(
GetSubtreeAsSymbol(*body_node, NodeEnum::kCoverPropertyBody, 0));
}

const SyntaxTreeNode *GetCoverSequenceStatementBody(
static const SyntaxTreeNode *GetCoverSequenceStatementBody(
const Symbol &cover_sequence) {
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
SymbolCastToNode(cover_sequence), NodeEnum::kCoverSequenceStatement));
Expand Down
2 changes: 1 addition & 1 deletion verible/verilog/CST/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const verible::SyntaxTreeLeaf *GetSymbolIdentifierFromEnumName(
return verible::GetSubtreeAsLeaf(enum_name, NodeEnum::kEnumName, 0);
}

const verible::SyntaxTreeLeaf *GetTypeIdentifierFromInterfaceType(
static const verible::SyntaxTreeLeaf *GetTypeIdentifierFromInterfaceType(
const verible::Symbol &interface_type) {
return verible::GetSubtreeAsLeaf(interface_type, NodeEnum::kInterfaceType, 2);
}
Expand Down
2 changes: 1 addition & 1 deletion verible/verilog/analysis/verilog-linter-configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static const verible::EnumNameMap<RuleSet> &RuleSetEnumStringMap() {
return kRuleSetEnumStringMap;
}

std::ostream &operator<<(std::ostream &stream, RuleSet rules) {
static std::ostream &operator<<(std::ostream &stream, RuleSet rules) {
return RuleSetEnumStringMap().Unparse(rules, stream);
}

Expand Down
13 changes: 7 additions & 6 deletions verible/verilog/formatting/align.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class VerilogColumnSchemaScanner : public ColumnSchemaScanner {
};

template <class ScannerType>
std::function<verible::AlignmentCellScannerFunction(const FormatStyle &)>
static std::function<verible::AlignmentCellScannerFunction(const FormatStyle &)>
UnstyledAlignmentCellScannerGenerator() {
return [](const FormatStyle &vstyle) {
return AlignmentCellScannerGenerator<ScannerType>(
Expand All @@ -243,9 +243,10 @@ UnstyledAlignmentCellScannerGenerator() {
}

template <class ScannerType>
std::function<verible::AlignmentCellScannerFunction(const FormatStyle &)>
UnstyledAlignmentCellScannerGenerator(
const verible::NonTreeTokensScannerFunction &non_tree_column_scanner) {
std::function<verible::AlignmentCellScannerFunction(
const FormatStyle
&)> static UnstyledAlignmentCellScannerGenerator(const verible::NonTreeTokensScannerFunction
&non_tree_column_scanner) {
return [non_tree_column_scanner](const FormatStyle &vstyle) {
return AlignmentCellScannerGenerator<ScannerType>(
[vstyle] { return ScannerType(vstyle); }, non_tree_column_scanner);
Expand Down Expand Up @@ -1292,8 +1293,8 @@ struct AlignmentGroupHandlers {
// Returns the referenced member by value.
// TODO(fangism): move this to an STL-style util/functional library
template <typename MemberType, typename StructType>
std::function<MemberType(const StructType &)> function_from_pointer_to_member(
MemberType StructType::*member) {
static std::function<MemberType(const StructType &)>
function_from_pointer_to_member(MemberType StructType::*member) {
return [member](const StructType &obj) { return obj.*member; };
}

Expand Down
7 changes: 4 additions & 3 deletions verible/verilog/formatting/formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ class Formatter {
};

// TODO(b/148482625): make this public/re-usable for general content comparison.
Status VerifyFormatting(const verible::TextStructureView &text_structure,
std::string_view formatted_output,
std::string_view filename) {
// Not declared in any header, but also used in formatter_test
extern Status VerifyFormatting(const verible::TextStructureView &text_structure,
std::string_view formatted_output,
std::string_view filename) {
// Verify that the formatted output creates the same lexical
// stream (filtered) as the original. If any tokens were lost, fall back to
// printing the original source unformatted.
Expand Down
6 changes: 3 additions & 3 deletions verible/verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ namespace verilog {
namespace formatter {

// private, extern function in formatter.cc, directly tested here.
absl::Status VerifyFormatting(const verible::TextStructureView &text_structure,
std::string_view formatted_output,
std::string_view filename);
extern absl::Status VerifyFormatting(
const verible::TextStructureView &text_structure,
std::string_view formatted_output, std::string_view filename);

namespace {

Expand Down
10 changes: 5 additions & 5 deletions verible/verilog/formatting/token-annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,11 @@ static WithReason<SpacingOptions> BreakDecisionBetween(
// Extern linkage for sake of direct testing, though not exposed in public
// headers.
// TODO(fangism): could move this to a -internal.h header.
void AnnotateFormatToken(const FormatStyle &style,
const PreFormatToken &prev_token,
PreFormatToken *curr_token,
const SyntaxTreeContext &prev_context,
const SyntaxTreeContext &curr_context) {
extern void AnnotateFormatToken(const FormatStyle &style,
const PreFormatToken &prev_token,
PreFormatToken *curr_token,
const SyntaxTreeContext &prev_context,
const SyntaxTreeContext &curr_context) {
const auto p = SpacesRequiredBetween(style, prev_token, *curr_token,
prev_context, curr_context);
curr_token->before.spaces_required = p.spaces_required;
Expand Down
Loading

0 comments on commit 005007b

Please sign in to comment.