diff --git a/src/V3Ast.h b/src/V3Ast.h index a945ea6a2..47661d626 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -95,18 +95,18 @@ public: // cppcheck-suppress uninitVar // responsibility of each subclass VNType() = default; // cppcheck-suppress noExplicitConstructor - VNType(en _e) + constexpr VNType(en _e) : m_e{_e} {} explicit VNType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const VNType& lhs, const VNType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VNType& lhs, VNType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VNType::en lhs, const VNType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VNType& lhs, const VNType& rhs) { return lhs.m_e == rhs.m_e; } +constexpr bool operator==(const VNType& lhs, VNType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VNType::en lhs, const VNType& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VNType& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VLifetime final { public: @@ -119,23 +119,25 @@ public: VLifetime() : m_e{NONE} {} // cppcheck-suppress noExplicitConstructor - VLifetime(en _e) + constexpr VLifetime(en _e) : m_e{_e} {} explicit VLifetime(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool isNone() const { return m_e == NONE; } bool isAutomatic() const { return m_e == AUTOMATIC; } bool isStatic() const { return m_e == STATIC; } }; -inline bool operator==(const VLifetime& lhs, const VLifetime& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VLifetime& lhs, VLifetime::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VLifetime::en lhs, const VLifetime& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VLifetime& lhs, const VLifetime& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VLifetime& lhs, VLifetime::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VLifetime::en lhs, const VLifetime& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VLifetime& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VAccess final { public: @@ -160,11 +162,11 @@ public: VAccess() : m_e{READ} {} // cppcheck-suppress noExplicitConstructor - VAccess(en _e) + constexpr VAccess(en _e) : m_e{_e} {} explicit VAccess(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } VAccess invert() const { return (m_e == READWRITE) ? VAccess{m_e} : (m_e == WRITE ? VAccess{READ} : VAccess{WRITE}); } @@ -174,12 +176,12 @@ public: bool isWriteOrRW() const { return m_e == WRITE || m_e == READWRITE; } bool isRW() const { return m_e == READWRITE; } }; -inline bool operator==(const VAccess& lhs, const VAccess& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VAccess& lhs, VAccess::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VAccess::en lhs, const VAccess& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VAccess& lhs, const VAccess& rhs) { return lhs.m_e == rhs.m_e; } +constexpr bool operator==(const VAccess& lhs, VAccess::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VAccess::en lhs, const VAccess& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VAccess& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VSigning final { public: @@ -197,26 +199,26 @@ public: VSigning() : m_e{UNSIGNED} {} // cppcheck-suppress noExplicitConstructor - VSigning(en _e) + constexpr VSigning(en _e) : m_e{_e} {} static VSigning fromBool(bool isSigned) { // Factory method return isSigned ? VSigning{SIGNED} : VSigning{UNSIGNED}; } explicit VSigning(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool isSigned() const { return m_e == SIGNED; } bool isNosign() const { return m_e == NOSIGN; } // No isUnsigned() as it's ambiguous if NOSIGN should be included or not. }; -inline bool operator==(const VSigning& lhs, const VSigning& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VSigning& lhs, VSigning::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VSigning::en lhs, const VSigning& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VSigning& lhs, const VSigning& rhs) { return lhs.m_e == rhs.m_e; } +constexpr bool operator==(const VSigning& lhs, VSigning::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VSigning::en lhs, const VSigning& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VSigning& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VPragmaType final { public: @@ -237,19 +239,19 @@ public: VPragmaType() : m_e{ILLEGAL} {} // cppcheck-suppress noExplicitConstructor - VPragmaType(en _e) + constexpr VPragmaType(en _e) : m_e{_e} {} explicit VPragmaType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const VPragmaType& lhs, const VPragmaType& rhs) { +constexpr bool operator==(const VPragmaType& lhs, const VPragmaType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VPragmaType& lhs, VPragmaType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VPragmaType::en lhs, const VPragmaType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VPragmaType& lhs, VPragmaType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VPragmaType::en lhs, const VPragmaType& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VEdgeType final { public: @@ -325,17 +327,19 @@ public: VEdgeType() : m_e{ET_ILLEGAL} {} // cppcheck-suppress noExplicitConstructor - VEdgeType(en _e) + constexpr VEdgeType(en _e) : m_e{_e} {} explicit VEdgeType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const VEdgeType& lhs, const VEdgeType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VEdgeType& lhs, VEdgeType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VEdgeType::en lhs, const VEdgeType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VEdgeType& lhs, const VEdgeType& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VEdgeType& lhs, VEdgeType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VEdgeType::en lhs, const VEdgeType& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VAttrType final { public: @@ -406,17 +410,19 @@ public: VAttrType() : m_e{ILLEGAL} {} // cppcheck-suppress noExplicitConstructor - VAttrType(en _e) + constexpr VAttrType(en _e) : m_e{_e} {} explicit VAttrType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const VAttrType& lhs, const VAttrType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VAttrType& lhs, VAttrType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VAttrType::en lhs, const VAttrType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VAttrType& lhs, const VAttrType& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VAttrType& lhs, VAttrType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VAttrType::en lhs, const VAttrType& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VBasicDTypeKwd final { public: @@ -473,11 +479,11 @@ public: VBasicDTypeKwd() : m_e{UNKNOWN} {} // cppcheck-suppress noExplicitConstructor - VBasicDTypeKwd(en _e) + constexpr VBasicDTypeKwd(en _e) : m_e{_e} {} explicit VBasicDTypeKwd(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } int width() const { switch (m_e) { case BIT: return 1; // scalar, can't bit extract unless ranged @@ -558,13 +564,13 @@ public: } } }; -inline bool operator==(const VBasicDTypeKwd& lhs, const VBasicDTypeKwd& rhs) { +constexpr bool operator==(const VBasicDTypeKwd& lhs, const VBasicDTypeKwd& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VBasicDTypeKwd& lhs, VBasicDTypeKwd::en rhs) { +constexpr bool operator==(const VBasicDTypeKwd& lhs, VBasicDTypeKwd::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VBasicDTypeKwd::en lhs, const VBasicDTypeKwd& rhs) { +constexpr bool operator==(VBasicDTypeKwd::en lhs, const VBasicDTypeKwd& rhs) { return lhs == rhs.m_e; } @@ -577,11 +583,11 @@ public: VDirection() : m_e{NONE} {} // cppcheck-suppress noExplicitConstructor - VDirection(en _e) + constexpr VDirection(en _e) : m_e{_e} {} explicit VDirection(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"NONE", "INPUT", "OUTPUT", "INOUT", "REF", "CONSTREF"}; return names[m_e]; @@ -605,14 +611,16 @@ public: bool isWritable() const { return m_e == OUTPUT || m_e == INOUT || m_e == REF; } bool isRefOrConstRef() const { return m_e == REF || m_e == CONSTREF; } }; -inline bool operator==(const VDirection& lhs, const VDirection& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VDirection& lhs, VDirection::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VDirection::en lhs, const VDirection& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VDirection& lhs, const VDirection& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VDirection& lhs, VDirection::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VDirection::en lhs, const VDirection& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VDirection& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### /// Boolean or unknown class VBoolOrUnknown final { @@ -623,7 +631,7 @@ public: VBoolOrUnknown() : m_e{BU_UNKNOWN} {} // cppcheck-suppress noExplicitConstructor - VBoolOrUnknown(en _e) + constexpr VBoolOrUnknown(en _e) : m_e{_e} {} explicit VBoolOrUnknown(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning @@ -638,13 +646,13 @@ public: bool unknown() const { return m_e == BU_UNKNOWN; } void setTrueOrFalse(bool flag) { m_e = flag ? BU_TRUE : BU_FALSE; } }; -inline bool operator==(const VBoolOrUnknown& lhs, const VBoolOrUnknown& rhs) { +constexpr bool operator==(const VBoolOrUnknown& lhs, const VBoolOrUnknown& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VBoolOrUnknown& lhs, VBoolOrUnknown::en rhs) { +constexpr bool operator==(const VBoolOrUnknown& lhs, VBoolOrUnknown::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VBoolOrUnknown::en lhs, const VBoolOrUnknown& rhs) { +constexpr bool operator==(VBoolOrUnknown::en lhs, const VBoolOrUnknown& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VBoolOrUnknown& rhs) { @@ -662,7 +670,7 @@ public: VJoinType() : m_e{JOIN} {} // cppcheck-suppress noExplicitConstructor - VJoinType(en _e) + constexpr VJoinType(en _e) : m_e{_e} {} explicit VJoinType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning @@ -678,14 +686,16 @@ public: bool joinAny() const { return m_e == JOIN_ANY; } bool joinNone() const { return m_e == JOIN_NONE; } }; -inline bool operator==(const VJoinType& lhs, const VJoinType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VJoinType& lhs, VJoinType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VJoinType::en lhs, const VJoinType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VJoinType& lhs, const VJoinType& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VJoinType& lhs, VJoinType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VJoinType::en lhs, const VJoinType& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VJoinType& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VVarType final { public: @@ -715,11 +725,11 @@ public: VVarType() : m_e{UNKNOWN} {} // cppcheck-suppress noExplicitConstructor - VVarType(en _e) + constexpr VVarType(en _e) : m_e{_e} {} explicit VVarType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = { "?", "GPARAM", "LPARAM", "GENVAR", "VAR", "SUPPLY0", "SUPPLY1", @@ -750,14 +760,14 @@ public: return (m_e == BLOCKTEMP || m_e == MODULETEMP || m_e == STMTTEMP || m_e == XTEMP); } }; -inline bool operator==(const VVarType& lhs, const VVarType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VVarType& lhs, VVarType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VVarType::en lhs, const VVarType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VVarType& lhs, const VVarType& rhs) { return lhs.m_e == rhs.m_e; } +constexpr bool operator==(const VVarType& lhs, VVarType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VVarType::en lhs, const VVarType& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VVarType& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VBranchPred final { public: @@ -767,11 +777,11 @@ public: VBranchPred() : m_e{BP_UNKNOWN} {} // cppcheck-suppress noExplicitConstructor - VBranchPred(en _e) + constexpr VBranchPred(en _e) : m_e{_e} {} explicit VBranchPred(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool unknown() const { return m_e == BP_UNKNOWN; } bool likely() const { return m_e == BP_LIKELY; } bool unlikely() const { return m_e == BP_UNLIKELY; } @@ -789,16 +799,16 @@ public: return names[m_e]; } }; -inline bool operator==(const VBranchPred& lhs, const VBranchPred& rhs) { +constexpr bool operator==(const VBranchPred& lhs, const VBranchPred& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VBranchPred& lhs, VBranchPred::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VBranchPred::en lhs, const VBranchPred& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VBranchPred& lhs, VBranchPred::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VBranchPred::en lhs, const VBranchPred& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VBranchPred& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VVarAttrClocker final { public: @@ -808,11 +818,11 @@ public: VVarAttrClocker() : m_e{CLOCKER_UNKNOWN} {} // cppcheck-suppress noExplicitConstructor - VVarAttrClocker(en _e) + constexpr VVarAttrClocker(en _e) : m_e{_e} {} explicit VVarAttrClocker(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool unknown() const { return m_e == CLOCKER_UNKNOWN; } VVarAttrClocker invert() const { if (m_e == CLOCKER_YES) { @@ -828,13 +838,13 @@ public: return names[m_e]; } }; -inline bool operator==(const VVarAttrClocker& lhs, const VVarAttrClocker& rhs) { +constexpr bool operator==(const VVarAttrClocker& lhs, const VVarAttrClocker& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VVarAttrClocker& lhs, VVarAttrClocker::en rhs) { +constexpr bool operator==(const VVarAttrClocker& lhs, VVarAttrClocker::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VVarAttrClocker::en lhs, const VVarAttrClocker& rhs) { +constexpr bool operator==(VVarAttrClocker::en lhs, const VVarAttrClocker& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VVarAttrClocker& rhs) { @@ -850,21 +860,23 @@ public: VAlwaysKwd() : m_e{ALWAYS} {} // cppcheck-suppress noExplicitConstructor - VAlwaysKwd(en _e) + constexpr VAlwaysKwd(en _e) : m_e{_e} {} explicit VAlwaysKwd(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"always", "always_ff", "always_latch", "always_comb"}; return names[m_e]; } }; -inline bool operator==(const VAlwaysKwd& lhs, const VAlwaysKwd& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VAlwaysKwd& lhs, VAlwaysKwd::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VAlwaysKwd::en lhs, const VAlwaysKwd& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VAlwaysKwd& lhs, const VAlwaysKwd& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VAlwaysKwd& lhs, VAlwaysKwd::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VAlwaysKwd::en lhs, const VAlwaysKwd& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VCaseType final { public: @@ -873,17 +885,19 @@ public: VCaseType() : m_e{CT_CASE} {} // cppcheck-suppress noExplicitConstructor - VCaseType(en _e) + constexpr VCaseType(en _e) : m_e{_e} {} explicit VCaseType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const VCaseType& lhs, const VCaseType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VCaseType& lhs, VCaseType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VCaseType::en lhs, const VCaseType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VCaseType& lhs, const VCaseType& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VCaseType& lhs, VCaseType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VCaseType::en lhs, const VCaseType& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VDisplayType final { public: @@ -901,11 +915,11 @@ public: VDisplayType() : m_e{DT_DISPLAY} {} // cppcheck-suppress noExplicitConstructor - VDisplayType(en _e) + constexpr VDisplayType(en _e) : m_e{_e} {} explicit VDisplayType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool addNewline() const { return m_e != DT_WRITE; } bool needScopeTracking() const { return m_e != DT_DISPLAY && m_e != DT_WRITE; } const char* ascii() const { @@ -914,13 +928,13 @@ public: return names[m_e]; } }; -inline bool operator==(const VDisplayType& lhs, const VDisplayType& rhs) { +constexpr bool operator==(const VDisplayType& lhs, const VDisplayType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VDisplayType& lhs, VDisplayType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VDisplayType::en lhs, const VDisplayType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VDisplayType& lhs, VDisplayType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VDisplayType::en lhs, const VDisplayType& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VDumpCtlType final { public: @@ -929,24 +943,24 @@ public: VDumpCtlType() : m_e{ON} {} // cppcheck-suppress noExplicitConstructor - VDumpCtlType(en _e) + constexpr VDumpCtlType(en _e) : m_e{_e} {} explicit VDumpCtlType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"$dumpfile", "$dumpvars", "$dumpall", "$dumpflush", "$dumplimit", "$dumpoff", "$dumpon"}; return names[m_e]; } }; -inline bool operator==(const VDumpCtlType& lhs, const VDumpCtlType& rhs) { +constexpr bool operator==(const VDumpCtlType& lhs, const VDumpCtlType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VDumpCtlType& lhs, VDumpCtlType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VDumpCtlType::en lhs, const VDumpCtlType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VDumpCtlType& lhs, VDumpCtlType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VDumpCtlType::en lhs, const VDumpCtlType& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VParseRefExp final { public: @@ -959,26 +973,26 @@ public: VParseRefExp() : m_e{PX_NONE} {} // cppcheck-suppress noExplicitConstructor - VParseRefExp(en _e) + constexpr VParseRefExp(en _e) : m_e{_e} {} explicit VParseRefExp(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"", "$root", "TEXT", "PREDOT"}; return names[m_e]; } }; -inline bool operator==(const VParseRefExp& lhs, const VParseRefExp& rhs) { +constexpr bool operator==(const VParseRefExp& lhs, const VParseRefExp& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VParseRefExp& lhs, VParseRefExp::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VParseRefExp::en lhs, const VParseRefExp& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VParseRefExp& lhs, VParseRefExp::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VParseRefExp::en lhs, const VParseRefExp& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VParseRefExp& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VStrength final { public: @@ -986,28 +1000,29 @@ public: enum en m_e; // cppcheck-suppress noExplicitConstructor - VStrength(en strengthLevel) + constexpr VStrength(en strengthLevel) : m_e(strengthLevel) {} explicit VStrength(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"highz", "small", "medium", "weak", "large", "pull", "strong", "supply"}; return names[m_e]; } }; -inline bool operator==(const VStrength& lhs, const VStrength& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VStrength& lhs, VStrength::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VStrength::en lhs, const VStrength& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VStrength& lhs, const VStrength& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VStrength& lhs, VStrength::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VStrength::en lhs, const VStrength& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VStrength& rhs) { return os << rhs.ascii(); } -//###################################################################### -// VNumRange - Structure containing numeric range information -// See also AstRange, which is a symbolic version of this +// ###################################################################### +// VNumRange - Structure containing numeric range information +// See also AstRange, which is a symbolic version of this class VNumRange final { public: @@ -1083,26 +1098,26 @@ public: VUseType() : m_e{IMP_FWD_CLASS} {} // cppcheck-suppress noExplicitConstructor - VUseType(en _e) + constexpr VUseType(en _e) : m_e{_e} {} explicit VUseType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning bool isInclude() const { return m_e == IMP_INCLUDE || m_e == INT_INCLUDE; } bool isFwdClass() const { return m_e == IMP_FWD_CLASS || m_e == INT_FWD_CLASS; } - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"IMP_INC", "INT_INC", "IMP_FWD", "INT_FWD"}; return names[m_e]; } }; -inline bool operator==(const VUseType& lhs, const VUseType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VUseType& lhs, VUseType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VUseType::en lhs, const VUseType& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VUseType& lhs, const VUseType& rhs) { return lhs.m_e == rhs.m_e; } +constexpr bool operator==(const VUseType& lhs, VUseType::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VUseType::en lhs, const VUseType& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const VUseType& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class VBasicTypeKey final { public: diff --git a/src/V3CCtors.cpp b/src/V3CCtors.cpp index bd8aa3e3a..c4af9097e 100644 --- a/src/V3CCtors.cpp +++ b/src/V3CCtors.cpp @@ -46,7 +46,7 @@ private: public: // cppcheck-suppress noExplicitConstructor - VCtorType(en _e) + constexpr VCtorType(en _e) : m_e{_e} {} bool isClass() const { return m_e == CLASS; } bool isCoverage() const { return m_e == COVERAGE; } diff --git a/src/V3Error.h b/src/V3Error.h index b538c250d..4e1de700c 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -146,12 +146,12 @@ public: V3ErrorCode() : m_e{EC_MIN} {} // cppcheck-suppress noExplicitConstructor - V3ErrorCode(en _e) + constexpr V3ErrorCode(en _e) : m_e{_e} {} explicit V3ErrorCode(const char* msgp); // Matching code or ERROR explicit V3ErrorCode(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { // clang-format off static const char* const names[] = { @@ -221,16 +221,16 @@ public: || m_e == VARHIDDEN); } }; -inline bool operator==(const V3ErrorCode& lhs, const V3ErrorCode& rhs) { +constexpr bool operator==(const V3ErrorCode& lhs, const V3ErrorCode& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const V3ErrorCode& lhs, V3ErrorCode::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(V3ErrorCode::en lhs, const V3ErrorCode& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const V3ErrorCode& lhs, V3ErrorCode::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(V3ErrorCode::en lhs, const V3ErrorCode& rhs) { return lhs == rhs.m_e; } inline std::ostream& operator<<(std::ostream& os, const V3ErrorCode& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class V3Error final { // Base class for any object that wants debugging and error reporting diff --git a/src/V3Global.h b/src/V3Global.h index 1341332f5..0a50e97b6 100644 --- a/src/V3Global.h +++ b/src/V3Global.h @@ -70,19 +70,19 @@ public: VWidthMinUsage() : m_e{LINT_WIDTH} {} // cppcheck-suppress noExplicitConstructor - VWidthMinUsage(en _e) + constexpr VWidthMinUsage(en _e) : m_e{_e} {} explicit VWidthMinUsage(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const VWidthMinUsage& lhs, const VWidthMinUsage& rhs) { +constexpr bool operator==(const VWidthMinUsage& lhs, const VWidthMinUsage& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VWidthMinUsage& lhs, VWidthMinUsage::en rhs) { +constexpr bool operator==(const VWidthMinUsage& lhs, VWidthMinUsage::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VWidthMinUsage::en lhs, const VWidthMinUsage& rhs) { +constexpr bool operator==(VWidthMinUsage::en lhs, const VWidthMinUsage& rhs) { return lhs == rhs.m_e; } diff --git a/src/V3Graph.h b/src/V3Graph.h index 8190e946e..0de50222a 100644 --- a/src/V3Graph.h +++ b/src/V3Graph.h @@ -61,7 +61,7 @@ public: : m_e{_e} {} explicit constexpr GraphWay(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } const char* ascii() const { static const char* const names[] = {"FORWARD", "REVERSE"}; return names[m_e]; @@ -71,9 +71,9 @@ public: constexpr bool forward() const { return m_e == FORWARD; } constexpr bool reverse() const { return m_e != FORWARD; } }; -inline bool operator==(const GraphWay& lhs, const GraphWay& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const GraphWay& lhs, GraphWay::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(GraphWay::en lhs, const GraphWay& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const GraphWay& lhs, const GraphWay& rhs) { return lhs.m_e == rhs.m_e; } +constexpr bool operator==(const GraphWay& lhs, GraphWay::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(GraphWay::en lhs, const GraphWay& rhs) { return lhs == rhs.m_e; } //============================================================================ diff --git a/src/V3LangCode.h b/src/V3LangCode.h index 1d2d70326..9deef638f 100644 --- a/src/V3LangCode.h +++ b/src/V3LangCode.h @@ -58,12 +58,12 @@ public: V3LangCode() : m_e{L_ERROR} {} // cppcheck-suppress noExplicitConstructor - V3LangCode(en _e) + constexpr V3LangCode(en _e) : m_e{_e} {} explicit V3LangCode(const char* textp); explicit V3LangCode(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; //###################################################################### diff --git a/src/V3Options.h b/src/V3Options.h index 353370b7f..782987d46 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -42,24 +42,24 @@ public: VOptionBool() : m_e{OPT_DEFAULT_FALSE} {} // cppcheck-suppress noExplicitConstructor - VOptionBool(en _e) + constexpr VOptionBool(en _e) : m_e{_e} {} explicit VOptionBool(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool isDefault() const { return m_e == OPT_DEFAULT_FALSE || m_e == OPT_DEFAULT_TRUE; } bool isTrue() const { return m_e == OPT_TRUE || m_e == OPT_DEFAULT_TRUE; } bool isSetTrue() const { return m_e == OPT_TRUE; } bool isSetFalse() const { return m_e == OPT_FALSE; } void setTrueOrFalse(bool flag) { m_e = flag ? OPT_TRUE : OPT_FALSE; } }; -inline bool operator==(const VOptionBool& lhs, const VOptionBool& rhs) { +constexpr bool operator==(const VOptionBool& lhs, const VOptionBool& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VOptionBool& lhs, VOptionBool::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VOptionBool::en lhs, const VOptionBool& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VOptionBool& lhs, VOptionBool::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VOptionBool::en lhs, const VOptionBool& rhs) { return lhs == rhs.m_e; } -//###################################################################### +// ###################################################################### class VTimescale final { public: @@ -81,7 +81,7 @@ public: VTimescale() : m_e{NONE} {} // cppcheck-suppress noExplicitConstructor - VTimescale(en _e) + constexpr VTimescale(en _e) : m_e{_e} {} explicit VTimescale(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning @@ -116,26 +116,30 @@ public: return values[m_e]; } }; -inline bool operator==(const VTimescale& lhs, const VTimescale& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const VTimescale& lhs, VTimescale::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(VTimescale::en lhs, const VTimescale& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const VTimescale& lhs, const VTimescale& rhs) { + return lhs.m_e == rhs.m_e; +} +constexpr bool operator==(const VTimescale& lhs, VTimescale::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(VTimescale::en lhs, const VTimescale& rhs) { return lhs == rhs.m_e; } // Comparisons are based on time, not enum values, so seconds > milliseconds -inline bool operator<(const VTimescale& lhs, const VTimescale& rhs) { return lhs.m_e > rhs.m_e; } +constexpr bool operator<(const VTimescale& lhs, const VTimescale& rhs) { + return lhs.m_e > rhs.m_e; +} inline std::ostream& operator<<(std::ostream& os, const VTimescale& rhs) { return os << rhs.ascii(); } -//###################################################################### +// ###################################################################### class TraceFormat final { public: enum en : uint8_t { VCD = 0, FST } m_e; // cppcheck-suppress noExplicitConstructor - TraceFormat(en _e = VCD) + constexpr TraceFormat(en _e = VCD) : m_e{_e} {} explicit TraceFormat(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } bool fst() const { return m_e == FST; } bool vcd() const { return m_e == VCD; } string classBase() const { @@ -147,16 +151,16 @@ public: return names[m_e]; } }; -inline bool operator==(const TraceFormat& lhs, const TraceFormat& rhs) { +constexpr bool operator==(const TraceFormat& lhs, const TraceFormat& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const TraceFormat& lhs, TraceFormat::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(TraceFormat::en lhs, const TraceFormat& rhs) { return lhs == rhs.m_e; } +constexpr bool operator==(const TraceFormat& lhs, TraceFormat::en rhs) { return lhs.m_e == rhs; } +constexpr bool operator==(TraceFormat::en lhs, const TraceFormat& rhs) { return lhs == rhs.m_e; } using V3StringList = std::vector; using V3StringSet = std::set; -//###################################################################### +// ###################################################################### // Information given by --hierarchical-block option class V3HierarchicalBlockOption final { diff --git a/src/V3OrderGraph.h b/src/V3OrderGraph.h index fb1fa67dc..109dfb3cb 100644 --- a/src/V3OrderGraph.h +++ b/src/V3OrderGraph.h @@ -90,19 +90,19 @@ struct OrderVEdgeType { OrderVEdgeType() : m_e{VERTEX_UNKNOWN} {} // cppcheck-suppress noExplicitConstructor - OrderVEdgeType(en _e) + constexpr OrderVEdgeType(en _e) : m_e{_e} {} explicit OrderVEdgeType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning - operator en() const { return m_e; } + constexpr operator en() const { return m_e; } }; -inline bool operator==(const OrderVEdgeType& lhs, const OrderVEdgeType& rhs) { +constexpr bool operator==(const OrderVEdgeType& lhs, const OrderVEdgeType& rhs) { return lhs.m_e == rhs.m_e; } -inline bool operator==(const OrderVEdgeType& lhs, OrderVEdgeType::en rhs) { +constexpr bool operator==(const OrderVEdgeType& lhs, OrderVEdgeType::en rhs) { return lhs.m_e == rhs; } -inline bool operator==(OrderVEdgeType::en lhs, const OrderVEdgeType& rhs) { +constexpr bool operator==(OrderVEdgeType::en lhs, const OrderVEdgeType& rhs) { return lhs == rhs.m_e; }