Skip to content

Commit

Permalink
Use final instead of override where possible.
Browse files Browse the repository at this point in the history
This serves as documentation for humans but also provides
hints for devirtualization for comilers.
  • Loading branch information
hzeller committed Nov 9, 2024
1 parent b4fbd15 commit 3afc1b4
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 115 deletions.
5 changes: 4 additions & 1 deletion include/Surelog/Common/PlatformFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class SymbolTable;
*
* Native platform specific file system implementation.
*
* Note, thie is final class from Surelogs perspective, but
* to make it simpler for users to override and change, keeping
* it overridable.
*/
class PlatformFileSystem : public FileSystem {
class PlatformFileSystem /*final*/ : public FileSystem {
public:
struct Configuration final {
std::filesystem::path m_sourceDir;
Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Design/DummyType.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ namespace SURELOG {

class FileContent;

class DummyType : public DataType {
class DummyType final : public DataType {
SURELOG_IMPLEMENT_RTTI(DummyType, DataType)
public:
DummyType(const FileContent* fC, NodeId nameId, NodeId structId);
~DummyType() override;
~DummyType() final;

NodeId getNameId() const { return m_nameId; }

Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Design/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ namespace SURELOG {
class FileContent;
class Value;

class Enum : public DataType {
class Enum final : public DataType {
SURELOG_IMPLEMENT_RTTI(Enum, DataType)
public:
Enum(const FileContent* fC, NodeId nameId, NodeId baseTypeId);
~Enum() override = default;
~Enum() final = default;

typedef std::map<std::string, std::pair<uint32_t, Value*>, std::less<>>
NameValueMap;
Expand Down
12 changes: 6 additions & 6 deletions include/Surelog/Design/FileContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class ModuleDefinition;
class Package;
class Program;

class FileContent : public DesignComponent {
class FileContent final : public DesignComponent {
SURELOG_IMPLEMENT_RTTI(FileContent, DesignComponent)
public:
FileContent(PathId fileId, Library* library, SymbolTable* symbolTable,
ErrorContainer* errors, FileContent* parent, PathId fileChunkId);
~FileContent() override;
~FileContent() final;

void setLibrary(Library* lib) { m_library = lib; }

Expand Down Expand Up @@ -94,12 +94,12 @@ class FileContent : public DesignComponent {
bool first = false) const;
// Recursively search for all items of types
// and stops at types stopPoints
uint32_t getSize() const override {
uint32_t getSize() const final {
return static_cast<uint32_t>(m_objects.size());
}
VObjectType getType() const override { return VObjectType::slNoType; }
bool isInstance() const override { return false; }
std::string_view getName() const override;
VObjectType getType() const final { return VObjectType::slNoType; }
bool isInstance() const final { return false; }
std::string_view getName() const final;
NodeId getRootNode() const;
std::string printObjects() const; // The whole file content
std::string printSubTree(
Expand Down
12 changes: 6 additions & 6 deletions include/Surelog/Design/ModuleDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ namespace SURELOG {
class CompileModule;
class FileContent;

class ModuleDefinition : public DesignComponent, public ClockingBlockHolder {
class ModuleDefinition final : public DesignComponent, public ClockingBlockHolder {
SURELOG_IMPLEMENT_RTTI(ModuleDefinition, DesignComponent)
friend CompileModule;

public:
ModuleDefinition(const FileContent* fileContent, NodeId nodeId,
std::string_view name);

~ModuleDefinition() override = default;
~ModuleDefinition() final = default;

std::string_view getName() const override { return m_name; }
VObjectType getType() const override;
bool isInstance() const override;
uint32_t getSize() const override;
std::string_view getName() const final { return m_name; }
VObjectType getType() const final;
bool isInstance() const final;
uint32_t getSize() const final;

typedef std::map<std::string, ClockingBlock> ClockingBlockMap;
typedef std::map<std::string, ModPort, std::less<>> ModPortSignalMap;
Expand Down
8 changes: 4 additions & 4 deletions include/Surelog/Design/ModuleInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class Parameter;
class PathId;
class SymbolTable;

class ModuleInstance : public ValuedComponentI {
class ModuleInstance final : public ValuedComponentI {
SURELOG_IMPLEMENT_RTTI(ModuleInstance, ValuedComponentI)
public:
ModuleInstance(DesignComponent* definition, const FileContent* fileContent,
NodeId nodeId, ModuleInstance* parent,
std::string_view instName, std::string_view moduleName);
~ModuleInstance() override;
~ModuleInstance() final;

typedef std::map<UHDM::module_array*, std::vector<ModuleInstance*>>
ModuleArrayModuleInstancesMap;
Expand Down Expand Up @@ -101,8 +101,8 @@ class ModuleInstance : public ValuedComponentI {
std::vector<Parameter*>& getTypeParams() { return m_typeParams; }

Value* getValue(std::string_view name,
ExprBuilder& exprBuilder) const override;
UHDM::expr* getComplexValue(std::string_view name) const override;
ExprBuilder& exprBuilder) const final;
UHDM::expr* getComplexValue(std::string_view name) const final;

ModuleInstance* getInstanceBinding() { return m_boundInstance; }
bool isElaborated() const { return m_elaborated; }
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/Design/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ namespace SURELOG {

class FileContent;

class Parameter : public DataType {
class Parameter final : public DataType {
SURELOG_IMPLEMENT_RTTI(Parameter, DataType)
public:
Parameter(const FileContent* fC, NodeId nodeId, std::string_view name,
NodeId node_type, bool port_param);

~Parameter() override;
~Parameter() final;

VObjectType getType() const override;
VObjectType getType() const final;
NodeId getNodeType() const { return m_ntype; }

void setUhdmParam(UHDM::any* param) { m_param = param; }
Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Design/SimpleType.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ namespace SURELOG {

class FileContent;

class SimpleType : public DataType {
class SimpleType final : public DataType {
SURELOG_IMPLEMENT_RTTI(SimpleType, DataType)
public:
SimpleType(const FileContent* fC, NodeId nameId, NodeId structId);
~SimpleType() override = default;
~SimpleType() final = default;

NodeId getNameId() const { return m_nameId; }

Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Design/Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class SubRoutineCallStmt : public Statement {
std::string_view getFunc() const { return m_func; }
bool isStatic() const { return m_static; }
bool isSystemCall() const { return m_system; }
Function* getFunction() override { return m_function; }
void setFunction(Function* function) override { m_function = function; }
Function* getFunction() final { return m_function; }
void setFunction(Function* function) final { m_function = function; }

private:
std::vector<NodeId> m_var_chain;
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/Design/Struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ namespace SURELOG {

class FileContent;

class Struct : public DataType {
class Struct final : public DataType {
SURELOG_IMPLEMENT_RTTI(Struct, DataType)
public:
Struct(const FileContent* fC, NodeId nameId, NodeId structId);
~Struct() override = default;
~Struct() final = default;

NodeId getNameId() const { return m_nameId; }

bool isNet() const override;
bool isNet() const final;

private:
const NodeId m_nameId;
Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Design/TfPortItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace SURELOG {
class Procedure;
class Value;

class TfPortItem : public Variable {
class TfPortItem final : public Variable {
public:
TfPortItem(Procedure* parent, const FileContent* fc, NodeId id, NodeId range,
std::string_view name, DataType* type, Value* default_value,
Expand All @@ -42,7 +42,7 @@ class TfPortItem : public Variable {
m_parent(parent),
m_default(default_value),
m_direction(direction) {}
~TfPortItem() override = default;
~TfPortItem() final = default;

Procedure* getParent() const { return m_parent; }
Value* getDefault() const { return m_default; }
Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/Design/Union.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

namespace SURELOG {

class Union : public DataType {
class Union final : public DataType {
SURELOG_IMPLEMENT_RTTI(Union, DataType)
public:
Union(const FileContent* fC, NodeId nameId, NodeId structId);
~Union() override = default;
~Union() final = default;

NodeId getNameId() const { return m_nameId; }

Expand Down
4 changes: 2 additions & 2 deletions include/Surelog/DesignCompile/CompileProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct FunctorCompileProgram {
ErrorContainer* const m_errors;
};

class CompileProgram : public CompileToolbox {
class CompileProgram final : public CompileToolbox {
public:
CompileProgram(CompileDesign* compiler, Program* program, Design* design,
SymbolTable* symbols, ErrorContainer* errors)
Expand All @@ -69,7 +69,7 @@ class CompileProgram : public CompileToolbox {

bool compile();

~CompileProgram() override = default;
~CompileProgram() final = default;

private:
enum CollectType { FUNCTION, DEFINITION, OTHER };
Expand Down
8 changes: 4 additions & 4 deletions include/Surelog/DesignCompile/DesignElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class BindStmt;
class ModuleDefinitionFactory;
class ModuleInstanceFactory;

class DesignElaboration : public TestbenchElaboration {
class DesignElaboration final : public TestbenchElaboration {
public:
explicit DesignElaboration(CompileDesign* compileDesign);
DesignElaboration(const DesignElaboration& orig) = delete;
~DesignElaboration() override;
~DesignElaboration() final;

bool createModuleAndPackageDefinitions();

bool elaborate() override;
bool elaborate() final;

private:
bool bindDataTypes_() override;
bool bindDataTypes_() final;
bool bindPackagesDataTypes_();
bool bindDataTypes_(ModuleInstance* instance, DesignComponent* component);
void bind_ports_nets_(std::vector<Signal*>& ports,
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/DesignCompile/NetlistElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ class ModuleInstance;
class Netlist;
class Signal;

class NetlistElaboration : public TestbenchElaboration {
class NetlistElaboration final : public TestbenchElaboration {
public:
explicit NetlistElaboration(CompileDesign* compileDesign);
NetlistElaboration(const NetlistElaboration& orig) = delete;

bool elaborate() override;
bool elaborate() final;
bool elaboratePackages();
bool elaborateInstance(ModuleInstance* instance);

~NetlistElaboration() override;
~NetlistElaboration() final;

typedef std::map<NodeId, UHDM::typespec*> TypespecCache;
bool elabSignal(Signal* sig, ModuleInstance* instance, ModuleInstance* child,
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/DesignCompile/PackageAndRootElaboration.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

namespace SURELOG {

class PackageAndRootElaboration : public ElaborationStep {
class PackageAndRootElaboration final : public ElaborationStep {
public:
explicit PackageAndRootElaboration(CompileDesign* compileDesign)
: ElaborationStep(compileDesign) {}

~PackageAndRootElaboration() override = default;
~PackageAndRootElaboration() final = default;

bool elaborate() override;
bool elaborate() final;

private:
};
Expand Down
38 changes: 19 additions & 19 deletions include/Surelog/DesignCompile/ResolveSymbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct FunctorResolve {
ErrorContainer* const m_errorContainer;
};

class ResolveSymbols : public CompileStep {
class ResolveSymbols final : public CompileStep {
public:
ResolveSymbols(CompileDesign* compileDesign, FileContent* fileContent,
SymbolTable* symbolTable, ErrorContainer* errors)
Expand All @@ -86,55 +86,55 @@ class ResolveSymbols : public CompileStep {

bool resolve();

VObject Object(NodeId index) const override;
VObject Object(NodeId index) const final;
VObject* MutableObject(NodeId index);

NodeId UniqueId(NodeId index) const override;
NodeId UniqueId(NodeId index) const final;

SymbolId Name(NodeId index) const override;
SymbolId Name(NodeId index) const final;

NodeId Child(NodeId index) const override;
NodeId Child(NodeId index) const final;

NodeId Sibling(NodeId index) const override;
NodeId Sibling(NodeId index) const final;

NodeId Definition(NodeId index) const override;
NodeId Definition(NodeId index) const final;
bool SetDefinition(NodeId index, NodeId node);

NodeId Parent(NodeId index) const override;
NodeId Parent(NodeId index) const final;

VObjectType Type(NodeId index) const override;
VObjectType Type(NodeId index) const final;
bool SetType(NodeId index, VObjectType type);

uint32_t Line(NodeId index) const override;
uint32_t Line(NodeId index) const final;

std::string_view Symbol(SymbolId id) const override;
std::string_view Symbol(SymbolId id) const final;

std::string_view SymName(NodeId index) const override;
std::string_view SymName(NodeId index) const final;

NodeId sl_get(NodeId parent,
VObjectType type) const override; // Get first item of type
VObjectType type) const final; // Get first item of type

NodeId sl_parent(
NodeId parent,
VObjectType type) const override; // Get first parent item of type
VObjectType type) const final; // Get first parent item of type

NodeId sl_parent(NodeId parent, const VObjectTypeUnorderedSet& types,
VObjectType& actualType) const override;
VObjectType& actualType) const final;

std::vector<NodeId> sl_get_all(
NodeId parent,
VObjectType type) const override; // get all items of type
VObjectType type) const final; // get all items of type

NodeId sl_collect(NodeId parent,
VObjectType type)
const override; // Recursively search for first item of type
const final; // Recursively search for first item of type

std::vector<NodeId> sl_collect_all(NodeId parent,
VObjectType type)
const override; // Recursively search for all items of type
const final; // Recursively search for all items of type

ResolveSymbols(const ResolveSymbols& orig);
~ResolveSymbols() override = default;
~ResolveSymbols() final = default;

Compiler* getCompiler() const;

Expand Down
Loading

0 comments on commit 3afc1b4

Please sign in to comment.