Skip to content

Commit 7f0bc2e

Browse files
committed
Be a bit more explicit with internal and external linkage.
There are a bunch of functions only really used locally, so make them explicitly static (or put in anonymous namespace). Functiont that are not in header files but are used externally (typically in their corresponding tests): mark explicitly extern. (Hat-tip to new clang-tidy check `[misc-use-internal-linkage]`)
1 parent d515916 commit 7f0bc2e

22 files changed

+76
-80
lines changed

verible/common/analysis/matcher/inner-match-handlers.cc

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "verible/common/analysis/matcher/inner-match-handlers.h"
16+
1517
#include <vector>
1618

1719
#include "verible/common/analysis/matcher/bound-symbol-manager.h"

verible/common/formatting/align.cc

+8-7
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ struct AlignmentCell {
132132
using AlignmentRow = VectorTree<AlignmentCell>;
133133
using AlignmentMatrix = std::vector<AlignmentRow>;
134134

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

483-
std::ostream &operator<<(std::ostream &stream,
484-
const VectorTree<AggregateColumnData> &tree) {
484+
static std::ostream &operator<<(std::ostream &stream,
485+
const VectorTree<AggregateColumnData> &tree) {
485486
ColumnsTreeFormatter<AggregateColumnData>(
486487
stream, tree, GetColumnDataCellLabel<AggregateColumnData>);
487488
return stream;
@@ -493,8 +494,8 @@ std::ostream &operator<<(std::ostream &stream, const ColumnPositionTree &tree) {
493494
return stream;
494495
}
495496

496-
std::ostream &operator<<(std::ostream &stream,
497-
const VectorTree<AlignmentCell> &tree) {
497+
static std::ostream &operator<<(std::ostream &stream,
498+
const VectorTree<AlignmentCell> &tree) {
498499
ColumnsTreeFormatter<AlignmentCell>(
499500
stream, tree,
500501
[](const VectorTree<AlignmentCell> &node)
@@ -515,8 +516,8 @@ std::ostream &operator<<(std::ostream &stream,
515516
return stream;
516517
}
517518

518-
std::ostream &operator<<(std::ostream &stream,
519-
const VectorTree<AlignedColumnConfiguration> &tree) {
519+
static std::ostream &operator<<(
520+
std::ostream &stream, const VectorTree<AlignedColumnConfiguration> &tree) {
520521
ColumnsTreeFormatter<AlignedColumnConfiguration>(
521522
stream, tree, [](const VectorTree<AlignedColumnConfiguration> &node) {
522523
const auto &cell = node.Value();

verible/common/lsp/dummy-ls.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using verible::lsp::JsonRpcDispatcher;
4444
using verible::lsp::MessageStreamSplitter;
4545

4646
// The "initialize" method requests server capabilities.
47-
InitializeResult InitializeServer(const nlohmann::json &params) {
47+
static InitializeResult InitializeServer(const nlohmann::json &params) {
4848
// Ignore passed client capabilities from params right now,
4949
// just announce what we do.
5050
InitializeResult result;

verible/common/lsp/jcxxgen.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ABSL_FLAG(std::string, json_header, "\"nlohmann/json.hpp\"",
3737
"Include path to json.hpp including brackets <> or quotes \"\" "
3838
"around.");
3939

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

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

92-
static bool contains(const std::string &s, char c) {
93-
return absl::StrContains(s, c);
94-
}
93+
bool contains(const std::string &s, char c) { return absl::StrContains(s, c); }
9594

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

@@ -150,7 +149,7 @@ static bool ParseObjectTypesFromFile(const std::string &filename,
150149
}
151150

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

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

361361
int main(int argc, char *argv[]) {
362362
const auto usage =
@@ -386,4 +386,5 @@ int main(int argc, char *argv[]) {
386386

387387
GenerateCode(schema_filename, absl::GetFlag(FLAGS_json_header),
388388
absl::GetFlag(FLAGS_class_namespace), *objects, out);
389+
fclose(out);
389390
}

verible/common/lsp/lsp-file-utils_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
namespace verible {
2424
namespace lsp {
2525

26-
std::string PathPrefix(const std::string &path) {
26+
static std::string PathPrefix(const std::string &path) {
2727
#ifdef _WIN32
2828
return absl::StrCat("y:/", path);
2929
#else
3030
return absl::StrCat("/", path);
3131
#endif
3232
}
3333

34-
std::string URIPrefix(const std::string &path) {
34+
static std::string URIPrefix(const std::string &path) {
3535
#ifdef _WIN32
3636
return absl::StrCat("file:///y%3a/", path);
3737
#else

verible/common/strings/diff_test.cc

+2-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <initializer_list>
1919
#include <ostream>
2020
#include <sstream>
21-
#include <string>
2221
#include <string_view>
2322
#include <vector>
2423

@@ -29,7 +28,7 @@
2928

3029
namespace diff {
3130
// Print functions copied from external_libs/editscript_test.cc
32-
std::ostream &operator<<(std::ostream &out, Operation operation) {
31+
static std::ostream &operator<<(std::ostream &out, Operation operation) {
3332
switch (operation) {
3433
case Operation::EQUALS:
3534
return (out << "EQUALS");
@@ -41,22 +40,11 @@ std::ostream &operator<<(std::ostream &out, Operation operation) {
4140
return out;
4241
}
4342

44-
std::ostream &operator<<(std::ostream &out, const diff::Edit &edit) {
43+
static std::ostream &operator<<(std::ostream &out, const diff::Edit &edit) {
4544
out << "{" << edit.operation << ",[" << edit.start << "," << edit.end << ")}";
4645
return out;
4746
}
4847

49-
std::ostream &operator<<(std::ostream &out, const Edits &edits) {
50-
out << "Edits{";
51-
std::string outer_delim;
52-
for (auto &edit : edits) {
53-
out << outer_delim << edit;
54-
outer_delim = ",";
55-
}
56-
out << "};";
57-
return out;
58-
}
59-
6048
} // namespace diff
6149

6250
namespace verible {

verible/common/text/text-structure.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static bool TokenLocationLess(const TokenInfo &token,
7878

7979
// Makes an iterator-writable copy of items_view without using const_cast.
8080
template <class V>
81-
std::vector<typename V::iterator> CopyWriteableIterators(
81+
static std::vector<typename V::iterator> CopyWriteableIterators(
8282
V &items, const std::vector<typename V::const_iterator> &items_view) {
8383
// precondition: items_view's iterators all point into items array.
8484
// postcondition: results's iterators point to the same items as items_view.

verible/common/text/text-structure_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ TEST(FilterTokensTest, EmptyTokens) {
7272
}
7373

7474
// Create a one-token token stream and syntax tree.
75-
void OneTokenTextStructureView(TextStructureView *view) {
75+
static void OneTokenTextStructureView(TextStructureView *view) {
7676
TokenInfo token(1, view->Contents());
7777
view->MutableTokenStream().push_back(token);
7878
view->MutableTokenStreamView().push_back(view->TokenStream().begin());
7979
view->MutableSyntaxTree() = Leaf(token);
8080
}
8181

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

469469
// Splits a single token into a syntax tree node with two leaves.
470-
void FakeParseToken(TextStructureView *data, int offset, int node_tag) {
470+
static void FakeParseToken(TextStructureView *data, int offset, int node_tag) {
471471
TokenSequence &tokens = data->MutableTokenStream();
472472
tokens.push_back(TokenInfo(11, data->Contents().substr(0, offset)));
473473
tokens.push_back(TokenInfo(12, data->Contents().substr(offset)));

verible/verilog/CST/module.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ std::vector<verible::TreeSearchMatch> FindAllProgramDeclarations(
5151
return SearchSyntaxTree(root, NodekProgramDeclaration());
5252
}
5353

54-
bool IsModuleOrInterfaceOrProgramDeclaration(
54+
static bool IsModuleOrInterfaceOrProgramDeclaration(
5555
const SyntaxTreeNode &declaration) {
5656
return declaration.MatchesTagAnyOf({NodeEnum::kModuleDeclaration,
5757
NodeEnum::kInterfaceDeclaration,

verible/verilog/CST/statement.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const SyntaxTreeNode *GetAssertionStatementAssertClause(
129129
NodeEnum::kAssertionClause);
130130
}
131131

132-
const SyntaxTreeNode *GetAssertionClauseStatementBody(
132+
static const SyntaxTreeNode *GetAssertionClauseStatementBody(
133133
const Symbol &assertion_clause) {
134134
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
135135
SymbolCastToNode(assertion_clause), NodeEnum::kAssertionClause));
@@ -154,7 +154,7 @@ const SyntaxTreeNode *GetAssumeStatementAssumeClause(
154154
NodeEnum::kAssumeClause);
155155
}
156156

157-
const SyntaxTreeNode *GetAssumeClauseStatementBody(
157+
static const SyntaxTreeNode *GetAssumeClauseStatementBody(
158158
const Symbol &assume_clause) {
159159
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
160160
SymbolCastToNode(assume_clause), NodeEnum::kAssumeClause));
@@ -197,7 +197,7 @@ const SyntaxTreeNode *GetAssertPropertyStatementAssertClause(
197197
NodeEnum::kAssertPropertyClause);
198198
}
199199

200-
const SyntaxTreeNode *GetAssertPropertyStatementBody(
200+
static const SyntaxTreeNode *GetAssertPropertyStatementBody(
201201
const Symbol &assert_clause) {
202202
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
203203
SymbolCastToNode(assert_clause), NodeEnum::kAssertPropertyClause));
@@ -225,7 +225,7 @@ const SyntaxTreeNode *GetAssumePropertyStatementAssumeClause(
225225
NodeEnum::kAssumePropertyClause);
226226
}
227227

228-
const SyntaxTreeNode *GetAssumePropertyStatementBody(
228+
static const SyntaxTreeNode *GetAssumePropertyStatementBody(
229229
const Symbol &assume_clause) {
230230
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
231231
SymbolCastToNode(assume_clause), NodeEnum::kAssumePropertyClause));
@@ -253,7 +253,7 @@ const SyntaxTreeNode *GetExpectPropertyStatementExpectClause(
253253
NodeEnum::kExpectPropertyClause);
254254
}
255255

256-
const SyntaxTreeNode *GetExpectPropertyStatementBody(
256+
static const SyntaxTreeNode *GetExpectPropertyStatementBody(
257257
const Symbol &expect_clause) {
258258
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
259259
SymbolCastToNode(expect_clause), NodeEnum::kExpectPropertyClause));
@@ -274,7 +274,7 @@ const SyntaxTreeNode *GetExpectPropertyStatementElseClause(
274274
NodeEnum::kElseClause);
275275
}
276276

277-
const SyntaxTreeNode *GetCoverPropertyStatementBody(
277+
static const SyntaxTreeNode *GetCoverPropertyStatementBody(
278278
const Symbol &cover_property) {
279279
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
280280
SymbolCastToNode(cover_property), NodeEnum::kCoverPropertyStatement));
@@ -283,7 +283,7 @@ const SyntaxTreeNode *GetCoverPropertyStatementBody(
283283
GetSubtreeAsSymbol(*body_node, NodeEnum::kCoverPropertyBody, 0));
284284
}
285285

286-
const SyntaxTreeNode *GetCoverSequenceStatementBody(
286+
static const SyntaxTreeNode *GetCoverSequenceStatementBody(
287287
const Symbol &cover_sequence) {
288288
const auto *body_node = GetGenericStatementBody(MatchNodeEnumOrNull(
289289
SymbolCastToNode(cover_sequence), NodeEnum::kCoverSequenceStatement));

verible/verilog/CST/type.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ const verible::SyntaxTreeLeaf *GetSymbolIdentifierFromEnumName(
350350
return verible::GetSubtreeAsLeaf(enum_name, NodeEnum::kEnumName, 0);
351351
}
352352

353-
const verible::SyntaxTreeLeaf *GetTypeIdentifierFromInterfaceType(
353+
static const verible::SyntaxTreeLeaf *GetTypeIdentifierFromInterfaceType(
354354
const verible::Symbol &interface_type) {
355355
return verible::GetSubtreeAsLeaf(interface_type, NodeEnum::kInterfaceType, 2);
356356
}

verible/verilog/analysis/verilog-linter-configuration.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static const verible::EnumNameMap<RuleSet> &RuleSetEnumStringMap() {
412412
return kRuleSetEnumStringMap;
413413
}
414414

415-
std::ostream &operator<<(std::ostream &stream, RuleSet rules) {
415+
static std::ostream &operator<<(std::ostream &stream, RuleSet rules) {
416416
return RuleSetEnumStringMap().Unparse(rules, stream);
417417
}
418418

verible/verilog/formatting/align.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class VerilogColumnSchemaScanner : public ColumnSchemaScanner {
234234
};
235235

236236
template <class ScannerType>
237-
std::function<verible::AlignmentCellScannerFunction(const FormatStyle &)>
237+
static std::function<verible::AlignmentCellScannerFunction(const FormatStyle &)>
238238
UnstyledAlignmentCellScannerGenerator() {
239239
return [](const FormatStyle &vstyle) {
240240
return AlignmentCellScannerGenerator<ScannerType>(
@@ -243,9 +243,10 @@ UnstyledAlignmentCellScannerGenerator() {
243243
}
244244

245245
template <class ScannerType>
246-
std::function<verible::AlignmentCellScannerFunction(const FormatStyle &)>
247-
UnstyledAlignmentCellScannerGenerator(
248-
const verible::NonTreeTokensScannerFunction &non_tree_column_scanner) {
246+
std::function<verible::AlignmentCellScannerFunction(
247+
const FormatStyle
248+
&)> static UnstyledAlignmentCellScannerGenerator(const verible::NonTreeTokensScannerFunction
249+
&non_tree_column_scanner) {
249250
return [non_tree_column_scanner](const FormatStyle &vstyle) {
250251
return AlignmentCellScannerGenerator<ScannerType>(
251252
[vstyle] { return ScannerType(vstyle); }, non_tree_column_scanner);
@@ -1292,8 +1293,8 @@ struct AlignmentGroupHandlers {
12921293
// Returns the referenced member by value.
12931294
// TODO(fangism): move this to an STL-style util/functional library
12941295
template <typename MemberType, typename StructType>
1295-
std::function<MemberType(const StructType &)> function_from_pointer_to_member(
1296-
MemberType StructType::*member) {
1296+
static std::function<MemberType(const StructType &)>
1297+
function_from_pointer_to_member(MemberType StructType::*member) {
12971298
return [member](const StructType &obj) { return obj.*member; };
12981299
}
12991300

verible/verilog/formatting/formatter.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ class Formatter {
115115
};
116116

117117
// TODO(b/148482625): make this public/re-usable for general content comparison.
118-
Status VerifyFormatting(const verible::TextStructureView &text_structure,
119-
std::string_view formatted_output,
120-
std::string_view filename) {
118+
// Not declared in any header, but also used in formatter_test
119+
extern Status VerifyFormatting(const verible::TextStructureView &text_structure,
120+
std::string_view formatted_output,
121+
std::string_view filename) {
121122
// Verify that the formatted output creates the same lexical
122123
// stream (filtered) as the original. If any tokens were lost, fall back to
123124
// printing the original source unformatted.

verible/verilog/formatting/formatter_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ namespace verilog {
5353
namespace formatter {
5454

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

6060
namespace {
6161

verible/verilog/formatting/token-annotator.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -922,11 +922,11 @@ static WithReason<SpacingOptions> BreakDecisionBetween(
922922
// Extern linkage for sake of direct testing, though not exposed in public
923923
// headers.
924924
// TODO(fangism): could move this to a -internal.h header.
925-
void AnnotateFormatToken(const FormatStyle &style,
926-
const PreFormatToken &prev_token,
927-
PreFormatToken *curr_token,
928-
const SyntaxTreeContext &prev_context,
929-
const SyntaxTreeContext &curr_context) {
925+
extern void AnnotateFormatToken(const FormatStyle &style,
926+
const PreFormatToken &prev_token,
927+
PreFormatToken *curr_token,
928+
const SyntaxTreeContext &prev_context,
929+
const SyntaxTreeContext &curr_context) {
930930
const auto p = SpacesRequiredBetween(style, prev_token, *curr_token,
931931
prev_context, curr_context);
932932
curr_token->before.spaces_required = p.spaces_required;

0 commit comments

Comments
 (0)