Skip to content

Commit 85d9195

Browse files
Make getters const
1 parent cfa8abd commit 85d9195

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

src/wasm.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,30 +2699,30 @@ class Module {
26992699
public:
27002700
Module() = default;
27012701

2702-
Export* getExport(Name name);
2703-
Function* getFunction(Name name);
2704-
Table* getTable(Name name);
2705-
ElementSegment* getElementSegment(Name name);
2706-
Memory* getMemory(Name name);
2707-
DataSegment* getDataSegment(Name name);
2708-
Global* getGlobal(Name name);
2709-
Tag* getTag(Name name);
2710-
2711-
Export* getExportOrNull(Name name);
2712-
Table* getTableOrNull(Name name);
2713-
Memory* getMemoryOrNull(Name name);
2714-
ElementSegment* getElementSegmentOrNull(Name name);
2715-
DataSegment* getDataSegmentOrNull(Name name);
2716-
Function* getFunctionOrNull(Name name);
2717-
Global* getGlobalOrNull(Name name);
2718-
Tag* getTagOrNull(Name name);
2702+
Export* getExport(Name name) const;
2703+
Function* getFunction(Name name) const;
2704+
Table* getTable(Name name) const;
2705+
ElementSegment* getElementSegment(Name name) const;
2706+
Memory* getMemory(Name name) const;
2707+
DataSegment* getDataSegment(Name name) const;
2708+
Global* getGlobal(Name name) const;
2709+
Tag* getTag(Name name) const;
2710+
2711+
Export* getExportOrNull(Name name) const;
2712+
Table* getTableOrNull(Name name) const;
2713+
Memory* getMemoryOrNull(Name name) const;
2714+
ElementSegment* getElementSegmentOrNull(Name name) const;
2715+
DataSegment* getDataSegmentOrNull(Name name) const;
2716+
Function* getFunctionOrNull(Name name) const;
2717+
Global* getGlobalOrNull(Name name) const;
2718+
Tag* getTagOrNull(Name name) const;
27192719

27202720
// get* methods that are generic over the kind, that is, items are identified
27212721
// by their kind and their name. Otherwise, they are similar to the above
27222722
// get* methods. These return items that can be imports.
27232723
// TODO: Add methods for things that cannot be imports (segments).
2724-
Importable* getImport(ModuleItemKind kind, Name name);
2725-
Importable* getImportOrNull(ModuleItemKind kind, Name name);
2724+
Importable* getImport(ModuleItemKind kind, Name name) const;
2725+
Importable* getImportOrNull(ModuleItemKind kind, Name name) const;
27262726

27272727
Export* addExport(Export* curr);
27282728
Function* addFunction(Function* curr);

src/wasm/wasm.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,44 +1706,43 @@ void Function::clearDebugInfo() {
17061706
}
17071707

17081708
template<typename Map>
1709-
typename Map::mapped_type&
1710-
getModuleElement(Map& m, Name name, std::string_view funcName) {
1709+
auto& getModuleElement(Map& m, Name name, std::string_view funcName) {
17111710
auto iter = m.find(name);
17121711
if (iter == m.end()) {
17131712
Fatal() << "Module::" << funcName << ": " << name << " does not exist";
17141713
}
17151714
return iter->second;
17161715
}
17171716

1718-
Export* Module::getExport(Name name) {
1717+
Export* Module::getExport(Name name) const {
17191718
return getModuleElement(exportsMap, name, "getExport");
17201719
}
17211720

1722-
Function* Module::getFunction(Name name) {
1721+
Function* Module::getFunction(Name name) const {
17231722
return getModuleElement(functionsMap, name, "getFunction");
17241723
}
17251724

1726-
Table* Module::getTable(Name name) {
1725+
Table* Module::getTable(Name name) const {
17271726
return getModuleElement(tablesMap, name, "getTable");
17281727
}
17291728

1730-
ElementSegment* Module::getElementSegment(Name name) {
1729+
ElementSegment* Module::getElementSegment(Name name) const {
17311730
return getModuleElement(elementSegmentsMap, name, "getElementSegment");
17321731
}
17331732

1734-
Memory* Module::getMemory(Name name) {
1733+
Memory* Module::getMemory(Name name) const {
17351734
return getModuleElement(memoriesMap, name, "getMemory");
17361735
}
17371736

1738-
DataSegment* Module::getDataSegment(Name name) {
1737+
DataSegment* Module::getDataSegment(Name name) const {
17391738
return getModuleElement(dataSegmentsMap, name, "getDataSegment");
17401739
}
17411740

1742-
Global* Module::getGlobal(Name name) {
1741+
Global* Module::getGlobal(Name name) const {
17431742
return getModuleElement(globalsMap, name, "getGlobal");
17441743
}
17451744

1746-
Tag* Module::getTag(Name name) {
1745+
Tag* Module::getTag(Name name) const {
17471746
return getModuleElement(tagsMap, name, "getTag");
17481747
}
17491748

@@ -1756,39 +1755,39 @@ typename Map::mapped_type getModuleElementOrNull(Map& m, Name name) {
17561755
return iter->second;
17571756
}
17581757

1759-
Export* Module::getExportOrNull(Name name) {
1758+
Export* Module::getExportOrNull(Name name) const {
17601759
return getModuleElementOrNull(exportsMap, name);
17611760
}
17621761

1763-
Function* Module::getFunctionOrNull(Name name) {
1762+
Function* Module::getFunctionOrNull(Name name) const {
17641763
return getModuleElementOrNull(functionsMap, name);
17651764
}
17661765

1767-
Table* Module::getTableOrNull(Name name) {
1766+
Table* Module::getTableOrNull(Name name) const {
17681767
return getModuleElementOrNull(tablesMap, name);
17691768
}
17701769

1771-
ElementSegment* Module::getElementSegmentOrNull(Name name) {
1770+
ElementSegment* Module::getElementSegmentOrNull(Name name) const {
17721771
return getModuleElementOrNull(elementSegmentsMap, name);
17731772
}
17741773

1775-
Memory* Module::getMemoryOrNull(Name name) {
1774+
Memory* Module::getMemoryOrNull(Name name) const {
17761775
return getModuleElementOrNull(memoriesMap, name);
17771776
}
17781777

1779-
DataSegment* Module::getDataSegmentOrNull(Name name) {
1778+
DataSegment* Module::getDataSegmentOrNull(Name name) const {
17801779
return getModuleElementOrNull(dataSegmentsMap, name);
17811780
}
17821781

1783-
Global* Module::getGlobalOrNull(Name name) {
1782+
Global* Module::getGlobalOrNull(Name name) const {
17841783
return getModuleElementOrNull(globalsMap, name);
17851784
}
17861785

1787-
Tag* Module::getTagOrNull(Name name) {
1786+
Tag* Module::getTagOrNull(Name name) const {
17881787
return getModuleElementOrNull(tagsMap, name);
17891788
}
17901789

1791-
Importable* Module::getImport(ModuleItemKind kind, Name name) {
1790+
Importable* Module::getImport(ModuleItemKind kind, Name name) const {
17921791
switch (kind) {
17931792
case ModuleItemKind::Function:
17941793
return getFunction(name);
@@ -1809,7 +1808,7 @@ Importable* Module::getImport(ModuleItemKind kind, Name name) {
18091808
WASM_UNREACHABLE("unexpected kind");
18101809
}
18111810

1812-
Importable* Module::getImportOrNull(ModuleItemKind kind, Name name) {
1811+
Importable* Module::getImportOrNull(ModuleItemKind kind, Name name) const {
18131812
auto doReturn = [](Importable* importable) {
18141813
return importable ? importable->imported() ? importable : nullptr : nullptr;
18151814
};

0 commit comments

Comments
 (0)